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

Commit 2f55b384 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Return valid task id of bottom activity for isTaskRoot

To match the documentation of Activity#isTaskRoot:
  The root is the first activity in a task.

Previously, the result may be affected by relinquishTaskIdentity.
For example:
Back from activity B to activity A[relinquishTaskIdentity=true]
in the same task. Activity#isTaskRoot will return true for B
because A uses the relinquish flag. That will cause
EnterTransitionCoordinator to skip the exit transition because
its mPendingExitNames will not be set.

Fix: 297013131
Test: atest TaskTests#testGetRootActivity_relinquishTaskIdentity
Change-Id: Iefa6e46c59a198f78a2f0495a20dc1239e04448c
parent 7b193950
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -615,7 +615,15 @@ class ActivityClientController extends IActivityClientController.Stub {
    @Override
    public int getTaskForActivity(IBinder token, boolean onlyRoot) {
        synchronized (mGlobalLock) {
            return ActivityRecord.getTaskForActivityLocked(token, onlyRoot);
            final ActivityRecord r = ActivityRecord.forTokenLocked(token);
            if (r == null) {
                return INVALID_TASK_ID;
            }
            final Task task = r.getTask();
            if (onlyRoot) {
                return task.getRootActivity() == r ? task.mTaskId : INVALID_TASK_ID;
            }
            return task.mTaskId;
        }
    }

+7 −4
Original line number Diff line number Diff line
@@ -7108,15 +7108,18 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return mVisibleRequested || nowVisible || mState == PAUSING || mState == RESUMED;
    }

    /**
     * Returns the task id of the activity token. If onlyRoot=true is specified, it will
     * return a valid id only if the activity is root or the activity is immediately above
     * the first non-relinquish-identity activity.
     * TODO(b/297476786): Clarify the use cases about when should get the bottom activity
     *                    or the first non-relinquish-identity activity from bottom.
     */
    static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
        final ActivityRecord r = ActivityRecord.forTokenLocked(token);
        if (r == null || r.getParent() == null) {
            return INVALID_TASK_ID;
        }
        return getTaskForActivityLocked(r, onlyRoot);
    }

    static int getTaskForActivityLocked(ActivityRecord r, boolean onlyRoot) {
        final Task task = r.task;
        if (onlyRoot && r.compareTo(task.getRootActivity(
                false /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)) > 0) {
+8 −3
Original line number Diff line number Diff line
@@ -1093,10 +1093,16 @@ public class TaskTests extends WindowTestsBase {
        final ActivityRecord activity0 = task.getBottomMostActivity();
        activity0.info.flags |= FLAG_RELINQUISH_TASK_IDENTITY;
        // Add an extra activity on top of the root one.
        new ActivityBuilder(mAtm).setTask(task).build();
        final ActivityRecord activity1 = new ActivityBuilder(mAtm).setTask(task).build();

        assertEquals("The root activity in the task must be reported.",
                task.getBottomMostActivity(), task.getRootActivity());
        assertEquals("The task id of root activity must be reported.",
                task.mTaskId, mAtm.mActivityClientController.getTaskForActivity(
                        activity0.token, true /* onlyRoot */));
        assertEquals("No task must be reported for non root activity if onlyRoot.",
                INVALID_TASK_ID, mAtm.mActivityClientController.getTaskForActivity(
                        activity1.token, true /* onlyRoot */));
    }

    /**
@@ -1572,8 +1578,7 @@ public class TaskTests extends WindowTestsBase {
    }

    private Task getTestTask() {
        final Task task = new TaskBuilder(mSupervisor).setCreateActivity(true).build();
        return task.getBottomMostTask();
        return new TaskBuilder(mSupervisor).setCreateActivity(true).build();
    }

    private void testRootTaskBoundsConfiguration(int windowingMode, Rect parentBounds, Rect bounds,