summaryrefslogtreecommitdiff
path: root/packages/SettingsProvider/src
diff options
context:
space:
mode:
authorRuslan Tkhakokhov <rthakohov@google.com>2020-04-22 16:21:47 +0100
committerRuslan Tkhakokhov <rthakohov@google.com>2020-04-27 19:50:37 +0000
commitda40cb86810f71a31fe7ac4373b455521bed6026 (patch)
tree022c47acee4fbb8ea00b908aa883bc5cd0930373 /packages/SettingsProvider/src
parent18f35e57473b34edaa7643c2c52771ae81fce2dc (diff)
Special-case backup/restore of replaced settings
Bug: 153940088 Test: atest SettingsProviderTest:SettingsHelperTest Values for some settings might be changed temporarily. If a backup happens at that moment, we want to backup the real values instead of the temporary ones. If a restore happens at that moment, we don't want to restore values for modified settings. See https://b.corp.google.com/issues/153940088#comment2 for context. Change-Id: I4866f56376ffa393220bbef828a4b876d586146b
Diffstat (limited to 'packages/SettingsProvider/src')
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java33
1 files changed, 32 insertions, 1 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
index b6e31d26a088..d023d98f2b73 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
@@ -48,6 +48,8 @@ import java.util.Locale;
public class SettingsHelper {
private static final String TAG = "SettingsHelper";
private static final String SILENT_RINGTONE = "_silent";
+ private static final String SETTINGS_REPLACED_KEY = "backup_skip_user_facing_data";
+ private static final String SETTING_ORIGINAL_KEY_SUFFIX = "_original";
private static final float FLOAT_TOLERANCE = 0.01f;
private Context mContext;
@@ -121,6 +123,10 @@ public class SettingsHelper {
*/
public void restoreValue(Context context, ContentResolver cr, ContentValues contentValues,
Uri destination, String name, String value, int restoredFromSdkInt) {
+ if (isReplacedSystemSetting(name)) {
+ return;
+ }
+
// Will we need a post-restore broadcast for this element?
String oldValue = null;
boolean sendBroadcast = false;
@@ -203,7 +209,32 @@ public class SettingsHelper {
}
}
// Return the original value
- return value;
+ return isReplacedSystemSetting(name) ? getRealValueForSystemSetting(name) : value;
+ }
+
+ /**
+ * The setting value might have been replaced temporarily. If that's the case, return the real
+ * value instead of the temporary one.
+ */
+ @VisibleForTesting
+ public String getRealValueForSystemSetting(String setting) {
+ return Settings.System.getString(mContext.getContentResolver(),
+ setting + SETTING_ORIGINAL_KEY_SUFFIX);
+ }
+
+ @VisibleForTesting
+ public boolean isReplacedSystemSetting(String setting) {
+ // This list should not be modified.
+ if (!Settings.System.MASTER_MONO.equals(setting)
+ && !Settings.System.SCREEN_OFF_TIMEOUT.equals(setting)) {
+ return false;
+ }
+ // If this flag is set, values for the system settings from the list above have been
+ // temporarily replaced. We don't want to back up the temporary value or run restore for
+ // such settings.
+ // TODO(154822946): Remove this logic in the next release.
+ return Settings.Secure.getInt(mContext.getContentResolver(), SETTINGS_REPLACED_KEY,
+ /* def */ 0) != 0;
}
/**