use of android.net.wifi.WifiInfo in project carat by amplab.
the class SamplingLibrary method getWifiSignalStrength.
/* Get current WiFi signal Strength */
public static int getWifiSignalStrength(Context context) {
WifiManager myWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo myWifiInfo = myWifiManager.getConnectionInfo();
int wifiRssi = myWifiInfo.getRssi();
// Log.v("WifiRssi", "Rssi:" + wifiRssi);
return wifiRssi;
}
use of android.net.wifi.WifiInfo in project android-common by litesuits.
the class AndroidUtil method getWifiMacAddress.
/**
* 获取 Wifi MAC 地址
* <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
*/
public static String getWifiMacAddress(Context context) {
//wifi mac地址
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
String mac = info.getMacAddress();
if (Log.isPrint) {
Log.i(TAG, "WIFI MAC:" + mac);
}
return mac;
}
use of android.net.wifi.WifiInfo in project Shuttle by timusus.
the class ShuttleUtilsPowerMockTest method testGetIpAddr.
@Test
public void testGetIpAddr() throws Exception {
ShuttleApplication mockApplication = mock(ShuttleApplication.class);
WifiManager mockWifiManager = mock(WifiManager.class);
WifiInfo mockWifiInfo = mock(WifiInfo.class);
// Setup mocked IP Address of 192.168.1.1
mockStatic(ShuttleApplication.class);
when(ShuttleApplication.getInstance()).thenReturn(mockApplication);
when(mockApplication.getSystemService(Context.WIFI_SERVICE)).thenReturn(mockWifiManager);
when(mockWifiManager.getConnectionInfo()).thenReturn(mockWifiInfo);
when(mockWifiInfo.getIpAddress()).thenReturn(16885952);
assertThat(ShuttleUtils.getIpAddr()).isEqualTo("192.168.1.1");
}
use of android.net.wifi.WifiInfo in project PhotoNoter by yydcdut.
the class PhoneUtils method getMacAddress.
public static String getMacAddress(Context var0) {
try {
WifiManager var1 = (WifiManager) var0.getSystemService(Context.WIFI_SERVICE);
if (checkPermission(var0, "android.permission.ACCESS_WIFI_STATE")) {
WifiInfo var2 = var1.getConnectionInfo();
return var2.getMacAddress();
}
YLog.e(TAG, "Could not get mac address.[no permission android.permission.ACCESS_WIFI_STATE");
} catch (Exception var3) {
YLog.e(TAG, "Could not get mac address." + var3.toString());
}
return "";
}
use of android.net.wifi.WifiInfo in project android_frameworks_base by DirtyUnicorns.
the class DevicePolicyManagerTest method testGetMacAddress.
public void testGetMacAddress() throws Exception {
mContext.callerPermissions.add(permission.MANAGE_DEVICE_ADMINS);
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
mContext.callerPermissions.add(permission.INTERACT_ACROSS_USERS_FULL);
// In this test, change the caller user to "system".
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
// Make sure admin1 is installed on system user.
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
// Test 1. Caller doesn't have DO or DA.
try {
dpm.getWifiMacAddress(admin1);
fail();
} catch (SecurityException e) {
MoreAsserts.assertContainsRegex("No active admin", e.getMessage());
}
// DO needs to be an DA.
dpm.setActiveAdmin(admin1, /* replace =*/
false);
assertTrue(dpm.isAdminActive(admin1));
// Test 2. Caller has DA, but not DO.
try {
dpm.getWifiMacAddress(admin1);
fail();
} catch (SecurityException e) {
MoreAsserts.assertContainsRegex("does not own the device", e.getMessage());
}
// Test 3. Caller has PO, but not DO.
assertTrue(dpm.setProfileOwner(admin1, null, UserHandle.USER_SYSTEM));
try {
dpm.getWifiMacAddress(admin1);
fail();
} catch (SecurityException e) {
MoreAsserts.assertContainsRegex("does not own the device", e.getMessage());
}
// Remove PO.
dpm.clearProfileOwner(admin1);
dpm.setActiveAdmin(admin1, false);
// Test 4, Caller is DO now.
assertTrue(dpm.setDeviceOwner(admin1, null, UserHandle.USER_SYSTEM));
// 4-1. But no WifiInfo.
assertNull(dpm.getWifiMacAddress(admin1));
// 4-2. Returns WifiInfo, but with the default MAC.
when(mContext.wifiManager.getConnectionInfo()).thenReturn(new WifiInfo());
assertNull(dpm.getWifiMacAddress(admin1));
// 4-3. With a real MAC address.
final WifiInfo wi = new WifiInfo();
wi.setMacAddress("11:22:33:44:55:66");
when(mContext.wifiManager.getConnectionInfo()).thenReturn(wi);
assertEquals("11:22:33:44:55:66", dpm.getWifiMacAddress(admin1));
}
Aggregations