diff options
4 files changed, 41 insertions, 3 deletions
diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java index a2291123e192..f5cd7b43c9fe 100644 --- a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java +++ b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java @@ -298,5 +298,9 @@ public class SecureSettings { Settings.Secure.DUAL_SHADE, Settings.Secure.BROWSER_CONTENT_FILTERS_ENABLED, Settings.Secure.SEARCH_CONTENT_FILTERS_ENABLED, + Settings.Secure.SPELL_CHECKER_ENABLED, + Settings.Secure.SELECTED_SPELL_CHECKER, + // SELECTED_SPELL_CHECKER_SUBTYPE needs to be restored after SELECTED_SPELL_CHECKER + Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, }; } diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java index a4325344709a..70f2c4b12aa8 100644 --- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java +++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java @@ -470,5 +470,8 @@ public class SecureSettingsValidators { VALIDATORS.put(Secure.DUAL_SHADE, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.BROWSER_CONTENT_FILTERS_ENABLED, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.SEARCH_CONTENT_FILTERS_ENABLED, BOOLEAN_VALIDATOR); + VALIDATORS.put(Secure.SPELL_CHECKER_ENABLED, BOOLEAN_VALIDATOR); + VALIDATORS.put(Secure.SELECTED_SPELL_CHECKER, NULLABLE_COMPONENT_NAME_VALIDATOR); + VALIDATORS.put(Secure.SELECTED_SPELL_CHECKER_SUBTYPE, ANY_INTEGER_VALIDATOR); } } diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java index fc402d45c3ec..41ec62187c4c 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java @@ -37,10 +37,12 @@ import android.app.backup.BackupDataInput; import android.app.backup.BackupDataOutput; import android.app.backup.BackupRestoreEventLogger; import android.app.backup.FullBackupDataOutput; +import android.content.ComponentName; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.content.pm.PackageManager; +import android.content.pm.ServiceInfo; import android.database.Cursor; import android.net.NetworkPolicy; import android.net.NetworkPolicyManager; @@ -941,6 +943,7 @@ public class SettingsBackupAgent extends BackupAgentHelper { Set<String> blockedSettings = getBlockedSettings(blockedSettingsArrayId); int restoredSettingsCount = 0; + boolean selectedSpellCheckerRestored = false; for (String key : allowlist.mSettingsAllowlist) { boolean isBlockedBySystem = blockedSettings != null && blockedSettings.contains(key); if (isBlockedBySystem || isBlockedByDynamicList(dynamicBlockList, contentUri, key)) { @@ -1068,6 +1071,25 @@ public class SettingsBackupAgent extends BackupAgentHelper { } continue; } + } else if (Settings.Secure.SELECTED_SPELL_CHECKER.equals(key)) { + ServiceInfo si = getServiceInfoOrNull(value); + if (si == null || si.applicationInfo == null) { + Log.i(TAG, "Skipping restore for setting selected_spell_checker " + + "as it is not installed"); + continue; + } else if (!si.applicationInfo.isSystemApp() + && !si.applicationInfo.isUpdatedSystemApp()) { + Log.i(TAG, "Skipping restore for setting selected_spell_checker " + + "as it is not a system app"); + continue; + } + selectedSpellCheckerRestored = true; + } else if (Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE.equals(key)) { + if (!selectedSpellCheckerRestored) { + Log.i(TAG, "Skipping restore for setting selected_spell_checker_subtype " + + "as selected_spell_checker was not restored"); + continue; + } } if (Settings.System.FONT_SCALE.equals(key)) { @@ -1868,6 +1890,18 @@ public class SettingsBackupAgent extends BackupAgentHelper { return result; } + @Nullable + private ServiceInfo getServiceInfoOrNull(@Nullable String flattenedServiceName) { + if (flattenedServiceName == null) return null; + ComponentName componentName = ComponentName.unflattenFromString(flattenedServiceName); + if (componentName == null) return null; + try { + return getBaseContext().getPackageManager().getServiceInfo(componentName, 0); + } catch (PackageManager.NameNotFoundException e) { + return null; + } + } + /** * Store the allowlist of settings to be backed up and validators for them. */ diff --git a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java index 70c042cb8eba..3148f22ab511 100644 --- a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +++ b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java @@ -749,15 +749,12 @@ public class SettingsBackupTest { Settings.Secure.SECURE_FRP_MODE, Settings.Secure.SEARCH_WEB_RESULTS_OVERRIDE_LIMIT, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, - Settings.Secure.SELECTED_SPELL_CHECKER, // Intentionally removed in Q - Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, // Intentionally removed in Q Settings.Secure.SETTINGS_CLASSNAME, Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING, // candidate? Settings.Secure.SHOW_ROTATION_SUGGESTIONS, Settings.Secure.SKIP_FIRST_USE_HINTS, // candidate? Settings.Secure.SLEEP_TIMEOUT, Settings.Secure.SMS_DEFAULT_APPLICATION, - Settings.Secure.SPELL_CHECKER_ENABLED, // Intentionally removed in Q Settings.Secure.TRUST_AGENTS_INITIALIZED, Settings.Secure.KNOWN_TRUST_AGENTS_INITIALIZED, Settings.Secure.TV_APP_USES_NON_SYSTEM_INPUTS, |