Search in sources :

Example 11 with NetworkInfo

use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityManagerMobileTest method testConnectToWifi.

// Test case 2: test connection to a given AP
@LargeTest
public void testConnectToWifi() {
    assertNotNull("SSID is null", mTestAccessPoint);
    NetworkInfo networkInfo;
    if (!mWifiOnlyFlag) {
        //Prepare for connectivity verification
        networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE, networkInfo.getState(), NetworkState.TO_DISCONNECTION, State.DISCONNECTED);
    }
    networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(), NetworkState.TO_CONNECTION, State.CONNECTED);
    // Enable Wifi and connect to a test access point
    assertTrue("failed to connect to " + mTestAccessPoint, cmActivity.connectToWifi(mTestAccessPoint));
    assertTrue(cmActivity.waitForWifiState(WifiManager.WIFI_STATE_ENABLED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
    log("wifi state is enabled");
    assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED, ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
    if (!mWifiOnlyFlag) {
        assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
    }
    // validate states
    if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
        log("Wifi state transition validation failed.");
        log("reason: " + cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
        assertTrue(false);
    }
    if (!mWifiOnlyFlag) {
        if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
            log("Mobile state transition validation failed.");
            log("reason: " + cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
            assertTrue(false);
        }
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 12 with NetworkInfo

use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityManagerMobileTest method testDisconnectWifi.

// Test case 4:  test disconnect Wifi
@LargeTest
public void testDisconnectWifi() {
    assertNotNull("SSID is null", mTestAccessPoint);
    // connect to Wifi
    assertTrue("failed to connect to " + mTestAccessPoint, cmActivity.connectToWifi(mTestAccessPoint));
    assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED, ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
    // Wait for a few seconds to avoid the state that both Mobile and Wifi is connected
    sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT);
    NetworkInfo networkInfo;
    if (!mWifiOnlyFlag) {
        networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE, networkInfo.getState(), NetworkState.TO_CONNECTION, State.CONNECTED);
    }
    networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(), NetworkState.TO_DISCONNECTION, State.DISCONNECTED);
    // clear Wifi
    cmActivity.removeConfiguredNetworksAndDisableWifi();
    assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
    if (!mWifiOnlyFlag) {
        assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
    }
    // validate states
    if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
        log("Wifi state transition validation failed.");
        log("reason: " + cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
        assertTrue(false);
    }
    if (!mWifiOnlyFlag) {
        if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
            log("Mobile state transition validation failed.");
            log("reason: " + cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
            assertTrue(false);
        }
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 13 with NetworkInfo

use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityService method handleCaptivePortalTrackerCheck.

private void handleCaptivePortalTrackerCheck(NetworkInfo info) {
    if (DBG)
        log("Captive portal check " + info);
    int type = info.getType();
    final NetworkStateTracker thisNet = mNetTrackers[type];
    if (mNetConfigs[type].isDefault()) {
        if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) {
            if (isNewNetTypePreferredOverCurrentNetType(type)) {
                if (DBG)
                    log("Captive check on " + info.getTypeName());
                mCaptivePortalTracker.detectCaptivePortal(new NetworkInfo(info));
                return;
            } else {
                if (DBG)
                    log("Tear down low priority net " + info.getTypeName());
                teardown(thisNet);
                return;
            }
        }
    }
    if (DBG)
        log("handleCaptivePortalTrackerCheck: call captivePortalCheckComplete ni=" + info);
    thisNet.captivePortalCheckComplete();
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkStateTracker(android.net.NetworkStateTracker)

Example 14 with NetworkInfo

use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityService method tryFailover.

private void tryFailover(int prevNetType) {
    /*
         * If this is a default network, check if other defaults are available.
         * Try to reconnect on all available and let them hash it out when
         * more than one connects.
         */
    if (mNetConfigs[prevNetType].isDefault()) {
        if (mActiveDefaultNetwork == prevNetType) {
            if (DBG) {
                log("tryFailover: set mActiveDefaultNetwork=-1, prevNetType=" + prevNetType);
            }
            mActiveDefaultNetwork = -1;
        }
        //            }
        for (int checkType = 0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
            if (checkType == prevNetType)
                continue;
            if (mNetConfigs[checkType] == null)
                continue;
            if (!mNetConfigs[checkType].isDefault())
                continue;
            if (mNetTrackers[checkType] == null)
                continue;
            // Enabling the isAvailable() optimization caused mobile to not get
            // selected if it was in the middle of error handling. Specifically
            // a moble connection that took 30 seconds to complete the DEACTIVATE_DATA_CALL
            // would not be available and we wouldn't get connected to anything.
            // So removing the isAvailable() optimization below for now. TODO: This
            // optimization should work and we need to investigate why it doesn't work.
            // This could be related to how DEACTIVATE_DATA_CALL is reporting its
            // complete before it is really complete.
            //                if (!mNetTrackers[checkType].isAvailable()) continue;
            //                if (currentPriority >= mNetConfigs[checkType].mPriority) continue;
            NetworkStateTracker checkTracker = mNetTrackers[checkType];
            NetworkInfo checkInfo = checkTracker.getNetworkInfo();
            if (!checkInfo.isConnectedOrConnecting() || checkTracker.isTeardownRequested()) {
                checkInfo.setFailover(true);
                checkTracker.reconnect();
            }
            if (DBG)
                log("Attempting to switch to " + checkInfo.getTypeName());
        }
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkStateTracker(android.net.NetworkStateTracker)

Example 15 with NetworkInfo

use of android.net.NetworkInfo in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityService method makeGeneralIntent.

private Intent makeGeneralIntent(NetworkInfo info, String bcastType) {
    if (mLockdownTracker != null) {
        info = mLockdownTracker.augmentNetworkInfo(info);
    }
    Intent intent = new Intent(bcastType);
    intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, new NetworkInfo(info));
    intent.putExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, info.getType());
    if (info.isFailover()) {
        intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
        info.setFailover(false);
    }
    if (info.getReason() != null) {
        intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
    }
    if (info.getExtraInfo() != null) {
        intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO, info.getExtraInfo());
    }
    intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
    return intent;
}
Also used : NetworkInfo(android.net.NetworkInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Aggregations

NetworkInfo (android.net.NetworkInfo)489 ConnectivityManager (android.net.ConnectivityManager)257 Intent (android.content.Intent)44 LinkProperties (android.net.LinkProperties)38 NetworkState (android.net.NetworkState)26 Test (org.junit.Test)24 PendingIntent (android.app.PendingIntent)22 NetworkCapabilities (android.net.NetworkCapabilities)18 Network (android.net.Network)17 LargeTest (android.test.suitebuilder.annotation.LargeTest)17 RemoteException (android.os.RemoteException)16 Context (android.content.Context)15 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)15 WifiInfo (android.net.wifi.WifiInfo)13 Bundle (android.os.Bundle)13 TestUtils.mockNetworkInfo (com.squareup.picasso.TestUtils.mockNetworkInfo)12 IOException (java.io.IOException)11 WifiManager (android.net.wifi.WifiManager)9 IntentFilter (android.content.IntentFilter)6 SharedPreferences (android.content.SharedPreferences)6