Search in sources :

Example 86 with NetworkInfo

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

the class NetworkStatsServiceTest method buildMobile3gState.

private static NetworkState buildMobile3gState(String subscriberId) {
    final NetworkInfo info = new NetworkInfo(TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UMTS, null, null);
    info.setDetailedState(DetailedState.CONNECTED, null, null);
    final LinkProperties prop = new LinkProperties();
    prop.setInterfaceName(TEST_IFACE);
    return new NetworkState(info, prop, null, subscriberId, null);
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkState(android.net.NetworkState) LinkProperties(android.net.LinkProperties)

Example 87 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 88 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 89 with NetworkInfo

use of android.net.NetworkInfo in project AnimeTaste by daimajia.

the class NetworkUtils method getConnectivityStatus.

public static int getConnectivityStatus(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (null != activeNetwork) {
        if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
            return TYPE_WIFI;
        if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
            return TYPE_MOBILE;
    }
    return TYPE_NOT_CONNECTED;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 90 with NetworkInfo

use of android.net.NetworkInfo in project AnimeTaste by daimajia.

the class NetworkUtils method isWifiConnected.

/**
	 * make true current connect service is wifi
	 * 
	 * @param mContext
	 * @return
	 */
public static boolean isWifiConnected(Context mContext) {
    ConnectivityManager connManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWifi.isConnected()) {
        return true;
    } else {
        return false;
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Aggregations

NetworkInfo (android.net.NetworkInfo)511 ConnectivityManager (android.net.ConnectivityManager)274 Intent (android.content.Intent)47 LinkProperties (android.net.LinkProperties)38 NetworkState (android.net.NetworkState)26 Test (org.junit.Test)26 PendingIntent (android.app.PendingIntent)23 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)8 BroadcastReceiver (android.content.BroadcastReceiver)7