diff options
| author | Xin Li <delphij@google.com> | 2020-08-31 21:21:38 -0700 |
|---|---|---|
| committer | Xin Li <delphij@google.com> | 2020-08-31 21:21:38 -0700 |
| commit | 628590d7ec80e10a3fc24b1c18a1afb55cca10a8 (patch) | |
| tree | 4b1c3f52d86d7fb53afbe9e9438468588fa489f8 /telephony/common/android | |
| parent | b11b8ec3aec8bb42f2c07e1c5ac7942da293baa8 (diff) | |
| parent | d2d3a20624d968199353ccf6ddbae6f3ac39c9af (diff) | |
Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709)
Bug: 166295507
Merged-In: I3d92a6de21a938f6b352ec26dc23420c0fe02b27
Change-Id: Ifdb80563ef042738778ebb8a7581a97c4e3d96e2
Diffstat (limited to 'telephony/common/android')
| -rw-r--r-- | telephony/common/android/telephony/LocationAccessPolicy.java | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/telephony/common/android/telephony/LocationAccessPolicy.java b/telephony/common/android/telephony/LocationAccessPolicy.java index 892e55942d3f..1985f7810873 100644 --- a/telephony/common/android/telephony/LocationAccessPolicy.java +++ b/telephony/common/android/telephony/LocationAccessPolicy.java @@ -24,20 +24,16 @@ import android.app.ActivityManager; import android.app.AppOpsManager; import android.content.Context; import android.content.pm.PackageManager; -import android.content.pm.UserInfo; import android.location.LocationManager; import android.os.Binder; import android.os.Build; import android.os.Process; import android.os.UserHandle; -import android.os.UserManager; import android.util.Log; import android.widget.Toast; import com.android.internal.telephony.util.TelephonyUtils; -import java.util.List; - /** * Helper for performing location access checks. * @hide @@ -111,6 +107,9 @@ public final class LocationAccessPolicy { return this; } + /** + * Mandatory parameter, used for performing permission checks. + */ public Builder setCallingUid(int callingUid) { mCallingUid = callingUid; return this; @@ -195,6 +194,17 @@ public final class LocationAccessPolicy { } } + private static String getAppOpsString(String manifestPermission) { + switch (manifestPermission) { + case Manifest.permission.ACCESS_FINE_LOCATION: + return AppOpsManager.OPSTR_FINE_LOCATION; + case Manifest.permission.ACCESS_COARSE_LOCATION: + return AppOpsManager.OPSTR_COARSE_LOCATION; + default: + return null; + } + } + private static LocationPermissionResult checkAppLocationPermissionHelper(Context context, LocationPermissionQuery query, String permissionToCheck) { String locationTypeForLog = @@ -208,8 +218,8 @@ public final class LocationAccessPolicy { if (hasManifestPermission) { // Only check the app op if the app has the permission. int appOpMode = context.getSystemService(AppOpsManager.class) - .noteOpNoThrow(AppOpsManager.permissionToOpCode(permissionToCheck), - query.callingUid, query.callingPackage); + .noteOpNoThrow(getAppOpsString(permissionToCheck), query.callingUid, + query.callingPackage, query.callingFeatureId, null); if (appOpMode == AppOpsManager.MODE_ALLOWED) { // If the app did everything right, return without logging. return LocationPermissionResult.ALLOWED; @@ -295,7 +305,7 @@ public final class LocationAccessPolicy { } private static boolean checkSystemLocationAccess(@NonNull Context context, int uid, int pid) { - if (!isLocationModeEnabled(context, UserHandle.getUserId(uid))) { + if (!isLocationModeEnabled(context, UserHandle.getUserHandleForUid(uid).getIdentifier())) { if (DBG) Log.w(TAG, "Location disabled, failed, (" + uid + ")"); return false; } @@ -322,20 +332,17 @@ public final class LocationAccessPolicy { private static boolean isCurrentProfile(@NonNull Context context, int uid) { long token = Binder.clearCallingIdentity(); try { - final int currentUser = ActivityManager.getCurrentUser(); - final int callingUserId = UserHandle.getUserId(uid); - if (callingUserId == currentUser) { + if (UserHandle.getUserHandleForUid(uid).getIdentifier() + == ActivityManager.getCurrentUser()) { return true; + } + ActivityManager activityManager = context.getSystemService(ActivityManager.class); + if (activityManager != null) { + return activityManager.isProfileForeground( + UserHandle.getUserHandleForUid(ActivityManager.getCurrentUser())); } else { - List<UserInfo> userProfiles = context.getSystemService( - UserManager.class).getProfiles(currentUser); - for (UserInfo user : userProfiles) { - if (user.id == callingUserId) { - return true; - } - } + return false; } - return false; } finally { Binder.restoreCallingIdentity(token); } |
