Loading services/core/java/com/android/server/location/FakeLocationResolver.java +7 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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( Loading Loading @@ -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), "", Loading @@ -173,6 +174,8 @@ public class FakeLocationResolver { } } catch(Exception e) { Log.w(TAG, "Can't getFakeLocation", e); } finally { Binder.restoreCallingIdentity(ident); } return null; } Loading services/core/java/com/android/server/location/provider/LocationProviderManager.java +34 −37 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading @@ -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); } Loading Loading @@ -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, Loading @@ -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); } Loading @@ -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, Loading @@ -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); } Loading Loading
services/core/java/com/android/server/location/FakeLocationResolver.java +7 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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( Loading Loading @@ -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), "", Loading @@ -173,6 +174,8 @@ public class FakeLocationResolver { } } catch(Exception e) { Log.w(TAG, "Can't getFakeLocation", e); } finally { Binder.restoreCallingIdentity(ident); } return null; } Loading
services/core/java/com/android/server/location/provider/LocationProviderManager.java +34 −37 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading @@ -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); } Loading Loading @@ -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, Loading @@ -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); } Loading @@ -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, Loading @@ -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); } Loading