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

Commit 6103b33f authored by Yunfan Chen's avatar Yunfan Chen Committed by Android (Google) Code Review
Browse files

Merge "Remove StackWindowController and StackWindowListener (46/n)"

parents c631eead 279f5585
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -278,12 +278,12 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack>
        }

        // Since positionChildAt() is called during the creation process of pinned stacks,
        // ActivityStack#getWindowContainerController() can be null. In this special case,
        // ActivityStack#getStack() can be null. In this special case,
        // since DisplayContest#positionStackAt() is called in TaskStack#onConfigurationChanged(),
        // we don't have to call WindowContainerController#positionChildAt() here.
        if (stack.getWindowContainerController() != null && mDisplayContent != null) {
        if (stack.getTaskStack() != null && mDisplayContent != null) {
            mDisplayContent.positionStackAt(insertPosition,
                    stack.getWindowContainerController().mContainer, includingParents);
                    stack.getTaskStack(), includingParents);
        }
        if (!wasContained) {
            stack.setParent(this);
@@ -450,13 +450,12 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack>
    @VisibleForTesting
    <T extends ActivityStack> T createStackUnchecked(int windowingMode, int activityType,
            int stackId, boolean onTop) {
        if (windowingMode == WINDOWING_MODE_PINNED) {
            return (T) new PinnedActivityStack(this, stackId,
                    mRootActivityContainer.mStackSupervisor, onTop);
        if (windowingMode == WINDOWING_MODE_PINNED && activityType != ACTIVITY_TYPE_STANDARD) {
            throw new IllegalArgumentException("Stack with windowing mode cannot with non standard "
                    + "activity type.");
        }
        return (T) new ActivityStack(this, stackId,
                mRootActivityContainer.mStackSupervisor, windowingMode, activityType,
                onTop);
                mRootActivityContainer.mStackSupervisor, windowingMode, activityType, onTop);
    }

    /**
@@ -1019,8 +1018,8 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack>
        return mSplitScreenPrimaryStack != null;
    }

    PinnedActivityStack getPinnedStack() {
        return (PinnedActivityStack) mPinnedStack;
    ActivityStack getPinnedStack() {
        return mPinnedStack;
    }

    boolean hasPinnedStack() {
+140 −32
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ import android.app.ActivityManagerInternal;
import android.app.ActivityOptions;
import android.app.AppGlobals;
import android.app.IActivityController;
import android.app.RemoteAction;
import android.app.ResultInfo;
import android.app.WindowConfiguration.ActivityType;
import android.app.WindowConfiguration.WindowingMode;
@@ -173,8 +174,7 @@ import java.util.Set;
/**
 * State and management of a single stack of activities.
 */
class ActivityStack<T extends StackWindowController> extends ConfigurationContainer
        implements StackWindowListener {
class ActivityStack extends ConfigurationContainer {
    private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_ATM;
    private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
    private static final String TAG_APP = TAG + POSTFIX_APP;
@@ -297,8 +297,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2;

    final ActivityTaskManagerService mService;
    private final WindowManagerService mWindowManager;
    T mWindowContainerController;
    final WindowManagerService mWindowManager;

    /**
     * The back history of all previous (and possibly still
@@ -397,6 +396,9 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    static final int DESTROY_ACTIVITIES_MSG = FIRST_ACTIVITY_STACK_MSG + 5;
    static final int TRANSLUCENT_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 6;

    // TODO: remove after unification.
    TaskStack mTaskStack;

    private static class ScheduleDestroyArgs {
        final WindowProcessController mOwner;
        final String mReason;
@@ -495,21 +497,30 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        // stacks on a wrong display.
        mDisplayId = display.mDisplayId;
        setActivityType(activityType);
        mWindowContainerController = createStackWindowController(display.mDisplayId, onTop,
                mTmpRect2);
        createTaskStack(display.mDisplayId, onTop, mTmpRect2);
        setWindowingMode(windowingMode, false /* animate */, false /* showRecents */,
                false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */,
                true /* creating */);
        display.addChild(this, onTop ? POSITION_TOP : POSITION_BOTTOM);
    }

    T createStackWindowController(int displayId, boolean onTop, Rect outBounds) {
        return (T) new StackWindowController(mStackId, this, displayId, onTop, outBounds,
                mRootActivityContainer.mWindowManager);
    void createTaskStack(int displayId, boolean onTop, Rect outBounds) {
        final DisplayContent dc = mWindowManager.mRoot.getDisplayContent(displayId);
        if (dc == null) {
            throw new IllegalArgumentException("Trying to add stackId=" + mStackId
                    + " to unknown displayId=" + displayId);
        }
        mTaskStack = new TaskStack(mWindowManager, mStackId, this);
        dc.setStackOnDisplay(mStackId, onTop, mTaskStack);
        if (mTaskStack.matchParentBounds()) {
            outBounds.setEmpty();
        } else {
            mTaskStack.getRawBounds(outBounds);
        }
    }

    T getWindowContainerController() {
        return mWindowContainerController;
    TaskStack getTaskStack() {
        return mTaskStack;
    }

    /**
@@ -553,6 +564,9 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        if (display == null) {
            return;
        }
        if (getTaskStack() == null) {
            return;
        }

        // Update bounds if applicable
        boolean hasNewOverrideBounds = false;
@@ -560,8 +574,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        if (getRequestedOverrideWindowingMode() == WINDOWING_MODE_PINNED) {
            // Pinned calculation already includes rotation
            mTmpRect2.set(mTmpRect);
            hasNewOverrideBounds = getWindowContainerController().mContainer
                            .calculatePinnedBoundsForConfigChange(mTmpRect2);
            hasNewOverrideBounds = getTaskStack().calculatePinnedBoundsForConfigChange(mTmpRect2);
        } else {
            final int newRotation = getWindowConfiguration().getRotation();
            if (!matchParentBounds()) {
@@ -588,7 +601,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                            || getRequestedOverrideWindowingMode()
                            == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) {
                        mTmpRect2.set(mTmpRect);
                        getWindowContainerController().mContainer
                        getTaskStack()
                                .calculateDockedBoundsForConfigChange(newParentConfig, mTmpRect2);
                        hasNewOverrideBounds = true;
                    }
@@ -786,7 +799,11 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai

            mTmpRect2.setEmpty();
            if (windowingMode != WINDOWING_MODE_FULLSCREEN) {
                mWindowContainerController.getRawBounds(mTmpRect2);
                if (mTaskStack.matchParentBounds()) {
                    mTmpRect2.setEmpty();
                } else {
                    mTaskStack.getRawBounds(mTmpRect2);
                }
            }

            if (!Objects.equals(getRequestedOverrideBounds(), mTmpRect2)) {
@@ -843,7 +860,12 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        // Reparent the window container before we try to update the position when adding it to
        // the new display below
        mTmpRect2.setEmpty();
        mWindowContainerController.reparent(activityDisplay.mDisplayId, mTmpRect2, onTop);
        if (mTaskStack == null) {
            // TODO: Remove after unification.
            Log.w(TAG, "Task stack is not valid when reparenting.");
        } else {
            mTaskStack.reparent(activityDisplay.mDisplayId, mTmpRect2, onTop);
        }
        setBounds(mTmpRect2.isEmpty() ? null : mTmpRect2);
        activityDisplay.addChild(this, onTop ? POSITION_TOP : POSITION_BOTTOM);
        if (!displayRemoved) {
@@ -876,8 +898,10 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    /** Removes the stack completely. Also calls WindowManager to do the same on its side. */
    void remove() {
        removeFromDisplay();
        mWindowContainerController.removeContainer();
        mWindowContainerController = null;
        if (mTaskStack != null) {
            mTaskStack.removeIfPossible();
            mTaskStack = null;
        }
        onParentChanged();
    }

@@ -890,26 +914,35 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
     */
    void getStackDockedModeBounds(Rect dockedBounds, Rect currentTempTaskBounds,
            Rect outStackBounds, Rect outTempTaskBounds) {
        mWindowContainerController.getStackDockedModeBounds(getParent().getConfiguration(),
                dockedBounds, currentTempTaskBounds,
                outStackBounds, outTempTaskBounds);
        if (mTaskStack != null) {
            mTaskStack.getStackDockedModeBoundsLocked(getParent().getConfiguration(), dockedBounds,
                    currentTempTaskBounds, outStackBounds, outTempTaskBounds);
        } else {
            outStackBounds.setEmpty();
            outTempTaskBounds.setEmpty();
        }
    }

    void prepareFreezingTaskBounds() {
        mWindowContainerController.prepareFreezingTaskBounds();
        if (mTaskStack != null) {
            // TODO: This cannot be false after unification.
            mTaskStack.prepareFreezingTaskBounds();
        }
    }

    void getWindowContainerBounds(Rect outBounds) {
        if (mWindowContainerController != null) {
            mWindowContainerController.getBounds(outBounds);
        if (mTaskStack != null) {
            mTaskStack.getBounds(outBounds);
            return;
        }
        outBounds.setEmpty();
    }

    void positionChildWindowContainerAtTop(TaskRecord child) {
        mWindowContainerController.positionChildAtTop(child.getTask(),
                true /* includingParents */);
        if (mTaskStack != null) {
            // TODO: Remove after unification. This cannot be false after that.
            mTaskStack.positionChildAtTop(child.getTask(), true /* includingParents */);
        }
    }

    void positionChildWindowContainerAtBottom(TaskRecord child) {
@@ -918,14 +951,27 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        // task to bottom, the next focusable stack on the same display should be focused.
        final ActivityStack nextFocusableStack = getDisplay().getNextFocusableStack(
                child.getStack(), true /* ignoreCurrent */);
        mWindowContainerController.positionChildAtBottom(child.getTask(),
        if (mTaskStack != null) {
            // TODO: Remove after unification. This cannot be false after that.
            mTaskStack.positionChildAtBottom(child.getTask(),
                    nextFocusableStack == null /* includingParents */);
        }
    }

    /**
     * Returns whether to defer the scheduling of the multi-window mode.
     */
    boolean deferScheduleMultiWindowModeChanged() {
        if (inPinnedWindowingMode()) {
            // For the pinned stack, the deferring of the multi-window mode changed is tied to the
            // transition animation into picture-in-picture, and is called once the animation
            // completes, or is interrupted in a way that would leave the stack in a non-fullscreen
            // state.
            // @see BoundsAnimationController
            // @see BoundsAnimationControllerTests
            if (getTaskStack() == null) return false;
            return getTaskStack().deferScheduleMultiWindowModeChanged();
        }
        return false;
    }

@@ -2994,7 +3040,10 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        position = getAdjustedPositionForTask(task, position, null /* starting */);
        mTaskHistory.remove(task);
        mTaskHistory.add(position, task);
        mWindowContainerController.positionChildAt(task.getTask(), position);
        if (mTaskStack != null) {
            // TODO: this could not be false after unification.
            mTaskStack.positionChildAt(task.getTask(), position);
        }
        updateTaskMovement(task, true);
    }

@@ -4909,8 +4958,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    }

    // TODO: Figure-out a way to consolidate with resize() method below.
    @Override
    public void requestResize(Rect bounds) {
    void requestResize(Rect bounds) {
        mService.resizeStack(mStackId, bounds,
                true /* allowResizeInDockedMode */, false /* preserveWindows */,
                false /* animate */, -1 /* animationDuration */);
@@ -4948,7 +4996,8 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    }

    void onPipAnimationEndResize() {
        mWindowContainerController.onPipAnimationEndResize();
        if (mTaskStack == null) return;
        mTaskStack.onPipAnimationEndResize();
    }


@@ -5494,6 +5543,65 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        }
    }


    Rect getDefaultPictureInPictureBounds(float aspectRatio) {
        if (getTaskStack() == null) return null;
        return getTaskStack().getPictureInPictureBounds(aspectRatio, null /* currentStackBounds */);
    }

    void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration,
            boolean fromFullscreen) {
        if (!inPinnedWindowingMode()) return;
        if (skipResizeAnimation(toBounds == null /* toFullscreen */)) {
            mService.moveTasksToFullscreenStack(mStackId, true /* onTop */);
        } else {
            if (getTaskStack() == null) return;
            getTaskStack().animateResizePinnedStack(toBounds, sourceHintBounds,
                    animationDuration, fromFullscreen);
        }
    }

    private boolean skipResizeAnimation(boolean toFullscreen) {
        if (!toFullscreen) {
            return false;
        }
        final Configuration parentConfig = getParent().getConfiguration();
        final ActivityRecord top = topRunningNonOverlayTaskActivity();
        return top != null && !top.isConfigurationCompatible(parentConfig);
    }

    void setPictureInPictureAspectRatio(float aspectRatio) {
        if (getTaskStack() == null) return;
        getTaskStack().setPictureInPictureAspectRatio(aspectRatio);
    }

    void setPictureInPictureActions(List<RemoteAction> actions) {
        if (getTaskStack() == null) return;
        getTaskStack().setPictureInPictureActions(actions);
    }

    boolean isAnimatingBoundsToFullscreen() {
        if (getTaskStack() == null) return false;
        return getTaskStack().isAnimatingBoundsToFullscreen();
    }

    public void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds,
            boolean forceUpdate) {
        // It is guaranteed that the activities requiring the update will be in the pinned stack at
        // this point (either reparented before the animation into PiP, or before reparenting after
        // the animation out of PiP)
        synchronized (mService.mGlobalLock) {
            if (!isAttached()) {
                return;
            }
            ArrayList<TaskRecord> tasks = getAllTasks();
            for (int i = 0; i < tasks.size(); i++) {
                mStackSupervisor.updatePictureInPictureMode(tasks.get(i), targetStackBounds,
                        forceUpdate);
            }
        }
    }

    public int getStackId() {
        return mStackId;
    }
