diff options
author | Roshan Pius <rpius@google.com> | 2019-08-13 11:23:28 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-08-13 22:40:42 +0000 |
commit | b46e815669ba3f376f7dda2a24479f84bad0b4a8 (patch) | |
tree | f4d3b4b6da4c3228ee886f7dcd295fd516e71428 /tests | |
parent | ece7e1bb352a57ed82124173449b7d5b6d479e8e (diff) |
WifiServiceImpl: Allow setWifiEnabled for system apps
This allows system apps to toggle wifi on/off during emergency calls to get
user's location for example.
Bug: 138091278
Test: atest com.android.server.wifi
Change-Id: I095f9755c60034064e467dedcdb16b33dc63d9eb
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 33e8c29d6..97257ab40 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -620,6 +620,24 @@ public class WifiServiceImplTest { } /** + * Verify that wifi can be enabled by the system apps targeting Q SDK. + */ + @Test + public void testSetWifiEnabledSuccessForSystemAppsTargetingQSDK() throws Exception { + doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) + .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); + when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), + eq(Build.VERSION_CODES.Q))).thenReturn(false); + mApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; + + when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true); + when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); + assertTrue(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, true)); + + verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED)); + } + + /** * Verify that wifi can be enabled by the apps targeting pre-Q SDK. */ @Test @@ -852,6 +870,25 @@ public class WifiServiceImplTest { } /** + * Verify that wifi can be disabled by the system apps targeting Q SDK. + */ + @Test + public void testSetWifiDisabledSuccessForSystemAppsTargetingQSDK() throws Exception { + doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) + .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); + when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(), + eq(Build.VERSION_CODES.Q))).thenReturn(false); + mApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; + + when(mSettingsStore.handleWifiToggled(eq(false))).thenReturn(true); + when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); + assertTrue(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, false)); + + verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED)); + } + + + /** * Verify that wifi can be disabled by the apps targeting pre-Q SDK. */ @Test |