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();
|
long identity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
final String allowedProviders = Settings.Secure.getStringForUser(
|
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||||
mContext.getContentResolver(),
|
Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF, userId)
|
||||||
Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
|
!= Settings.Secure.LOCATION_MODE_OFF;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(identity);
|
Binder.restoreCallingIdentity(identity);
|
||||||
@@ -2624,41 +2609,10 @@ public class LocationManagerService extends ILocationManager.Stub {
|
|||||||
long identity = Binder.clearCallingIdentity();
|
long identity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
final Set<String> allRealProviders = mRealProviders.keySet();
|
int locationMode = enabled ? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY
|
||||||
// Update all providers on device plus gps and network provider when disabling
|
: Settings.Secure.LOCATION_MODE_OFF;
|
||||||
// location
|
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||||
Set<String> allProvidersSet = new ArraySet<>(allRealProviders.size() + 2);
|
Settings.Secure.LOCATION_MODE, locationMode, userId);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(identity);
|
Binder.restoreCallingIdentity(identity);
|
||||||
|
|||||||
Reference in New Issue
Block a user