diff options
author | Soonil Nagarkar <sooniln@google.com> | 2019-01-31 14:36:56 -0800 |
---|---|---|
committer | Soonil Nagarkar <sooniln@google.com> | 2019-02-04 10:58:24 -0800 |
commit | 0d77ea68937f382c36c3c122ebe504d4db2ca83f (patch) | |
tree | 8acb9d4b893bc3c3f47c99338a557427e6f02c81 /location/lib | |
parent | affa55b49baebce7ae1b8bb893e015379df83a49 (diff) |
Change provider packages API to test all providers
This will replace the LocationManager.getNetworkProviderPackage() API
with LocationManager.isProviderPackage(). The network provider should
not be considered special.
In addition, providers now have the ability to specify additional
packages that may make location requests on their behalf, so that those
packages can be considered location providers as well.
Bug: 117177078
Test: manually
Change-Id: I204b56e7bb40874ac3347988474fb8afa787feb8
Diffstat (limited to 'location/lib')
-rw-r--r-- | location/lib/api/current.txt | 1 | ||||
-rw-r--r-- | location/lib/java/com/android/location/provider/LocationProviderBase.java | 30 |
2 files changed, 31 insertions, 0 deletions
diff --git a/location/lib/api/current.txt b/location/lib/api/current.txt index c7212183a37e..67d64965ac96 100644 --- a/location/lib/api/current.txt +++ b/location/lib/api/current.txt @@ -19,6 +19,7 @@ package com.android.location.provider { method protected boolean onSendExtraCommand(@Nullable String, @Nullable android.os.Bundle); method protected abstract void onSetRequest(com.android.location.provider.ProviderRequestUnbundled, android.os.WorkSource); method public void reportLocation(android.location.Location); + method public void setAdditionalProviderPackages(java.util.List<java.lang.String>); method public void setEnabled(boolean); method public void setProperties(com.android.location.provider.ProviderPropertiesUnbundled); field public static final String EXTRA_NO_GPS_LOCATION = "noGPSLocation"; diff --git a/location/lib/java/com/android/location/provider/LocationProviderBase.java b/location/lib/java/com/android/location/provider/LocationProviderBase.java index 5bcec92c4fba..7cd7207c26a0 100644 --- a/location/lib/java/com/android/location/provider/LocationProviderBase.java +++ b/location/lib/java/com/android/location/provider/LocationProviderBase.java @@ -36,6 +36,8 @@ import com.android.internal.location.ProviderRequest; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; /** * Base class for location providers implemented as unbundled services. @@ -88,6 +90,7 @@ public abstract class LocationProviderBase { @Nullable private volatile ILocationProviderManager mManager; private volatile ProviderProperties mProperties; private volatile boolean mEnabled; + private final ArrayList<String> mAdditionalProviderPackages; public LocationProviderBase(String tag, ProviderPropertiesUnbundled properties) { mTag = tag; @@ -99,6 +102,7 @@ public abstract class LocationProviderBase { mManager = null; mProperties = properties.getProviderProperties(); mEnabled = true; + mAdditionalProviderPackages = new ArrayList<>(0); } public IBinder getBinder() { @@ -160,6 +164,29 @@ public abstract class LocationProviderBase { } /** + * Sets a list of additional packages that should be considered as part of this location + * provider for the purposes of generating locations. This should generally only be used when + * another package may issue location requests on behalf of this package in the course of + * providing location. This will inform location services to treat the other packages as + * location providers as well. + */ + public void setAdditionalProviderPackages(List<String> packageNames) { + synchronized (mBinder) { + mAdditionalProviderPackages.clear(); + mAdditionalProviderPackages.addAll(packageNames); + } + + ILocationProviderManager manager = mManager; + if (manager != null) { + try { + manager.onSetAdditionalProviderPackages(mAdditionalProviderPackages); + } catch (RemoteException | RuntimeException e) { + Log.w(mTag, e); + } + } + } + + /** * Returns true if this provider has been set as enabled. This will be true unless explicitly * set otherwise. */ @@ -275,6 +302,9 @@ public abstract class LocationProviderBase { public void setLocationProviderManager(ILocationProviderManager manager) { synchronized (mBinder) { try { + if (!mAdditionalProviderPackages.isEmpty()) { + manager.onSetAdditionalProviderPackages(mAdditionalProviderPackages); + } manager.onSetProperties(mProperties); manager.onSetEnabled(mEnabled); } catch (RemoteException e) { |