summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Soonil Nagarkar <sooniln@google.com> 2019-03-04 17:17:22 -0800
committer Jack He <siyuanh@google.com> 2019-03-12 21:47:07 +0000
commit1841870f226e33fafab19d56322ebd0848cab6c7 (patch)
treef4a8b9e0a78e0a7aa30cc80a9e182d1e53cbc4c9
parentf96cc080668db4442b38e8e48d70db2e010ed354 (diff)
DO NOT MERGE Let isLocationEnabledForUser() return true location setting
* In API 28, LocationManager#isLocationEnabled() and LocationManager#isLocationEnabledForUser(UserHandle) always return false when a device has neither LocationManager#GPS_PROVIDER nor LocationManager#NETWORK_PROVIDER. * Instead of letting setLocationEnabled() and isLocationEnabled() depend on whether device has GPS or NETWORK location provider, this CL changes these two APIs to directly use LOCATION_MODE setting to store the location enable state * Hence when LOCATION_PROVIDERS_ALLOWED contains a provider, the provider may be used, but it is not guaranteed to exist * Settings.java has two workarounds that actually convert: - putInt(LOCATION_MODE, LOCATION_MODE_HIGH_ACCURACY) => putString(LOCATION_PROVIDERS_ALLOWED, "+gps"); => putString(LOCATION_PROVIDERS_ALLOWED, "+network"); - getInt(LOCATION_MODE, LOCATION_MODE_HIGH_ACCURACY) => getString(LOCATION_PROVIDERS_ALLOWED): - "gps,network" - LOCATION_MODE_HIGH_ACCURACY - "gps" - LOCATION_MODE_SENSORS_ONLY - "network" - LOCATION_MODE_BATTERY_SAVING - others - LOCATION_MODE_OFF * Hence this is NOT a new behavior Bug: 121040693 Bug: 118242060 Bug: 127359153 Test: CTS tests, android.bluetooth.cts.BluetoothLeScanTest#testBasicBleScan, android.bluetooth.cts.BluetoothLeScanTest#testScanFilter, android.location.cts.LocationManagerTest, android.location2.cts.LocationManagerTest Change-Id: I7972d8f97f4ca82c58c29641a081ef73fdcb106c
-rw-r--r--services/core/java/com/android/server/LocationManagerService.java60
1 files changed, 7 insertions, 53 deletions
diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java
index 7b02a4fb3fd8..f4b6aa87da27 100644
--- a/services/core/java/com/android/server/LocationManagerService.java
+++ b/services/core/java/com/android/server/LocationManagerService.java
@@ -2582,24 +2582,9 @@ public class LocationManagerService extends ILocationManager.Stub {
long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
- final String allowedProviders = Settings.Secure.getStringForUser(
- mContext.getContentResolver(),
- Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
- userId);
- if (allowedProviders == null) {
- return false;
- }
- final List<String> providerList = Arrays.asList(allowedProviders.split(","));
- for(String provider : mRealProviders.keySet()) {
- if (provider.equals(LocationManager.PASSIVE_PROVIDER)
- || provider.equals(LocationManager.FUSED_PROVIDER)) {
- continue;
- }
- if (providerList.contains(provider)) {
- return true;
- }
- }
- return false;
+ return Settings.Secure.getIntForUser(mContext.getContentResolver(),
+ Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF, userId)
+ != Settings.Secure.LOCATION_MODE_OFF;
}
} finally {
Binder.restoreCallingIdentity(identity);
@@ -2624,41 +2609,10 @@ public class LocationManagerService extends ILocationManager.Stub {
long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
- final Set<String> allRealProviders = mRealProviders.keySet();
- // Update all providers on device plus gps and network provider when disabling
- // location
- Set<String> allProvidersSet = new ArraySet<>(allRealProviders.size() + 2);
- allProvidersSet.addAll(allRealProviders);
- // When disabling location, disable gps and network provider that could have been
- // enabled by location mode api.
- if (enabled == false) {
- allProvidersSet.add(LocationManager.GPS_PROVIDER);
- allProvidersSet.add(LocationManager.NETWORK_PROVIDER);
- }
- if (allProvidersSet.isEmpty()) {
- return;
- }
- // to ensure thread safety, we write the provider name with a '+' or '-'
- // and let the SettingsProvider handle it rather than reading and modifying
- // the list of enabled providers.
- final String prefix = enabled ? "+" : "-";
- StringBuilder locationProvidersAllowed = new StringBuilder();
- for (String provider : allProvidersSet) {
- if (provider.equals(LocationManager.PASSIVE_PROVIDER)
- || provider.equals(LocationManager.FUSED_PROVIDER)) {
- continue;
- }
- locationProvidersAllowed.append(prefix);
- locationProvidersAllowed.append(provider);
- locationProvidersAllowed.append(",");
- }
- // Remove the trailing comma
- locationProvidersAllowed.setLength(locationProvidersAllowed.length() - 1);
- Settings.Secure.putStringForUser(
- mContext.getContentResolver(),
- Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
- locationProvidersAllowed.toString(),
- userId);
+ int locationMode = enabled ? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY
+ : Settings.Secure.LOCATION_MODE_OFF;
+ Settings.Secure.putIntForUser(mContext.getContentResolver(),
+ Settings.Secure.LOCATION_MODE, locationMode, userId);
}
} finally {
Binder.restoreCallingIdentity(identity);