From 77a9227b19cb4afefbf14fb4616d2d917f9bffb5 Mon Sep 17 00:00:00 2001 From: Soonil Nagarkar Date: Tue, 11 Feb 2020 14:04:39 -0800 Subject: Fix work profile handling across location There were a couple problems with work profile state in location. First, we assumed that notifications sent to parent users would also be sent to profiles but this is not true. Second we had assumed location status in profiles was always identical to the parent user, but work profiles may have user restrictions applied which are not present on the parent user. The easiest way to handle these issues seems to be to expand LMS user handling to deal with all users, rather than making various assumptions which may or may not be true. This also means we need to store last locations on a per profile basis. Since we're refactoring how last location works completely, we also removed the special NO_GPS handling for last locations. With the new permission strings we now no longer have to exclude gnss based location from coarsening. This lets us: 1) deprecate and remove various constants and methods use for storing coarse locations tied to fine locations 2) substantially simplify code that calculated coarse location This also exposed numerous bugs in the location service where we were using the current user's state instead of the calling user's state, which could have exposed the current user's location to other users inappropriately. Bug: 148798374 Bug: 146071833 Test: presubmits + manual Change-Id: I2d3216a9fb58b73d0124d563b05de8870b70b716 --- location/java/android/location/ILocationManager.aidl | 2 +- location/java/android/location/Location.java | 13 ++++--------- location/java/android/location/LocationManager.java | 5 +++-- location/java/android/location/LocationManagerInternal.java | 9 +++++++++ 4 files changed, 17 insertions(+), 12 deletions(-) (limited to 'location/java') diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl index a99e68fbb7b6..7de4d89dfa4f 100644 --- a/location/java/android/location/ILocationManager.aidl +++ b/location/java/android/location/ILocationManager.aidl @@ -93,7 +93,7 @@ interface ILocationManager boolean startGnssBatch(long periodNanos, boolean wakeOnFifoFull, String packageName); void flushGnssBatch(String packageName); boolean stopGnssBatch(); - boolean injectLocation(in Location location); + void injectLocation(in Location location); @UnsupportedAppUsage List getAllProviders(); diff --git a/location/java/android/location/Location.java b/location/java/android/location/Location.java index eb76c29301c6..6724324bfcb9 100644 --- a/location/java/android/location/Location.java +++ b/location/java/android/location/Location.java @@ -63,24 +63,19 @@ public class Location implements Parcelable { */ public static final int FORMAT_SECONDS = 2; - /** - * Bundle key for a version of the location that has been fed through - * LocationFudger. Allows location providers to flag locations as being - * safe for use with ACCESS_COARSE_LOCATION permission. - * - * @hide - */ - public static final String EXTRA_COARSE_LOCATION = "coarseLocation"; - /** * Bundle key for a version of the location containing no GPS data. * Allows location providers to flag locations as being safe to * feed to LocationFudger. * * @hide + * @deprecated As of Android R, this extra is longer in use, since it is not necessary to keep + * gps locations separate from other locations for coarsening. Providers that do not need to + * support platforms below Android R should not use this constant. */ @TestApi @SystemApi + @Deprecated public static final String EXTRA_NO_GPS_LOCATION = "noGPSLocation"; /** diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index 8ae967fe79c2..0fec611bc522 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -1215,7 +1215,7 @@ public class LocationManager { * the first fix. * * @param location newly available {@link Location} object - * @return true if the location was successfully injected, false otherwise + * @return true if the location was injected, false otherwise * * @throws IllegalArgumentException if location is null * @throws SecurityException if permissions are not present @@ -1229,7 +1229,8 @@ public class LocationManager { "incomplete location object, missing timestamp or accuracy?"); try { - return mService.injectLocation(location); + mService.injectLocation(location); + return true; } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/location/java/android/location/LocationManagerInternal.java b/location/java/android/location/LocationManagerInternal.java index 69162bab3167..085602cbcd4f 100644 --- a/location/java/android/location/LocationManagerInternal.java +++ b/location/java/android/location/LocationManagerInternal.java @@ -42,6 +42,15 @@ public abstract class LocationManagerInternal { */ public abstract void requestSetProviderAllowed(@NonNull String provider, boolean allowed); + /** + * Returns true if the given provider is enabled for the given user. + * + * @param provider A location provider as listed by {@link LocationManager#getAllProviders()} + * @param userId The user id to check + * @return True if the provider is enabled, false otherwise + */ + public abstract boolean isProviderEnabledForUser(@NonNull String provider, int userId); + /** * Returns true if the given package belongs to a location provider, and so should be afforded * some special privileges. -- cgit v1.2.3-59-g8ed1b