Merge "Migrate compat mode allowed list to DeviceConfig"

This commit is contained in:
TYM Tsai
2022-01-06 11:46:39 +00:00
committed by Android (Google) Code Review
9 changed files with 78 additions and 40 deletions

View File

@@ -10016,7 +10016,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";

View File

@@ -2877,6 +2877,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

View File

@@ -15216,7 +15216,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 =

View File

@@ -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).
*
* <p>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 */

View File

@@ -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);

View File

@@ -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,

View File

@@ -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<UserInfo> 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<String, String[]> whiteListedPackages = getWhitelistedCompatModePackages();
final Map<String, String[]> 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<String, String[]> getWhitelistedCompatModePackages() {
return getWhitelistedCompatModePackages(getWhitelistedCompatModePackagesFromSettings());
private Map<String, String[]> getAllowedCompatModePackages() {
return getAllowedCompatModePackages(getAllowedCompatModePackagesFromDeviceConfig());
}
private void send(@NonNull IResultReceiver receiver, int value) {
@@ -771,7 +791,7 @@ public final class AutofillManagerService
@Nullable
@VisibleForTesting
static Map<String, String[]> getWhitelistedCompatModePackages(String setting) {
static Map<String, String[]> 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));

View File

@@ -509,7 +509,7 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
*
* <pre><code>
* resolver.registerContentObserver(Settings.Global.getUriFor(
* Settings.Global.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES), false, observer,
* Settings.Global.AUTOFILL_LOGGING_LEVEL), false, observer,
* UserHandle.USER_ALL);
* </code></pre>
*

View File

@@ -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<String, String[]> 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<String, String[]> 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<String, String[]> result = getWhitelistedCompatModePackages("one:two[");
public void testGetAllowedCompatModePackages_multiplePackagesOneInvalid() {
final Map<String, String[]> result = getAllowedCompatModePackages("one:two[");
assertThat(result).hasSize(1);
assertThat(result.get("one")).isNull();
}
@Test
public void testGetWhitelistedCompatModePackages_multiplePackagesMultipleUrls() {
public void testGetAllowedCompatModePackages_multiplePackagesMultipleUrls() {
final Map<String, String[]> 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<String, String[]> 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");