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

Commit 2322bedc authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Merge Task level of window hierarchy (58/n)

Bug: 80414790
Fixes: 143491035
Test: Existing tests pass
Change-Id: I1b39a70afce86f9807ee7b257e10b7e9d6b6e95b
parent 793442c5
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -100,7 +100,8 @@ message ActivityStackProto {
message TaskRecordProto {
    option (.android.msg_privacy).dest = DEST_AUTOMATIC;

    optional .com.android.server.wm.ConfigurationContainerProto configuration_container = 1;
    // To be removed soon.
    optional .com.android.server.wm.ConfigurationContainerProto configuration_container = 1 [deprecated=true];
    optional int32 id = 2;
    repeated ActivityRecordProto activities = 3;
    optional int32 stack_id = 4;
@@ -113,6 +114,7 @@ message TaskRecordProto {
    optional .android.graphics.RectProto bounds = 11;
    optional int32 min_width = 12;
    optional int32 min_height = 13;
    optional .com.android.server.wm.TaskProto task = 14;
}

message ActivityRecordProto {
+1 −2
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import static com.android.server.am.ActivityDisplayProto.RESUMED_ACTIVITY;
import static com.android.server.am.ActivityDisplayProto.SINGLE_TASK_INSTANCE;
import static com.android.server.am.ActivityDisplayProto.STACKS;
import static com.android.server.wm.ActivityStack.ActivityState.RESUMED;
import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING;
import static com.android.server.wm.ActivityStack.STACK_VISIBILITY_VISIBLE;
import static com.android.server.wm.ActivityStackSupervisor.TAG_TASKS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK;
@@ -1523,7 +1522,7 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack> {
            final ActivityStack stack = getChildAt(i);
            final ArrayList<TaskRecord> tasks = stack.getAllTasks();
            for (int j = tasks.size() - 1; j >= 0; --j) {
                stack.removeTask(tasks.get(j), "removeAllTasks", REMOVE_TASK_MODE_DESTROYING);
                stack.removeChild(tasks.get(j), "removeAllTasks");
            }
        }
    }
+18 −78
Original line number Diff line number Diff line
@@ -1148,55 +1148,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
    }

    // TODO(task-unify): Remove once TaskRecord and Task are unified.
    TaskRecord getTaskRecord() {
        return task;
    }

    /**
     * Sets reference to the {@link TaskRecord} the {@link ActivityRecord} will treat as its parent.
     * Note that this does not actually add the {@link ActivityRecord} as a {@link TaskRecord}
     * children. However, this method will clean up references to this {@link ActivityRecord} in
     * {@link ActivityStack}.
     * @param task The new parent {@link TaskRecord}.
     */
    // TODO(task-unify): Can be remove after task level unification. Callers can just use addChild
    void setTask(TaskRecord task) {
        // Do nothing if the {@link TaskRecord} is the same as the current {@link getTaskRecord}.
        if (task != null && task == getTaskRecord()) {
            return;
        }

        final ActivityStack oldStack = getActivityStack();
        final ActivityStack newStack = task != null ? task.getStack() : null;

        // Inform old stack (if present) of activity removal and new stack (if set) of activity
        // addition.
        if (oldStack != newStack) {
            if (oldStack != null) {
                oldStack.onActivityRemovedFromStack(this);
            }

            if (newStack != null) {
                newStack.onActivityAddedToStack(this);
            }
        }

        final TaskRecord oldTask = this.task;
        this.task = task;

        // This is attaching the activity to the task which we only want to do once.
        // TODO(task-unify): Need to re-work after unifying the task level since it will already
        // have a parent then. Just need to restructure the re-parent case not to do this. NOTE that
        // the reparenting flag passed in can't be used directly for this as it isn't set in
        // ActivityRecord#reparent() case that ends up calling this method.
        if (task != null && getParent() == null) {
            task.addChild(this);
        } else {
            onParentChanged(task, oldTask);
        }
    }

    /**
     * Sets the Task on this activity for the purposes of re-use during launch where we will
     * re-use another activity instead of this one for the launch.
@@ -1220,8 +1175,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

    @Override
    void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) {
        final TaskRecord oldTask = (oldParent != null) ? ((Task) oldParent).mTaskRecord : null;
        final TaskRecord newTask = (newParent != null) ? ((Task) newParent).mTaskRecord : null;
        final TaskRecord oldTask = oldParent != null ? (TaskRecord) oldParent : null;
        final TaskRecord newTask = newParent != null ? (TaskRecord) newParent : null;
        this.task = newTask;

        super.onParentChanged(newParent, oldParent);
@@ -1230,14 +1185,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

        if (oldParent == null && newParent != null) {
            // First time we are adding the activity to the system.
            // TODO(task-unify): See if mVoiceInteraction variable is really needed after task level
            // unification.
            mVoiceInteraction = task.mTaskRecord != null && task.mTaskRecord.voiceSession != null;
            mVoiceInteraction = newTask.voiceSession != null;
            mInputDispatchingTimeoutNanos = getInputDispatchingTimeoutLocked(this) * 1000000L;
            onDisplayChanged(task.getDisplayContent());
            if (task.mTaskRecord != null) {
                task.mTaskRecord.updateOverrideConfigurationFromLaunchBounds();
            }
            // TODO(b/36505427): Maybe this call should be moved inside
            // updateOverrideConfiguration()
            newTask.updateOverrideConfigurationFromLaunchBounds();
            // Make sure override configuration is up-to-date before using to create window
            // controller.
            updateSizeCompatMode();
@@ -1279,8 +1232,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // Inform old stack (if present) of activity removal and new stack (if set) of activity
        // addition.
        if (oldStack != newStack) {
            // TODO(task-unify): Might be better to use onChildAdded and onChildRemoved signal for
            // this once task level is unified.
            if (oldStack !=  null) {
                oldStack.onActivityRemovedFromStack(this);
            }
@@ -1964,15 +1915,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

        ProtoLog.i(WM_DEBUG_ADD_REMOVE, "reparent: moving activity=%s"
                + " to task=%d at %d", this, task.mTaskId, position);

        reparent(newTask.getTask(), position);
    }

    // TODO(task-unify): Remove once Task level is unified.
    void onParentChanged(TaskRecord newParent, TaskRecord oldParent) {
        onParentChanged(
                newParent != null ? newParent.mTask : null,
                oldParent != null ? oldParent.mTask : null);
        reparent(newTask, position);
    }

    private boolean isHomeIntent(Intent intent) {
@@ -2051,7 +1994,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    /**
     * @return Stack value from current task, null if there is no task.
     */
    // TODO: Remove once ActivityStack and TaskStack are unified.
    // TODO(stack-unify): Remove once ActivityStack and TaskStack are unified.
    <T extends ActivityStack> T getActivityStack() {
        return task != null ? (T) task.getStack() : null;
    }
@@ -2339,7 +2282,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

    /** Finish all activities in the task with the same affinity as this one. */
    void finishActivityAffinity() {
        final ArrayList<ActivityRecord> activities = getTaskRecord().mActivities;
        final ArrayList<ActivityRecord> activities = getTaskRecord().mChildren;
        for (int index = activities.indexOf(this); index >= 0; --index) {
            final ActivityRecord cur = activities.get(index);
            if (!Objects.equals(cur.taskAffinity, taskAffinity)) {
@@ -2451,7 +2394,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY,
                    mUserId, System.identityHashCode(this),
                    task.mTaskId, shortComponentName, reason);
            final ArrayList<ActivityRecord> activities = task.mActivities;
            final ArrayList<ActivityRecord> activities = task.mChildren;
            final int index = activities.indexOf(this);
            if (index < (task.getChildCount() - 1)) {
                if ((intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
@@ -2505,7 +2448,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                // When finishing the activity preemptively take the snapshot before the app window
                // is marked as hidden and any configuration changes take place
                if (mAtmService.mWindowManager.mTaskSnapshotController != null) {
                    final ArraySet<Task> tasks = Sets.newArraySet(task.mTask);
                    final ArraySet<Task> tasks = Sets.newArraySet(task);
                    mAtmService.mWindowManager.mTaskSnapshotController.snapshotTasks(tasks);
                    mAtmService.mWindowManager.mTaskSnapshotController
                            .addSkipClosingAppSnapshotTasks(tasks);
@@ -2547,7 +2490,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                // In this case, we can set the visibility of all the task overlay activities when
                // we detect the last one is finishing to keep them in sync.
                if (task.onlyHasTaskOverlayActivities(true /* excludeFinishing */)) {
                    for (ActivityRecord taskOverlay : task.mActivities) {
                    for (int i = task.getChildCount() - 1; i >= 0 ; --i) {
                        final ActivityRecord taskOverlay = task.getChildAt(i);
                        if (!taskOverlay.mTaskOverlay) {
                            continue;
                        }
@@ -2819,8 +2763,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    }

    /** Note: call {@link #cleanUp(boolean, boolean)} before this method. */
    // TODO(task-unify): Look into consolidating this with TaskRecord.removeChild once we unify
    // task level.
    void removeFromHistory(String reason) {
        finishActivityResults(Activity.RESULT_CANCELED, null /* resultData */);
        makeFinishingLocked();
@@ -4659,7 +4601,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }

        // Check if position in task allows to become paused
        final int positionInTask = task.mActivities.indexOf(this);
        final int positionInTask = task.mChildren.indexOf(this);
        if (positionInTask == -1) {
            throw new IllegalStateException("Activity not found in its task");
        }
@@ -5387,7 +5329,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            return INVALID_TASK_ID;
        }
        final TaskRecord task = r.task;
        final int activityNdx = task.mActivities.indexOf(r);
        final int activityNdx = task.mChildren.indexOf(r);
        if (activityNdx < 0
                || (onlyRoot && activityNdx > task.findRootIndex(true /* effectiveRoot */))) {
            return INVALID_TASK_ID;
@@ -5751,7 +5693,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    @Override
    boolean isWaitingForTransitionStart() {
        final DisplayContent dc = getDisplayContent();
        // TODO: Test for null can be removed once unification is done.
        // TODO(display-unify): Test for null can be removed once unification is done.
        if (dc == null) return false;
        return dc.mAppTransition.isTransitionSet()
                && (dc.mOpeningApps.contains(this)
@@ -6559,8 +6501,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                // If the changes come from change-listener, the incoming parent configuration is
                // still the old one. Make sure their orientations are the same to reduce computing
                // the compatibility bounds for the intermediate state.
                && (task.mTaskRecord == null || task.mTaskRecord
                .getConfiguration().orientation == newParentConfig.orientation)) {
                && (task.getConfiguration().orientation == newParentConfig.orientation)) {
            final Rect taskBounds = task.getBounds();
            // Since we only center the activity horizontally, if only the fixed height is smaller
            // than its container, the override bounds don't need to take effect.
@@ -6878,8 +6819,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            preserveWindow &= isResizeOnlyChange(changes);
            final boolean hasResizeChange = hasResizeChange(changes & ~info.getRealConfigChanged());
            if (hasResizeChange) {
                final boolean isDragResizing =
                        getTaskRecord().getTask().isDragResizing();
                final boolean isDragResizing = getTaskRecord().isDragResizing();
                mRelaunchReason = isDragResizing ? RELAUNCH_REASON_FREE_RESIZE
                        : RELAUNCH_REASON_WINDOWING_MODE_RESIZE;
            } else {
+112 −156

File changed.

Preview size limit exceeded, changes collapsed.

+13 −17
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS;

import static com.android.server.wm.ActivityStack.ActivityState.PAUSED;
import static com.android.server.wm.ActivityStack.ActivityState.PAUSING;
import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_MOVING;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_IDLE;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_PAUSE;
@@ -83,6 +82,7 @@ import static com.android.server.wm.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT;
import static com.android.server.wm.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE;
import static com.android.server.wm.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT;
import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION;
import static com.android.server.wm.WindowContainer.POSITION_TOP;

import android.Manifest;
import android.app.Activity;
@@ -1420,7 +1420,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
                // WM resizeTask must be done after the task is moved to the correct stack,
                // because Task's setBounds() also updates dim layer's bounds, but that has
                // dependency on the stack.
                task.resizeWindowContainer();
                task.resize(false /* relayout */, false /* forced */);
            }
        }

@@ -1885,26 +1885,22 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
        final ActivityStack stack =
                mRootActivityContainer.getLaunchStack(null, aOptions, task, onTop);
        final ActivityStack currentStack = task.getStack();
        if (currentStack != null) {
            // Task has already been restored once. See if we need to do anything more

        if (currentStack == stack) {
            // Nothing else to do since it is already restored in the right stack.
            return true;
        }
            // Remove current stack association, so we can re-associate the task with the
            // right stack below.
            currentStack.removeTask(task, "restoreRecentTaskLocked", REMOVE_TASK_MODE_MOVING);

        if (currentStack != null) {
            // Task has already been restored once. Just re-parent it to the new stack.
            task.reparent(stack.mTaskStack,
                    POSITION_TOP, true /*moveParents*/, "restoreRecentTaskLocked");
            return true;
        }

        stack.addTask(task, onTop, "restoreRecentTask");
        // TODO: move call for creation here and other place into Stack.addTask()
        task.createTask(onTop, true /* showForAllUsers */);
        stack.addChild(task, onTop, true /* showForAllUsers */);
        if (DEBUG_RECENTS) Slog.v(TAG_RECENTS,
                "Added restored task=" + task + " to stack=" + stack);
        for (int activityNdx = task.getChildCount() - 1; activityNdx >= 0; --activityNdx) {
            final ActivityRecord r = task.getChildAt(activityNdx);
            r.setTask(task);
        }
        return true;
    }

Loading