Java Code Examples for android.net.NetworkInfo#isFailover()

The following examples show how to use android.net.NetworkInfo#isFailover() . 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: GetDeviceInfo.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
private static List<NetworkInfoModel> extractNetworkInfo(DeviceInfoHelper deviceInfoHelper) {
    List<NetworkInfoModel> result = new ArrayList<>();
    for (Network network : deviceInfoHelper.getNetworks()) {
        NetworkInfoModel resultItem = new NetworkInfoModel();
        NetworkInfo networkInfo = deviceInfoHelper.extractInfo(network);
        if (networkInfo != null) {
            resultItem.type = networkInfo.getType();
            resultItem.typeName = networkInfo.getTypeName();
            resultItem.subtype = networkInfo.getSubtype();
            resultItem.subtypeName = networkInfo.getSubtypeName();
            resultItem.isConnected = networkInfo.isConnected();
            resultItem.detailedState = networkInfo.getDetailedState().name();
            resultItem.state = networkInfo.getState().name();
            resultItem.extraInfo = networkInfo.getExtraInfo();
            resultItem.isAvailable = networkInfo.isAvailable();
            resultItem.isFailover = networkInfo.isFailover();
            resultItem.isRoaming = networkInfo.isRoaming();
        }

        NetworkCapabilities networkCaps = deviceInfoHelper.extractCapabilities(network);
        NetworkCapabilitiesModel caps = new NetworkCapabilitiesModel();
        if (networkCaps != null) {
            caps.transportTypes = DeviceInfoHelper.extractTransportTypes(networkCaps);
            caps.networkCapabilities = DeviceInfoHelper.extractCapNames(networkCaps);
            caps.linkUpstreamBandwidthKbps = networkCaps.getLinkUpstreamBandwidthKbps();
            caps.linkDownBandwidthKbps = networkCaps.getLinkDownstreamBandwidthKbps();
            caps.signalStrength = extractSafeValue("mSignalStrength", networkCaps);
            caps.SSID = extractSafeValue("mSSID", networkCaps);
        }
        resultItem.capabilities = networkCaps == null ? null : caps;

        if (networkInfo != null || networkCaps != null) {
            result.add(resultItem);
        }
    }
    return result;
}
 
Example 2
Source File: DownloaderService.java    From QtAndroidTools with MIT License 4 votes vote down vote up
private void updateNetworkState(NetworkInfo info) {
    boolean isConnected = mIsConnected;
    boolean isFailover = mIsFailover;
    boolean isCellularConnection = mIsCellularConnection;
    boolean isRoaming = mIsRoaming;
    boolean isAtLeast3G = mIsAtLeast3G;
    if (null != info) {
        mIsRoaming = info.isRoaming();
        mIsFailover = info.isFailover();
        mIsConnected = info.isConnected();
        updateNetworkType(info.getType(), info.getSubtype());
    } else {
        mIsRoaming = false;
        mIsFailover = false;
        mIsConnected = false;
        updateNetworkType(-1, -1);
    }
    mStateChanged = (mStateChanged || isConnected != mIsConnected
            || isFailover != mIsFailover
            || isCellularConnection != mIsCellularConnection
            || isRoaming != mIsRoaming || isAtLeast3G != mIsAtLeast3G);
    if (Constants.LOGVV) {
        if (mStateChanged) {
            Log.v(LOG_TAG, "Network state changed: ");
            Log.v(LOG_TAG, "Starting State: " +
                    (isConnected ? "Connected " : "Not Connected ") +
                    (isCellularConnection ? "Cellular " : "WiFi ") +
                    (isRoaming ? "Roaming " : "Local ") +
                    (isAtLeast3G ? "3G+ " : "<3G "));
            Log.v(LOG_TAG, "Ending State: " +
                    (mIsConnected ? "Connected " : "Not Connected ") +
                    (mIsCellularConnection ? "Cellular " : "WiFi ") +
                    (mIsRoaming ? "Roaming " : "Local ") +
                    (mIsAtLeast3G ? "3G+ " : "<3G "));

            if (isServiceRunning()) {
                if (mIsRoaming) {
                    mStatus = STATUS_WAITING_FOR_NETWORK;
                    mControl = CONTROL_PAUSED;
                } else if (mIsCellularConnection) {
                    DownloadsDB db = DownloadsDB.getDB(this);
                    int flags = db.getFlags();
                    if (0 == (flags & FLAGS_DOWNLOAD_OVER_CELLULAR)) {
                        mStatus = STATUS_QUEUED_FOR_WIFI;
                        mControl = CONTROL_PAUSED;
                    }
                }
            }

        }
    }
}
 
