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

Commit 01e4eeb0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Added StackWindowContainerController"

parents b04c54fd 1666e317
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -135,9 +135,6 @@ interface IWindowManager
    // ids that were affected by the update, ActivityManager should resize these stacks.
    int[] setNewDisplayOverrideConfiguration(in Configuration overrideConfig, int displayId);

    // Retrieves the new bounds after the configuration update evaluated by window manager.
    Rect getBoundsForNewConfiguration(int stackId);

    void startFreezingScreen(int exitAnim, int enterAnim);
    void stopFreezingScreen();

+10 −10
Original line number Diff line number Diff line
@@ -7625,12 +7625,11 @@ public class ActivityManagerService extends IActivityManager.Stub
                    final float aspectRatio = r.pictureInPictureArgs.getAspectRatio();
                    final List<RemoteAction> actions = r.pictureInPictureArgs.getActions();
                    final Rect bounds = isValidPictureInPictureAspectRatio(aspectRatio)
                            ? mWindowManager.getPictureInPictureBounds(DEFAULT_DISPLAY,
                                    aspectRatio)
                            ? mWindowManager.getPictureInPictureBounds(DEFAULT_DISPLAY, aspectRatio)
                            : mWindowManager.getPictureInPictureDefaultBounds(DEFAULT_DISPLAY);
                    mStackSupervisor.moveActivityToPinnedStackLocked(r, "enterPictureInPictureMode",
                            bounds, true /* moveHomeStackToFront */);
                    mWindowManager.setPictureInPictureActions(actions);
                    mStackSupervisor.getStack(PINNED_STACK_ID).setPictureInPictureActions(actions);
                };
                if (isKeyguardLocked()) {
@@ -7678,12 +7677,11 @@ public class ActivityManagerService extends IActivityManager.Stub
                // Only update the saved args from the args that are set
                r.pictureInPictureArgs.copyOnlySet(args);
                if (r.getStack().getStackId() == PINNED_STACK_ID) {
                final ActivityStack stack = r.getStack();
                if (stack.getStackId() == PINNED_STACK_ID) {
                    // If the activity is already in picture-in-picture, update the pinned stack now
                    mWindowManager.setPictureInPictureAspectRatio(
                            r.pictureInPictureArgs.getAspectRatio());
                    mWindowManager.setPictureInPictureActions(
                            r.pictureInPictureArgs.getActions());
                    stack.setPictureInPictureAspectRatio(r.pictureInPictureArgs.getAspectRatio());
                    stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions());
                }
            }
        } finally {
@@ -10221,7 +10219,9 @@ public class ActivityManagerService extends IActivityManager.Stub
            synchronized (this) {
                if (animate) {
                    if (stackId == PINNED_STACK_ID) {
                        mWindowManager.animateResizePinnedStack(bounds, animationDuration);
                        final ActivityStack pinnedStack =
                                mStackSupervisor.getStack(PINNED_STACK_ID);
                        pinnedStack.animateResizePinnedStack(bounds, animationDuration);
                    } else {
                        throw new IllegalArgumentException("Stack: " + stackId
                                + " doesn't support animated resize.");
@@ -19594,7 +19594,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    /** Helper method that requests bounds from WM and applies them to stack. */
    private void resizeStackWithBoundsFromWindowManager(int stackId, boolean deferResume) {
        final Rect newBounds = mWindowManager.getBoundsForNewConfiguration(stackId);
        final Rect newBounds = mStackSupervisor.getStack(stackId).getBoundsForNewConfiguration();
        mStackSupervisor.resizeStackLocked(
                stackId, newBounds, null /* tempTaskBounds */, null /* tempTaskInsetBounds */,
                false /* preserveWindows */, false /* allowResizeInDockedMode */, deferResume);
+102 −42
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ import android.app.ActivityManager.StackId;
import android.app.ActivityOptions;
import android.app.AppGlobals;
import android.app.IActivityController;
import android.app.RemoteAction;
import android.app.ResultInfo;
import android.content.ComponentName;
import android.content.Intent;
@@ -114,6 +115,8 @@ import com.android.internal.os.BatteryStatsImpl;
import com.android.server.Watchdog;
import com.android.server.am.ActivityManagerService.ItemMatcher;
import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
import com.android.server.wm.StackWindowController;
import com.android.server.wm.StackWindowListener;
import com.android.server.wm.WindowManagerService;

import java.io.FileDescriptor;
@@ -128,7 +131,7 @@ import java.util.Set;
/**
 * State and management of a single stack of activities.
 */
final class ActivityStack extends ConfigurationContainer {
final class ActivityStack extends ConfigurationContainer implements StackWindowListener {

    private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM;
    private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
@@ -240,6 +243,7 @@ final class ActivityStack extends ConfigurationContainer {

    final ActivityManagerService mService;
    private final WindowManagerService mWindowManager;
    private StackWindowController mWindowContainerController;
    private final RecentTasks mRecentTasks;

    /**
@@ -328,7 +332,7 @@ final class ActivityStack extends ConfigurationContainer {
    private final SparseArray<Configuration> mTmpConfigs = new SparseArray<>();
    private final SparseArray<Rect> mTmpBounds = new SparseArray<>();
    private final SparseArray<Rect> mTmpInsetBounds = new SparseArray<>();
    private final Rect tempRect2 = new Rect();
    private final Rect mTmpRect2 = new Rect();

    /** Run all ActivityStacks through this */
    private final ActivityStackSupervisor mStackSupervisor;
@@ -441,7 +445,7 @@ final class ActivityStack extends ConfigurationContainer {
    }

    ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer,
            RecentTasks recentTasks) {
            RecentTasks recentTasks, boolean onTop) {
        mActivityContainer = activityContainer;
        mStackSupervisor = activityContainer.getOuter();
        mService = mStackSupervisor.mService;
@@ -452,13 +456,25 @@ final class ActivityStack extends ConfigurationContainer {
        mRecentTasks = recentTasks;
        mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID
                ? new LaunchingTaskPositioner() : null;
        final ActivityStackSupervisor.ActivityDisplay display = mActivityContainer.mActivityDisplay;
        mTmpRect2.setEmpty();
        mWindowContainerController = new StackWindowController(mStackId, this,
                display.mDisplayId, onTop, mTmpRect2);
        activityContainer.mStack = this;
        mStackSupervisor.mActivityContainers.put(mStackId, activityContainer);
        postAddToDisplay(display, mTmpRect2.isEmpty() ? null : mTmpRect2, onTop);
    }

    StackWindowController getWindowContainerController() {
        return mWindowContainerController;
    }

    /** Adds the stack to specified display and calls WindowManager to do the same. */
    void addToDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay, boolean onTop) {
        final Rect bounds = mWindowManager.addStackToDisplay(mStackId, activityDisplay.mDisplayId,
                onTop);
        postAddToDisplay(activityDisplay, bounds);
    void reparent(ActivityStackSupervisor.ActivityDisplay activityDisplay, boolean onTop) {
        removeFromDisplay();
        mTmpRect2.setEmpty();
        mWindowContainerController.reparent(activityDisplay.mDisplayId, mTmpRect2);
        postAddToDisplay(activityDisplay, mTmpRect2.isEmpty() ? null : mTmpRect2, onTop);
    }

    /**
@@ -467,10 +483,10 @@ final class ActivityStack extends ConfigurationContainer {
     * @param bounds Updated bounds.
     */
    private void postAddToDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay,
            Rect bounds) {
            Rect bounds, boolean onTop) {
        mDisplayId = activityDisplay.mDisplayId;
        mStacks = activityDisplay.mStacks;
        mBounds = bounds;
        mBounds = bounds != null ? new Rect(bounds) : null;
        mFullscreen = mBounds == null;
        if (mTaskPositioner != null) {
            mTaskPositioner.setDisplay(activityDisplay.mDisplay);
@@ -478,6 +494,7 @@ final class ActivityStack extends ConfigurationContainer {
        }
        onParentChanged();

        activityDisplay.attachStack(this, onTop);
        if (mStackId == DOCKED_STACK_ID) {
            // If we created a docked stack we want to resize it so it resizes all other stacks
            // in the system.
@@ -486,16 +503,6 @@ final class ActivityStack extends ConfigurationContainer {
        }
    }

    /**
     * Moves the stack to specified display.
     * @param activityDisplay Target display to move the stack to.
     */
    void moveToDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay) {
        removeFromDisplay();
        final Rect bounds = mWindowManager.moveStackToDisplay(mStackId, activityDisplay.mDisplayId);
        postAddToDisplay(activityDisplay, bounds);
    }

    /**
     * Updates the inner state of the stack to remove it from its current parent, so it can be
     * either destroyed completely or re-parented.
@@ -518,7 +525,8 @@ final class ActivityStack extends ConfigurationContainer {
    void remove() {
        removeFromDisplay();
        mStackSupervisor.deleteActivityContainerRecord(mStackId);
        mWindowManager.removeStack(mStackId);
        mWindowContainerController.removeContainer();
        mWindowContainerController = null;
        onParentChanged();
    }

@@ -526,6 +534,42 @@ final class ActivityStack extends ConfigurationContainer {
        mActivityContainer.mActivityDisplay.mDisplay.getSize(out);
    }

    void animateResizePinnedStack(Rect bounds, int animationDuration) {
        mWindowContainerController.animateResizePinnedStack(bounds, animationDuration);
    }

    void setPictureInPictureAspectRatio(float aspectRatio) {
        mWindowContainerController.setPictureInPictureAspectRatio(aspectRatio);
    }

    void getStackDockedModeBounds(Rect outBounds, boolean ignoreVisibility) {
        mWindowContainerController.getStackDockedModeBounds(outBounds, ignoreVisibility);
    }

    void prepareFreezingTaskBounds() {
        mWindowContainerController.prepareFreezingTaskBounds();
    }

    void setPictureInPictureActions(List<RemoteAction> actions) {
        mWindowContainerController.setPictureInPictureActions(actions);
    }

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

    Rect getBoundsForNewConfiguration() {
        return mWindowContainerController.getBoundsForNewConfiguration();
    }

    void positionChildWindowContainerAtTop(TaskRecord child) {
        mWindowContainerController.positionChildAtTop(child.getWindowContainerController(),
                true /* includingParents */);
    }

    /**
     * Defers updating the bounds of the stack. If the stack was resized/repositioned while
     * deferring, the bounds will update in {@link #continueUpdateBounds()}.
@@ -546,8 +590,7 @@ final class ActivityStack extends ConfigurationContainer {
        final boolean wasDeferred = mUpdateBoundsDeferred;
        mUpdateBoundsDeferred = false;
        if (wasDeferred && mUpdateBoundsDeferredCalled) {
            mStackSupervisor.resizeStackUncheckedLocked(this,
                    mDeferredBounds.isEmpty() ? null : mDeferredBounds,
            resize(mDeferredBounds.isEmpty() ? null : mDeferredBounds,
                    mDeferredTaskBounds.isEmpty() ? null : mDeferredTaskBounds,
                    mDeferredTaskInsetBounds.isEmpty() ? null : mDeferredTaskInsetBounds);
        }
@@ -765,7 +808,8 @@ final class ActivityStack extends ConfigurationContainer {

        task = topTask();
        if (task != null) {
            task.moveWindowContainerToTop(true /* includingParents */);
            mWindowContainerController.positionChildAtTop(task.getWindowContainerController(),
                    true /* includingParents */);
        }
    }

@@ -784,7 +828,7 @@ final class ActivityStack extends ConfigurationContainer {
            mTaskHistory.remove(task);
            mTaskHistory.add(0, task);
            updateTaskMovement(task, false);
            task.moveWindowContainerToBottom();
            mWindowContainerController.positionChildAtBottom(task.getWindowContainerController());
        }
    }

@@ -2578,7 +2622,8 @@ final class ActivityStack extends ConfigurationContainer {
        position = getAdjustedPositionForTask(task, position, null /* starting */);
        mTaskHistory.remove(task);
        mTaskHistory.add(position, task);
        task.positionWindowContainerAt(position);
        mWindowContainerController.positionChildAt(task.getWindowContainerController(), position,
                task.mBounds, task.getOverrideConfiguration());
        updateTaskMovement(task, true);
    }

@@ -2590,7 +2635,8 @@ final class ActivityStack extends ConfigurationContainer {
        final int position = getAdjustedPositionForTask(task, mTaskHistory.size(), starting);
        mTaskHistory.add(position, task);
        updateTaskMovement(task, true);
        task.moveWindowContainerToTop(true /* includingParents */);
        mWindowContainerController.positionChildAtTop(task.getWindowContainerController(),
                true /* includingParents */);
    }

    private void updateTaskReturnToForTopInsertion(TaskRecord task) {
@@ -2618,7 +2664,7 @@ final class ActivityStack extends ConfigurationContainer {
                // This also makes sure that non-home activities are visible under a transparent
                // non-home activity.
                task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE);
            } else if (!isHomeOrRecentsStack() && (fromHomeOrRecents || topTask != task)) {
            } else if (!isHomeOrRecentsStack() && (fromHomeOrRecents || topTask() != task)) {
                // If it's a last task over home - we default to keep its return to type not to
                // make underlying task focused when this one will be finished.
                int returnToType = isLastTaskOverHome
@@ -2868,7 +2914,8 @@ final class ActivityStack extends ConfigurationContainer {
                    targetTask.addActivityAtBottom(p);
                }

                targetTask.moveWindowContainerToBottom();
                mWindowContainerController.positionChildAtBottom(
                        targetTask.getWindowContainerController());
                replyChainEnd = -1;
            } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) {
                // If the activity should just be removed -- either
@@ -3004,7 +3051,8 @@ final class ActivityStack extends ConfigurationContainer {
                        if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p
                                + " from " + srcPos + " in to resetting task " + task);
                    }
                    task.moveWindowContainerToTop(true /* includingParents */);
                    mWindowContainerController.positionChildAtTop(
                            task.getWindowContainerController(), true /* includingParents */);

                    // Now we've moved it in to place...  but what if this is
                    // a singleTop activity and we have put it on top of another
@@ -4373,7 +4421,7 @@ final class ActivityStack extends ConfigurationContainer {
        }

        mWindowManager.prepareAppTransition(TRANSIT_TASK_TO_BACK, false);
        tr.moveWindowContainerToBottom();
        mWindowContainerController.positionChildAtBottom(tr.getWindowContainerController());

        final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null;
        if (prevIsHome || (task == tr && canGoHome) || (numTasks <= 1 && isOnHomeDisplay())) {
@@ -4436,11 +4484,24 @@ final class ActivityStack extends ConfigurationContainer {
        }
    }

    /** Update override configurations of all tasks in the stack. */
    void updateOverrideConfiguration(Rect stackBounds, Rect tempTaskBounds,
            Rect tempTaskInsetBounds) {
    // TODO: Figure-out a way to consolidate with resize() method below.
    @Override
    public void requestResize(Rect bounds) {
        mService.resizeStack(mStackId, bounds, true /* allowResizeInDockedMode */,
                false /* preserveWindows */, false /* animate */, -1 /* animationDuration */);
    }

    // TODO: Can only be called from special methods in ActivityStackSupervisor.
    // Need to consolidate those calls points into this resize method so anyone can call directly.
    void resize(Rect bounds, Rect tempTaskBounds, Rect tempTaskInsetBounds) {
        bounds = TaskRecord.validateBounds(bounds);

        if (!updateBoundsAllowed(bounds, tempTaskBounds, tempTaskInsetBounds)) {
            return;
        }

        final Rect taskBounds = tempTaskBounds != null ? tempTaskBounds : stackBounds;
        // Update override configurations of all tasks in the stack.
        final Rect taskBounds = tempTaskBounds != null ? tempTaskBounds : bounds;
        final Rect insetBounds = tempTaskInsetBounds != null ? tempTaskInsetBounds : taskBounds;

        mTmpBounds.clear();
@@ -4454,9 +4515,9 @@ final class ActivityStack extends ConfigurationContainer {
                    // For freeform stack we don't adjust the size of the tasks to match that
                    // of the stack, but we do try to make sure the tasks are still contained
                    // with the bounds of the stack.
                    tempRect2.set(task.mBounds);
                    fitWithinBounds(tempRect2, stackBounds);
                    task.updateOverrideConfiguration(tempRect2);
                    mTmpRect2.set(task.mBounds);
                    fitWithinBounds(mTmpRect2, bounds);
                    task.updateOverrideConfiguration(mTmpRect2);
                } else {
                    task.updateOverrideConfiguration(taskBounds, insetBounds);
                }
@@ -4469,11 +4530,9 @@ final class ActivityStack extends ConfigurationContainer {
            }
        }

        // We might trigger a configuration change. Save the current task bounds for freezing.
        mWindowManager.prepareFreezingTaskBounds(mStackId);
        mFullscreen = mWindowManager.resizeStack(mStackId, stackBounds, mTmpConfigs, mTmpBounds,
        mFullscreen = mWindowContainerController.resize(bounds, mTmpConfigs, mTmpBounds,
                mTmpInsetBounds);
        setBounds(stackBounds);
        setBounds(bounds);
    }


@@ -4897,7 +4956,8 @@ final class ActivityStack extends ConfigurationContainer {
        addTask(task, toTop ? MAX_VALUE : 0, reason);
        if (toTop) {
            // TODO: figure-out a way to remove this call.
            task.moveWindowContainerToTop(true /* includingParents */);
            mWindowContainerController.positionChildAtTop(task.getWindowContainerController(),
                    true /* includingParents */);
        }
    }

+40 −55

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -1835,7 +1835,7 @@ class ActivityStarter {
                mSupervisor.getNextTaskIdForUserLocked(mStartActivity.userId), mStartActivity.info,
                mIntent, null, null, true, mStartActivity.mActivityType);
        mStartActivity.setTask(task, null);
        mStartActivity.task.moveWindowContainerToTop(true /* includingParents */);
        mStartActivity.task.getStack().positionChildWindowContainerAtTop(mStartActivity.task);
        if (DEBUG_TASKS) Slog.v(TAG_TASKS,
                "Starting new activity " + mStartActivity + " in new guessed " + mStartActivity.task);
    }
Loading