summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-08-18 09:14:27 -0700
committerRebecca Silberstein <silberst@google.com>2017-08-23 17:38:55 +0000
commit4faa2de343ff7ef3deb2f313cd60365d9a487f03 (patch)
tree5fc34183c3ebc07c7344756e5ffccab2759a09f8 /tests
parent529bed806618e5232cad35492307796cf1165dac (diff)
WifiServiceImpl: use context to check network settings
Instead of using the ActivityManager to check the NETWORK_SETTINGS permission by uid, use the context. This will allow the shell to pass the permission check. To limit the scope of this change, the check is fixed locally in WifiServiceImpl. WifiConfigManager also uses the WifiPermissionsUtil helper method that checks the permission via the ActivityManager. Switching the helper method will be a much bigger change since it would involve plumbing the pid through several layers of calls and it is not triggered via a shell command, so the existing permission check will work as is. Bug: 64683466 Test: manually verified wifi can be toggled when airplane mode is active Change-Id: I198b364fcc9c08f4f0dc6f89141b55c9a668bb75
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java16
1 files changed, 12 insertions, 4 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 055050deb..e43bdc201 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -400,7 +400,9 @@ public class WifiServiceImplTest {
public void testSetWifiEnabledFromNetworkSettingsHolderWhenInAirplaneMode() throws Exception {
when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true);
when(mSettingsStore.isAirplaneModeOn()).thenReturn(true);
- when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
+ when(mContext.checkPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS), anyInt(), anyInt()))
+ .thenReturn(PackageManager.PERMISSION_GRANTED);
assertTrue(mWifiServiceImpl.setWifiEnabled(SYSUI_PACKAGE_NAME, true));
verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED));
}
@@ -413,7 +415,9 @@ public class WifiServiceImplTest {
public void testSetWifiEnabledFromAppFailsWhenInAirplaneMode() throws Exception {
when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true);
when(mSettingsStore.isAirplaneModeOn()).thenReturn(true);
- when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false);
+ when(mContext.checkPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS), anyInt(), anyInt()))
+ .thenReturn(PackageManager.PERMISSION_DENIED);
assertFalse(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, true));
verify(mWifiController, never()).sendMessage(eq(CMD_WIFI_TOGGLED));
}
@@ -426,7 +430,9 @@ public class WifiServiceImplTest {
public void testSetWifiEnabledFromNetworkSettingsHolderWhenApEnabled() throws Exception {
when(mWifiStateMachine.syncGetWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED);
when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true);
- when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
+ when(mContext.checkPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS), anyInt(), anyInt()))
+ .thenReturn(PackageManager.PERMISSION_GRANTED);
when(mSettingsStore.isAirplaneModeOn()).thenReturn(false);
assertTrue(mWifiServiceImpl.setWifiEnabled(SYSUI_PACKAGE_NAME, true));
verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED));
@@ -438,7 +444,9 @@ public class WifiServiceImplTest {
@Test
public void testSetWifiEnabledFromAppFailsWhenApEnabled() throws Exception {
when(mWifiStateMachine.syncGetWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED);
- when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false);
+ when(mContext.checkPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS), anyInt(), anyInt()))
+ .thenReturn(PackageManager.PERMISSION_DENIED);
when(mSettingsStore.isAirplaneModeOn()).thenReturn(false);
assertFalse(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, true));
verify(mSettingsStore, never()).handleWifiToggled(anyBoolean());