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

Commit cb9e0875 authored by Manish Singh's avatar Manish Singh Committed by Android (Google) Code Review
Browse files

Merge "Add filter respecting user's quiet mode" into main

parents e720c46f 70939f7b
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -1992,6 +1992,40 @@ public class ApplicationsState {
        }
    };

    /**
     * Displays a combined list with "downloaded" and "visible in launcher" apps which belong to a
     * user which is either not in quiet mode or allows showing apps even when in quiet mode.
     */
    public static final AppFilter FILTER_DOWNLOADED_AND_LAUNCHER_NOT_QUIET = new AppFilter() {
        @Override
        public void init() {
        }

        @Override
        public boolean filterApp(@NonNull AppEntry entry) {
            if (entry.hideInQuietMode) {
                return false;
            }
            if (AppUtils.isInstant(entry.info)) {
                return false;
            } else if (hasFlag(entry.info.flags, ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) {
                return true;
            } else if (!hasFlag(entry.info.flags, ApplicationInfo.FLAG_SYSTEM)) {
                return true;
            } else if (entry.hasLauncherEntry) {
                return true;
            } else if (hasFlag(entry.info.flags, ApplicationInfo.FLAG_SYSTEM) && entry.isHomeApp) {
                return true;
            }
            return false;
        }

        @Override
        public void refreshAppEntryOnRebuild(@NonNull AppEntry appEntry, boolean hideInQuietMode) {
            appEntry.hideInQuietMode = hideInQuietMode;
        }
    };

    /**
     * Displays a combined list with "downloaded" and "visible in launcher" apps only.
     */
+50 −0
Original line number Diff line number Diff line
@@ -239,6 +239,56 @@ public class ApplicationsStateTest {
                .isTrue();
    }

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

        // should include updated system apps
        when(mEntry.info.isInstantApp()).thenReturn(false);
        mEntry.info.flags = ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_NOT_QUIET.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_NOT_QUIET.filterApp(mEntry))
                .isFalse();

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

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

        // should not include updated system apps when in quiet mode
        when(mEntry.info.isInstantApp()).thenReturn(false);
        mEntry.info.flags = ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
        mEntry.hideInQuietMode = true;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_NOT_QUIET.filterApp(mEntry))
                .isFalse();

        // should not include the home app when in quiet mode
        mEntry.isHomeApp = true;
        mEntry.hideInQuietMode = true;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_NOT_QUIET.filterApp(mEntry))
                .isFalse();

        // should not include any System app with a launcher entry when in quiet mode
        mEntry.isHomeApp = false;
        mEntry.hasLauncherEntry = true;
        mEntry.hideInQuietMode = true;
        assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_NOT_QUIET.filterApp(mEntry))
                .isFalse();
    }

    @Test
    public void testOtherAppsRejectsLegacyGame() {
        mEntry.info.flags = ApplicationInfo.FLAG_IS_GAME;