From 9f8d8c01712ba1854b5b321a89d5777824605889 Mon Sep 17 00:00:00 2001 From: TYM Tsai Date: Wed, 4 Aug 2021 00:48:55 +0800 Subject: [PATCH] Migrate compat mode allowed list to DeviceConfig To test, manually played with 'adb shell device_config'. Examples: $ adb shell device_config list autofill $ adb shell device_config delete autofill compat_mode_allowed_packages $ adb shell device_config list autofill compat_mode_allowed_packages: not found $ adb shell device_config put autofill compat_mode_allowed_packages com.android.chrome[url_bar]:com.brave.browser[url_bar] $ adb shell device_config list autofill compat_mode_allowed_packages: found, value is com.android.chrome[url_bar]:com.brave.browser[url_bar] $ adb shell dumpsys autofill see: Autofill Compat State: User: 0 com.android.chrome: maxVersionCode=10000000000, urlBarResourceIds=[url_bar] from device config: com.android.chrome[url_bar]:com.brave.browser[url_bar] Bug: 194967348 Test: atest CtsAutoFillServiceTestCases Test: atest com.android.server.autofill.AutofillManagerServiceTest Change-Id: I775782622adecb42b86de508f502f03039cc34ca --- core/api/system-current.txt | 2 +- core/api/test-current.txt | 1 + core/java/android/provider/Settings.java | 3 ++ .../view/autofill/AutofillManager.java | 18 +++++++ .../settings/SettingsProtoDumpUtil.java | 3 -- .../android/provider/SettingsBackupTest.java | 1 - .../autofill/AutofillManagerService.java | 50 +++++++++++++------ .../infra/AbstractMasterSystemService.java | 2 +- .../autofill/AutofillManagerServiceTest.java | 38 +++++++------- 9 files changed, 78 insertions(+), 40 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index f2a145e96f747..bf128738b6616 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -9652,7 +9652,7 @@ package android.provider { method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public static void resetToDefaults(@NonNull android.content.ContentResolver, @Nullable String); field public static final String AIRPLANE_MODE_TOGGLEABLE_RADIOS = "airplane_mode_toggleable_radios"; field public static final String APP_STANDBY_ENABLED = "app_standby_enabled"; - field public static final String AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES = "autofill_compat_mode_allowed_packages"; + field @Deprecated public static final String AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES = "autofill_compat_mode_allowed_packages"; field public static final String CARRIER_APP_NAMES = "carrier_app_names"; field public static final String CARRIER_APP_WHITELIST = "carrier_app_whitelist"; field public static final String DEFAULT_SM_DP_PLUS = "default_sm_dp_plus"; diff --git a/core/api/test-current.txt b/core/api/test-current.txt index ba0b6aaf1bf2a..a706cc60277af 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -2956,6 +2956,7 @@ package android.view.autofill { } public final class AutofillManager { + field public static final String DEVICE_CONFIG_AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES = "compat_mode_allowed_packages"; field public static final String DEVICE_CONFIG_AUTOFILL_SMART_SUGGESTION_SUPPORTED_MODES = "smart_suggestion_supported_modes"; field public static final int FLAG_SMART_SUGGESTION_OFF = 0; // 0x0 field public static final int FLAG_SMART_SUGGESTION_SYSTEM = 1; // 0x1 diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index d08475d09faa1..9a69d209733f6 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -15035,7 +15035,10 @@ public final class Settings { * {@code p1[url_bar]:p2:p3[url_foo,url_bas]} * * @hide + * @deprecated Use {@link android.view.autofill.AutofillManager + * #DEVICE_CONFIG_AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES} instead. */ + @Deprecated @SystemApi @Readable public static final String AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES = diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java index 11220561b00ce..bb13c1e789644 100644 --- a/core/java/android/view/autofill/AutofillManager.java +++ b/core/java/android/view/autofill/AutofillManager.java @@ -472,6 +472,24 @@ public final class AutofillManager { public static final String DEVICE_CONFIG_AUGMENTED_SERVICE_REQUEST_TIMEOUT = "augmented_service_request_timeout"; + /** + * Sets allowed list for the autofill compatibility mode. + * + * The list of packages is {@code ":"} colon delimited, and each entry has the name of the + * package and an optional list of url bar resource ids (the list is delimited by + * brackets&mdash{@code [} and {@code ]}&mdash and is also comma delimited). + * + *

For example, a list with 3 packages {@code p1}, {@code p2}, and {@code p3}, where + * package {@code p1} have one id ({@code url_bar}, {@code p2} has none, and {@code p3 } + * have 2 ids {@code url_foo} and {@code url_bas}) would be + * {@code p1[url_bar]:p2:p3[url_foo,url_bas]} + * + * @hide + */ + @TestApi + public static final String DEVICE_CONFIG_AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES = + "compat_mode_allowed_packages"; + /** @hide */ public static final int RESULT_OK = 0; /** @hide */ diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java index 5d75d4f2c7dab..877c80ff74945 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java @@ -243,9 +243,6 @@ class SettingsProtoDumpUtil { GlobalSettingsProto.AUDIO_SAFE_VOLUME_STATE); final long autofillToken = p.start(GlobalSettingsProto.AUTOFILL); - dumpSetting(s, p, - Settings.Global.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES, - GlobalSettingsProto.Autofill.COMPAT_MODE_ALLOWED_PACKAGES); dumpSetting(s, p, Settings.Global.AUTOFILL_LOGGING_LEVEL, GlobalSettingsProto.Autofill.LOGGING_LEVEL); diff --git a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java index c9c93c48af9d4..6446acc37bf77 100644 --- a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +++ b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java @@ -134,7 +134,6 @@ public class SettingsBackupTest { Settings.Global.ART_VERIFIER_VERIFY_DEBUGGABLE, Settings.Global.ASSISTED_GPS_ENABLED, Settings.Global.AUDIO_SAFE_VOLUME_STATE, - Settings.Global.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES, Settings.Global.AUTOFILL_LOGGING_LEVEL, Settings.Global.AUTOFILL_MAX_PARTITIONS_SIZE, Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS, diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java index 422749e9a75af..051281c5dd08f 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java @@ -240,9 +240,6 @@ public final class AutofillManagerService @Override // from AbstractMasterSystemService protected void registerForExtraSettingsChanges(@NonNull ContentResolver resolver, @NonNull ContentObserver observer) { - resolver.registerContentObserver(Settings.Global.getUriFor( - Settings.Global.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES), false, observer, - UserHandle.USER_ALL); resolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.AUTOFILL_LOGGING_LEVEL), false, observer, UserHandle.USER_ALL); @@ -274,8 +271,6 @@ public final class AutofillManagerService break; default: Slog.w(TAG, "Unexpected property (" + property + "); updating cache instead"); - // fall through - case Settings.Global.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES: synchronized (mLock) { updateCachedServiceLocked(userId); } @@ -307,6 +302,9 @@ public final class AutofillManagerService case AutofillManager.DEVICE_CONFIG_AUGMENTED_SERVICE_REQUEST_TIMEOUT: setDeviceConfigProperties(); break; + case AutofillManager.DEVICE_CONFIG_AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES: + updateCachedServices(); + break; default: Slog.i(mTag, "Ignoring change on " + key); } @@ -588,6 +586,15 @@ public final class AutofillManagerService } } + private void updateCachedServices() { + List supportedUsers = getSupportedUsers(); + for (UserInfo userInfo : supportedUsers) { + synchronized (mLock) { + updateCachedServiceLocked(userInfo.id); + } + } + } + // Called by Shell command. void calculateScore(@Nullable String algorithmName, @NonNull String value1, @NonNull String value2, @NonNull RemoteCallback callback) { @@ -702,31 +709,44 @@ public final class AutofillManagerService return; } - final Map whiteListedPackages = getWhitelistedCompatModePackages(); + final Map allowedPackages = getAllowedCompatModePackages(); final int compatPackageCount = compatPackages.size(); for (int i = 0; i < compatPackageCount; i++) { final String packageName = compatPackages.keyAt(i); - if (whiteListedPackages == null || !whiteListedPackages.containsKey(packageName)) { - Slog.w(TAG, "Ignoring not whitelisted compat package " + packageName); + if (allowedPackages == null || !allowedPackages.containsKey(packageName)) { + Slog.w(TAG, "Ignoring not allowed compat package " + packageName); continue; } final Long maxVersionCode = compatPackages.valueAt(i); if (maxVersionCode != null) { mAutofillCompatState.addCompatibilityModeRequest(packageName, - maxVersionCode, whiteListedPackages.get(packageName), userId); + maxVersionCode, allowedPackages.get(packageName), userId); } } } - private String getWhitelistedCompatModePackagesFromSettings() { + private String getAllowedCompatModePackagesFromDeviceConfig() { + String config = DeviceConfig.getString( + DeviceConfig.NAMESPACE_AUTOFILL, + AutofillManager.DEVICE_CONFIG_AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES, + /* defaultValue */ null); + if (!TextUtils.isEmpty(config)) { + return config; + } + // Fallback to Settings.Global.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES if + // the device config is null. + return getAllowedCompatModePackagesFromSettings(); + } + + private String getAllowedCompatModePackagesFromSettings() { return Settings.Global.getString( getContext().getContentResolver(), Settings.Global.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES); } @Nullable - private Map getWhitelistedCompatModePackages() { - return getWhitelistedCompatModePackages(getWhitelistedCompatModePackagesFromSettings()); + private Map getAllowedCompatModePackages() { + return getAllowedCompatModePackages(getAllowedCompatModePackagesFromDeviceConfig()); } private void send(@NonNull IResultReceiver receiver, int value) { @@ -771,7 +791,7 @@ public final class AutofillManagerService @Nullable @VisibleForTesting - static Map getWhitelistedCompatModePackages(String setting) { + static Map getAllowedCompatModePackages(String setting) { if (TextUtils.isEmpty(setting)) { return null; } @@ -1756,8 +1776,8 @@ public final class AutofillManagerService mUi.dump(pw); pw.print("Autofill Compat State: "); mAutofillCompatState.dump(prefix, pw); - pw.print("from settings: "); - pw.println(getWhitelistedCompatModePackagesFromSettings()); + pw.print("from device config: "); + pw.println(getAllowedCompatModePackagesFromDeviceConfig()); if (mSupportedSmartSuggestionModes != 0) { pw.print("Smart Suggestion modes: "); pw.println(getSmartSuggestionModeToString(mSupportedSmartSuggestionModes)); diff --git a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java index 14616754e1604..9e00f95c9c6f0 100644 --- a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java +++ b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java @@ -509,7 +509,7 @@ public abstract class AbstractMasterSystemService * resolver.registerContentObserver(Settings.Global.getUriFor( - * Settings.Global.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES), false, observer, + * Settings.Global.AUTOFILL_LOGGING_LEVEL), false, observer, * UserHandle.USER_ALL); * * diff --git a/services/tests/servicestests/src/com/android/server/autofill/AutofillManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/autofill/AutofillManagerServiceTest.java index d5a28f6b1d76f..d2ea9c4056e69 100644 --- a/services/tests/servicestests/src/com/android/server/autofill/AutofillManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/autofill/AutofillManagerServiceTest.java @@ -15,7 +15,7 @@ */ package com.android.server.autofill; -import static com.android.server.autofill.AutofillManagerService.getWhitelistedCompatModePackages; +import static com.android.server.autofill.AutofillManagerService.getAllowedCompatModePackages; import static com.google.common.truth.Truth.assertThat; @@ -29,54 +29,54 @@ import java.util.Map; public class AutofillManagerServiceTest { @Test - public void testGetWhitelistedCompatModePackages_null() { - assertThat(getWhitelistedCompatModePackages(null)).isNull(); + public void testGetAllowedCompatModePackages_null() { + assertThat(getAllowedCompatModePackages(null)).isNull(); } @Test - public void testGetWhitelistedCompatModePackages_empty() { - assertThat(getWhitelistedCompatModePackages("")).isNull(); + public void testGetAllowedCompatModePackages_empty() { + assertThat(getAllowedCompatModePackages("")).isNull(); } @Test - public void testGetWhitelistedCompatModePackages_onePackageNoUrls() { - assertThat(getWhitelistedCompatModePackages("one_is_the_loniest_package")) + public void testGetAllowedCompatModePackages_onePackageNoUrls() { + assertThat(getAllowedCompatModePackages("one_is_the_loniest_package")) .containsExactly("one_is_the_loniest_package", null); } @Test - public void testGetWhitelistedCompatModePackages_onePackageMissingEndDelimiter() { - assertThat(getWhitelistedCompatModePackages("one_is_the_loniest_package[")).isEmpty(); + public void testGetAllowedCompatModePackages_onePackageMissingEndDelimiter() { + assertThat(getAllowedCompatModePackages("one_is_the_loniest_package[")).isEmpty(); } @Test - public void testGetWhitelistedCompatModePackages_onePackageOneUrl() { + public void testGetAllowedCompatModePackages_onePackageOneUrl() { final Map result = - getWhitelistedCompatModePackages("one_is_the_loniest_package[url]"); + getAllowedCompatModePackages("one_is_the_loniest_package[url]"); assertThat(result).hasSize(1); assertThat(result.get("one_is_the_loniest_package")).asList().containsExactly("url"); } @Test - public void testGetWhitelistedCompatModePackages_onePackageMultipleUrls() { + public void testGetAllowedCompatModePackages_onePackageMultipleUrls() { final Map result = - getWhitelistedCompatModePackages("one_is_the_loniest_package[4,5,8,15,16,23,42]"); + getAllowedCompatModePackages("one_is_the_loniest_package[4,5,8,15,16,23,42]"); assertThat(result).hasSize(1); assertThat(result.get("one_is_the_loniest_package")).asList() .containsExactly("4", "5", "8", "15", "16", "23", "42"); } @Test - public void testGetWhitelistedCompatModePackages_multiplePackagesOneInvalid() { - final Map result = getWhitelistedCompatModePackages("one:two["); + public void testGetAllowedCompatModePackages_multiplePackagesOneInvalid() { + final Map result = getAllowedCompatModePackages("one:two["); assertThat(result).hasSize(1); assertThat(result.get("one")).isNull(); } @Test - public void testGetWhitelistedCompatModePackages_multiplePackagesMultipleUrls() { + public void testGetAllowedCompatModePackages_multiplePackagesMultipleUrls() { final Map result = - getWhitelistedCompatModePackages("p1[p1u1]:p2:p3[p3u1,p3u2]"); + getAllowedCompatModePackages("p1[p1u1]:p2:p3[p3u1,p3u2]"); assertThat(result).hasSize(3); assertThat(result.get("p1")).asList().containsExactly("p1u1"); assertThat(result.get("p2")).isNull(); @@ -84,9 +84,9 @@ public class AutofillManagerServiceTest { } @Test - public void testGetWhitelistedCompatModePackages_threePackagesOneInvalid() { + public void testGetAllowedCompatModePackages_threePackagesOneInvalid() { final Map result = - getWhitelistedCompatModePackages("p1[p1u1]:p2[:p3[p3u1,p3u2]"); + getAllowedCompatModePackages("p1[p1u1]:p2[:p3[p3u1,p3u2]"); assertThat(result).hasSize(2); assertThat(result.get("p1")).asList().containsExactly("p1u1"); assertThat(result.get("p3")).asList().containsExactly("p3u1", "p3u2");