summaryrefslogtreecommitdiff
path: root/location/java
diff options
context:
space:
mode:
author Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2020-03-09 22:00:44 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2020-03-09 22:00:44 +0000
commit5eb75138e11cd0dd13e4c49be2f95ffd888fd394 (patch)
tree5850f539040506e0bab37449500bf18b7603375c /location/java
parentd730326ac22d0c1858c5994cc1ff7d677082fea3 (diff)
parentb62baf2ea9c7a10d46afae514dd1b5b1ea722835 (diff)
Merge "Restore legacy SecurityException behavior" into rvc-dev am: 0ea91490c5 am: 9942a42bd6 am: 963cc1a02f am: d1b373fef8 am: b62baf2ea9
Change-Id: I95450ce350d170bf1997e6a3880cea4e0186e822
Diffstat (limited to 'location/java')
-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 0bf7add422cf..e394721f4dc5 100644
--- a/location/java/android/location/LocationManager.java
+++ b/location/java/android/location/LocationManager.java
@@ -104,6 +104,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.
*
@@ -1385,6 +1395,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) {