Properly upgrade LOCATION_MODE

Upgrade LOCATION_MODE setting from previous LOCATION_PROVIDERS_ALLOWED
setting. This should remove the necessity for fallback behavior in
LocationManagerService.

Test: manually
Change-Id: I24a546d91906fcf00c41b2e5191bf75f27f3a759
This commit is contained in:
Soonil Nagarkar
2019-01-22 11:29:27 -08:00
parent 6f19cbdd2f
commit 42da1b173e
3 changed files with 49 additions and 30 deletions

View File

@@ -40,11 +40,8 @@
<bool name="def_wifi_display_on">false</bool>
<bool name="def_install_non_market_apps">false</bool>
<bool name="def_package_verifier_enable">true</bool>
<!-- Comma-separated list of location providers.
Network location is off by default because it requires
user opt-in via Setup Wizard or Settings.
-->
<string name="def_location_providers_allowed" translatable="false">gps</string>
<!-- Comma-separated list of location providers -->
<string name="def_location_providers_allowed" translatable="false">gps,network</string>
<bool name="assisted_gps_enabled">true</bool>
<bool name="def_netstats_enabled">true</bool>
<bool name="def_usb_mass_storage_enabled">true</bool>

View File

@@ -3232,7 +3232,7 @@ public class SettingsProvider extends ContentProvider {
}
private final class UpgradeController {
private static final int SETTINGS_VERSION = 172;
private static final int SETTINGS_VERSION = 173;
private final int mUserId;
@@ -4217,6 +4217,41 @@ public class SettingsProvider extends ContentProvider {
currentVersion = 172;
}
if (currentVersion == 172) {
// Version 172: Set the default value for Secure Settings: LOCATION_MODE
final SettingsState secureSettings = getSecureSettingsLocked(userId);
final Setting locationMode = secureSettings.getSettingLocked(
Secure.LOCATION_MODE);
if (locationMode.isNull()) {
final Setting locationProvidersAllowed = secureSettings.getSettingLocked(
Secure.LOCATION_PROVIDERS_ALLOWED);
String defLocationMode = Integer.toString(
!TextUtils.isEmpty(locationProvidersAllowed.getValue())
? Secure.LOCATION_MODE_HIGH_ACCURACY
: Secure.LOCATION_MODE_OFF);
secureSettings.insertSettingLocked(
Secure.LOCATION_MODE, defLocationMode,
null, true, SettingsState.SYSTEM_PACKAGE_NAME);
// also reset LOCATION_PROVIDERS_ALLOWED back to the default value - this
// setting is now only for debug/test purposes, and will likely be removed
// in a later release. LocationManagerService is responsible for adjusting
// these settings to the proper state.
String defLocationProvidersAllowed = getContext().getResources().getString(
R.string.def_location_providers_allowed);
secureSettings.insertSettingLocked(
Secure.LOCATION_PROVIDERS_ALLOWED, defLocationProvidersAllowed,
null, true, SettingsState.SYSTEM_PACKAGE_NAME);
}
currentVersion = 173;
}
// vXXX: Add new settings above this point.
if (currentVersion != newVersion) {

View File

@@ -830,6 +830,15 @@ public class LocationManagerService extends ILocationManager.Stub {
mAllowed = !mIsManagedBySettings;
mEnabled = false;
mProperties = null;
if (mIsManagedBySettings) {
// since we assume providers are disabled by default
Settings.Secure.putStringForUser(
mContext.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
"-" + mName,
mCurrentUserId);
}
}
@GuardedBy("mLock")
@@ -2865,33 +2874,11 @@ public class LocationManagerService extends ILocationManager.Stub {
long identity = Binder.clearCallingIdentity();
try {
boolean enabled;
try {
enabled = Settings.Secure.getIntForUser(
return Settings.Secure.getIntForUser(
mContext.getContentResolver(),
Settings.Secure.LOCATION_MODE,
Settings.Secure.LOCATION_MODE_OFF,
userId) != Settings.Secure.LOCATION_MODE_OFF;
} catch (Settings.SettingNotFoundException e) {
// OS upgrade case where mode isn't set yet
enabled = !TextUtils.isEmpty(Settings.Secure.getStringForUser(
mContext.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
userId));
try {
Settings.Secure.putIntForUser(
mContext.getContentResolver(),
Settings.Secure.LOCATION_MODE,
enabled
? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY
: Settings.Secure.LOCATION_MODE_OFF,
userId);
} catch (RuntimeException ex) {
// any problem with writing should not be propagated
Slog.e(TAG, "error updating location mode", ex);
}
}
return enabled;
} finally {
Binder.restoreCallingIdentity(identity);
}