Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5eb75138 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Restore legacy SecurityException behavior" into rvc-dev am: 0ea91490...

Merge "Restore legacy SecurityException behavior" into rvc-dev am: 0ea91490 am: 9942a42b am: 963cc1a0 am: d1b373fe am: b62baf2e

Change-Id: I95450ce350d170bf1997e6a3880cea4e0186e822
parents d730326a b62baf2e
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -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.
@@ -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) {