Merge "Do not preserve settings changed by 'android' package" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
00562369ed
@@ -1313,7 +1313,8 @@ final class SettingsState {
|
||||
}
|
||||
|
||||
// isValuePreservedInRestore shouldn't change back to false if it has been set to true.
|
||||
boolean isPreserved = shouldPreserveSetting(overrideableByRestore, resetToDefault);
|
||||
boolean isPreserved = shouldPreserveSetting(overrideableByRestore, resetToDefault,
|
||||
packageName, value);
|
||||
|
||||
// Is something gonna change?
|
||||
if (Objects.equals(value, this.value)
|
||||
@@ -1339,11 +1340,16 @@ final class SettingsState {
|
||||
}
|
||||
|
||||
private boolean shouldPreserveSetting(boolean overrideableByRestore,
|
||||
boolean resetToDefault) {
|
||||
boolean resetToDefault, String packageName, String value) {
|
||||
if (resetToDefault) {
|
||||
// By default settings are not marked as preserved.
|
||||
return false;
|
||||
}
|
||||
if (value != null && value.equals(this.value)
|
||||
&& SYSTEM_PACKAGE_NAME.equals(packageName)) {
|
||||
// Do not mark preserved if it's the system reinitializing to the same value.
|
||||
return false;
|
||||
}
|
||||
|
||||
// isValuePreservedInRestore shouldn't change back to false if it has been set to true.
|
||||
return this.isValuePreservedInRestore || !overrideableByRestore;
|
||||
|
||||
@@ -47,6 +47,7 @@ public class SettingsStateTest extends AndroidTestCase {
|
||||
"日本語";
|
||||
|
||||
private static final String TEST_PACKAGE = "package";
|
||||
private static final String SYSTEM_PACKAGE = "android";
|
||||
private static final String SETTING_NAME = "test_setting";
|
||||
|
||||
private final Object mLock = new Object();
|
||||
@@ -253,6 +254,26 @@ public class SettingsStateTest extends AndroidTestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testModifySettingBySystemPackage_sameValue_preserveFlagNotSet() {
|
||||
SettingsState settingsState = getSettingStateObject();
|
||||
// Initialize the setting.
|
||||
settingsState.insertSettingLocked(SETTING_NAME, "1", null, false, SYSTEM_PACKAGE);
|
||||
// Update the setting.
|
||||
settingsState.insertSettingLocked(SETTING_NAME, "1", null, false, SYSTEM_PACKAGE);
|
||||
|
||||
assertFalse(settingsState.getSettingLocked(SETTING_NAME).isValuePreservedInRestore());
|
||||
}
|
||||
|
||||
public void testModifySettingBySystemPackage_newValue_preserveFlagSet() {
|
||||
SettingsState settingsState = getSettingStateObject();
|
||||
// Initialize the setting.
|
||||
settingsState.insertSettingLocked(SETTING_NAME, "1", null, false, SYSTEM_PACKAGE);
|
||||
// Update the setting.
|
||||
settingsState.insertSettingLocked(SETTING_NAME, "2", null, false, SYSTEM_PACKAGE);
|
||||
|
||||
assertTrue(settingsState.getSettingLocked(SETTING_NAME).isValuePreservedInRestore());
|
||||
}
|
||||
|
||||
private SettingsState getSettingStateObject() {
|
||||
SettingsState settingsState = new SettingsState(getContext(), mLock, mSettingsFile, 1,
|
||||
SettingsState.MAX_BYTES_PER_APP_PACKAGE_UNLIMITED, Looper.getMainLooper());
|
||||
|
||||
Reference in New Issue
Block a user