diff options
author | Yu-Han Yang <yuhany@google.com> | 2021-01-06 10:01:08 -0800 |
---|---|---|
committer | Yu-Han Yang <yuhany@google.com> | 2021-01-12 16:08:30 -0800 |
commit | cc163bab25c8bacdb92b88d2e68bb9926594597c (patch) | |
tree | 3f55073f54a370668914691f19e92ec9c8ec65c8 | |
parent | 77ff851a5797d492cedc50f65be51b21dc083685 (diff) |
Remove indoorProbability from NLP extras before delivering to clients
Bug: 176905795
Test: on device
Change-Id: I56f0a2f117acfa9971222980acc7ed9f273da820
-rw-r--r-- | location/lib/java/com/android/location/provider/LocationProviderBase.java | 47 |
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 47e425629783..746f8ff900b8 100644 --- a/location/lib/java/com/android/location/provider/LocationProviderBase.java +++ b/location/lib/java/com/android/location/provider/LocationProviderBase.java @@ -91,6 +91,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; @@ -257,21 +261,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); @@ -283,6 +273,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(); |