Merge "DO NOT MERGE Let isLocationEnabledForUser() return true location setting"
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user