org.chromium.net.ConnectionType Java Examples

The following examples show how to use org.chromium.net.ConnectionType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConnectivityTask.java    From delion with Apache License 2.0 6 votes vote down vote up
static String getHumanReadableConnectionType(int connectionType) {
    switch (connectionType) {
        case ConnectionType.CONNECTION_UNKNOWN:
            return "Unknown";
        case ConnectionType.CONNECTION_ETHERNET:
            return "Ethernet";
        case ConnectionType.CONNECTION_WIFI:
            return "WiFi";
        case ConnectionType.CONNECTION_2G:
            return "2G";
        case ConnectionType.CONNECTION_3G:
            return "3G";
        case ConnectionType.CONNECTION_4G:
            return "4G";
        case ConnectionType.CONNECTION_NONE:
            return "NONE";
        case ConnectionType.CONNECTION_BLUETOOTH:
            return "Bluetooth";
        default:
            return "Unknown connection type " + connectionType;
    }
}
 
Example #2
Source File: DownloadManagerService.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnectionTypeChanged(int connectionType) {
    if (mAutoResumableDownloadIds.isEmpty()) return;
    if (connectionType == ConnectionType.CONNECTION_NONE) return;
    boolean isMetered = isActiveNetworkMetered(mContext);
    Iterator<String> iterator = mAutoResumableDownloadIds.iterator();
    while (iterator.hasNext()) {
        final String id = iterator.next();
        final DownloadProgress progress = mDownloadProgressMap.get(id);
        // Introduce some delay in each resumption so we don't start all of them immediately.
        if (progress != null && (progress.mCanDownloadWhileMetered || !isMetered)) {
            // Remove the pending resumable item so that the task won't be posted again on the
            // next connectivity change.
            iterator.remove();
            // Post a delayed task to avoid an issue that when connectivity status just changed
            // to CONNECTED, immediately establishing a connection will sometimes fail.
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    resumeDownload(progress.mDownloadItem, false);
                }
            }, mUpdateDelayInMillis);
        }
    }
    stopListenToConnectionChangeIfNotNeeded();
}
 
Example #3
Source File: DownloadManagerService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnectionTypeChanged(int connectionType) {
    if (mAutoResumableDownloadIds.isEmpty()) return;
    if (connectionType == ConnectionType.CONNECTION_NONE) return;
    boolean isMetered = isActiveNetworkMetered(mContext);
    // Make a copy of |mAutoResumableDownloadIds| as scheduleDownloadResumption() may delete
    // elements inside the array.
    List<String> copies = new ArrayList<String>(mAutoResumableDownloadIds);
    Iterator<String> iterator = copies.iterator();
    while (iterator.hasNext()) {
        final String id = iterator.next();
        final DownloadProgress progress = mDownloadProgressMap.get(id);
        // Introduce some delay in each resumption so we don't start all of them immediately.
        if (progress != null && (progress.mCanDownloadWhileMetered || !isMetered)) {
            scheduleDownloadResumption(progress.mDownloadItem);
        }
    }
    stopListenToConnectionChangeIfNotNeeded();
}
 
Example #4
Source File: ConnectivityTask.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
static String getHumanReadableConnectionType(int connectionType) {
    switch (connectionType) {
        case ConnectionType.CONNECTION_UNKNOWN:
            return "Unknown";
        case ConnectionType.CONNECTION_ETHERNET:
            return "Ethernet";
        case ConnectionType.CONNECTION_WIFI:
            return "WiFi";
        case ConnectionType.CONNECTION_2G:
            return "2G";
        case ConnectionType.CONNECTION_3G:
            return "3G";
        case ConnectionType.CONNECTION_4G:
            return "4G";
        case ConnectionType.CONNECTION_NONE:
            return "NONE";
        case ConnectionType.CONNECTION_BLUETOOTH:
            return "Bluetooth";
        default:
            return "Unknown connection type " + connectionType;
    }
}
 
