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

Commit 4dfc42d4 authored by Kohsuke Yatoh's avatar Kohsuke Yatoh Committed by Android (Google) Code Review
Browse files

Merge "Backup spell checker settings (again)." into main

parents 5f55b688 e1981a3f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -300,5 +300,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
@@ -472,5 +472,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,