Example usage for android.net ConnectivityManager isNetworkTypeMobile

List of usage examples for android.net ConnectivityManager isNetworkTypeMobile

Introduction

In this page you can find the example usage for android.net ConnectivityManager isNetworkTypeMobile.

Prototype

@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 130143562)
public static boolean isNetworkTypeMobile(int networkType) 

Source Link

Document

Checks if a given type uses the cellular data connection.

Usage

From source file:com.android.providers.downloads.DownloadInfo.java

/**
 * Check if the download's size prohibits it from running over the current network.
 * @return one of the NETWORK_* constants
 */// w ww.  j  av  a2  s  .  c o m
private NetworkState checkSizeAllowedForNetwork(int networkType, long totalBytes) {
    if (totalBytes <= 0) {
        // we don't know the size yet
        return NetworkState.OK;
    }

    if (ConnectivityManager.isNetworkTypeMobile(networkType)) {
        Long maxBytesOverMobile = mSystemFacade.getMaxBytesOverMobile();
        if (maxBytesOverMobile != null && totalBytes > maxBytesOverMobile) {
            return NetworkState.UNUSABLE_DUE_TO_SIZE;
        }
        if (mBypassRecommendedSizeLimit == 0) {
            Long recommendedMaxBytesOverMobile = mSystemFacade.getRecommendedMaxBytesOverMobile();
            if (recommendedMaxBytesOverMobile != null && totalBytes > recommendedMaxBytesOverMobile) {
                return NetworkState.RECOMMENDED_UNUSABLE_DUE_TO_SIZE;
            }
        }
    }

    return NetworkState.OK;
}

From source file:com.android.exchange.ExchangeService.java

/**
 * Determine whether the account is allowed to sync automatically, as opposed to manually, based
 * on whether the "require manual sync when roaming" policy is in force and applicable
 * @param account the account// w  w  w  . j ava  2s  .c o m
 * @return whether or not the account can sync automatically
 */
/*package*/ static boolean canAutoSync(Account account) {
    ExchangeService exchangeService = INSTANCE;
    if (exchangeService == null) {
        return false;
    }
    NetworkInfo networkInfo = exchangeService.mNetworkInfo;

    // Enforce manual sync only while roaming here
    long policyKey = account.mPolicyKey;
    // Quick exit from this check
    if ((policyKey != 0) && (networkInfo != null)
            && (ConnectivityManager.isNetworkTypeMobile(networkInfo.getType()))) {
        // We'll cache the Policy data here
        Policy policy = account.mPolicy;
        if (policy == null) {
            policy = Policy.restorePolicyWithId(INSTANCE, policyKey);
            account.mPolicy = policy;
        }
        if (policy != null && policy.mRequireManualSyncWhenRoaming && networkInfo.isRoaming()) {
            return false;
        }
    }
    return true;
}