From 4faa2de343ff7ef3deb2f313cd60365d9a487f03 Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Fri, 18 Aug 2017 09:14:27 -0700 Subject: 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 --- .../src/com/android/server/wifi/WifiServiceImplTest.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'tests') 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()); -- cgit v1.2.3