Search in sources :

Example 61 with WifiInfo

use of android.net.wifi.WifiInfo in project robolectric by robolectric.

the class ShadowWifiInfoTest method shouldReturnNetworkId.

@Test
public void shouldReturnNetworkId() {
    WifiManager wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getNetworkId()).isEqualTo(-1);
    shadowOf(wifiInfo).setNetworkId(10);
    wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getNetworkId()).isEqualTo(10);
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo) Test(org.junit.Test)

Example 62 with WifiInfo

use of android.net.wifi.WifiInfo in project robolectric by robolectric.

the class ShadowWifiInfoTest method shouldReturnLinkSpeed.

@Test
public void shouldReturnLinkSpeed() {
    WifiManager wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getLinkSpeed()).isEqualTo(-1);
    shadowOf(wifiInfo).setLinkSpeed(10);
    wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getLinkSpeed()).isEqualTo(10);
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo) Test(org.junit.Test)

Example 63 with WifiInfo

use of android.net.wifi.WifiInfo in project android_frameworks_base by ParanoidAndroid.

the class PiePolicy method getWifiSsid.

public static String getWifiSsid() {
    String ssid = mContext.getString(R.string.quick_settings_wifi_not_connected);
    ConnectivityManager connManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (networkInfo.isConnected()) {
        final WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
        ssid = NetworkController.huntForSsid(wifiManager, connectionInfo);
    }
    return ssid.toUpperCase();
}
Also used : WifiManager(android.net.wifi.WifiManager) NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) WifiInfo(android.net.wifi.WifiInfo)

Example 64 with WifiInfo

use of android.net.wifi.WifiInfo in project android_frameworks_base by ParanoidAndroid.

the class NetworkIdentity method buildNetworkIdentity.

/**
     * Build a {@link NetworkIdentity} from the given {@link NetworkState},
     * assuming that any mobile networks are using the current IMSI.
     */
public static NetworkIdentity buildNetworkIdentity(Context context, NetworkState state) {
    final int type = state.networkInfo.getType();
    final int subType = state.networkInfo.getSubtype();
    // TODO: consider moving subscriberId over to LinkCapabilities, so it
    // comes from an authoritative source.
    String subscriberId = null;
    String networkId = null;
    boolean roaming = false;
    if (isNetworkTypeMobile(type)) {
        final TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        roaming = telephony.isNetworkRoaming();
        if (state.subscriberId != null) {
            subscriberId = state.subscriberId;
        } else {
            subscriberId = telephony.getSubscriberId();
        }
    } else if (type == TYPE_WIFI) {
        if (state.networkId != null) {
            networkId = state.networkId;
        } else {
            final WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            final WifiInfo info = wifi.getConnectionInfo();
            networkId = info != null ? info.getSSID() : null;
        }
    }
    return new NetworkIdentity(type, subType, subscriberId, networkId, roaming);
}
Also used : WifiManager(android.net.wifi.WifiManager) TelephonyManager(android.telephony.TelephonyManager) WifiInfo(android.net.wifi.WifiInfo)

Example 65 with WifiInfo

use of android.net.wifi.WifiInfo in project android_frameworks_base by ParanoidAndroid.

the class WifiAssociationTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    WifiAssociationTestRunner mRunner = (WifiAssociationTestRunner) getInstrumentation();
    mWifiManager = (WifiManager) mRunner.getContext().getSystemService(Context.WIFI_SERVICE);
    mAct = getActivity();
    Bundle arguments = mRunner.getArguments();
    mSecurityType = arguments.getString("security-type");
    mSsid = arguments.getString("ssid");
    mPassword = arguments.getString("password");
    mFrequencyBand = arguments.getString("frequency-band");
    mBand = mRunner.mBand;
    assertNotNull("Security type is empty", mSecurityType);
    assertNotNull("Ssid is empty", mSsid);
    validateFrequencyBand();
    // enable Wifi and verify wpa_supplicant is started
    assertTrue("enable Wifi failed", mAct.enableWifi());
    sleep(2 * ConnectivityManagerTestActivity.SHORT_TIMEOUT, "interrupted while waiting for WPA_SUPPLICANT to start");
    WifiInfo mConnection = mAct.mWifiManager.getConnectionInfo();
    assertNotNull(mConnection);
    assertTrue("wpa_supplicant is not started ", mAct.mWifiManager.pingSupplicant());
}
Also used : Bundle(android.os.Bundle) WifiAssociationTestRunner(com.android.connectivitymanagertest.WifiAssociationTestRunner) WifiInfo(android.net.wifi.WifiInfo)

Aggregations

WifiInfo (android.net.wifi.WifiInfo)99 WifiManager (android.net.wifi.WifiManager)53 WifiConfiguration (android.net.wifi.WifiConfiguration)16 NetworkInfo (android.net.NetworkInfo)13 Intent (android.content.Intent)11 IOException (java.io.IOException)8 Test (org.junit.Test)8 Bundle (android.os.Bundle)7 ScanResult (android.net.wifi.ScanResult)6 WifiAssociationTestRunner (com.android.connectivitymanagertest.WifiAssociationTestRunner)6 PendingIntent (android.app.PendingIntent)5 ConnectivityManager (android.net.ConnectivityManager)5 Network (android.net.Network)5 CellIdentityCdma (android.telephony.CellIdentityCdma)5 CellIdentityGsm (android.telephony.CellIdentityGsm)5 CellIdentityLte (android.telephony.CellIdentityLte)5 CellIdentityWcdma (android.telephony.CellIdentityWcdma)5 CellInfo (android.telephony.CellInfo)5 CellInfoCdma (android.telephony.CellInfoCdma)5 CellInfoGsm (android.telephony.CellInfoGsm)5