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

Commit 70ebc5a5 authored by Adam He's avatar Adam He
Browse files

Check for empty arguments in setWhitelist().

Bug: 125348180
Test: atest CtsContentCaptureServiceTestCases
Test: atest FrameworksCoreTests:com.android.internal.infra.WhitelistHelperTest
Change-Id: I9c2296ebe2762e97f03350b365b148429b15ab60
parent 6240eab1
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -71,12 +71,14 @@ public final class AutofillOptions implements Parcelable {
     * Returns whether activity is whitelisted for augmented autofill.
     */
    public boolean isAugmentedAutofillEnabled(@NonNull Context context) {
        if (!augmentedAutofillEnabled) return false;

        final ContentCaptureClient contentCaptureClient = context.getContentCaptureClient();
        if (contentCaptureClient == null) return false;

        final ComponentName component = contentCaptureClient.contentCaptureClientGetComponentName();
        return augmentedAutofillEnabled && (whitelistedActivitiesForAugmentedAutofill == null
                || whitelistedActivitiesForAugmentedAutofill.contains(component));
        return whitelistedActivitiesForAugmentedAutofill == null
                || whitelistedActivitiesForAugmentedAutofill.contains(component);
    }

    /**
+7 −0
Original line number Diff line number Diff line
@@ -49,12 +49,19 @@ public final class WhitelistHelper {
     *
     * @param packageNames packages to be whitelisted.
     * @param components activities to be whitelisted.
     *
     * @throws IllegalArgumentException if packages or components are empty.
     */
    public void setWhitelist(@Nullable ArraySet<String> packageNames,
            @Nullable ArraySet<ComponentName> components) {
        mWhitelistedPackages = null;
        if (packageNames == null && components == null) return;

        if ((packageNames != null && packageNames.isEmpty())
                || (components != null && components.isEmpty())) {
            throw new IllegalArgumentException("Packages or Components cannot be empty.");
        }

        mWhitelistedPackages = new ArrayMap<>();

        if (packageNames != null) {
+11 −1
Original line number Diff line number Diff line
@@ -46,7 +46,17 @@ public class WhitelistHelperTest {
    private ComponentName mComponentDifferentPkg = new ComponentName(mPackage2, "class3");

    @Test
    public void testWhitelistHelper_invalidArguments() {
    public void testSetWhitelist_emptyArguments() {
        assertThrows(IllegalArgumentException.class,
                () -> mWhitelistHelper.setWhitelist(new ArraySet<>(), null));
        assertThrows(IllegalArgumentException.class,
                () -> mWhitelistHelper.setWhitelist(null, new ArraySet<>()));
        assertThrows(IllegalArgumentException.class,
                () -> mWhitelistHelper.setWhitelist(new ArraySet<>(), new ArraySet<>()));
    }

    @Test
    public void testWhitelistHelper_nullArguments() {
        assertThrows(NullPointerException.class,
                () -> mWhitelistHelper.isWhitelisted((String) null));
        assertThrows(NullPointerException.class,
+4 −0
Original line number Diff line number Diff line
@@ -1177,6 +1177,10 @@ final class AutofillManagerServiceImpl
                .getWhitelistedComponents(packageName);
    }

    /**
     *
     * @throws IllegalArgumentException if packages or components are empty.
     */
    private void whitelistForAugmentedAutofillPackages(@Nullable List<String> packages,
            @Nullable List<ComponentName> components) {
        // TODO(b/123100824): add CTS test for when it's null
+3 −0
Original line number Diff line number Diff line
@@ -275,6 +275,9 @@ final class ContentCapturePerUserService
        return mWhitelistHelper.isWhitelisted(componentName);
    }

    /**
     * @throws IllegalArgumentException if packages or components are empty.
     */
    private void setWhitelist(@Nullable List<String> packages,
            @Nullable List<ComponentName> components) {
        // TODO(b/122595322): add CTS test for when it's null