diff options
author | Rebecca Silberstein <silberst@google.com> | 2017-05-30 16:02:56 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-05-30 16:02:57 +0000 |
commit | d01882a64facb9824327b06daf9931a32b0e0494 (patch) | |
tree | 2326598271fdc7ef29f9f66dc9ac9c711d7005e6 /tests | |
parent | 296cdef42bd9a8b998536e52acc07395f8ee9a51 (diff) | |
parent | 584a9023ae5f9c88593a2f5c5c2451a26729cc53 (diff) |
Merge "WifiServiceImpl: setWifiEnabled permission check"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 01f243db7..01ab0755f 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -113,7 +113,6 @@ public class WifiServiceImplTest { private static final long WIFI_BACKGROUND_SCAN_INTERVAL = 10000; private static final String ANDROID_SYSTEM_PACKAGE = "android"; private static final String TEST_PACKAGE_NAME = "TestPackage"; - private static final String SETTINGS_PACKAGE_NAME = "com.android.settings"; private static final String SYSUI_PACKAGE_NAME = "com.android.systemui"; private static final int TEST_PID = 6789; private static final int TEST_PID2 = 9876; @@ -366,23 +365,16 @@ public class WifiServiceImplTest { } /** - * Verify that a call from Settings can enable wifi if we are in softap mode. + * Verify that a call from an app with the NETWORK_SETTINGS permission can enable wifi if we + * are in softap mode. */ @Test - public void testSetWifiEnabledFromSettingsWhenApEnabled() throws Exception { - when(mWifiStateMachine.syncGetWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED); - when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); - assertTrue(mWifiServiceImpl.setWifiEnabled(SETTINGS_PACKAGE_NAME, true)); - verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED)); - } - - /** - * Verify that a call from SysUI can enable wifi if we are in softap mode. - */ - @Test - public void testSetWifiEnabledFromSysUiWhenApEnabled() throws Exception { + public void testSetWifiEnabledFromNetworkSettingsHolderWhenApEnabled() throws Exception { when(mWifiStateMachine.syncGetWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED); when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); + when(mContext.checkCallingOrSelfPermission( + eq(android.Manifest.permission.NETWORK_SETTINGS))) + .thenReturn(PackageManager.PERMISSION_GRANTED); assertTrue(mWifiServiceImpl.setWifiEnabled(SYSUI_PACKAGE_NAME, true)); verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED)); } @@ -393,6 +385,9 @@ public class WifiServiceImplTest { @Test public void testSetWifiEnabledFromAppFailsWhenApEnabled() throws Exception { when(mWifiStateMachine.syncGetWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED); + when(mContext.checkCallingOrSelfPermission( + eq(android.Manifest.permission.NETWORK_SETTINGS))) + .thenReturn(PackageManager.PERMISSION_DENIED); assertFalse(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, true)); verify(mSettingsStore, never()).handleWifiToggled(anyBoolean()); verify(mWifiController, never()).sendMessage(eq(CMD_WIFI_TOGGLED)); |