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

Commit d67a04ec authored by Jerry Chang's avatar Jerry Chang Committed by Android (Google) Code Review
Browse files

Merge "Update active time to visible leaf tasks" into tm-dev

parents 6113844d 4f5b1bec
Loading
Loading
Loading
Loading
+8 −21
Original line number Diff line number Diff line
@@ -57,8 +57,6 @@ class RunningTasks {
    private ArraySet<Integer> mProfileIds;
    private boolean mAllowed;
    private boolean mFilterOnlyVisibleRecents;
    private Task mTopDisplayFocusRootTask;
    private Task mTopDisplayAdjacentTask;
    private RecentTasks mRecentTasks;
    private boolean mKeepIntentExtra;

@@ -78,17 +76,9 @@ class RunningTasks {
        mAllowed = (flags & FLAG_ALLOWED) == FLAG_ALLOWED;
        mFilterOnlyVisibleRecents =
                (flags & FLAG_FILTER_ONLY_VISIBLE_RECENTS) == FLAG_FILTER_ONLY_VISIBLE_RECENTS;
        mTopDisplayFocusRootTask = root.getTopDisplayFocusedRootTask();
        mRecentTasks = root.mService.getRecentTasks();
        mKeepIntentExtra = (flags & FLAG_KEEP_INTENT_EXTRA) == FLAG_KEEP_INTENT_EXTRA;

        if (mTopDisplayFocusRootTask != null
                && mTopDisplayFocusRootTask.getAdjacentTaskFragment() != null) {
            mTopDisplayAdjacentTask = mTopDisplayFocusRootTask.getAdjacentTaskFragment().asTask();
        } else {
            mTopDisplayAdjacentTask = null;
        }

        final PooledConsumer c = PooledLambda.obtainConsumer(RunningTasks::processTask, this,
                PooledLambda.__(Task.class));
        root.forAllLeafTasks(c, false);
@@ -132,18 +122,15 @@ class RunningTasks {
            return;
        }

        final Task rootTask = task.getRootTask();
        if (rootTask == mTopDisplayFocusRootTask && rootTask.getTopMostTask() == task) {
            // For the focused top root task, update the last root task active time so that it
            // can be used to determine the order of the tasks (it may not be set for newly
            // created tasks)
        if (task.isVisible()) {
            // For the visible task, update the last active time so that it can be used to determine
            // the order of the tasks (it may not be set for newly created tasks)
            task.touchActiveTime();
        } else if (rootTask == mTopDisplayAdjacentTask && rootTask.getTopMostTask() == task) {
            // The short-term workaround for launcher could get suitable running task info in
            // split screen.
            task.touchActiveTime();
            // TreeSet doesn't allow same value and make sure this task is lower than focus one.
            task.lastActiveTime--;
            if (!task.isFocused()) {
                // TreeSet doesn't allow the same value and make sure this task is lower than the
                // focused one.
                task.lastActiveTime -= mTmpSortedSet.size();
            }
        }

        mTmpSortedSet.add(task);
+1 −1
Original line number Diff line number Diff line
@@ -4280,7 +4280,7 @@ class Task extends TaskFragment {
    /**
     * @return true if the task is currently focused.
     */
    private boolean isFocused() {
    boolean isFocused() {
        if (mDisplayContent == null || mDisplayContent.mFocusedApp == null) {
            return false;
        }
+34 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.wm;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.server.wm.RunningTasks.FLAG_ALLOWED;
import static com.android.server.wm.RunningTasks.FLAG_CROSS_USERS;
import static com.android.server.wm.RunningTasks.FLAG_KEEP_INTENT_EXTRA;
@@ -81,7 +82,9 @@ public class RunningTasksTest extends WindowTestsBase {
            rootTasks.add(task);
        }, false /* traverseTopToBottom */);
        for (int i = 0; i < numTasks; i++) {
            final Task task =
                    createTask(rootTasks.get(i % numStacks), ".Task" + i, i, activeTime++, null);
            doReturn(false).when(task).isVisible();
        }

        // Ensure that the latest tasks were returned in order of decreasing last active time,
@@ -158,6 +161,36 @@ public class RunningTasksTest extends WindowTestsBase {
        }
    }

    @Test
    public void testUpdateLastActiveTimeOfVisibleTasks() {
        final DisplayContent display = new TestDisplayContent.Builder(mAtm, 1000, 2500).build();
        final int numTasks = 10;
        final ArrayList<Task> tasks = new ArrayList<>();
        for (int i = 0; i < numTasks; i++) {
            final Task task = createTask(null, ".Task" + i, i, i, null);
            doReturn(false).when(task).isVisible();
            tasks.add(task);
        }

        final Task visibleTask = tasks.get(0);
        doReturn(true).when(visibleTask).isVisible();

        final Task focusedTask = tasks.get(1);
        doReturn(true).when(focusedTask).isVisible();
        doReturn(true).when(focusedTask).isFocused();

        // Ensure that the last active time of visible tasks were updated while the focused one had
        // the largest last active time.
        final int numFetchTasks = 5;
        final ArrayList<RunningTaskInfo> fetchTasks = new ArrayList<>();
        mRunningTasks.getTasks(numFetchTasks, fetchTasks,
                FLAG_ALLOWED | FLAG_CROSS_USERS | FLAG_KEEP_INTENT_EXTRA, mRootWindowContainer,
                -1 /* callingUid */, PROFILE_IDS);
        assertThat(fetchTasks).hasSize(numFetchTasks);
        assertEquals(fetchTasks.get(0).id, focusedTask.mTaskId);
        assertEquals(fetchTasks.get(1).id, visibleTask.mTaskId);
    }

    /**
     * Create a task with a single activity in it, with the given last active time.
     */