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

Commit ad6fd393 authored by Winson Chung's avatar Winson Chung
Browse files

Don't assume there will be a running task

- During tests, if apps and launcher are killed, then there may be no
  running task

Change-Id: Iaef1c4ad0b31cec3c8da7d868e3e7b49d3b09faa
parent 445ab9d8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -227,7 +227,7 @@ public class OverviewCommandHelper {
        public RecentsActivityCommand() {
            mHelper = getActivityControlHelper();
            mCreateTime = SystemClock.elapsedRealtime();
            mRunningTaskId = mAM.getRunningTask().id;
            mRunningTaskId = RecentsModel.getRunningTaskId();

            // Preload the plan
            mRecentsModel.getTasks(null);
+11 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.quickstep;
import static com.android.quickstep.TaskUtils.checkCurrentOrManagedUserId;

import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.os.Build;
@@ -94,6 +95,15 @@ public class RecentsModel extends TaskStackChangeListener {
        return mTaskList.getTasks(-1, false /* loadKeysOnly */, callback);
    }

    /**
     * @return The task id of the running task, or -1 if there is no current running task.
     */
    public static int getRunningTaskId() {
        ActivityManager.RunningTaskInfo runningTask =
                ActivityManagerWrapper.getInstance().getRunningTask();
        return runningTask != null ? runningTask.id : -1;
    }

    /**
     * @return Whether the provided {@param changeId} is the latest recent tasks list id.
     */
@@ -134,7 +144,7 @@ public class RecentsModel extends TaskStackChangeListener {

        // Keep the cache up to date with the latest thumbnails
        mTaskList.getTasks(mThumbnailCache.getCacheSize(), true /* keysOnly */, (tasks) -> {
            int runningTaskId = ActivityManagerWrapper.getInstance().getRunningTask().id;
            int runningTaskId = RecentsModel.getRunningTaskId();
            for (Task task : tasks) {
                if (task.key.id == runningTaskId) {
                    // Skip the running task, it's not going to have an up-to-date snapshot by the