diff options
author | Roshan Pius <rpius@google.com> | 2019-09-17 09:45:49 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-09-18 10:17:47 -0700 |
commit | a61a3c5c15c6564d60af0e8c08b879cdfa7c509d (patch) | |
tree | 3118d676232d5199ae52d71ef4a9360720893561 /service | |
parent | 07ba9343d2142ee08bffa4febb1e7813d10d7774 (diff) |
WifiPermissionsUtil: Use getApplicationInfoAsUser for target SDK checks
To handle multi-user scenarios, pass in the corresponding app's user id
to fetch app info.
Bug: 140895783
Test: atest com.android.server.wifi
Change-Id: I0ff22e39513778b13648b226e91d8a27effc7596
Diffstat (limited to 'service')
3 files changed, 10 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index be75f96b3..354c0a555 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -853,7 +853,7 @@ public class WifiServiceImpl extends BaseWifiService { * Note: Invoke mAppOps.checkPackage(uid, packageName) before to ensure correct package name. */ private boolean isTargetSdkLessThanQOrPrivileged(String packageName, int pid, int uid) { - return mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q) + return mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q, uid) || isPrivileged(pid, uid) // DO/PO apps should be able to add/modify saved networks. || isDeviceOrProfileOwner(uid) @@ -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, + Binder.getCallingUid()) && !isSystem(packageName)) { mLog.info("setWifiEnabled not allowed for uid=%") .c(Binder.getCallingUid()).flush(); @@ -2309,7 +2310,7 @@ public class WifiServiceImpl extends BaseWifiService { final int uid = Binder.getCallingUid(); if (!mWifiPermissionsUtil.checkNetworkSettingsPermission(uid) && !mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(uid)) { - if (mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q)) { + if (mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q, uid)) { return false; } throw new SecurityException(TAG + ": Permission denied"); @@ -2334,7 +2335,7 @@ public class WifiServiceImpl extends BaseWifiService { mAppOps.checkPackage(uid, packageName); if (!mWifiPermissionsUtil.checkNetworkSettingsPermission(uid) && !mWifiPermissionsUtil.checkNetworkSetupWizardPermission(uid)) { - if (mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q)) { + if (mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q, uid)) { return new ArrayList<>(); } throw new SecurityException(TAG + ": Permission denied"); diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java index 1ac73aef8..5832ee898 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java @@ -1286,7 +1286,7 @@ public class WifiAwareDataPathStateManager { // Note: checks are done on the manager. This is a backup for apps which bypass the // check. if (!allowNdpResponderFromAnyOverride && !wifiPermissionsUtil.isTargetSdkLessThan( - client.getCallingPackage(), Build.VERSION_CODES.P)) { + client.getCallingPackage(), Build.VERSION_CODES.P, uid)) { if (ns.type != WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_IB && ns.type != WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_OOB) { Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns diff --git a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java index 2834ad765..b1ceaf37a 100644 --- a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java +++ b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java @@ -124,10 +124,11 @@ public class WifiPermissionsUtil { /** * Checks whether than the target SDK of the package is less than the specified version code. */ - public boolean isTargetSdkLessThan(String packageName, int versionCode) { + public boolean isTargetSdkLessThan(String packageName, int versionCode, int callingUid) { long ident = Binder.clearCallingIdentity(); try { - if (mContext.getPackageManager().getApplicationInfo(packageName, 0).targetSdkVersion + if (mContext.getPackageManager().getApplicationInfoAsUser( + packageName, 0, UserHandle.getUserId(callingUid)).targetSdkVersion < versionCode) { return true; } @@ -153,7 +154,7 @@ public class WifiPermissionsUtil { */ public boolean checkCallersLocationPermission(String pkgName, int uid, boolean coarseForTargetSdkLessThanQ) { - boolean isTargetSdkLessThanQ = isTargetSdkLessThan(pkgName, Build.VERSION_CODES.Q); + boolean isTargetSdkLessThanQ = isTargetSdkLessThan(pkgName, Build.VERSION_CODES.Q, uid); String permissionType = Manifest.permission.ACCESS_FINE_LOCATION; if (coarseForTargetSdkLessThanQ && isTargetSdkLessThanQ) { |