From f6a861a34fbfea24b47c988bb604d131f56d6278 Mon Sep 17 00:00:00 2001 From: Soonil Nagarkar Date: Tue, 29 Sep 2020 13:03:08 -0700 Subject: Add quality to LocationRequest/ProviderRequest Expose quality APIs publically after refactoring them to match external usage of quality constants. Removes list of location requests from provider request, as there is no client that really uses this, and it feels like too much information to give to providers. Bug: 168624248 Test: presubmits Change-Id: Icf8a9f6096da0071d97190d3f7196948492e52a1 --- .../server/location/LocationProviderManager.java | 34 ++++++++-------------- .../location/PassiveLocationProviderManager.java | 15 ++++------ .../server/location/gnss/GnssLocationProvider.java | 4 +-- .../location/LocationProviderManagerTest.java | 7 ----- 4 files changed, 20 insertions(+), 40 deletions(-) (limited to 'services') diff --git a/services/core/java/com/android/server/location/LocationProviderManager.java b/services/core/java/com/android/server/location/LocationProviderManager.java index 52065710f38e..179fb7d2f723 100644 --- a/services/core/java/com/android/server/location/LocationProviderManager.java +++ b/services/core/java/com/android/server/location/LocationProviderManager.java @@ -23,15 +23,12 @@ import static android.location.LocationManager.GPS_PROVIDER; import static android.location.LocationManager.KEY_LOCATION_CHANGED; import static android.location.LocationManager.KEY_PROVIDER_ENABLED; import static android.location.LocationManager.PASSIVE_PROVIDER; -import static android.location.LocationRequest.PASSIVE_INTERVAL; import static android.os.IPowerManager.LOCATION_MODE_NO_CHANGE; import static android.os.PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF; import static android.os.PowerManager.LOCATION_MODE_FOREGROUND_ONLY; import static android.os.PowerManager.LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF; import static android.os.PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF; -import static com.android.internal.location.ProviderRequest.EMPTY_REQUEST; -import static com.android.internal.location.ProviderRequest.INTERVAL_DISABLED; import static com.android.server.location.LocationManagerService.D; import static com.android.server.location.LocationManagerService.TAG; import static com.android.server.location.LocationPermissions.PERMISSION_COARSE; @@ -503,14 +500,7 @@ class LocationProviderManager extends LocationRequest.Builder builder = new LocationRequest.Builder(baseRequest); if (mPermissionLevel < PERMISSION_FINE) { - switch (baseRequest.getQuality()) { - case LocationRequest.ACCURACY_FINE: - builder.setQuality(LocationRequest.ACCURACY_BLOCK); - break; - case LocationRequest.POWER_HIGH: - builder.setQuality(LocationRequest.POWER_LOW); - break; - } + builder.setQuality(LocationRequest.QUALITY_LOW_POWER); if (baseRequest.getIntervalMillis() < MIN_COARSE_INTERVAL_MS) { builder.setIntervalMillis(MIN_COARSE_INTERVAL_MS); } @@ -1709,7 +1699,7 @@ class LocationProviderManager extends @Override protected boolean registerWithService(ProviderRequest request, Collection registrations) { - return reregisterWithService(EMPTY_REQUEST, request, registrations); + return reregisterWithService(ProviderRequest.EMPTY_REQUEST, request, registrations); } @GuardedBy("mLock") @@ -1778,8 +1768,8 @@ class LocationProviderManager extends Preconditions.checkState(Thread.holdsLock(mLock)); } - mLocationEventLog.logProviderUpdateRequest(mName, EMPTY_REQUEST); - mProvider.setRequest(EMPTY_REQUEST); + mLocationEventLog.logProviderUpdateRequest(mName, ProviderRequest.EMPTY_REQUEST); + mProvider.setRequest(ProviderRequest.EMPTY_REQUEST); } @GuardedBy("mLock") @@ -1839,27 +1829,27 @@ class LocationProviderManager extends Preconditions.checkState(Thread.holdsLock(mLock)); } - long intervalMs = INTERVAL_DISABLED; + long intervalMs = ProviderRequest.INTERVAL_DISABLED; + int quality = LocationRequest.QUALITY_LOW_POWER; boolean locationSettingsIgnored = false; boolean lowPower = true; - ArrayList locationRequests = new ArrayList<>(registrations.size()); for (Registration registration : registrations) { LocationRequest request = registration.getRequest(); // passive requests do not contribute to the provider request - if (request.getIntervalMillis() == PASSIVE_INTERVAL) { + if (request.getIntervalMillis() == LocationRequest.PASSIVE_INTERVAL) { continue; } intervalMs = min(request.getIntervalMillis(), intervalMs); + quality = min(request.getQuality(), quality); locationSettingsIgnored |= request.isLocationSettingsIgnored(); lowPower &= request.isLowPower(); - locationRequests.add(request); } - if (intervalMs == INTERVAL_DISABLED) { - return EMPTY_REQUEST; + if (intervalMs == ProviderRequest.INTERVAL_DISABLED) { + return ProviderRequest.EMPTY_REQUEST; } // calculate who to blame for power in a somewhat arbitrary fashion. we pick a threshold @@ -1872,7 +1862,7 @@ class LocationProviderManager extends } catch (ArithmeticException e) { // check for and handle overflow by setting to one below the passive interval so passive // requests are automatically skipped - thresholdIntervalMs = PASSIVE_INTERVAL - 1; + thresholdIntervalMs = LocationRequest.PASSIVE_INTERVAL - 1; } WorkSource workSource = new WorkSource(); @@ -1884,9 +1874,9 @@ class LocationProviderManager extends return new ProviderRequest.Builder() .setIntervalMillis(intervalMs) + .setQuality(quality) .setLocationSettingsIgnored(locationSettingsIgnored) .setLowPower(lowPower) - .setLocationRequests(locationRequests) .setWorkSource(workSource) .build(); } diff --git a/services/core/java/com/android/server/location/PassiveLocationProviderManager.java b/services/core/java/com/android/server/location/PassiveLocationProviderManager.java index fc10d5fcf1b7..b7718611cffc 100644 --- a/services/core/java/com/android/server/location/PassiveLocationProviderManager.java +++ b/services/core/java/com/android/server/location/PassiveLocationProviderManager.java @@ -63,15 +63,7 @@ class PassiveLocationProviderManager extends LocationProviderManager { @Override protected ProviderRequest mergeRegistrations(Collection registrations) { - boolean locationSettingsIgnored = false; - for (Registration registration : registrations) { - locationSettingsIgnored |= registration.getRequest().isLocationSettingsIgnored(); - } - - return new ProviderRequest.Builder() - .setIntervalMillis(0) - .setLocationSettingsIgnored(locationSettingsIgnored) - .build(); + return new ProviderRequest.Builder().setIntervalMillis(0).build(); } @Override @@ -79,4 +71,9 @@ class PassiveLocationProviderManager extends LocationProviderManager { Collection registrations) { return 0; } + + @Override + protected String getServiceState() { + return mProvider.getCurrentRequest().isActive() ? "registered" : "unregistered"; + } } diff --git a/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java b/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java index e144b403240c..e25e605cf7d2 100644 --- a/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java +++ b/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java @@ -708,12 +708,12 @@ public class GnssLocationProvider extends AbstractLocationProvider implements // For fast GNSS TTFF provider = LocationManager.NETWORK_PROVIDER; locationListener = mNetworkLocationListener; - locationRequest.setQuality(LocationRequest.POWER_LOW); + locationRequest.setQuality(LocationRequest.QUALITY_LOW_POWER); } else { // For Device-Based Hybrid (E911) provider = LocationManager.FUSED_PROVIDER; locationListener = mFusedLocationListener; - locationRequest.setQuality(LocationRequest.ACCURACY_FINE); + locationRequest.setQuality(LocationRequest.QUALITY_HIGH_ACCURACY); } // Ignore location settings if in emergency mode. This is only allowed for diff --git a/services/tests/mockingservicestests/src/com/android/server/location/LocationProviderManagerTest.java b/services/tests/mockingservicestests/src/com/android/server/location/LocationProviderManagerTest.java index 31ec4a53908c..3aedd3c7d753 100644 --- a/services/tests/mockingservicestests/src/com/android/server/location/LocationProviderManagerTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/location/LocationProviderManagerTest.java @@ -710,7 +710,6 @@ public class LocationProviderManagerTest { @Test public void testProviderRequest() { assertThat(mProvider.getRequest().isActive()).isFalse(); - assertThat(mProvider.getRequest().getLocationRequests()).isEmpty(); ILocationListener listener1 = createMockLocationListener(); LocationRequest request1 = new LocationRequest.Builder(5).setWorkSource( @@ -718,7 +717,6 @@ public class LocationProviderManagerTest { mManager.registerLocationRequest(request1, IDENTITY, PERMISSION_FINE, listener1); assertThat(mProvider.getRequest().isActive()).isTrue(); - assertThat(mProvider.getRequest().getLocationRequests()).containsExactly(request1); assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isFalse(); assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(5); assertThat(mProvider.getRequest().isLowPower()).isFalse(); @@ -732,8 +730,6 @@ public class LocationProviderManagerTest { mManager.registerLocationRequest(request2, IDENTITY, PERMISSION_FINE, listener2); assertThat(mProvider.getRequest().isActive()).isTrue(); - assertThat(mProvider.getRequest().getLocationRequests()).containsExactly(request1, - request2); assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isFalse(); assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(1); assertThat(mProvider.getRequest().isLowPower()).isFalse(); @@ -742,7 +738,6 @@ public class LocationProviderManagerTest { mManager.unregisterLocationRequest(listener1); assertThat(mProvider.getRequest().isActive()).isTrue(); - assertThat(mProvider.getRequest().getLocationRequests()).containsExactly(request2); assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isFalse(); assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(1); assertThat(mProvider.getRequest().isLowPower()).isTrue(); @@ -751,7 +746,6 @@ public class LocationProviderManagerTest { mManager.unregisterLocationRequest(listener2); assertThat(mProvider.getRequest().isActive()).isFalse(); - assertThat(mProvider.getRequest().getLocationRequests()).isEmpty(); } @Test @@ -855,7 +849,6 @@ public class LocationProviderManagerTest { mInjector.getSettingsHelper().setLocationEnabled(false, IDENTITY.getUserId()); assertThat(mProvider.getRequest().isActive()).isTrue(); - assertThat(mProvider.getRequest().getLocationRequests()).containsExactly(request2); assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(5); assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isTrue(); } -- cgit v1.2.3-59-g8ed1b