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

Commit e902012c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Prevent crash in recent app list"

parents e887ee15 e04101be
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -325,7 +325,7 @@ public class RecentAppsPreferenceController extends AbstractPreferenceController
            // Not visible on launcher -> likely not a user visible app, skip if non-instant.
            final ApplicationsState.AppEntry appEntry =
                    mApplicationsState.getEntry(pkgName, mUserId);
            if (!AppUtils.isInstant(appEntry.info)) {
            if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) {
                Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName);
                return false;
            }
+1 −1
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
            // Not visible on launcher -> likely not a user visible app, skip if non-instant.
            final ApplicationsState.AppEntry appEntry =
                    mApplicationsState.getEntry(pkgName, mUserId);
            if (!AppUtils.isInstant(appEntry.info)) {
            if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) {
                Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName);
                return false;
            }
+27 −0
Original line number Diff line number Diff line
@@ -247,6 +247,33 @@ public class RecentAppsPreferenceControllerTest {
        assertThat(prefs.get(0).getKey()).isEqualTo(stat2.mPackageName);
    }

    @Test
    public void display_showRecentsWithNullAppEntryOrInfo() {
        final List<UsageStats> stats = new ArrayList<>();
        final UsageStats stat1 = new UsageStats();
        final UsageStats stat2 = new UsageStats();
        stat1.mLastTimeUsed = System.currentTimeMillis();
        stat1.mPackageName = "pkg.class";
        stats.add(stat1);

        stat2.mLastTimeUsed = System.currentTimeMillis();
        stat2.mPackageName = "pkg.class2";
        stats.add(stat2);

        // app1 has AppEntry with null info, app2 has null AppEntry.
        mAppEntry.info = null;
        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
                .thenReturn(mAppEntry);
        when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId()))
                .thenReturn(null);

        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
                .thenReturn(stats);

        // We should not crash here.
        mController.displayPreference(mScreen);
    }

    @Test
    public void display_hasRecentButNoneDisplayable_showAppInfo() {
        final List<UsageStats> stats = new ArrayList<>();