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

Commit 2570e334 authored by Louis Chang's avatar Louis Chang
Browse files

Update the surface size for tasks when config changes

The surface size was only set for the root task and the
surface size was not updated after entering split-screen
mode since those tasks were reparented to split-screen
organized tasks and were no longer be the root tasks.

Applying crop to root tasks, unless the task is created by
organizer. And also remove crop of the descendant tasks.

Bug: 153605363
Test: enter split-screen and rotate device
Test: atest TaskStackTests
Change-Id: I7b21c20dc676aa0be06c3c6e1b6b11c07a3d048d
parent d4fdca6e
Loading
Loading
Loading
Loading
+1 −63
Original line number Diff line number Diff line
@@ -18,11 +18,8 @@ package com.android.server.wm;

import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.PINNED_WINDOWING_MODE_ELEVATION_IN_DIP;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
@@ -142,13 +139,11 @@ import android.os.SystemClock;
import android.os.Trace;
import android.os.UserHandle;
import android.service.voice.IVoiceInteractionSession;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.SurfaceControl;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@@ -157,7 +152,6 @@ import com.android.internal.os.logging.MetricsLoggerWrapper;
import com.android.internal.util.function.pooled.PooledConsumer;
import com.android.internal.util.function.pooled.PooledFunction;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.internal.util.function.pooled.PooledPredicate;
import com.android.server.Watchdog;
import com.android.server.am.ActivityManagerService;
import com.android.server.am.ActivityManagerService.ItemMatcher;
@@ -276,11 +270,6 @@ class ActivityStack extends Task {

    Rect mPreAnimationBounds = new Rect();

    /**
     * For {@link #prepareSurfaces}.
     */
    private final Point mLastSurfaceSize = new Point();

    private final AnimatingActivityRegistry mAnimatingActivityRegistry =
            new AnimatingActivityRegistry();

@@ -606,10 +595,6 @@ class ActivityStack extends Task {

        super.onConfigurationChanged(newParentConfig);

        // Only need to update surface size here since the super method will handle updating
        // surface position.
        updateSurfaceSize(getPendingTransaction());

        final TaskDisplayArea taskDisplayArea = getDisplayArea();
        if (taskDisplayArea == null) {
            return;
@@ -3262,61 +3247,14 @@ class ActivityStack extends Task {
        scheduleAnimation();
    }

    /**
     * Calculate an amount by which to expand the stack bounds in each direction.
     * Used to make room for shadows in the pinned windowing mode.
     */
    int getStackOutset() {
        // If we are drawing shadows on the task then don't outset the stack.
        if (mWmService.mRenderShadowsInCompositor) {
            return 0;
        }
        DisplayContent displayContent = getDisplayContent();
        if (inPinnedWindowingMode() && displayContent != null) {
            final DisplayMetrics displayMetrics = displayContent.getDisplayMetrics();

            // We multiply by two to match the client logic for converting view elevation
            // to insets, as in {@link WindowManager.LayoutParams#setSurfaceInsets}
            return (int) Math.ceil(
                    mWmService.dipToPixel(PINNED_WINDOWING_MODE_ELEVATION_IN_DIP, displayMetrics)
                            * 2);
        }
        return 0;
    }

    @Override
    void getRelativePosition(Point outPos) {
        super.getRelativePosition(outPos);
        final int outset = getStackOutset();
        final int outset = getTaskOutset();
        outPos.x -= outset;
        outPos.y -= outset;
    }

    private void updateSurfaceSize(SurfaceControl.Transaction transaction) {
        if (mSurfaceControl == null) {
            return;
        }

        final Rect stackBounds = getBounds();
        int width = stackBounds.width();
        int height = stackBounds.height();

        final int outset = getStackOutset();
        width += 2 * outset;
        height += 2 * outset;

        if (width == mLastSurfaceSize.x && height == mLastSurfaceSize.y) {
            return;
        }
        transaction.setWindowCrop(mSurfaceControl, width, height);
        mLastSurfaceSize.set(width, height);
    }

    @VisibleForTesting
    Point getLastSurfaceSize() {
        return mLastSurfaceSize;
    }

    @Override
    void onDisplayChanged(DisplayContent dc) {
        super.onDisplayChanged(dc);
+57 −24
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Debug;
import android.os.IBinder;
@@ -213,7 +214,6 @@ class Task extends WindowContainer<WindowContainer> {

    static final int INVALID_MIN_SIZE = -1;
    private float mShadowRadius = 0;
    private final Rect mLastSurfaceCrop = new Rect();

    /**
     * The modes to control how the stack is moved to the front when calling {@link Task#reparent}.
@@ -397,6 +397,7 @@ class Task extends WindowContainer<WindowContainer> {

    private Dimmer mDimmer = new Dimmer(this);
    private final Rect mTmpDimBoundsRect = new Rect();
    private final Point mLastSurfaceSize = new Point();

    /** @see #setCanAffectSystemUiFlags */
    private boolean mCanAffectSystemUiFlags = true;
@@ -1943,6 +1944,10 @@ class Task extends WindowContainer<WindowContainer> {
        mTmpPrevBounds.set(getBounds());
        final boolean wasInMultiWindowMode = inMultiWindowMode();
        super.onConfigurationChanged(newParentConfig);
        // Only need to update surface size here since the super method will handle updating
        // surface position.
        updateSurfaceSize(getPendingTransaction());

        if (wasInMultiWindowMode != inMultiWindowMode()) {
            mStackSupervisor.scheduleUpdateMultiWindowMode(this);
        }
@@ -1995,6 +2000,57 @@ class Task extends WindowContainer<WindowContainer> {
        return (prevWinMode == WINDOWING_MODE_FREEFORM) != (newWinMode == WINDOWING_MODE_FREEFORM);
    }

    void updateSurfaceSize(SurfaceControl.Transaction transaction) {
        if (mSurfaceControl == null || mCreatedByOrganizer) {
            return;
        }

        // Apply crop to root tasks only and clear the crops of the descendant tasks.
        int width = 0;
        int height = 0;
        if (isRootTask()) {
            final Rect taskBounds = getBounds();
            width = taskBounds.width();
            height = taskBounds.height();

            final int outset = getTaskOutset();
            width += 2 * outset;
            height += 2 * outset;
        }
        if (width == mLastSurfaceSize.x && height == mLastSurfaceSize.y) {
            return;
        }
        transaction.setWindowCrop(mSurfaceControl, width, height);
        mLastSurfaceSize.set(width, height);
    }

    /**
     * Calculate an amount by which to expand the task bounds in each direction.
     * Used to make room for shadows in the pinned windowing mode.
     */
    int getTaskOutset() {
        // If we are drawing shadows on the task then don't outset the stack.
        if (mWmService.mRenderShadowsInCompositor) {
            return 0;
        }
        DisplayContent displayContent = getDisplayContent();
        if (inPinnedWindowingMode() && displayContent != null) {
            final DisplayMetrics displayMetrics = displayContent.getDisplayMetrics();

            // We multiply by two to match the client logic for converting view elevation
            // to insets, as in {@link WindowManager.LayoutParams#setSurfaceInsets}
            return (int) Math.ceil(
                    mWmService.dipToPixel(PINNED_WINDOWING_MODE_ELEVATION_IN_DIP, displayMetrics)
                            * 2);
        }
        return 0;
    }

    @VisibleForTesting
    Point getLastSurfaceSize() {
        return mLastSurfaceSize;
    }

    @VisibleForTesting
    boolean isInChangeTransition() {
        return mSurfaceFreezer.hasLeash() || AppTransition.isChangeTransit(mTransit);
@@ -2803,28 +2859,6 @@ class Task extends WindowContainer<WindowContainer> {
        return boundsChange;
    }

    private void updateSurfaceCrop() {
        // Only update the crop if we are drawing shadows on the task.
        if (mSurfaceControl == null || !mWmService.mRenderShadowsInCompositor || !isRootTask()) {
            return;
        }

        if (inSplitScreenWindowingMode()) {
            // inherit crop from parent
            mTmpRect.setEmpty();
        } else {
            getBounds(mTmpRect);
        }

        mTmpRect.offsetTo(0, 0);
        if (mLastSurfaceCrop.equals(mTmpRect)) {
            return;
        }

        getPendingTransaction().setWindowCrop(mSurfaceControl, mTmpRect);
        mLastSurfaceCrop.set(mTmpRect);
    }

    @Override
    public boolean onDescendantOrientationChanged(IBinder freezeDisplayToken,
            ConfigurationContainer requestingContainer) {
@@ -3453,7 +3487,6 @@ class Task extends WindowContainer<WindowContainer> {
            mTmpDimBoundsRect.offsetTo(0, 0);
        }

        updateSurfaceCrop();
        updateShadowsRadius(isFocused(), getPendingTransaction());

        if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
+1 −1
Original line number Diff line number Diff line
@@ -5289,7 +5289,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        // to account for it. If we actually have shadows we will
        // then un-inset ourselves by the surfaceInsets.
        if (stack != null) {
            final int outset = stack.getStackOutset();
            final int outset = stack.getTaskOutset();
            outPoint.offset(outset, outset);
        }

+1 −1
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ public class TaskStackTests extends WindowTestsBase {
        final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent);
        final int stackOutset = 10;
        spyOn(stack);
        doReturn(stackOutset).when(stack).getStackOutset();
        doReturn(stackOutset).when(stack).getTaskOutset();
        doReturn(true).when(stack).inMultiWindowMode();

        // Mock the resolved override windowing mode to non-fullscreen