diff options
author | 2020-03-04 23:05:49 +0000 | |
---|---|---|
committer | 2020-03-04 23:05:49 +0000 | |
commit | 1eb8014bd2d07ad03de3ee17243bb48b1e513297 (patch) | |
tree | 2e059301b8790e349581425a9bd46bff6cacd107 /location/lib/java | |
parent | e445b758067f0fbe0796fab069a04aed2e1d1d06 (diff) | |
parent | 470c8f6a3f5a8f6d2c877019d1c22fc619eccad6 (diff) |
Merge "Give location providers a known identity"
Diffstat (limited to 'location/lib/java')
-rw-r--r-- | location/lib/java/com/android/location/provider/LocationProviderBase.java | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/location/lib/java/com/android/location/provider/LocationProviderBase.java b/location/lib/java/com/android/location/provider/LocationProviderBase.java index d3fb58fe257e..624e8d1b702b 100644 --- a/location/lib/java/com/android/location/provider/LocationProviderBase.java +++ b/location/lib/java/com/android/location/provider/LocationProviderBase.java @@ -39,7 +39,6 @@ import com.android.internal.location.ProviderRequest; import java.io.FileDescriptor; import java.io.PrintWriter; -import java.util.ArrayList; import java.util.List; /** @@ -65,7 +64,10 @@ public abstract class LocationProviderBase { * 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. + * + * @deprecated Do not use from Android R onwards. */ + @Deprecated public static final String EXTRA_NO_GPS_LOCATION = Location.EXTRA_NO_GPS_LOCATION; /** @@ -76,8 +78,9 @@ public abstract class LocationProviderBase { */ public static final String FUSED_PROVIDER = LocationManager.FUSED_PROVIDER; - private final String mTag; - private final IBinder mBinder; + final String mTag; + final String mFeatureId; + final IBinder mBinder; /** * This field may be removed in the future, do not rely on it. @@ -90,13 +93,30 @@ public abstract class LocationProviderBase { protected final ILocationManager mLocationManager; // write locked on mBinder, read lock is optional depending on atomicity requirements - @Nullable private volatile ILocationProviderManager mManager; - private volatile ProviderProperties mProperties; - private volatile boolean mAllowed; - private final ArrayList<String> mAdditionalProviderPackages; + @Nullable + volatile ILocationProviderManager mManager; + volatile ProviderProperties mProperties; + volatile boolean mAllowed; + /** + * @deprecated Prefer + * {@link #LocationProviderBase(Context, String, ProviderPropertiesUnbundled)}. + */ + @Deprecated public LocationProviderBase(String tag, ProviderPropertiesUnbundled properties) { + this(null, tag, properties); + } + + /** + * This constructor associates the feature id of the given context with this location provider. + * The location service may afford special privileges to incoming calls identified as belonging + * to this location provider. + */ + @RequiresApi(VERSION_CODES.R) + public LocationProviderBase(Context context, String tag, + ProviderPropertiesUnbundled properties) { mTag = tag; + mFeatureId = context != null ? context.getFeatureId() : null; mBinder = new Service(); mLocationManager = ILocationManager.Stub.asInterface( @@ -105,7 +125,6 @@ public abstract class LocationProviderBase { mManager = null; mProperties = properties.getProviderProperties(); mAllowed = true; - mAdditionalProviderPackages = new ArrayList<>(0); } public IBinder getBinder() { @@ -183,23 +202,12 @@ public abstract class LocationProviderBase { * 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. + * + * @deprecated On Android R and above this has no effect. */ + @Deprecated @RequiresApi(VERSION_CODES.Q) - 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); - } - } - } + public void setAdditionalProviderPackages(List<String> packageNames) {} /** * @deprecated Use {@link #isAllowed()} instead. @@ -317,12 +325,15 @@ public abstract class LocationProviderBase { private final class Service extends ILocationProvider.Stub { + Service() { + } + @Override public void setLocationProviderManager(ILocationProviderManager manager) { synchronized (mBinder) { try { - if (!mAdditionalProviderPackages.isEmpty()) { - manager.onSetAdditionalProviderPackages(mAdditionalProviderPackages); + if (mFeatureId != null) { + manager.onSetFeatureId(mFeatureId); } manager.onSetProperties(mProperties); manager.onSetAllowed(mAllowed); |