summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tsung-Mao Fang <tmfang@google.com> 2022-05-06 18:19:25 +0800
committer Tsung-Mao Fang <tmfang@google.com> 2022-05-10 02:53:57 +0000
commit00d3d3086a2c2b142ac9dd3b5ff5817c5778236c (patch)
tree83f10b30b7a3f11734f1c879feb703e0bdcfd885
parentdc25f23cb2265c30e236fd64b1d818ec0a869bb1 (diff)
Create an #isAppInstalled() util method
Test: robo test Bug: 230303570 Change-Id: I39bf4129cda09b0b3e2913543e425f272d80df9d
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java17
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/AppUtilsTest.java22
2 files changed, 37 insertions, 2 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java b/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java
index cc4fef8399c3..7f65837d5716 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<ApplicationsState.AppEntry> 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 8e448aa0eace..994c1ee5013f 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";