Example #5
Source File: DeviceConditions.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** Returns the NCN network type corresponding to the connectivity manager network type */
private static int convertAndroidNetworkTypeToConnectionType(
        int connectivityManagerNetworkType) {
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_WIFI) {
        return ConnectionType.CONNECTION_WIFI;
    }
    // for mobile, we don't know if it is 2G, 3G, or 4G, default to worst case of 2G.
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_MOBILE) {
        return ConnectionType.CONNECTION_2G;
    }
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_BLUETOOTH) {
        return ConnectionType.CONNECTION_BLUETOOTH;
    }
    // Since NetworkConnectivityManager doesn't understand the other types, call them UNKNOWN.
    return ConnectionType.CONNECTION_UNKNOWN;
}
 
Example #6
Source File: DeviceConditions.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static int getConnectionType(Context context) {
    // Get the connection type from chromium's internal object.
    int connectionType = NetworkChangeNotifier.getInstance().getCurrentConnectionType();

    // Sometimes the NetworkConnectionNotifier lags the actual connection type, especially when
    // the GCM NM wakes us from doze state.  If we are really connected, report the connection
    // type from android.
    if (connectionType == ConnectionType.CONNECTION_NONE) {
        // Get the connection type from android in case chromium's type is not yet set.
        ConnectivityManager cm =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
        if (isConnected) {
            connectionType = convertAndroidNetworkTypeToConnectionType(activeNetwork.getType());
        }
    }
    return connectionType;
}
 
Example #7
Source File: DownloadManagerService.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnectionTypeChanged(int connectionType) {
    if (mAutoResumableDownloadIds.isEmpty()) return;
    if (connectionType == ConnectionType.CONNECTION_NONE) return;
    boolean isMetered = isActiveNetworkMetered(mContext);
    Iterator<String> iterator = mAutoResumableDownloadIds.iterator();
    while (iterator.hasNext()) {
        final String id = iterator.next();
        final DownloadProgress progress = mDownloadProgressMap.get(id);
        // Introduce some delay in each resumption so we don't start all of them immediately.
        if (progress != null && (progress.mCanDownloadWhileMetered || !isMetered)) {
            // Remove the pending resumable item so that the task won't be posted again on the
            // next connectivity change.
            iterator.remove();
            // Post a delayed task to avoid an issue that when connectivity status just changed
            // to CONNECTED, immediately establishing a connection will sometimes fail.
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    resumeDownload(progress.mDownloadItem, false);
                }
            }, mUpdateDelayInMillis);
        }
    }
    stopListenToConnectionChangeIfNotNeeded();
}
 
Example #8
Source File: ConnectivityTask.java    From 365browser with Apache License 2.0 6 votes vote down vote up
static String getHumanReadableConnectionType(int connectionType) {
    switch (connectionType) {
        case ConnectionType.CONNECTION_UNKNOWN:
            return "Unknown";
        case ConnectionType.CONNECTION_ETHERNET:
            return "Ethernet";
        case ConnectionType.CONNECTION_WIFI:
            return "WiFi";
        case ConnectionType.CONNECTION_2G:
            return "2G";
        case ConnectionType.CONNECTION_3G:
            return "3G";
        case ConnectionType.CONNECTION_4G:
            return "4G";
        case ConnectionType.CONNECTION_NONE:
            return "NONE";
        case ConnectionType.CONNECTION_BLUETOOTH:
            return "Bluetooth";
        default:
            return "Unknown connection type " + connectionType;
    }
}
 
Example #9
Source File: MinidumpUploadRetry.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
@Override
public void onConnectionTypeChanged(int connectionType) {
    // Early-out if not connected at all - to avoid checking the current network state.
    if (connectionType == ConnectionType.CONNECTION_NONE) {
        return;
    }
    if (!mPermissionManager.isNetworkAvailableForCrashUploads()) {
        return;
    }
    MinidumpUploadService.tryUploadAllCrashDumps();
    NetworkChangeNotifier.removeConnectionTypeObserver(this);
    sSingleton = null;
}
 
