From 69d1e6f63aa8fec1a3b54703780bfdf547d4f326 Mon Sep 17 00:00:00 2001 From: Songchun Fan Date: Tue, 14 Mar 2023 09:00:55 -0700 Subject: [PATCH] [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 --- .../settings/GenerationRegistry.java | 15 +++++--- .../providers/settings/SettingsProvider.java | 35 ++++--------------- .../providers/settings/SettingsState.java | 20 +++++++++++ 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java b/packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java index db6cc1a39ef12..a4c59ea4178df 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java @@ -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) diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java index e6408bf988ceb..7607909dc40b1 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java @@ -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; diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java index 4d8705f135af3..e3153e046a969 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java @@ -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)) + "]";