diff options
author | Soonil Nagarkar <sooniln@google.com> | 2020-03-28 13:59:26 -0700 |
---|---|---|
committer | Soonil Nagarkar <sooniln@google.com> | 2020-03-28 13:59:26 -0700 |
commit | 39766392a7100dd4f7ec163510223b4a901f6e94 (patch) | |
tree | 129e08ce5164462a13b76136e2f40e20cf5366a5 /location | |
parent | 810c90c70e038d12adee25beac20cbd9523bcd4d (diff) |
DO NOT MERGE Refactor appops across location
-Add a new app ops helper to make testing easier.
-Consolidate app identity within CallerIdentity class.
-Remove location age restriction for coarse locations, was a bit
arbitrary.
-Remove listener identifiers from LM. These were not being properly
propagated and add a lot of binder overhead with what appears to be
little benefit since we have featureIds, which contain much better
information.
-Remove appops checks from some GNSS APIs that shouldn't require it.
-Move location fudger into location providers and reset them after mock
providers are used so that offset information cannot be leaked.
Bug: 149375028
Test: presubmits + manual
(cherry picked from commit 6033344baaa8aa10b89a779864b7f5f82f4baf32)
Change-Id: I18e2cf3c39836f31d28180e1a4613df4ad675ab7
Diffstat (limited to 'location')
-rw-r--r-- | location/java/android/location/ILocationManager.aidl | 35 | ||||
-rw-r--r-- | location/java/android/location/Location.java | 10 | ||||
-rw-r--r-- | location/java/android/location/LocationManager.java | 57 |
3 files changed, 47 insertions, 55 deletions
diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl index 8600dc48c6a4..415092623531 100644 --- a/location/java/android/location/ILocationManager.aidl +++ b/location/java/android/location/ILocationManager.aidl @@ -47,16 +47,14 @@ interface ILocationManager Location getLastLocation(in LocationRequest request, String packageName, String featureId); boolean getCurrentLocation(in LocationRequest request, in ICancellationSignal cancellationSignal, in ILocationListener listener, - String packageName, String featureId, String listenerIdentifier); + String packageName, String featureId); void requestLocationUpdates(in LocationRequest request, in ILocationListener listener, - in PendingIntent intent, String packageName, String featureId, - String listenerIdentifier); - void removeUpdates(in ILocationListener listener, in PendingIntent intent, String packageName); + in PendingIntent intent, String packageName, String featureId); + void removeUpdates(in ILocationListener listener, in PendingIntent intent); void requestGeofence(in LocationRequest request, in Geofence geofence, - in PendingIntent intent, String packageName, String featureId, - String listenerIdentifier); + in PendingIntent intent, String packageName, String featureId); void removeGeofence(in Geofence fence, in PendingIntent intent, String packageName); boolean registerGnssStatusCallback(IGnssStatusListener callback, String packageName, @@ -73,34 +71,31 @@ interface ILocationManager boolean addGnssMeasurementsListener(in GnssRequest request, in IGnssMeasurementsListener listener, - String packageName, String featureId, - String listenerIdentifier); + String packageName, String featureId); void injectGnssMeasurementCorrections(in GnssMeasurementCorrections corrections, in String packageName); - long getGnssCapabilities(in String packageName); + long getGnssCapabilities(); void removeGnssMeasurementsListener(in IGnssMeasurementsListener listener); boolean addGnssAntennaInfoListener(in IGnssAntennaInfoListener listener, - String packageName, String featureId, String listenerIdentifier); + String packageName, String featureId); void removeGnssAntennaInfoListener(in IGnssAntennaInfoListener listener); boolean addGnssNavigationMessageListener(in IGnssNavigationMessageListener listener, - String packageName, String featureId, String listenerIdentifier); + String packageName, String featureId); void removeGnssNavigationMessageListener(in IGnssNavigationMessageListener listener); int getGnssYearOfHardware(); String getGnssHardwareModelName(); int getGnssBatchSize(String packageName); - boolean addGnssBatchingCallback(in IBatchedLocationCallback callback, String packageName, - String featureId, String listenerIdentifier); + boolean addGnssBatchingCallback(in IBatchedLocationCallback callback, String packageName, String featureId); void removeGnssBatchingCallback(); - boolean startGnssBatch(long periodNanos, boolean wakeOnFifoFull, String packageName); + boolean startGnssBatch(long periodNanos, boolean wakeOnFifoFull, String packageName, String featureId); void flushGnssBatch(String packageName); boolean stopGnssBatch(); void injectLocation(in Location location); - @UnsupportedAppUsage List<String> getAllProviders(); List<String> getProviders(in Criteria criteria, boolean enabledOnly); String getBestProvider(in Criteria criteria, boolean enabledOnly); @@ -116,11 +111,11 @@ interface ILocationManager boolean isProviderEnabledForUser(String provider, int userId); boolean isLocationEnabledForUser(int userId); void setLocationEnabledForUser(boolean enabled, int userId); - void addTestProvider(String name, in ProviderProperties properties, String opPackageName); - void removeTestProvider(String provider, String opPackageName); - void setTestProviderLocation(String provider, in Location loc, String opPackageName); - void setTestProviderEnabled(String provider, boolean enabled, String opPackageName); - List<LocationRequest> getTestProviderCurrentRequests(String provider, String opPackageName); + void addTestProvider(String name, in ProviderProperties properties, String packageName, String featureId); + void removeTestProvider(String provider, String packageName, String featureId); + void setTestProviderLocation(String provider, in Location location, String packageName, String featureId); + void setTestProviderEnabled(String provider, boolean enabled, String packageName, String featureId); + List<LocationRequest> getTestProviderCurrentRequests(String provider); LocationTime getGnssTimeMillis(); boolean sendExtraCommand(String provider, String command, inout Bundle extras); diff --git a/location/java/android/location/Location.java b/location/java/android/location/Location.java index 6724324bfcb9..9aa0c870e512 100644 --- a/location/java/android/location/Location.java +++ b/location/java/android/location/Location.java @@ -585,6 +585,16 @@ public class Location implements Parcelable { return mElapsedRealtimeNanos; } + /** @hide */ + public long getElapsedRealtimeAgeNanos(long referenceRealtimeNs) { + return referenceRealtimeNs - mElapsedRealtimeNanos; + } + + /** @hide */ + public long getElapsedRealtimeAgeNanos() { + return getElapsedRealtimeAgeNanos(SystemClock.elapsedRealtimeNanos()); + } + /** * Set the time of this fix, in elapsed real-time since system boot. * diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index ff7049ee565b..fcbd3e540291 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -652,19 +652,6 @@ public class LocationManager { } /** - * Create a string that allows an app to identify a listener - * - * @param listener The listener - * - * @return A identifying string - */ - private static String getListenerIdentifier(@NonNull Object listener) { - return listener.getClass().getName() - + '@' - + Integer.toHexString(System.identityHashCode(listener)); - } - - /** * Asynchronously returns a single current location fix. This may activate sensors in order to * compute a new location, unlike {@link #getLastKnownLocation(String)}, which will only return * a cached fix if available. The given callback will be invoked once and only once, either with @@ -742,8 +729,7 @@ public class LocationManager { try { if (mService.getCurrentLocation(currentLocationRequest, remoteCancellationSignal, - listenerTransport, mContext.getPackageName(), mContext.getAttributionTag(), - getListenerIdentifier(consumer))) { + listenerTransport, mContext.getPackageName(), mContext.getAttributionTag())) { listenerTransport.register(mContext.getSystemService(AlarmManager.class), remoteCancellationSignal); if (cancellationSignal != null) { @@ -1189,8 +1175,7 @@ public class LocationManager { boolean registered = false; try { mService.requestLocationUpdates(locationRequest, transport, null, - mContext.getPackageName(), mContext.getAttributionTag(), - getListenerIdentifier(listener)); + mContext.getPackageName(), mContext.getAttributionTag()); registered = true; } catch (RemoteException e) { throw e.rethrowFromSystemServer(); @@ -1235,8 +1220,7 @@ public class LocationManager { try { mService.requestLocationUpdates(locationRequest, null, pendingIntent, - mContext.getPackageName(), mContext.getAttributionTag(), - getListenerIdentifier(pendingIntent)); + mContext.getPackageName(), mContext.getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1293,7 +1277,7 @@ public class LocationManager { transport.unregister(); try { - mService.removeUpdates(transport, null, mContext.getPackageName()); + mService.removeUpdates(transport, null); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1312,7 +1296,7 @@ public class LocationManager { Preconditions.checkArgument(pendingIntent != null, "invalid null pending intent"); try { - mService.removeUpdates(null, pendingIntent, mContext.getPackageName()); + mService.removeUpdates(null, pendingIntent); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1515,7 +1499,8 @@ public class LocationManager { requiresSatellite, requiresCell, hasMonetaryCost, supportsAltitude, supportsSpeed, supportsBearing, powerRequirement, accuracy); try { - mService.addTestProvider(provider, properties, mContext.getOpPackageName()); + mService.addTestProvider(provider, properties, mContext.getOpPackageName(), + mContext.getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1536,7 +1521,8 @@ public class LocationManager { Preconditions.checkArgument(provider != null, "invalid null provider"); try { - mService.removeTestProvider(provider, mContext.getOpPackageName()); + mService.removeTestProvider(provider, mContext.getOpPackageName(), + mContext.getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1570,7 +1556,8 @@ public class LocationManager { } try { - mService.setTestProviderLocation(provider, location, mContext.getOpPackageName()); + mService.setTestProviderLocation(provider, location, mContext.getOpPackageName(), + mContext.getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1599,7 +1586,8 @@ public class LocationManager { Preconditions.checkArgument(provider != null, "invalid null provider"); try { - mService.setTestProviderEnabled(provider, enabled, mContext.getOpPackageName()); + mService.setTestProviderEnabled(provider, enabled, mContext.getOpPackageName(), + mContext.getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1643,8 +1631,7 @@ public class LocationManager { public List<LocationRequest> getTestProviderCurrentRequests(String providerName) { Preconditions.checkArgument(providerName != null, "invalid null provider"); try { - return mService.getTestProviderCurrentRequests(providerName, - mContext.getOpPackageName()); + return mService.getTestProviderCurrentRequests(providerName); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1711,7 +1698,7 @@ public class LocationManager { LocationRequest request = new LocationRequest().setExpireIn(expiration); try { mService.requestGeofence(request, fence, intent, mContext.getPackageName(), - mContext.getAttributionTag(), getListenerIdentifier(intent)); + mContext.getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1798,7 +1785,7 @@ public class LocationManager { try { mService.requestGeofence(request, fence, intent, mContext.getPackageName(), - mContext.getAttributionTag(), getListenerIdentifier(intent)); + mContext.getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1867,7 +1854,7 @@ public class LocationManager { */ public @NonNull GnssCapabilities getGnssCapabilities() { try { - long gnssCapabilities = mService.getGnssCapabilities(mContext.getPackageName()); + long gnssCapabilities = mService.getGnssCapabilities(); if (gnssCapabilities == GnssCapabilities.INVALID_CAPABILITIES) { gnssCapabilities = 0L; } @@ -2493,7 +2480,7 @@ public class LocationManager { try { if (mBatchedLocationCallbackManager.addListener(callback, handler)) { return mService.startGnssBatch(periodNanos, wakeOnFifoFull, - mContext.getPackageName()); + mContext.getPackageName(), mContext.getAttributionTag()); } return false; } catch (RemoteException e) { @@ -3012,7 +2999,7 @@ public class LocationManager { GnssMeasurementsListener transport = new GnssMeasurementsListener(); if (mService.addGnssMeasurementsListener(request, transport, mContext.getPackageName(), - mContext.getAttributionTag(), "gnss measurement callback")) { + mContext.getAttributionTag())) { mListenerTransport = transport; return true; } else { @@ -3065,7 +3052,7 @@ public class LocationManager { GnssNavigationMessageListener transport = new GnssNavigationMessageListener(); if (mService.addGnssNavigationMessageListener(transport, mContext.getPackageName(), - mContext.getAttributionTag(), "gnss navigation callback")) { + mContext.getAttributionTag())) { mListenerTransport = transport; return true; } else { @@ -3106,7 +3093,7 @@ public class LocationManager { GnssAntennaInfoListener transport = new GnssAntennaInfoListener(); if (mService.addGnssAntennaInfoListener(transport, mContext.getPackageName(), - mContext.getAttributionTag(), "gnss antenna info callback")) { + mContext.getAttributionTag())) { mListenerTransport = transport; return true; } else { @@ -3143,7 +3130,7 @@ public class LocationManager { BatchedLocationCallback transport = new BatchedLocationCallback(); if (mService.addGnssBatchingCallback(transport, mContext.getPackageName(), - mContext.getAttributionTag(), "batched location callback")) { + mContext.getAttributionTag())) { mListenerTransport = transport; return true; } else { |