Example #10
Source File: OfflinePageUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Records UMA data when the Offline Pages Background Load service awakens.
 * @param context android context
 */
public static void recordWakeupUMA(Context context, long taskScheduledTimeMillis) {
    DeviceConditions deviceConditions = DeviceConditions.getCurrentConditions(context);
    if (deviceConditions == null) return;

    // Report charging state.
    RecordHistogram.recordBooleanHistogram(
            "OfflinePages.Wakeup.ConnectedToPower", deviceConditions.isPowerConnected());

    // Report battery percentage.
    RecordHistogram.recordPercentageHistogram(
            "OfflinePages.Wakeup.BatteryPercentage", deviceConditions.getBatteryPercentage());

    // Report the default network found (or none, if we aren't connected).
    int connectionType = deviceConditions.getNetConnectionType();
    Log.d(TAG, "Found default network of type " + connectionType);
    RecordHistogram.recordEnumeratedHistogram("OfflinePages.Wakeup.NetworkAvailable",
            connectionType, ConnectionType.CONNECTION_LAST + 1);

    // Collect UMA on the time since the request started.
    long nowMillis = System.currentTimeMillis();
    long delayInMilliseconds = nowMillis - taskScheduledTimeMillis;
    if (delayInMilliseconds <= 0) {
        return;
    }
    RecordHistogram.recordLongTimesHistogram(
            "OfflinePages.Wakeup.DelayTime",
            delayInMilliseconds,
            TimeUnit.MILLISECONDS);
}
 
Example #11
Source File: MinidumpUploadRetry.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
@Override
public void onConnectionTypeChanged(int connectionType) {
    // Look for "favorable" connections. Note that we never
    // know what the user's crash upload preference is until
    // the time when we are actually uploading.
    if (connectionType == ConnectionType.CONNECTION_NONE) {
        return;
    }
    MinidumpUploadService.tryUploadAllCrashDumps(mContext);
    NetworkChangeNotifier.removeConnectionTypeObserver(this);
    sSingleton = null;
}
 
Example #12
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Returns the NCN network type corresponding to the connectivity manager network type */
protected int convertAndroidNetworkTypeToConnectionType(int connectivityManagerNetworkType) {
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_WIFI) {
        return ConnectionType.CONNECTION_WIFI;
    }
    // for mobile, we don't know if it is 2G, 3G, or 4G, default to worst case of 2G.
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_MOBILE) {
        return ConnectionType.CONNECTION_2G;
    }
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_BLUETOOTH) {
        return ConnectionType.CONNECTION_BLUETOOTH;
    }
    // Since NetworkConnectivityManager doesn't understand the other types, call them UNKNOWN.
    return ConnectionType.CONNECTION_UNKNOWN;
}
 
Example #13
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Returns the current device conditions. May be overridden for testing. */
protected DeviceConditions getDeviceConditionsImpl(Context context) {
    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    // Note this is a sticky intent, so we aren't really registering a receiver, just getting
    // the sticky intent.  That means that we don't need to unregister the filter later.
    Intent batteryStatus = context.registerReceiver(null, filter);
    if (batteryStatus == null) return null;

    // Get the connection type from chromium's internal object.
    int connectionType = NetworkChangeNotifier.getInstance().getCurrentConnectionType();

    // Sometimes the NetworkConnectionNotifier lags the actual connection type, especially when
    // the GCM NM wakes us from doze state.  If we are really connected, report the connection
    // type from android.
    if (connectionType == ConnectionType.CONNECTION_NONE) {
        // Get the connection type from android in case chromium's type is not yet set.
        ConnectivityManager cm =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
        if (isConnected) {
            connectionType = convertAndroidNetworkTypeToConnectionType(activeNetwork.getType());
        }
    }

    return new DeviceConditions(
            isPowerConnected(batteryStatus), batteryPercentage(batteryStatus), connectionType);
}
 
