From 68c549b0814a3129c97ed9c67a005d18601dbe17 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Mon, 29 Jul 2019 11:08:36 -0700 Subject: WifiService: Allow DO/PO apps to toggle wifi Allow DO/PO apps to toggle wifi even if they target Q SDK. Bug: 136487810 Test: atest com.android.server.wifi.WifiServiceImplTest Change-Id: If59dd4485a6265077f50800c0089a0dd9d61c2f0 --- .../android/server/wifi/WifiServiceImplTest.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (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 80b7406ee..33e8c29d6 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -599,6 +599,26 @@ public class WifiServiceImplTest { verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED)); } + /** + * Verify that wifi can be enabled by the DO apps targeting Q SDK. + */ + @Test + public void testSetWifiEnabledSuccessForDOAppsTargetingQSDK() 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); + when(mDevicePolicyManagerInternal.isActiveAdminWithPolicy( + Process.myUid(), DeviceAdminInfo.USES_POLICY_DEVICE_OWNER)) + .thenReturn(true); + + 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. */ @@ -811,6 +831,26 @@ public class WifiServiceImplTest { verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED)); } + /** + * Verify that wifi can be disabled by the PO apps targeting Q SDK. + */ + @Test + public void testSetWifiDisabledSuccessForPOAppsTargetingQSDK() 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); + when(mDevicePolicyManagerInternal.isActiveAdminWithPolicy( + Process.myUid(), DeviceAdminInfo.USES_POLICY_PROFILE_OWNER)) + .thenReturn(true); + + 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. */ -- cgit v1.2.3