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

Commit daa4b22f authored by Jesse Evans's avatar Jesse Evans Committed by android-build-merger
Browse files

Merge "Adds appropriate filtering for instant apps" into oc-dev

am: de5be119

Change-Id: I7c4ea3c1bfcefa59cf0abedc3c5c1d8ec8effa08
parents e4007684 de5be119
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -1394,7 +1394,9 @@ public class ApplicationsState {

        @Override
        public boolean filterApp(AppEntry entry) {
            if ((entry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
            if (AppUtils.isInstant(entry.info)) {
                return false;
            } else if ((entry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
                return true;
            } else if ((entry.info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                return true;
@@ -1407,6 +1409,23 @@ public class ApplicationsState {
        }
    };

    /**
     * Displays a combined list with "downloaded" and "visible in launcher" apps only.
     */
    public static final AppFilter FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT = new AppFilter() {

        @Override
        public void init() {
        }

        @Override
        public boolean filterApp(AppEntry entry) {
            return AppUtils.isInstant(entry.info)
                    || FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(entry);
        }

    };

    public static final AppFilter FILTER_THIRD_PARTY = new AppFilter() {
        @Override
        public void init() {
+64 −0
Original line number Diff line number Diff line
@@ -109,6 +109,70 @@ public class ApplicationsStateTest {
        assertThat(ApplicationsState.FILTER_OTHER_APPS.filterApp(mEntry)).isTrue();
    }

    @Test
    public void testDownloadAndLauncherAndInstantAcceptsCorrectApps() {
        // should include instant apps
        mEntry.isHomeApp = false;
        mEntry.hasLauncherEntry = false;
        when(mEntry.info.isInstantApp()).thenReturn(true);
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT.filterApp(mEntry))
                .isTrue();

        // should included updated system apps
        when(mEntry.info.isInstantApp()).thenReturn(false);
        mEntry.info.flags = ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT.filterApp(mEntry))
                .isTrue();

        // should not include system apps other than the home app
        mEntry.info.flags = ApplicationInfo.FLAG_SYSTEM;
        mEntry.isHomeApp = false;
        mEntry.hasLauncherEntry = false;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT.filterApp(mEntry))
                .isFalse();

        // should include the home app
        mEntry.isHomeApp = true;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT.filterApp(mEntry))
                .isTrue();

        // should include any System app with a launcher entry
        mEntry.isHomeApp = false;
        mEntry.hasLauncherEntry = true;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT.filterApp(mEntry))
                .isTrue();
    }

    @Test
    public void testDownloadAndLauncherAcceptsCorrectApps() {
        mEntry.isHomeApp = false;
        mEntry.hasLauncherEntry = false;

        // should included updated system apps
        when(mEntry.info.isInstantApp()).thenReturn(false);
        mEntry.info.flags = ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(mEntry))
                .isTrue();

        // should not include system apps other than the home app
        mEntry.info.flags = ApplicationInfo.FLAG_SYSTEM;
        mEntry.isHomeApp = false;
        mEntry.hasLauncherEntry = false;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(mEntry))
                .isFalse();

        // should include the home app
        mEntry.isHomeApp = true;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(mEntry))
                .isTrue();

        // should include any System app with a launcher entry
        mEntry.isHomeApp = false;
        mEntry.hasLauncherEntry = true;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(mEntry))
                .isTrue();
    }

    @Test
    public void testInstantFilterAcceptsInstantApp() {
        when(mEntry.info.isInstantApp()).thenReturn(true);