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

Commit 69d1e6f6 authored by Songchun Fan's avatar Songchun Fan Committed by Song Chun Fan
Browse files

[SettingsProvider] fix caching of Global settings on non-system users

Global settings are shared across users, so all users should share the
same generation tracking cache for Global settings.

BUG: 272251616
BUG: 228619157
Test: atest android.accessibilityservice.cts.AccessibilityWindowReportingTest#testDisableWindowAnimations
Change-Id: I933fa0b8a1687f26c907b96e741433b165037748
parent 5e80fbe6
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.providers.settings;

import android.annotation.NonNull;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.MemoryIntArray;
@@ -81,6 +82,10 @@ final class GenerationRegistry {
    }

    private void incrementGenerationInternal(int key, @NonNull String indexMapKey) {
        if (SettingsState.isGlobalSettingsKey(key)) {
            // Global settings are shared across users, so ignore the userId in the key
            key = SettingsState.makeKey(SettingsState.SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM);
        }
        synchronized (mLock) {
            final MemoryIntArray backingStore = getBackingStoreLocked(key,
                    /* createIfNotExist= */ false);
@@ -126,6 +131,10 @@ final class GenerationRegistry {
     *  returning the result.
     */
    public void addGenerationData(Bundle bundle, int key, String indexMapKey) {
        if (SettingsState.isGlobalSettingsKey(key)) {
            // Global settings are shared across users, so ignore the userId in the key
            key = SettingsState.makeKey(SettingsState.SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM);
        }
        synchronized (mLock) {
            final MemoryIntArray backingStore = getBackingStoreLocked(key,
                    /* createIfNotExist= */ true);
@@ -140,11 +149,9 @@ final class GenerationRegistry {
                    // Should not happen unless having error accessing the backing store
                    return;
                }
                bundle.putParcelable(Settings.CALL_METHOD_TRACK_GENERATION_KEY,
                        backingStore);
                bundle.putParcelable(Settings.CALL_METHOD_TRACK_GENERATION_KEY, backingStore);
                bundle.putInt(Settings.CALL_METHOD_GENERATION_INDEX_KEY, index);
                bundle.putInt(Settings.CALL_METHOD_GENERATION_KEY,
                        backingStore.get(index));
                bundle.putInt(Settings.CALL_METHOD_GENERATION_KEY, backingStore.get(index));
                if (DEBUG) {
                    Slog.i(LOG_TAG, "Exported index:" + index + " for "
                            + (indexMapKey.isEmpty() ? "unset settings" : "setting:" + indexMapKey)
+7 −28
Original line number Diff line number Diff line
@@ -35,6 +35,13 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OV
import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
import static com.android.internal.accessibility.util.AccessibilityUtils.ACCESSIBILITY_MENU_IN_SYSTEM;
import static com.android.providers.settings.SettingsState.FALLBACK_FILE_SUFFIX;
import static com.android.providers.settings.SettingsState.getTypeFromKey;
import static com.android.providers.settings.SettingsState.getUserIdFromKey;
import static com.android.providers.settings.SettingsState.isConfigSettingsKey;
import static com.android.providers.settings.SettingsState.isGlobalSettingsKey;
import static com.android.providers.settings.SettingsState.isSecureSettingsKey;
import static com.android.providers.settings.SettingsState.isSsaidSettingsKey;
import static com.android.providers.settings.SettingsState.isSystemSettingsKey;
import static com.android.providers.settings.SettingsState.makeKey;

import android.Manifest;
@@ -376,14 +383,6 @@ public class SettingsProvider extends ContentProvider {
    @GuardedBy("mLock")
    private boolean mSyncConfigDisabledUntilReboot;

    public static int getTypeFromKey(int key) {
        return SettingsState.getTypeFromKey(key);
    }

    public static int getUserIdFromKey(int key) {
        return SettingsState.getUserIdFromKey(key);
    }

    @ChangeId
    @EnabledSince(targetSdkVersion=android.os.Build.VERSION_CODES.S)
    private static final long ENFORCE_READ_PERMISSION_FOR_MULTI_SIM_DATA_CALL = 172670679L;
@@ -3620,26 +3619,6 @@ public class SettingsProvider extends ContentProvider {
            }
        }

        private boolean isConfigSettingsKey(int key) {
            return getTypeFromKey(key) == SETTINGS_TYPE_CONFIG;
        }

        private boolean isGlobalSettingsKey(int key) {
            return getTypeFromKey(key) == SETTINGS_TYPE_GLOBAL;
        }

        private boolean isSystemSettingsKey(int key) {
            return getTypeFromKey(key) == SETTINGS_TYPE_SYSTEM;
        }

        private boolean isSecureSettingsKey(int key) {
            return getTypeFromKey(key) == SETTINGS_TYPE_SECURE;
        }

        private boolean isSsaidSettingsKey(int key) {
            return getTypeFromKey(key) == SETTINGS_TYPE_SSAID;
        }

        private boolean shouldBan(int type) {
            if (SETTINGS_TYPE_CONFIG != type) {
                return false;
+20 −0
Original line number Diff line number Diff line
@@ -255,6 +255,26 @@ final class SettingsState {
        }
    }

    public static boolean isConfigSettingsKey(int key) {
        return getTypeFromKey(key) == SETTINGS_TYPE_CONFIG;
    }

    public static boolean isGlobalSettingsKey(int key) {
        return getTypeFromKey(key) == SETTINGS_TYPE_GLOBAL;
    }

    public static boolean isSystemSettingsKey(int key) {
        return getTypeFromKey(key) == SETTINGS_TYPE_SYSTEM;
    }

    public static boolean isSecureSettingsKey(int key) {
        return getTypeFromKey(key) == SETTINGS_TYPE_SECURE;
    }

    public static boolean isSsaidSettingsKey(int key) {
        return getTypeFromKey(key) == SETTINGS_TYPE_SSAID;
    }

    public static String keyToString(int key) {
        return "Key[user=" + getUserIdFromKey(key) + ";type="
                + settingTypeToString(getTypeFromKey(key)) + "]";