From 13be12e3149b8510f9310bdf0d4fef547b545bf2 Mon Sep 17 00:00:00 2001 From: Jesse Evans Date: Thu, 30 Mar 2017 17:30:00 -0700 Subject: [PATCH] Adds appropriate filtering for instant apps Adds a new filter that includes downloaded and launcher apps, as well as instant apps, and ensured that instant apps do not appear where they previously were not expected (downloaded and launcher apps). Test: Added testing for the existing filter and the new one. Bug: 36515324 Change-Id: I7ef94442bae14ee18d4b4d70f04f9bf62af9eff8 (cherry picked from commit a4e0356ed48021c353a6964ec8ea4c6b55006282) --- .../applications/ApplicationsState.java | 21 +++++- .../applications/ApplicationsStateTest.java | 64 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java index c2ce7c9fd5de8..8833fb8cab531 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java @@ -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() { diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/applications/ApplicationsStateTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/applications/ApplicationsStateTest.java index e204a3a65c720..6a029f0be64db 100644 --- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/applications/ApplicationsStateTest.java +++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/applications/ApplicationsStateTest.java @@ -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);