From 86e9405b422de5c5d72a2149d839551ae2251efc Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 12 Mar 2018 10:28:42 -0700 Subject: [PATCH] Add default URL bar resource id for autofill compat mode. These ids used to be defined at the manifest but now are defined on settings, so we need to provide default values until the settings are fixed. Test: atest FrameworksServicesTests:AutofillManagerServiceTest Bug: 74445943 Change-Id: I050a96d73cb9e008179865381c6abc3041e82844 --- .../autofill/AutofillManagerService.java | 6 +++- .../autofill/AutofillManagerServiceTest.java | 28 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java index 8a66414358aa5..a5339e0e65496 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java @@ -108,6 +108,10 @@ public final class AutofillManagerService extends SystemService { private static final char COMPAT_PACKAGE_URL_IDS_BLOCK_BEGIN = '['; private static final char COMPAT_PACKAGE_URL_IDS_BLOCK_END = ']'; + // TODO(b/74445943): temporary work around until P Development Preview 3 is branched + private static final List DEFAULT_BUTTONS = Arrays.asList("url_bar", + "location_bar_edit_text"); + private final Context mContext; private final AutoFillUI mUi; @@ -596,7 +600,7 @@ public final class AutofillManagerService extends SystemService { final List urlBarIds; if (urlBlockIndex == -1) { packageName = packageBlock; - urlBarIds = null; + urlBarIds = DEFAULT_BUTTONS; // TODO(b/74445943): back to null } else { if (packageBlock.charAt(packageBlock.length() - 1) != COMPAT_PACKAGE_URL_IDS_BLOCK_END) { 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..c348e70bb3756 100644 --- a/services/tests/servicestests/src/com/android/server/autofill/AutofillManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/autofill/AutofillManagerServiceTest.java @@ -27,6 +27,8 @@ import java.util.Map; @RunWith(JUnit4.class) public class AutofillManagerServiceTest { + // TODO(b/74445943): temporary work around until P Development Preview 3 is branched + private static final boolean ADDS_DEFAULT_BUTTON = true; @Test public void testGetWhitelistedCompatModePackages_null() { @@ -40,8 +42,16 @@ public class AutofillManagerServiceTest { @Test public void testGetWhitelistedCompatModePackages_onePackageNoUrls() { - assertThat(getWhitelistedCompatModePackages("one_is_the_loniest_package")) - .containsExactly("one_is_the_loniest_package", null); + if (ADDS_DEFAULT_BUTTON) { + final Map result = + getWhitelistedCompatModePackages("one_is_the_loniest_package"); + assertThat(result).hasSize(1); + assertThat(result.get("one_is_the_loniest_package")).asList() + .containsExactly("url_bar", "location_bar_edit_text"); + } else { + assertThat(getWhitelistedCompatModePackages("one_is_the_loniest_package")) + .containsExactly("one_is_the_loniest_package", null); + } } @Test @@ -70,7 +80,12 @@ public class AutofillManagerServiceTest { public void testGetWhitelistedCompatModePackages_multiplePackagesOneInvalid() { final Map result = getWhitelistedCompatModePackages("one:two["); assertThat(result).hasSize(1); - assertThat(result.get("one")).isNull(); + if (ADDS_DEFAULT_BUTTON) { + assertThat(result.get("one")).asList() + .containsExactly("url_bar", "location_bar_edit_text"); + } else { + assertThat(result.get("one")).isNull(); + } } @Test @@ -79,7 +94,12 @@ public class AutofillManagerServiceTest { getWhitelistedCompatModePackages("p1[p1u1]:p2:p3[p3u1,p3u2]"); assertThat(result).hasSize(3); assertThat(result.get("p1")).asList().containsExactly("p1u1"); - assertThat(result.get("p2")).isNull(); + if (ADDS_DEFAULT_BUTTON) { + assertThat(result.get("p2")).asList() + .containsExactly("url_bar", "location_bar_edit_text"); + } else { + assertThat(result.get("p2")).isNull(); + } assertThat(result.get("p3")).asList().containsExactly("p3u1", "p3u2"); }