summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-08-03 06:21:08 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-08-03 06:21:08 +0000
commit43dbd2ea7c484a687b0019522e9b57715e3013a9 (patch)
treead0386efcc1a0687aaf693cc2dacfa0b3a682dd9
parentb7de92f5a3cf0113ff4e892c7e536e5b58c2e4f8 (diff)
parent68c549b0814a3129c97ed9c67a005d18601dbe17 (diff)
Merge "WifiService: Allow DO/PO apps to toggle wifi" into qt-qpr1-dev
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java40
2 files changed, 41 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index b25a84593..66b9b276a 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -874,7 +874,7 @@ public class WifiServiceImpl extends BaseWifiService {
return false;
}
boolean isPrivileged = isPrivileged(Binder.getCallingPid(), Binder.getCallingUid());
- if (!isPrivileged
+ if (!isPrivileged && !isDeviceOrProfileOwner(Binder.getCallingUid())
&& !mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q)) {
mLog.info("setWifiEnabled not allowed for uid=%")
.c(Binder.getCallingUid()).flush();
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
@@ -600,6 +600,26 @@ public class WifiServiceImplTest {
}
/**
+ * 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.
*/
@Test
@@ -812,6 +832,26 @@ public class WifiServiceImplTest {
}
/**
+ * 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.
*/
@Test