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