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

Commit 010a711c authored by Jerry Chang's avatar Jerry Chang Committed by Automerger Merge Worker
Browse files

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

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16983291

Change-Id: Ifbced48092d7a94e7e6ec1479311152ef90eb9ba
parents 374dfc86 d67a04ec
Loading
Loading
Loading
Loading
+8 −21
Original line number Original line Diff line number Diff line
@@ -57,8 +57,6 @@ class RunningTasks {
    private ArraySet<Integer> mProfileIds;
    private ArraySet<Integer> mProfileIds;
    private boolean mAllowed;
    private boolean mAllowed;
    private boolean mFilterOnlyVisibleRecents;
    private boolean mFilterOnlyVisibleRecents;
    private Task mTopDisplayFocusRootTask;
    private Task mTopDisplayAdjacentTask;
    private RecentTasks mRecentTasks;
    private RecentTasks mRecentTasks;
    private boolean mKeepIntentExtra;
    private boolean mKeepIntentExtra;


@@ -78,17 +76,9 @@ class RunningTasks {
        mAllowed = (flags & FLAG_ALLOWED) == FLAG_ALLOWED;
        mAllowed = (flags & FLAG_ALLOWED) == FLAG_ALLOWED;
        mFilterOnlyVisibleRecents =
        mFilterOnlyVisibleRecents =
                (flags & FLAG_FILTER_ONLY_VISIBLE_RECENTS) == FLAG_FILTER_ONLY_VISIBLE_RECENTS;
                (flags & FLAG_FILTER_ONLY_VISIBLE_RECENTS) == FLAG_FILTER_ONLY_VISIBLE_RECENTS;
        mTopDisplayFocusRootTask = root.getTopDisplayFocusedRootTask();
        mRecentTasks = root.mService.getRecentTasks();
        mRecentTasks = root.mService.getRecentTasks();
        mKeepIntentExtra = (flags & FLAG_KEEP_INTENT_EXTRA) == FLAG_KEEP_INTENT_EXTRA;
        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,
        final PooledConsumer c = PooledLambda.obtainConsumer(RunningTasks::processTask, this,
                PooledLambda.__(Task.class));
                PooledLambda.__(Task.class));
        root.forAllLeafTasks(c, false);
        root.forAllLeafTasks(c, false);
@@ -132,18 +122,15 @@ class RunningTasks {
            return;
            return;
        }
        }


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


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


package com.android.server.wm;
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_ALLOWED;
import static com.android.server.wm.RunningTasks.FLAG_CROSS_USERS;
import static com.android.server.wm.RunningTasks.FLAG_CROSS_USERS;
import static com.android.server.wm.RunningTasks.FLAG_KEEP_INTENT_EXTRA;
import static com.android.server.wm.RunningTasks.FLAG_KEEP_INTENT_EXTRA;
@@ -81,7 +82,9 @@ public class RunningTasksTest extends WindowTestsBase {
            rootTasks.add(task);
            rootTasks.add(task);
        }, false /* traverseTopToBottom */);
        }, false /* traverseTopToBottom */);
        for (int i = 0; i < numTasks; i++) {
        for (int i = 0; i < numTasks; i++) {
            final Task task =
                    createTask(rootTasks.get(i % numStacks), ".Task" + i, i, activeTime++, null);
                    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,
        // 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.
     * Create a task with a single activity in it, with the given last active time.
     */
     */