Search in sources :

Example 11 with WifiInfo

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

the class ShadowWifiInfoTest method shouldReturnFrequency.

@Test
@Config(minSdk = LOLLIPOP)
public void shouldReturnFrequency() {
    WifiManager wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getFrequency()).isEqualTo(-1);
    shadowOf(wifiInfo).setFrequency(10);
    wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getFrequency()).isEqualTo(10);
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 12 with WifiInfo

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

the class ShadowWifiInfoTest method shouldReturnBSSID.

@Test
public void shouldReturnBSSID() {
    WifiManager wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getBSSID()).isEqualTo(null);
    shadowOf(wifiInfo).setBSSID("BSSID");
    wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getBSSID()).isEqualTo("BSSID");
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo) Test(org.junit.Test)

Example 13 with WifiInfo

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

the class ShadowWifiInfoTest method shouldReturnMacAddress.

@Test
public void shouldReturnMacAddress() {
    WifiManager wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getMacAddress()).isEqualTo(// WifiInfo.DEFAULT_MAC_ADDRESS
    "02:00:00:00:00:00");
    shadowOf(wifiInfo).setMacAddress("mac address");
    wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getMacAddress()).isEqualTo("mac address");
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo) Test(org.junit.Test)

Example 14 with WifiInfo

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

the class ShadowWifiInfoTest method shouldReturnSSID.

@Test
public void shouldReturnSSID() {
    WifiManager wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    // WifiSsid.NONE
    assertThat(wifiInfo.getSSID()).isEqualTo("<unknown ssid>");
    shadowOf(wifiInfo).setSSID("SSID");
    wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
    wifiInfo = wifiManager.getConnectionInfo();
    assertThat(wifiInfo.getSSID()).isEqualTo("SSID");
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo) Test(org.junit.Test)

Example 15 with WifiInfo

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

the class WifiAssociationTest method testWifiAssociation.

/**
     * Test that the wifi can associate with a given access point.
     */
@LargeTest
public void testWifiAssociation() {
    WifiAssociationTestRunner runner = (WifiAssociationTestRunner) getInstrumentation();
    Bundle arguments = runner.getArguments();
    String ssid = arguments.getString("ssid");
    assertNotNull("ssid is empty", ssid);
    String securityTypeStr = arguments.getString("security-type");
    assertNotNull("security-type is empty", securityTypeStr);
    SecurityType securityType = SecurityType.valueOf(securityTypeStr);
    String password = arguments.getString("password");
    assertTrue("enable Wifi failed", enableWifi());
    WifiInfo wi = mWifiManager.getConnectionInfo();
    logv("%s", wi);
    assertNotNull("no active wifi info", wi);
    WifiConfiguration config = getConfig(ssid, securityType, password);
    logv("Network config: %s", config.toString());
    connectToWifi(config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) Bundle(android.os.Bundle) WifiAssociationTestRunner(com.android.connectivitymanagertest.WifiAssociationTestRunner) WifiInfo(android.net.wifi.WifiInfo) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

WifiInfo (android.net.wifi.WifiInfo)98 WifiManager (android.net.wifi.WifiManager)52 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