summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2021-01-13 19:57:55 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-01-13 19:57:55 +0000
commiteeed46fd0b3c297e27f17b80b86cd264ac4e93d5 (patch)
tree70c78f7d5b156baf774743b78582fbb292f283f7
parent79745b3cae2c715386b8efcf01662dd26b48f527 (diff)
parentcc163bab25c8bacdb92b88d2e68bb9926594597c (diff)
Merge "Remove indoorProbability from NLP extras before delivering to clients"
-rw-r--r--location/lib/java/com/android/location/provider/LocationProviderBase.java47
1 files changed, 32 insertions, 15 deletions
diff --git a/location/lib/java/com/android/location/provider/LocationProviderBase.java b/location/lib/java/com/android/location/provider/LocationProviderBase.java
index b545a834529d..aea93ce80e9b 100644
--- a/location/lib/java/com/android/location/provider/LocationProviderBase.java
+++ b/location/lib/java/com/android/location/provider/LocationProviderBase.java
@@ -94,6 +94,10 @@ public abstract class LocationProviderBase {
*/
public static final String FUSED_PROVIDER = LocationManager.FUSED_PROVIDER;
+ private static final String EXTRA_KEY_COARSE_LOCATION = "coarseLocation";
+ private static final String EXTRA_KEY_NO_GPS_LOCATION = "noGPSLocation";
+ private static final String EXTRA_KEY_INDOOR_PROB = "indoorProbability";
+
final String mTag;
@Nullable final String mPackageName;
@Nullable final String mAttributionTag;
@@ -260,21 +264,7 @@ public abstract class LocationProviderBase {
public void reportLocation(LocationResult locationResult) {
ILocationProviderManager manager = mManager;
if (manager != null) {
- locationResult = locationResult.map(location -> {
- // remove deprecated extras to save on serialization costs
- Bundle extras = location.getExtras();
- if (extras != null && (extras.containsKey("noGPSLocation")
- || extras.containsKey("coarseLocation"))) {
- location = new Location(location);
- extras = location.getExtras();
- extras.remove("noGPSLocation");
- extras.remove("coarseLocation");
- if (extras.isEmpty()) {
- location.setExtras(null);
- }
- }
- return location;
- });
+ locationResult = locationResult.map(this::cleanUpExtras);
try {
manager.onReportLocation(locationResult);
@@ -286,6 +276,33 @@ public abstract class LocationProviderBase {
}
}
+ /**
+ * Remove deprecated/unnecessary extras to save on serialization costs.
+ *
+ * {@link #EXTRA_KEY_NO_GPS_LOCATION} and {@link #EXTRA_KEY_COARSE_LOCATION} are deprecated.
+ *
+ * {@link #EXTRA_KEY_INDOOR_PROB} should only be used in the framework.
+ */
+ private Location cleanUpExtras(Location location) {
+ Bundle extras = location.getExtras();
+ if (extras == null) {
+ return location;
+ }
+ if (extras.containsKey(EXTRA_KEY_NO_GPS_LOCATION)
+ || extras.containsKey(EXTRA_KEY_COARSE_LOCATION)
+ || extras.containsKey(EXTRA_KEY_INDOOR_PROB)) {
+ location = new Location(location);
+ extras = location.getExtras();
+ extras.remove(EXTRA_KEY_NO_GPS_LOCATION);
+ extras.remove(EXTRA_KEY_COARSE_LOCATION);
+ extras.remove(EXTRA_KEY_INDOOR_PROB);
+ if (extras.isEmpty()) {
+ location.setExtras(null);
+ }
+ }
+ return location;
+ }
+
protected void onInit() {
// call once so that providers designed for APIs pre-Q are not broken
onEnable();