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

Commit 83af6f36 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Return valid task id of bottom activity for isTaskRoot" into main

parents 646c87e7 2f55b384
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
@@ -7122,15 +7122,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,