Skip to content

Commit 779b774

Browse files
author
Victoria Lease
committed
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
1 parent 03f7ebf commit 779b774

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

location/java/android/location/Location.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@ public class Location implements Parcelable {
6060
public static final int FORMAT_SECONDS = 2;
6161

6262
/**
63+
* Bundle key for a version of the location that has been fed through
64+
* LocationFudger. Allows location providers to flag locations as being
65+
* safe for use with ACCESS_COARSE_LOCATION permission.
66+
*
6367
* @hide
6468
*/
6569
public static final String EXTRA_COARSE_LOCATION = "coarseLocation";
6670

6771
/**
72+
* Bundle key for a version of the location containing no GPS data.
73+
* Allows location providers to flag locations as being safe to
74+
* feed to LocationFudger.
75+
*
6876
* @hide
6977
*/
7078
public static final String EXTRA_NO_GPS_LOCATION = "noGPSLocation";

location/lib/java/com/android/location/provider/LocationProviderBase.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import android.content.Context;
2424
import android.location.ILocationManager;
2525
import android.location.Location;
26+
import android.location.LocationManager;
27+
import android.location.LocationRequest;
2628
import android.os.Bundle;
2729
import android.os.IBinder;
2830
import android.os.RemoteException;
@@ -58,6 +60,21 @@ public abstract class LocationProviderBase {
5860
private final ProviderProperties mProperties;
5961
private final IBinder mBinder;
6062

63+
/**
64+
* Bundle key for a version of the location containing no GPS data.
65+
* Allows location providers to flag locations as being safe to
66+
* feed to LocationFudger.
67+
*/
68+
public static final String EXTRA_NO_GPS_LOCATION = Location.EXTRA_NO_GPS_LOCATION;
69+
70+
/**
71+
* Name of the Fused location provider.
72+
*
73+
* <p>This provider combines inputs for all possible location sources
74+
* to provide the best possible Location fix.
75+
*/
76+
public static final String FUSED_PROVIDER = LocationManager.FUSED_PROVIDER;
77+
6178
private final class Service extends ILocationProvider.Stub {
6279
@Override
6380
public void enable() {

packages/FusedLocation/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ LOCAL_JAVA_LIBRARIES := com.android.location.provider
2323

2424
LOCAL_PACKAGE_NAME := FusedLocation
2525
LOCAL_CERTIFICATE := platform
26+
LOCAL_SDK_VERSION := current
2627

2728
include $(BUILD_PACKAGE)

packages/FusedLocation/src/com/android/location/fused/FusionEngine.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.PrintWriter;
2121
import java.util.HashMap;
2222

23+
import com.android.location.provider.LocationProviderBase;
2324
import com.android.location.provider.ProviderRequestUnbundled;
2425

2526
import android.content.Context;
@@ -29,6 +30,7 @@
2930
import android.location.LocationRequest;
3031
import android.os.Bundle;
3132
import android.os.Looper;
33+
import android.os.Parcelable;
3234
import android.os.SystemClock;
3335
import android.os.WorkSource;
3436
import android.util.Log;
@@ -41,6 +43,7 @@ public interface Callback {
4143
private static final String TAG = "FusedLocation";
4244
private static final String NETWORK = LocationManager.NETWORK_PROVIDER;
4345
private static final String GPS = LocationManager.GPS_PROVIDER;
46+
private static final String FUSED = LocationProviderBase.FUSED_PROVIDER;
4447

4548
public static final long SWITCH_ON_FRESHNESS_CLIFF_NS = 11 * 1000000000; // 11 seconds
4649

@@ -72,6 +75,7 @@ public FusionEngine(Context context, Looper looper) {
7275
mStats.get(GPS).available = mLocationManager.isProviderEnabled(GPS);
7376
mStats.put(NETWORK, new ProviderStats());
7477
mStats.get(NETWORK).available = mLocationManager.isProviderEnabled(NETWORK);
78+
7579
}
7680

7781
public void init(Callback callback) {
@@ -226,10 +230,24 @@ private void updateFusedLocation() {
226230
} else {
227231
mFusedLocation = new Location(mNetworkLocation);
228232
}
233+
mFusedLocation.setProvider(FUSED);
229234
if (mNetworkLocation != null) {
230-
mFusedLocation.setExtraLocation(Location.EXTRA_NO_GPS_LOCATION, mNetworkLocation);
235+
// copy NO_GPS_LOCATION extra from mNetworkLocation into mFusedLocation
236+
Bundle srcExtras = mNetworkLocation.getExtras();
237+
if (srcExtras != null) {
238+
Parcelable srcParcelable =
239+
srcExtras.getParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION);
240+
if (srcParcelable instanceof Location) {
241+
Bundle dstExtras = mFusedLocation.getExtras();
242+
if (dstExtras == null) {
243+
dstExtras = new Bundle();
244+
mFusedLocation.setExtras(dstExtras);
245+
}
246+
dstExtras.putParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION,
247+
(Location) srcParcelable);
248+
}
249+
}
231250
}
232-
mFusedLocation.setProvider(LocationManager.FUSED_PROVIDER);
233251

234252
mCallback.reportLocation(mFusedLocation);
235253
}

0 commit comments

Comments
 (0)