diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index be38df7568c83..1235b787c8e21 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -11113,6 +11113,19 @@ public final class Settings { public static final String NAVIGATION_MODE = "navigation_mode"; + /** + * The value is from another(source) device's {@link #NAVIGATION_MODE} during restore. + * It's supposed to be written only by + * {@link com.android.providers.settings.SettingsHelper}. + * This setting should not be added into backup array. + *
Value: -1 = Can't get value from restore(default), + * 0 = 3 button, + * 1 = 2 button, + * 2 = fully gestural. + * @hide + */ + public static final String NAVIGATION_MODE_RESTORE = "navigation_mode_restore"; + /** * Scale factor for the back gesture inset size on the left side of the screen. * @hide diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java index f6c2f69187390..e5f7f889138e0 100644 --- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java +++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java @@ -259,6 +259,8 @@ public class SecureSettingsValidators { VALIDATORS.put(Secure.NAV_BAR_KIDS_MODE, BOOLEAN_VALIDATOR); VALIDATORS.put( Secure.NAVIGATION_MODE, new DiscreteValueValidator(new String[] {"0", "1", "2"})); + VALIDATORS.put(Secure.NAVIGATION_MODE_RESTORE, + new DiscreteValueValidator(new String[] {"-1", "0", "1", "2"})); VALIDATORS.put(Secure.BACK_GESTURE_INSET_SCALE_LEFT, new InclusiveFloatRangeValidator(0.0f, Float.MAX_VALUE)); VALIDATORS.put(Secure.BACK_GESTURE_INSET_SCALE_RIGHT, diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java index 11154d165109f..056be2ed64515 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java @@ -813,7 +813,11 @@ public class SettingsBackupAgent extends BackupAgentHelper { continue; } - if (settingsToPreserve.contains(getQualifiedKeyForSetting(key, contentUri))) { + // Filter out Settings.Secure.NAVIGATION_MODE from modified preserve settings. + // Let it take part in restore process. See also b/244532342. + boolean isSettingPreserved = settingsToPreserve.contains( + getQualifiedKeyForSetting(key, contentUri)); + if (isSettingPreserved && !Settings.Secure.NAVIGATION_MODE.equals(key)) { Log.i(TAG, "Skipping restore for setting " + key + " as it is marked as " + "preserved"); continue; @@ -874,6 +878,23 @@ public class SettingsBackupAgent extends BackupAgentHelper { } else { destination = contentUri; } + + // Value is written to NAVIGATION_MODE_RESTORE to mark navigation mode + // has been set before on source device. + // See also: b/244532342. + if (Settings.Secure.NAVIGATION_MODE.equals(key)) { + contentValues.clear(); + contentValues.put(Settings.NameValueTable.NAME, + Settings.Secure.NAVIGATION_MODE_RESTORE); + contentValues.put(Settings.NameValueTable.VALUE, value); + cr.insert(destination, contentValues); + // Avoid restore original setting if it has been preserved. + if (isSettingPreserved) { + Log.i(TAG, "Skipping restore for setting navigation_mode " + + "as it is marked as preserved"); + continue; + } + } settingsHelper.restoreValue(this, cr, contentValues, destination, key, value, mRestoredFromSdkInt); diff --git a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java index 5583384d89988..9b8e47300f9bf 100644 --- a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +++ b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java @@ -848,7 +848,8 @@ public class SettingsBackupTest { Settings.Secure.ACCESSIBILITY_FLOATING_MENU_MIGRATION_TOOLTIP_PROMPT, Settings.Secure.UI_TRANSLATION_ENABLED, Settings.Secure.CREDENTIAL_SERVICE, - Settings.Secure.CREDENTIAL_SERVICE_PRIMARY); + Settings.Secure.CREDENTIAL_SERVICE_PRIMARY, + Settings.Secure.NAVIGATION_MODE_RESTORE); @Test public void systemSettingsBackedUpOrDenied() {