Merge "Do not preserve settings changed by 'android' package" into rvc-dev am: 00562369ed am: 4072b06d15
Change-Id: I4131a06c1a01e0d942e1b9958d531fd274e0ba80
This commit is contained in:
@@ -1313,7 +1313,8 @@ final class SettingsState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// isValuePreservedInRestore shouldn't change back to false if it has been set to true.
|
// 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?
|
// Is something gonna change?
|
||||||
if (Objects.equals(value, this.value)
|
if (Objects.equals(value, this.value)
|
||||||
@@ -1339,11 +1340,16 @@ final class SettingsState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldPreserveSetting(boolean overrideableByRestore,
|
private boolean shouldPreserveSetting(boolean overrideableByRestore,
|
||||||
boolean resetToDefault) {
|
boolean resetToDefault, String packageName, String value) {
|
||||||
if (resetToDefault) {
|
if (resetToDefault) {
|
||||||
// By default settings are not marked as preserved.
|
// By default settings are not marked as preserved.
|
||||||
return false;
|
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.
|
// isValuePreservedInRestore shouldn't change back to false if it has been set to true.
|
||||||
return this.isValuePreservedInRestore || !overrideableByRestore;
|
return this.isValuePreservedInRestore || !overrideableByRestore;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public class SettingsStateTest extends AndroidTestCase {
|
|||||||
"日本語";
|
"日本語";
|
||||||
|
|
||||||
private static final String TEST_PACKAGE = "package";
|
private static final String TEST_PACKAGE = "package";
|
||||||
|
private static final String SYSTEM_PACKAGE = "android";
|
||||||
private static final String SETTING_NAME = "test_setting";
|
private static final String SETTING_NAME = "test_setting";
|
||||||
|
|
||||||
private final Object mLock = new Object();
|
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() {
|
private SettingsState getSettingStateObject() {
|
||||||
SettingsState settingsState = new SettingsState(getContext(), mLock, mSettingsFile, 1,
|
SettingsState settingsState = new SettingsState(getContext(), mLock, mSettingsFile, 1,
|
||||||
SettingsState.MAX_BYTES_PER_APP_PACKAGE_UNLIMITED, Looper.getMainLooper());
|
SettingsState.MAX_BYTES_PER_APP_PACKAGE_UNLIMITED, Looper.getMainLooper());
|
||||||
|
|||||||
Reference in New Issue
Block a user