Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1981a3f authored by Kohsuke Yatoh's avatar Kohsuke Yatoh
Browse files

Backup spell checker settings (again).

We stopped backing up spell checker settings in
  commit 1893bd16
The main concern was that enabling a (non-system) Spell checker from
a previous device may not work on the new device, which may have
a different default Spell checker or different security policies.

This CL does the following two things to address the forementioned
concern:
(1) Backup and restore spell checker on/off state, regardless of what
    spell checker is used. This part should not be problematic,
    as long as the new device supports Spell Checker functionality.
(2) Backup selected spell checker and its language, and restore them
    only when the back-ed up spell checker is a system app in the
    destination device.

Bug: 314702821
Bug: 314703108
Test: atest SettingsProviderTest
Flag: EXEMPT bugfix
Change-Id: I98225d0b8dc51c734622ba3b60da41d799338261
parent cb925aeb
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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,
    };
}
+3 −0
Original line number Diff line number Diff line
@@ -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);
    }
}
+34 −0
Original line number Diff line number Diff line
@@ -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.
     */
+0 −3
Original line number Diff line number Diff line
@@ -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,