fix NLP for COARSE applications, build FLP with SDK
In this commit, we provide a means for unbundled location providers to attach an EXTRA_NO_GPS_LOCATION to the Locations that they report. We also build FusedLocation against the SDK rather than the internal tree. Used in conjunction with I394ded497b8de40d1f85618bff282553cdf378cb to fix NLP for applications with only ACCESS_COARSE_LOCATION permission. Bug: 7453355 Change-Id: Ie696f7abff9ef5237740ab87fe9f537a1c812c54
This commit is contained in:
@@ -60,11 +60,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
|
||||
*/
|
||||
public static final String EXTRA_NO_GPS_LOCATION = "noGPSLocation";
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.io.PrintWriter;
|
||||
import android.content.Context;
|
||||
import android.location.ILocationManager;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.location.LocationRequest;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
@@ -58,6 +60,21 @@ public abstract class LocationProviderBase {
|
||||
private final ProviderProperties mProperties;
|
||||
private final IBinder mBinder;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final String EXTRA_NO_GPS_LOCATION = Location.EXTRA_NO_GPS_LOCATION;
|
||||
|
||||
/**
|
||||
* Name of the Fused location provider.
|
||||
*
|
||||
* <p>This provider combines inputs for all possible location sources
|
||||
* to provide the best possible Location fix.
|
||||
*/
|
||||
public static final String FUSED_PROVIDER = LocationManager.FUSED_PROVIDER;
|
||||
|
||||
private final class Service extends ILocationProvider.Stub {
|
||||
@Override
|
||||
public void enable() {
|
||||
|
||||
@@ -23,5 +23,6 @@ LOCAL_JAVA_LIBRARIES := com.android.location.provider
|
||||
|
||||
LOCAL_PACKAGE_NAME := FusedLocation
|
||||
LOCAL_CERTIFICATE := platform
|
||||
LOCAL_SDK_VERSION := current
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.android.location.provider.LocationProviderBase;
|
||||
import com.android.location.provider.ProviderRequestUnbundled;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -29,6 +30,7 @@ import android.location.LocationManager;
|
||||
import android.location.LocationRequest;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.os.Parcelable;
|
||||
import android.os.SystemClock;
|
||||
import android.os.WorkSource;
|
||||
import android.util.Log;
|
||||
@@ -41,6 +43,7 @@ public class FusionEngine implements LocationListener {
|
||||
private static final String TAG = "FusedLocation";
|
||||
private static final String NETWORK = LocationManager.NETWORK_PROVIDER;
|
||||
private static final String GPS = LocationManager.GPS_PROVIDER;
|
||||
private static final String FUSED = LocationProviderBase.FUSED_PROVIDER;
|
||||
|
||||
public static final long SWITCH_ON_FRESHNESS_CLIFF_NS = 11 * 1000000000; // 11 seconds
|
||||
|
||||
@@ -72,6 +75,7 @@ public class FusionEngine implements LocationListener {
|
||||
mStats.get(GPS).available = mLocationManager.isProviderEnabled(GPS);
|
||||
mStats.put(NETWORK, new ProviderStats());
|
||||
mStats.get(NETWORK).available = mLocationManager.isProviderEnabled(NETWORK);
|
||||
|
||||
}
|
||||
|
||||
public void init(Callback callback) {
|
||||
@@ -226,10 +230,24 @@ public class FusionEngine implements LocationListener {
|
||||
} else {
|
||||
mFusedLocation = new Location(mNetworkLocation);
|
||||
}
|
||||
mFusedLocation.setProvider(FUSED);
|
||||
if (mNetworkLocation != null) {
|
||||
mFusedLocation.setExtraLocation(Location.EXTRA_NO_GPS_LOCATION, mNetworkLocation);
|
||||
// copy NO_GPS_LOCATION extra from mNetworkLocation into mFusedLocation
|
||||
Bundle srcExtras = mNetworkLocation.getExtras();
|
||||
if (srcExtras != null) {
|
||||
Parcelable srcParcelable =
|
||||
srcExtras.getParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION);
|
||||
if (srcParcelable instanceof Location) {
|
||||
Bundle dstExtras = mFusedLocation.getExtras();
|
||||
if (dstExtras == null) {
|
||||
dstExtras = new Bundle();
|
||||
mFusedLocation.setExtras(dstExtras);
|
||||
}
|
||||
dstExtras.putParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION,
|
||||
(Location) srcParcelable);
|
||||
}
|
||||
}
|
||||
}
|
||||
mFusedLocation.setProvider(LocationManager.FUSED_PROVIDER);
|
||||
|
||||
mCallback.reportLocation(mFusedLocation);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user