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

Commit 00d3d308 authored by Tsung-Mao Fang's avatar Tsung-Mao Fang
Browse files

Create an #isAppInstalled() util method

Test: robo test
Bug: 230303570
Change-Id: I39bf4129cda09b0b3e2913543e425f272d80df9d
parent dc25f23c
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -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) {
+22 −0
Original line number Diff line number Diff line
@@ -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";