Example #14
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Records UMA data when the Offline Pages Background Load service awakens.
 * @param context android context
 */
public static void recordWakeupUMA(Context context, long taskScheduledTimeMillis) {
    DeviceConditions deviceConditions = getDeviceConditions(context);
    if (deviceConditions == null) return;

    // Report charging state.
    RecordHistogram.recordBooleanHistogram(
            "OfflinePages.Wakeup.ConnectedToPower", deviceConditions.isPowerConnected());

    // Report battery percentage.
    RecordHistogram.recordPercentageHistogram(
            "OfflinePages.Wakeup.BatteryPercentage", deviceConditions.getBatteryPercentage());

    // Report the default network found (or none, if we aren't connected).
    int connectionType = deviceConditions.getNetConnectionType();
    Log.d(TAG, "Found default network of type " + connectionType);
    RecordHistogram.recordEnumeratedHistogram("OfflinePages.Wakeup.NetworkAvailable",
            connectionType, ConnectionType.CONNECTION_LAST + 1);

    // Collect UMA on the time since the request started.
    long nowMillis = System.currentTimeMillis();
    long delayInMilliseconds = nowMillis - taskScheduledTimeMillis;
    if (delayInMilliseconds <= 0) {
        return;
    }
    RecordHistogram.recordLongTimesHistogram(
            "OfflinePages.Wakeup.DelayTime",
            delayInMilliseconds,
            TimeUnit.MILLISECONDS);
}
 
Example #15
Source File: MinidumpUploadRetry.java    From delion with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
@Override
public void onConnectionTypeChanged(int connectionType) {
    // Look for "favorable" connections. Note that we never
    // know what the user's crash upload preference is until
    // the time when we are actually uploading.
    if (connectionType == ConnectionType.CONNECTION_NONE) {
        return;
    }
    MinidumpUploadService.tryUploadAllCrashDumps(mContext);
    NetworkChangeNotifier.removeConnectionTypeObserver(this);
    sSingleton = null;
}
 
Example #16
Source File: OfflinePageUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Records UMA data when the Offline Pages Background Load service awakens.
 * @param context android context
 */
public static void recordWakeupUMA(Context context, long taskScheduledTimeMillis) {
    DeviceConditions deviceConditions = getDeviceConditions(context);
    if (deviceConditions == null) return;

    // Report charging state.
    RecordHistogram.recordBooleanHistogram(
            "OfflinePages.Wakeup.ConnectedToPower", deviceConditions.isPowerConnected());

    // Report battery percentage.
    RecordHistogram.recordPercentageHistogram(
            "OfflinePages.Wakeup.BatteryPercentage", deviceConditions.getBatteryPercentage());

    // Report the default network found (or none, if we aren't connected).
    int connectionType = deviceConditions.getNetConnectionType();
    Log.d(TAG, "Found default network of type " + connectionType);
    RecordHistogram.recordEnumeratedHistogram("OfflinePages.Wakeup.NetworkAvailable",
            connectionType, ConnectionType.CONNECTION_LAST + 1);

    // Collect UMA on the time since the request started.
    long nowMillis = System.currentTimeMillis();
    long delayInMilliseconds = nowMillis - taskScheduledTimeMillis;
    if (delayInMilliseconds <= 0) {
        return;
    }
    RecordHistogram.recordLongTimesHistogram(
            "OfflinePages.Wakeup.DelayTime",
            delayInMilliseconds,
            TimeUnit.MILLISECONDS);
}
 
Example #17
Source File: DeviceConditions.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
DeviceConditions() {
    mPowerConnected = false;
    mBatteryPercentage = 0;
    mNetConnectionType = ConnectionType.CONNECTION_NONE;
}