diff options
author | Rebecca Silberstein <silberst@google.com> | 2017-08-25 22:51:41 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-08-25 22:51:41 +0000 |
commit | f77fca37902331575d779df9754566db471db85f (patch) | |
tree | 4ab5c8c81fe4c3ce205407d97755e5170f895f54 | |
parent | b7072d6c59ff67573155a0abb3a13c554dc80fa3 (diff) | |
parent | 4faa2de343ff7ef3deb2f313cd60365d9a487f03 (diff) |
Merge "WifiServiceImpl: use context to check network settings" into oc-mr1-dev
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 9 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 16 |
2 files changed, 19 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 6ef045591..bb995b7d1 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -713,6 +713,11 @@ public class WifiServiceImpl extends IWifiManager.Stub { } } + private boolean checkNetworkSettingsPermission(int pid, int uid) { + return mContext.checkPermission(android.Manifest.permission.NETWORK_SETTINGS, pid, uid) + == PackageManager.PERMISSION_GRANTED; + } + private void enforceNetworkSettingsPermission() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, "WifiService"); @@ -780,8 +785,8 @@ public class WifiServiceImpl extends IWifiManager.Stub { mLog.info("setWifiEnabled package=% uid=% enable=%").c(packageName) .c(Binder.getCallingUid()).c(enable).flush(); - boolean isFromSettings = - mWifiPermissionsUtil.checkNetworkSettingsPermission(Binder.getCallingUid()); + boolean isFromSettings = checkNetworkSettingsPermission( + Binder.getCallingPid(), Binder.getCallingUid()); // If Airplane mode is enabled, only Settings is allowed to toggle Wifi if (mSettingsStore.isAirplaneModeOn() && !isFromSettings) { 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()); |