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

Commit 92162b99 authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

feat:8489: MR review fixes.

parent 6efe72f2
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.location.LocationResult;
import android.location.LocationManager;
import android.location.util.identity.CallerIdentity;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
@@ -117,7 +118,7 @@ public class FakeLocationResolver {
        }

        final String fakeProvider = (provider != null) ? provider : FAKE_LOCATION_PROVIDER;
        return buildFakeLocationObject(latLon, provider);
        return buildFakeLocationObject(latLon, fakeProvider);
    }

    public static boolean deliverFakeLocationQuickly(
@@ -155,12 +156,12 @@ public class FakeLocationResolver {
    }

    private static @Nullable FakeLocation getFakeLocation(@NonNull Context context, @NonNull String packageName, int uid) {
        // getContentResolver requires that
        // binder.getCallingUId() and context.getOpPackageName() are coherent.
        final long ident = Binder.clearCallingIdentity();
        try {
            final Bundle extra = new Bundle();
            extra.putInt(PARAM_UID, uid);
            // getContentResolver requires that
            // binder.getCallingUId() and context.getOpPackageName() are coherent.
            // which may require Binder.clearCallingIdentity() calls.
            final Bundle result = context.getContentResolver().call(
                    Uri.parse(FAKE_LOCATIONS_URI),
                    "",
@@ -173,6 +174,8 @@ public class FakeLocationResolver {
            }
        } catch(Exception e) {
            Log.w(TAG, "Can't getFakeLocation", e);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
        return null;
    }
+34 −37
Original line number Diff line number Diff line
@@ -1752,16 +1752,7 @@ public class LocationProviderManager extends
            return null;
        }

        Location fakeLocation = null;
        synchronized (mMultiplexerLock) {
            final long ident = Binder.clearCallingIdentity();
            try {
                fakeLocation = FakeLocationResolver.buildFakeLocation(mContext, identity, null);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }

        Location fakeLocation = FakeLocationResolver.buildFakeLocation(mContext, identity, null);
        Location location = null;
        if (fakeLocation != null) {
            location = fakeLocation;
@@ -1926,6 +1917,15 @@ public class LocationProviderManager extends
                    .build();
        }

        if (FakeLocationResolver.deliverFakeLocationQuickly(
                mContext,
                identity,
                new GetCurrentLocationTransport(callback),
                request.getProvider()
        )) {
            return CancellationSignal.createTransport();
        }

        GetCurrentLocationListenerRegistration registration =
                new GetCurrentLocationListenerRegistration(
                        request,
@@ -1937,18 +1937,11 @@ public class LocationProviderManager extends
            Preconditions.checkState(mState != STATE_STOPPED);
            final long ident = Binder.clearCallingIdentity();
            try {
                if (!FakeLocationResolver.deliverFakeLocationQuickly(
                        mContext,
                        identity,
                        new GetCurrentLocationTransport(callback),
                        request.getProvider()
                )) {
                putRegistration(callback.asBinder(), registration);
                if (!registration.isActive()) {
                    // if the registration never activated, fail it immediately
                    registration.deliverNull();
                }
                }
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
@@ -1988,6 +1981,15 @@ public class LocationProviderManager extends

    public void registerLocationRequest(LocationRequest request, CallerIdentity identity,
            @PermissionLevel int permissionLevel, ILocationListener listener) {
        if (FakeLocationResolver.deliverFakeLocationQuickly(
                mContext,
                identity,
                new LocationListenerTransport(listener),
                request.getProvider()
        )) {
            return;
        }

        LocationListenerRegistration registration = new LocationListenerRegistration(
                request,
                identity,
@@ -1998,14 +2000,7 @@ public class LocationProviderManager extends
            Preconditions.checkState(mState != STATE_STOPPED);
            final long ident = Binder.clearCallingIdentity();
            try {
                if (!FakeLocationResolver.deliverFakeLocationQuickly(
                        mContext,
                        identity,
                        new LocationListenerTransport(listener),
                        request.getProvider()
                )) {
                putRegistration(listener.asBinder(), registration);
                }
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
@@ -2014,6 +2009,15 @@ public class LocationProviderManager extends

    public void registerLocationRequest(LocationRequest request, CallerIdentity callerIdentity,
            @PermissionLevel int permissionLevel, PendingIntent pendingIntent) {
        if (FakeLocationResolver.deliverFakeLocationQuickly(
                mContext,
                callerIdentity,
                new LocationPendingIntentTransport(mContext, pendingIntent),
                request.getProvider()
        )) {
            return;
        }

        LocationPendingIntentRegistration registration = new LocationPendingIntentRegistration(
                request,
                callerIdentity,
@@ -2024,14 +2028,7 @@ public class LocationProviderManager extends
            Preconditions.checkState(mState != STATE_STOPPED);
            final long identity = Binder.clearCallingIdentity();
            try {
                if (!FakeLocationResolver.deliverFakeLocationQuickly(
                        mContext,
                        callerIdentity,
                        new LocationPendingIntentTransport(mContext, pendingIntent),
                        request.getProvider()
                )) {
                putRegistration(pendingIntent, registration);
                }
            } finally {
                Binder.restoreCallingIdentity(identity);
            }