Example 3
Source File: DownloaderService.java    From play-apk-expansion with Apache License 2.0 4 votes vote down vote up
private void updateNetworkState(NetworkInfo info) {
    boolean isConnected = mIsConnected;
    boolean isFailover = mIsFailover;
    boolean isCellularConnection = mIsCellularConnection;
    boolean isRoaming = mIsRoaming;
    boolean isAtLeast3G = mIsAtLeast3G;
    if (null != info) {
        mIsRoaming = info.isRoaming();
        mIsFailover = info.isFailover();
        mIsConnected = info.isConnected();
        updateNetworkType(info.getType(), info.getSubtype());
    } else {
        mIsRoaming = false;
        mIsFailover = false;
        mIsConnected = false;
        updateNetworkType(-1, -1);
    }
    mStateChanged = (mStateChanged || isConnected != mIsConnected
            || isFailover != mIsFailover
            || isCellularConnection != mIsCellularConnection
            || isRoaming != mIsRoaming || isAtLeast3G != mIsAtLeast3G);
    if (Constants.LOGVV) {
        if (mStateChanged) {
            Log.v(LOG_TAG, "Network state changed: ");
            Log.v(LOG_TAG, "Starting State: " +
                    (isConnected ? "Connected " : "Not Connected ") +
                    (isCellularConnection ? "Cellular " : "WiFi ") +
                    (isRoaming ? "Roaming " : "Local ") +
                    (isAtLeast3G ? "3G+ " : "<3G "));
            Log.v(LOG_TAG, "Ending State: " +
                    (mIsConnected ? "Connected " : "Not Connected ") +
                    (mIsCellularConnection ? "Cellular " : "WiFi ") +
                    (mIsRoaming ? "Roaming " : "Local ") +
                    (mIsAtLeast3G ? "3G+ " : "<3G "));

            if (isServiceRunning()) {
                if (mIsRoaming) {
                    mStatus = STATUS_WAITING_FOR_NETWORK;
                    mControl = CONTROL_PAUSED;
                } else if (mIsCellularConnection) {
                    DownloadsDB db = DownloadsDB.getDB(this);
                    int flags = db.getFlags();
                    if (0 == (flags & FLAGS_DOWNLOAD_OVER_CELLULAR)) {
                        mStatus = STATUS_QUEUED_FOR_WIFI;
                        mControl = CONTROL_PAUSED;
                    }
                }
            }

        }
    }
}
 
Example 4
Source File: DownloaderService.java    From travelguide with Apache License 2.0 4 votes vote down vote up
private void updateNetworkState(NetworkInfo info) {
    boolean isConnected = mIsConnected;
    boolean isFailover = mIsFailover;
    boolean isCellularConnection = mIsCellularConnection;
    boolean isRoaming = mIsRoaming;
    boolean isAtLeast3G = mIsAtLeast3G;
    if (null != info) {
        mIsRoaming = info.isRoaming();
        mIsFailover = info.isFailover();
        mIsConnected = info.isConnected();
        updateNetworkType(info.getType(), info.getSubtype());
    } else {
        mIsRoaming = false;
        mIsFailover = false;
        mIsConnected = false;
        updateNetworkType(-1, -1);
    }
    mStateChanged = (mStateChanged || isConnected != mIsConnected
            || isFailover != mIsFailover
            || isCellularConnection != mIsCellularConnection
            || isRoaming != mIsRoaming || isAtLeast3G != mIsAtLeast3G);
    if (Constants.LOGVV) {
        if (mStateChanged) {
            Log.v(LOG_TAG, "Network state changed: ");
            Log.v(LOG_TAG, "Starting State: " +
                    (isConnected ? "Connected " : "Not Connected ") +
                    (isCellularConnection ? "Cellular " : "WiFi ") +
                    (isRoaming ? "Roaming " : "Local ") +
                    (isAtLeast3G ? "3G+ " : "<3G "));
            Log.v(LOG_TAG, "Ending State: " +
                    (mIsConnected ? "Connected " : "Not Connected ") +
                    (mIsCellularConnection ? "Cellular " : "WiFi ") +
                    (mIsRoaming ? "Roaming " : "Local ") +
                    (mIsAtLeast3G ? "3G+ " : "<3G "));

            if (isServiceRunning()) {
                if (mIsRoaming) {
                    mStatus = STATUS_WAITING_FOR_NETWORK;
                    mControl = CONTROL_PAUSED;
                } else if (mIsCellularConnection) {
                    DownloadsDB db = DownloadsDB.getDB(this);
                    int flags = db.getFlags();
                    if (0 == (flags & FLAGS_DOWNLOAD_OVER_CELLULAR)) {
                        mStatus = STATUS_QUEUED_FOR_WIFI;
                        mControl = CONTROL_PAUSED;
                    }
                }
            }

        }
    }
}
 
