diff options
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 3 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 37 |
2 files changed, 39 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 66b9b276a..b2abdd2b6 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -875,7 +875,8 @@ public class WifiServiceImpl extends BaseWifiService { } boolean isPrivileged = isPrivileged(Binder.getCallingPid(), Binder.getCallingUid()); if (!isPrivileged && !isDeviceOrProfileOwner(Binder.getCallingUid()) - && !mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q)) { + && !mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q) + && !isSystem(packageName)) { mLog.info("setWifiEnabled not allowed for uid=%") .c(Binder.getCallingUid()).flush(); return false; 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 |