diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java b/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java index cc4fef8399c3b..7f65837d57167 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java @@ -268,9 +268,9 @@ public class AppUtils { /** * Preload the top N icons of app entry list. * - * @param context caller's context + * @param context caller's context * @param appEntries AppEntry list of ApplicationsState - * @param number the number of Top N icons of the appEntries + * @param number the number of Top N icons of the appEntries */ public static void preloadTopIcons(Context context, ArrayList appEntries, int number) { @@ -286,6 +286,19 @@ public class AppUtils { } } + /** + * Returns a boolean indicating whether this app is installed or not. + * + * @param appEntry AppEntry of ApplicationsState. + * @return true if the app is in installed state. + */ + public static boolean isAppInstalled(ApplicationsState.AppEntry appEntry) { + if (appEntry == null || appEntry.info == null) { + return false; + } + return (appEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) != 0; + } + private static void setAppEntryMounted(ApplicationsState.AppEntry appEntry, boolean mounted) { if (appEntry.mounted != mounted) { synchronized (appEntry) { diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/AppUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/AppUtilsTest.java index 8e448aa0eacef..994c1ee5013f8 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/AppUtilsTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/AppUtilsTest.java @@ -129,6 +129,28 @@ public class AppUtilsTest { assertThat(mAppIconCacheManager.get(APP_PACKAGE_NAME, APP_UID)).isNotNull(); } + @Test + public void isAppInstalled_noAppEntry_shouldReturnFalse() { + assertThat(AppUtils.isAppInstalled(null)).isFalse(); + } + + @Test + public void isAppInstalled_hasAppEntryWithInstalledFlag_shouldReturnTrue() { + final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class); + appEntry.info = new ApplicationInfo(); + appEntry.info.flags = ApplicationInfo.FLAG_INSTALLED; + + assertThat(AppUtils.isAppInstalled(appEntry)).isTrue(); + } + + @Test + public void isAppInstalled_hasAppEntryWithoutInstalledFlag_shouldReturnFalse() { + final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class); + appEntry.info = new ApplicationInfo(); + + assertThat(AppUtils.isAppInstalled(appEntry)).isFalse(); + } + private ApplicationsState.AppEntry createAppEntry(ApplicationInfo appInfo, int id) { ApplicationsState.AppEntry appEntry = new ApplicationsState.AppEntry(mContext, appInfo, id); appEntry.label = "label";