Example 5
Source File: DownloaderService.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
private void updateNetworkState(NetworkInfo info) {
    boolean isConnected = mIsConnected;
    boolean isFailover = mIsFailover;
    boolean isCellularConnection = mIsCellularConnection;
    boolean isRoaming = mIsRoaming;
    boolean isAtLeast3G = mIsAtLeast3G;
    if (null != info) {
        mIsRoaming = info.isRoaming();
        mIsFailover = info.isFailover();
        mIsConnected = info.isConnected();
        updateNetworkType(info.getType(), info.getSubtype());
    } else {
        mIsRoaming = false;
        mIsFailover = false;
        mIsConnected = false;
        updateNetworkType(-1, -1);
    }
    mStateChanged = (mStateChanged || isConnected != mIsConnected
            || isFailover != mIsFailover
            || isCellularConnection != mIsCellularConnection
            || isRoaming != mIsRoaming || isAtLeast3G != mIsAtLeast3G);
    if (Constants.LOGVV) {
        if (mStateChanged) {
            Log.v(LOG_TAG, "Network state changed: ");
            Log.v(LOG_TAG, "Starting State: " +
                    (isConnected ? "Connected " : "Not Connected ") +
                    (isCellularConnection ? "Cellular " : "WiFi ") +
                    (isRoaming ? "Roaming " : "Local ") +
                    (isAtLeast3G ? "3G+ " : "<3G "));
            Log.v(LOG_TAG, "Ending State: " +
                    (mIsConnected ? "Connected " : "Not Connected ") +
                    (mIsCellularConnection ? "Cellular " : "WiFi ") +
                    (mIsRoaming ? "Roaming " : "Local ") +
                    (mIsAtLeast3G ? "3G+ " : "<3G "));

            if (isServiceRunning()) {
                if (mIsRoaming) {
                    mStatus = STATUS_WAITING_FOR_NETWORK;
                    mControl = CONTROL_PAUSED;
                } else if (mIsCellularConnection) {
                    DownloadsDB db = DownloadsDB.getDB(this);
                    int flags = db.getFlags();
                    if (0 == (flags & FLAGS_DOWNLOAD_OVER_CELLULAR)) {
                        mStatus = STATUS_QUEUED_FOR_WIFI;
                        mControl = CONTROL_PAUSED;
                    }
                }
            }

        }
    }
}
 
Example 6
Source File: DownloaderService.java    From UnityOBBDownloader with Apache License 2.0 4 votes vote down vote up
private void updateNetworkState(NetworkInfo info) {
    boolean isConnected = mIsConnected;
    boolean isFailover = mIsFailover;
    boolean isCellularConnection = mIsCellularConnection;
    boolean isRoaming = mIsRoaming;
    boolean isAtLeast3G = mIsAtLeast3G;
    if (null != info) {
        mIsRoaming = info.isRoaming();
        mIsFailover = info.isFailover();
        mIsConnected = info.isConnected();
        updateNetworkType(info.getType(), info.getSubtype());
    } else {
        mIsRoaming = false;
        mIsFailover = false;
        mIsConnected = false;
        updateNetworkType(-1, -1);
    }
    mStateChanged = (mStateChanged || isConnected != mIsConnected
            || isFailover != mIsFailover
            || isCellularConnection != mIsCellularConnection
            || isRoaming != mIsRoaming || isAtLeast3G != mIsAtLeast3G);
    if (Constants.LOGVV) {
        if (mStateChanged) {
            Log.v(LOG_TAG, "Network state changed: ");
            Log.v(LOG_TAG, "Starting State: " +
                    (isConnected ? "Connected " : "Not Connected ") +
                    (isCellularConnection ? "Cellular " : "WiFi ") +
                    (isRoaming ? "Roaming " : "Local ") +
                    (isAtLeast3G ? "3G+ " : "<3G "));
            Log.v(LOG_TAG, "Ending State: " +
                    (mIsConnected ? "Connected " : "Not Connected ") +
                    (mIsCellularConnection ? "Cellular " : "WiFi ") +
                    (mIsRoaming ? "Roaming " : "Local ") +
                    (mIsAtLeast3G ? "3G+ " : "<3G "));

            if (isServiceRunning()) {
                if (mIsRoaming) {
                    mStatus = STATUS_WAITING_FOR_NETWORK;
                    mControl = CONTROL_PAUSED;
                } else if (mIsCellularConnection) {
                    DownloadsDB db = DownloadsDB.getDB(this);
                    int flags = db.getFlags();
                    if (0 == (flags & FLAGS_DOWNLOAD_OVER_CELLULAR)) {
                        mStatus = STATUS_QUEUED_FOR_WIFI;
                        mControl = CONTROL_PAUSED;
                    }
                }
            }

        }
    }
}