+7 −8
Original line number Diff line number Diff line
@@ -1674,8 +1674,8 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
    }

    void resizePinnedStackLocked(Rect pinnedBounds, Rect tempPinnedTaskBounds) {
        // TODO(multi-display): Pinned stack display should be passed in.
        final PinnedActivityStack stack =
        // TODO(multi-display): The display containing the stack should be passed in.
        final ActivityStack stack =
                mRootActivityContainer.getDefaultDisplay().getPinnedStack();
        if (stack == null) {
            Slog.w(TAG, "resizePinnedStackLocked: pinned stack not found");
@@ -1686,7 +1686,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
        // another AM call that is holding the AMS lock. In such a case, the pinnedBounds may be
        // incorrect if AMS.resizeStackWithBoundsFromWindowManager() is already called while waiting
        // for the AMS lock to be freed. So check and make sure these bounds are still good.
        final PinnedStackWindowController stackController = stack.getWindowContainerController();
        final TaskStack stackController = stack.getTaskStack();
        if (stackController.pinnedStackResizeDisallowed()) {
            return;
        }
@@ -1730,15 +1730,14 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
             * invisible as well and added to the stopping list.  After which we process the
             * stopping list by handling the idle.
             */
            final PinnedActivityStack pinnedStack = (PinnedActivityStack) stack;
            pinnedStack.mForceHidden = true;
            pinnedStack.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS);
            pinnedStack.mForceHidden = false;
            stack.mForceHidden = true;
            stack.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS);
            stack.mForceHidden = false;
            activityIdleInternalLocked(null, false /* fromTimeout */,
                    true /* processPausingActivites */, null /* configuration */);

            // Move all the tasks to the bottom of the fullscreen stack
            moveTasksToFullscreenStackLocked(pinnedStack, !ON_TOP);
            moveTasksToFullscreenStackLocked(stack, !ON_TOP);
        } else {
            for (int i = tasks.size() - 1; i >= 0; i--) {
                removeTaskByIdLocked(tasks.get(i).taskId, true /* killProcess */,
+9 −13
Original line number Diff line number Diff line
@@ -82,13 +82,10 @@ import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HEA
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HOME_PROC;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.LAUNCHING_ACTIVITY;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto
        .PREVIOUS_PROC_VISIBLE_TIME_MS;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC_VISIBLE_TIME_MS;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.SCREEN_COMPAT_PACKAGES;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage
        .MODE;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage
        .PACKAGE;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.MODE;
import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.PACKAGE;
import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING;
import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME;
import static com.android.server.wm.ActivityStackSupervisor.ON_TOP;
@@ -2408,7 +2405,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        try {
            synchronized (mGlobalLock) {
                if (animate) {
                    final PinnedActivityStack stack = mRootActivityContainer.getStack(stackId);
                    final ActivityStack stack = mRootActivityContainer.getStack(stackId);
                    if (stack == null) {
                        Slog.w(TAG, "resizeStack: stackId " + stackId + " not found.");
                        return;
@@ -3713,7 +3710,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                final PinnedActivityStack stack =
                final ActivityStack stack =
                        mRootActivityContainer.getDefaultDisplay().getPinnedStack();
                if (stack == null) {
                    Slog.w(TAG, "dismissPip: pinned stack not found.");
@@ -3835,9 +3832,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {

        // If we are animating to fullscreen then we have already dispatched the PIP mode
        // changed, so we should reflect that check here as well.
        final PinnedActivityStack stack = r.getActivityStack();
        final PinnedStackWindowController windowController = stack.getWindowContainerController();
        return !windowController.mContainer.isAnimatingBoundsToFullscreen();
        final TaskStack taskStack = r.getActivityStack().getTaskStack();
        return !taskStack.isAnimatingBoundsToFullscreen();
    }

    @Override
@@ -3871,7 +3867,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                                r.pictureInPictureArgs.getSourceRectHint());
                        mRootActivityContainer.moveActivityToPinnedStack(
                                r, sourceBounds, aspectRatio, "enterPictureInPictureMode");
                        final PinnedActivityStack stack = r.getActivityStack();
                        final ActivityStack stack = r.getActivityStack();
                        stack.setPictureInPictureAspectRatio(aspectRatio);
                        stack.setPictureInPictureActions(actions);
                        MetricsLoggerWrapper.logPictureInPictureEnter(mContext, r.appInfo.uid,
@@ -3915,7 +3911,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    // If the activity is already in picture-in-picture, update the pinned stack now
                    // if it is not already expanding to fullscreen. Otherwise, the arguments will
                    // be used the next time the activity enters PiP
                    final PinnedActivityStack stack = r.getActivityStack();
                    final ActivityStack stack = r.getActivityStack();
                    if (!stack.isAnimatingBoundsToFullscreen()) {
                        stack.setPictureInPictureAspectRatio(
                                r.pictureInPictureArgs.getAspectRatio());
+4 −6
Original line number Diff line number Diff line
@@ -2309,13 +2309,12 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        out.set(mDisplayFrames.mStable);
    }

    TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
        if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
                + mDisplayId);
    void setStackOnDisplay(int stackId, boolean onTop, TaskStack stack) {
        if (DEBUG_STACK) {
            Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId=" + mDisplayId);
        }

        final TaskStack stack = new TaskStack(mWmService, stackId, controller);
        mTaskStackContainers.addStackToDisplay(stack, onTop);
        return stack;
    }

    void moveStackToDisplay(TaskStack stack, boolean onTop) {
@@ -4017,7 +4016,6 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

        /**
         * Adds the stack to this container.
         * @see DisplayContent#createStack(int, boolean, StackWindowController)
         */
        void addStackToDisplay(TaskStack stack, boolean onTop) {
            addStackReferenceIfNeeded(stack);
Loading