summaryrefslogtreecommitdiff
path: root/location
diff options
context:
space:
mode:
authorSoonil Nagarkar <sooniln@google.com>2020-03-08 20:08:23 -0700
committerSoonil Nagarkar <sooniln@google.com>2020-03-09 03:15:51 +0000
commitbf016bb7ea8faa68e0fddfec68c588903229c281 (patch)
tree0fb2294ce442bd6a1b8c5214e5c53a7dea0c0fb4 /location
parent82f3ed2925a9520e160165fdb39e0601400b453c (diff)
Restore legacy SecurityException behavior
For apps that do not target R+, throw SecurityExceptions within getProvider(). Bug: 150935354 Test: na Change-Id: I37e9fc1cbcc1cb6ed941c3905ff253d798fc0ac8
Diffstat (limited to 'location')
-rw-r--r--location/java/android/location/LocationManager.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java
index e2309178b297..550e41f28f85 100644
--- a/location/java/android/location/LocationManager.java
+++ b/location/java/android/location/LocationManager.java
@@ -103,6 +103,16 @@ public class LocationManager {
private final Object mLock = new Object();
/**
+ * For apps targeting Android R and above, {@link #getProvider(String)} will no longer throw any
+ * security exceptions.
+ *
+ * @hide
+ */
+ @ChangeId
+ @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
+ private static final long GET_PROVIDER_SECURITY_EXCEPTIONS = 150935354L;
+
+ /**
* For apps targeting Android K and above, supplied {@link PendingIntent}s must be targeted to a
* specific package.
*
@@ -1401,6 +1411,22 @@ public class LocationManager {
*/
public @Nullable LocationProvider getProvider(@NonNull String provider) {
Preconditions.checkArgument(provider != null, "invalid null provider");
+
+ if (!Compatibility.isChangeEnabled(GET_PROVIDER_SECURITY_EXCEPTIONS)) {
+ if (NETWORK_PROVIDER.equals(provider) || FUSED_PROVIDER.equals(provider)) {
+ try {
+ mContext.enforcePermission(ACCESS_FINE_LOCATION, Process.myPid(),
+ Process.myUid(), null);
+ } catch (SecurityException e) {
+ mContext.enforcePermission(ACCESS_COARSE_LOCATION, Process.myPid(),
+ Process.myUid(), null);
+ }
+ } else {
+ mContext.enforcePermission(ACCESS_FINE_LOCATION, Process.myPid(), Process.myUid(),
+ null);
+ }
+ }
+
try {
ProviderProperties properties = mService.getProviderProperties(provider);
if (properties == null) {