Java Code Examples for org.chromium.net.ConnectionType#CONNECTION_NONE

The following examples show how to use org.chromium.net.ConnectionType#CONNECTION_NONE . 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: 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 4
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 5
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 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 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 8
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 9
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 10
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 11
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 12
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;
}