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);
}
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);
}
}
}
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);
}
}
}
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;
}
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;
}
}
Aggregations