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

Commit ea5e87f6 authored by Wale Ogunwale's avatar Wale Ogunwale Committed by Louis Chang
Browse files

Clean-up Bounds Animator code path (92/n)

Use configBounds to set the configuration bounds exposed to the app and
displayedbounds to set what the user see happening with the surface.
This is clearer than the concept of stack bounds vs. task bounds. which
we won't be able to use for tasks/stacks that are only one level deep.

Bug: 10163964
Test: Pip works and existing tests pass.
Change-Id: I986a5098cd81ea1c455c44eb2f704d803cf10b50
parent 0d46519b
Loading
Loading
Loading
Loading
+25 −22
Original line number Diff line number Diff line
@@ -742,8 +742,8 @@ class ActivityStack extends Task implements BoundsAnimationTarget {
                setBounds(newBounds);
            } else if (overrideWindowingMode != WINDOWING_MODE_PINNED) {
                // For pinned stack, resize is now part of the {@link WindowContainerTransaction}
                resize(new Rect(newBounds), null /* tempTaskBounds */,
                        null /* tempTaskInsetBounds */, PRESERVE_WINDOWS, true /* deferResume */);
                resize(new Rect(newBounds), null /* configBounds */,
                        PRESERVE_WINDOWS, true /* deferResume */);
            }
        }
        if (prevIsAlwaysOnTop != isAlwaysOnTop()) {
@@ -952,7 +952,7 @@ class ActivityStack extends Task implements BoundsAnimationTarget {
            }

            if (!Objects.equals(getRequestedOverrideBounds(), mTmpRect2)) {
                resize(mTmpRect2, null /* tempTaskBounds */, null /* tempTaskInsetBounds */,
                resize(mTmpRect2, null /*configBounds*/,
                        false /*preserveWindows*/, true /*deferResume*/);
            }
        } finally {
@@ -3093,24 +3093,30 @@ class ActivityStack extends Task implements BoundsAnimationTarget {

    // 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,
            boolean preserveWindows, boolean deferResume) {
        if (!updateBoundsAllowed(bounds)) {
    void resize(Rect displayedBounds, Rect configBounds, boolean preserveWindows,
            boolean deferResume) {
        if (!updateBoundsAllowed(displayedBounds)) {
            return;
        }

        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "stack.resize_" + getRootTaskId());
        mAtmService.deferWindowLayout();
        try {
            // TODO: Why not just set this on the stack directly vs. on each tasks?
            // Update override configurations of all tasks in the stack.
            final Rect taskBounds = tempTaskBounds != null ? tempTaskBounds : bounds;
            final PooledConsumer c = PooledLambda.obtainConsumer(
                    ActivityStack::processTaskResizeBounds, PooledLambda.__(Task.class),
                    taskBounds, tempTaskInsetBounds);
            forAllLeafTasks(c, true /* traverseTopToBottom */);
                    displayedBounds, configBounds);
            forAllTasks(c, true /* traverseTopToBottom */);
            c.recycle();

            setBounds(bounds);
            if (mBoundsAnimating) {
                // Force to update task surface bounds and relayout windows, since configBounds
                // remains unchanged during bounds animation.
                updateSurfaceBounds();
                getDisplay().setLayoutNeeded();
                mWmService.requestTraversal();
            }

            if (!deferResume) {
                ensureVisibleActivitiesConfiguration(topRunningActivity(), preserveWindows);
@@ -3121,15 +3127,16 @@ class ActivityStack extends Task implements BoundsAnimationTarget {
        }
    }

    private static void processTaskResizeBounds(Task task, Rect bounds, Rect insetBounds) {
    private static void processTaskResizeBounds(
            Task task, Rect displayedBounds, Rect configBounds) {
        if (!task.isResizeable()) return;

        if (insetBounds != null && !insetBounds.isEmpty()) {
            task.setOverrideDisplayedBounds(bounds);
            task.setBounds(insetBounds);
        if (configBounds != null && !configBounds.isEmpty()) {
            task.setOverrideDisplayedBounds(displayedBounds);
            task.setBounds(configBounds);
        } else {
            task.setOverrideDisplayedBounds(null);
            task.setBounds(bounds);
            task.setBounds(displayedBounds);
        }
    }

@@ -4583,19 +4590,15 @@ class ActivityStack extends Task implements BoundsAnimationTarget {
        return task != null;
    }

    public boolean setPinnedStackSize(Rect stackBounds, Rect tempTaskBounds) {
    public boolean setPinnedStackSize(Rect displayedBounds, Rect configBounds) {
        // Hold the lock since this is called from the BoundsAnimator running on the UiThread
        synchronized (mWmService.mGlobalLock) {
            if (mCancelCurrentBoundsAnimation) {
                return false;
            }
            mStackSupervisor.resizePinnedStack(displayedBounds, configBounds);
        }

        try {
            mWmService.mActivityTaskManager.resizePinnedStack(stackBounds, tempTaskBounds);
        } catch (RemoteException e) {
            // I don't believe you.
        }
        return true;
    }

+17 −21
Original line number Diff line number Diff line
@@ -1443,8 +1443,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
                // still need moveTaskToFrontLocked() below for any transition settings.
            }
            if (stack.shouldResizeStackWithLaunchBounds()) {
                stack.resize(bounds, null /* tempTaskBounds */, null /* tempTaskInsetBounds */,
                        !PRESERVE_WINDOWS, !DEFER_RESUME);
                stack.resize(bounds, null /* configBounds */, !PRESERVE_WINDOWS, !DEFER_RESUME);
            } else {
                // 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
@@ -1604,7 +1603,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
                false /* deferResume */);
    }

    void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds,
    void resizeDockedStackLocked(Rect displayedBounds, Rect tempDockedTaskBounds,
            Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds,
            boolean preserveWindows, boolean deferResume) {

@@ -1622,7 +1621,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {

        if (mDockedStackResizing) {
            mHasPendingDockedBounds = true;
            mPendingDockedBounds = copyOrNull(dockedBounds);
            mPendingDockedBounds = copyOrNull(displayedBounds);
            mPendingTempDockedTaskBounds = copyOrNull(tempDockedTaskBounds);
            mPendingTempDockedTaskInsetBounds = copyOrNull(tempDockedTaskInsetBounds);
            mPendingTempOtherTaskBounds = copyOrNull(tempOtherTaskBounds);
@@ -1635,13 +1634,13 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
            // Don't allow re-entry while resizing. E.g. due to docked stack detaching.
            mAllowDockedStackResize = false;
            ActivityRecord r = stack.topRunningActivity();
            stack.resize(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds,
            stack.resize(displayedBounds, tempDockedTaskBounds,
                    !PRESERVE_WINDOWS, DEFER_RESUME);

            // TODO: Checking for isAttached might not be needed as if the user passes in null
            // dockedBounds then they want the docked stack to be dismissed.
            if (stack.getWindowingMode() == WINDOWING_MODE_FULLSCREEN
                    || (dockedBounds == null && !stack.isAttached())) {
                    || (displayedBounds == null && !stack.isAttached())) {
                // The dock stack either was dismissed or went fullscreen, which is kinda the same.
                // In this case we make all other static stacks fullscreen and move all
                // docked stack tasks to the fullscreen stack.
@@ -1669,7 +1668,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
                        // interaction.
                        continue;
                    }
                    current.getStackDockedModeBounds(dockedBounds,
                    current.getStackDockedModeBounds(displayedBounds,
                            tempOtherTaskBounds /* currentTempTaskBounds */,
                            tempRect /* outStackBounds */,
                            otherTaskRect /* outTempTaskBounds */);
@@ -1684,9 +1683,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
                                + " non-fullscreen stack");
                    }

                    current.resize(tempRect,
                            !otherTaskRect.isEmpty() ? otherTaskRect : tempOtherTaskBounds,
                            tempOtherTaskInsetBounds, preserveWindows, deferResume);
                    current.resize(tempRect, tempOtherTaskBounds, preserveWindows, deferResume);
                }
            }
            if (!deferResume) {
@@ -1699,7 +1696,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
        }
    }

    void resizePinnedStackLocked(Rect pinnedBounds, Rect tempPinnedTaskBounds) {
    void resizePinnedStack(Rect displayedBounds, Rect inConfigBounds) {
        // TODO(multi-display): The display containing the stack should be passed in.
        final ActivityStack stack =
                mRootWindowContainer.getDefaultDisplay().getRootPinnedTask();
@@ -1711,23 +1708,22 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "resizePinnedStack");
        mService.deferWindowLayout();
        try {
            Rect insetBounds = null;
            if (tempPinnedTaskBounds != null && stack.isAnimatingBoundsToFullscreen()) {
            Rect configBounds = null;
            if (inConfigBounds != null) {
                // Use 0,0 as the position for the inset rect because we are headed for fullscreen.
                insetBounds = tempRect;
                insetBounds.top = 0;
                insetBounds.left = 0;
                insetBounds.right = tempPinnedTaskBounds.width();
                insetBounds.bottom = tempPinnedTaskBounds.height();
                configBounds = tempRect;
                configBounds.top = 0;
                configBounds.left = 0;
                configBounds.right = inConfigBounds.width();
                configBounds.bottom = inConfigBounds.height();
            }
            if (pinnedBounds != null && tempPinnedTaskBounds == null) {
            if (displayedBounds != null && inConfigBounds == null) {
                // We have finished the animation into PiP, and are resizing the tasks to match the
                // stack bounds, while layouts are deferred, update any task state as a part of
                // transitioning it from fullscreen into a floating state.
                stack.onPipAnimationEndResize();
            }
            stack.resize(pinnedBounds, tempPinnedTaskBounds, insetBounds, !PRESERVE_WINDOWS,
                    !DEFER_RESUME);
            stack.resize(displayedBounds, configBounds, !PRESERVE_WINDOWS, !DEFER_RESUME);
        } finally {
            mService.continueWindowLayout();
            Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
+2 −2
Original line number Diff line number Diff line
@@ -4434,12 +4434,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
    }

    @Override
    public void resizePinnedStack(Rect pinnedBounds, Rect tempPinnedTaskBounds) {
    public void resizePinnedStack(Rect displayedBounds, Rect configBounds) {
        enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizePinnedStack()");
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                mStackSupervisor.resizePinnedStackLocked(pinnedBounds, tempPinnedTaskBounds);
                mStackSupervisor.resizePinnedStack(displayedBounds, configBounds);
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ interface BoundsAnimationTarget {
     * animation is now invalid and not required. In such a case, the cancel will trigger the
     * animation end callback as well, but will not send any further size changes.
     */
    boolean setPinnedStackSize(Rect stackBounds, Rect taskBounds);
    boolean setPinnedStackSize(Rect displayedBounds, Rect configBounds);

    /** Sets the alpha of the animation target */
    boolean setPinnedStackAlpha(float alpha);
+1 −0
Original line number Diff line number Diff line
@@ -2627,6 +2627,7 @@ class Task extends WindowContainer<WindowContainer> {
     */
    void setOverrideDisplayedBounds(Rect overrideDisplayedBounds) {
        if (overrideDisplayedBounds != null) {
            adjustForMinimalTaskDimensions(overrideDisplayedBounds, mOverrideDisplayedBounds);
            mOverrideDisplayedBounds.set(overrideDisplayedBounds);
        } else {
            mOverrideDisplayedBounds.setEmpty();
Loading