diff options
author | Patrik Fimml <patrikf@google.com> | 2019-10-22 15:35:15 +0200 |
---|---|---|
committer | Patrik Fimml <patrikf@google.com> | 2019-10-22 16:28:46 +0200 |
commit | 542231c5abc5585a864e4ef68bde57bf4f1197bc (patch) | |
tree | 55d8378502c6030ec5c6a2353cebbaaeb284bb70 | |
parent | f6185e0b31a8258a762b31dd9839a4d731db8946 (diff) |
LOHS: Use system identity for foreground check.
Previously, LOHS would fail in isForeground() if the user app lacks
android.permission.PACKAGE_USAGE_STATS permission, which it shouldn't
need to use LOHS.
With this change, the CTS test that triggered this still doesn't pass on
emulator, but it gets one step further past the permission check.
Bug: 143120756
Bug: 142977313
Test: cts-tradefed run cts-dev -l DEBUG --module CtsNetTestCases --test android.net.wifi.cts.WifiManagerTest#testStartLocalOnlyHotspotSuccess
Change-Id: I576f28c9edcaa5944549100ad86ca2412cce2f54
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 9527c0045..6bfcd52b3 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -1321,14 +1321,9 @@ public class WifiServiceImpl extends BaseWifiService { return LocalOnlyHotspotCallback.ERROR_GENERIC; } enforceLocationPermission(packageName, uid); - long ident = Binder.clearCallingIdentity(); - try { - // also need to verify that Locations services are enabled. - if (!mWifiPermissionsUtil.isLocationModeEnabled()) { - throw new SecurityException("Location mode is not enabled."); - } - } finally { - Binder.restoreCallingIdentity(ident); + // also need to verify that Locations services are enabled. + if (!Binder.withCleanCallingIdentity(() -> mWifiPermissionsUtil.isLocationModeEnabled())) { + throw new SecurityException("Location mode is not enabled."); } // verify that tethering is not disabled @@ -1337,7 +1332,8 @@ public class WifiServiceImpl extends BaseWifiService { } // the app should be in the foreground - if (!mFrameworkFacade.isAppForeground(mContext, uid)) { + if (!Binder.withCleanCallingIdentity( + () -> mFrameworkFacade.isAppForeground(mContext, uid))) { return LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE; } |