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

Commit 33bb1eb9 authored by Ikram Gabiyev's avatar Ikram Gabiyev Committed by Android (Google) Code Review
Browse files

Merge "Update PiP on display change" into main

parents fcd43343 a50a0106
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -115,8 +115,11 @@ public final class TransitionRequestInfo implements Parcelable {
    @DataClass(genToString = true, genSetters = true, genBuilder = false, genConstructor = false)
    @DataClass(genToString = true, genSetters = true, genBuilder = false, genConstructor = false)
    public static final class DisplayChange implements Parcelable {
    public static final class DisplayChange implements Parcelable {
        private final int mDisplayId;
        private final int mDisplayId;

        // If non-null, these bounds changes should ignore any potential rotation changes.
        @Nullable private Rect mStartAbsBounds = null;
        @Nullable private Rect mStartAbsBounds = null;
        @Nullable private Rect mEndAbsBounds = null;
        @Nullable private Rect mEndAbsBounds = null;

        private int mStartRotation = WindowConfiguration.ROTATION_UNDEFINED;
        private int mStartRotation = WindowConfiguration.ROTATION_UNDEFINED;
        private int mEndRotation = WindowConfiguration.ROTATION_UNDEFINED;
        private int mEndRotation = WindowConfiguration.ROTATION_UNDEFINED;
        private boolean mPhysicalDisplayChanged = false;
        private boolean mPhysicalDisplayChanged = false;
+10 −2
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.Size;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseArray;
import android.view.Display;
import android.view.Display;
@@ -193,8 +194,8 @@ public class DisplayController {




    /** Called when a display rotate requested. */
    /** Called when a display rotate requested. */
    public void onDisplayRotateRequested(WindowContainerTransaction wct, int displayId,
    public void onDisplayChangeRequested(WindowContainerTransaction wct, int displayId,
            int fromRotation, int toRotation) {
            Rect startAbsBounds, Rect endAbsBounds, int fromRotation, int toRotation) {
        synchronized (mDisplays) {
        synchronized (mDisplays) {
            final DisplayRecord dr = mDisplays.get(displayId);
            final DisplayRecord dr = mDisplays.get(displayId);
            if (dr == null) {
            if (dr == null) {
@@ -203,6 +204,13 @@ public class DisplayController {
            }
            }


            if (dr.mDisplayLayout != null) {
            if (dr.mDisplayLayout != null) {
                if (endAbsBounds != null) {
                    // If there is a change in the display dimensions update the layout as well;
                    // note that endAbsBounds should ignore any potential rotation changes, so
                    // we still need to rotate the layout after if needed.
                    dr.mDisplayLayout.resizeTo(dr.mContext.getResources(),
                            new Size(endAbsBounds.width(), endAbsBounds.height()));
                }
                dr.mDisplayLayout.rotateTo(dr.mContext.getResources(), toRotation);
                dr.mDisplayLayout.rotateTo(dr.mContext.getResources(), toRotation);
            }
            }


+11 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ import android.graphics.Rect;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.provider.Settings;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.DisplayMetrics;
import android.util.Size;
import android.view.Display;
import android.view.Display;
import android.view.DisplayCutout;
import android.view.DisplayCutout;
import android.view.DisplayInfo;
import android.view.DisplayInfo;
@@ -244,6 +245,16 @@ public class DisplayLayout {
        recalcInsets(res);
        recalcInsets(res);
    }
    }


    /**
     * Update the dimensions of this layout.
     */
    public void resizeTo(Resources res, Size displaySize) {
        mWidth = displaySize.getWidth();
        mHeight = displaySize.getHeight();

        recalcInsets(res);
    }

    /** Get this layout's non-decor insets. */
    /** Get this layout's non-decor insets. */
    public Rect nonDecorInsets() {
    public Rect nonDecorInsets() {
        return mNonDecorInsets;
        return mNonDecorInsets;
+18 −25
Original line number Original line Diff line number Diff line
@@ -29,7 +29,6 @@ import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Bundle;
import android.view.InsetsState;
import android.view.SurfaceControl;
import android.view.SurfaceControl;
import android.window.DisplayAreaInfo;
import android.window.DisplayAreaInfo;
import android.window.WindowContainerTransaction;
import android.window.WindowContainerTransaction;
@@ -200,16 +199,7 @@ public class PipController implements ConfigurationChangeListener,
        DisplayLayout layout = new DisplayLayout(mContext, mContext.getDisplay());
        DisplayLayout layout = new DisplayLayout(mContext, mContext.getDisplay());
        mPipDisplayLayoutState.setDisplayLayout(layout);
        mPipDisplayLayoutState.setDisplayLayout(layout);


        mDisplayController.addDisplayWindowListener(this);
        mDisplayController.addDisplayChangingController(this);
        mDisplayController.addDisplayChangingController(this);
        mDisplayInsetsController.addInsetsChangedListener(mPipDisplayLayoutState.getDisplayId(),
                new DisplayInsetsController.OnInsetsChangedListener() {
                    @Override
                    public void insetsChanged(InsetsState insetsState) {
                        setDisplayLayout(mDisplayController
                                        .getDisplayLayout(mPipDisplayLayoutState.getDisplayId()));
                    }
                });
        mDisplayInsetsController.addInsetsChangedListener(mPipDisplayLayoutState.getDisplayId(),
        mDisplayInsetsController.addInsetsChangedListener(mPipDisplayLayoutState.getDisplayId(),
                new ImeListener(mDisplayController, mPipDisplayLayoutState.getDisplayId()) {
                new ImeListener(mDisplayController, mPipDisplayLayoutState.getDisplayId()) {
                    @Override
                    @Override
@@ -285,34 +275,37 @@ public class PipController implements ConfigurationChangeListener,
        setDisplayLayout(mDisplayController.getDisplayLayout(displayId));
        setDisplayLayout(mDisplayController.getDisplayLayout(displayId));
    }
    }


    @Override
    public void onDisplayConfigurationChanged(int displayId, Configuration newConfig) {
        if (displayId != mPipDisplayLayoutState.getDisplayId()) {
            return;
        }
        setDisplayLayout(mDisplayController.getDisplayLayout(displayId));
    }

    /**
    /**
     * A callback for any observed transition that contains a display change in its
     * A callback for any observed transition that contains a display change in its
     * {@link android.window.TransitionRequestInfo} with a non-zero rotation delta.
     * {@link android.window.TransitionRequestInfo},
     */
     */
    @Override
    @Override
    public void onDisplayChange(int displayId, int fromRotation, int toRotation,
    public void onDisplayChange(int displayId, int fromRotation, int toRotation,
            @Nullable DisplayAreaInfo newDisplayAreaInfo, WindowContainerTransaction t) {
            @Nullable DisplayAreaInfo newDisplayAreaInfo, WindowContainerTransaction t) {
        if (displayId != mPipDisplayLayoutState.getDisplayId()) {
            return;
        }
        final float snapFraction = mPipBoundsAlgorithm.getSnapFraction(mPipBoundsState.getBounds());
        final float boundsScale = mPipBoundsState.getBoundsScale();

        // Update the display layout caches even if we are not in PiP.
        setDisplayLayout(mDisplayController.getDisplayLayout(displayId));

        if (!mPipTransitionState.isInPip()) {
        if (!mPipTransitionState.isInPip()) {
            return;
            return;
        }
        }


        // Calculate the snap fraction pre-rotation.
        mPipTouchHandler.updateMinMaxSize(mPipBoundsState.getAspectRatio());
        float snapFraction = mPipBoundsAlgorithm.getSnapFraction(mPipBoundsState.getBounds());


        // Update the caches to reflect the new display layout and movement bounds.
        // Update the caches to reflect the new display layout in the movement bounds;
        mPipDisplayLayoutState.rotateTo(toRotation);
        // temporarily update bounds to be at the top left for the movement bounds calculation.
        Rect toBounds = new Rect(0, 0,
                (int) Math.ceil(mPipBoundsState.getMaxSize().x * boundsScale),
                (int) Math.ceil(mPipBoundsState.getMaxSize().y * boundsScale));
        mPipBoundsState.setBounds(toBounds);
        mPipTouchHandler.updateMovementBounds();
        mPipTouchHandler.updateMovementBounds();


        // The policy is to keep PiP width, height and snap fraction invariant.
        // The policy is to keep PiP snap fraction invariant.
        Rect toBounds = mPipBoundsState.getBounds();
        mPipBoundsAlgorithm.applySnapFraction(toBounds, snapFraction);
        mPipBoundsAlgorithm.applySnapFraction(toBounds, snapFraction);
        mPipBoundsState.setBounds(toBounds);
        mPipBoundsState.setBounds(toBounds);
        t.setBounds(mPipTransitionState.mPipTaskToken, toBounds);
        t.setBounds(mPipTransitionState.mPipTaskToken, toBounds);
+6 −3
Original line number Original line Diff line number Diff line
@@ -1187,12 +1187,15 @@ public class Transitions implements RemoteCallable<Transitions>,
            }
            }
            if (request.getDisplayChange() != null) {
            if (request.getDisplayChange() != null) {
                TransitionRequestInfo.DisplayChange change = request.getDisplayChange();
                TransitionRequestInfo.DisplayChange change = request.getDisplayChange();
                if (change.getEndRotation() != change.getStartRotation()) {
                if (change.getStartRotation() != change.getEndRotation()
                    // Is a rotation, so dispatch to all displayChange listeners
                        || (change.getStartAbsBounds() != null
                        && !change.getStartAbsBounds().equals(change.getEndAbsBounds()))) {
                    // Is a display change, so dispatch to all displayChange listeners
                    if (wct == null) {
                    if (wct == null) {
                        wct = new WindowContainerTransaction();
                        wct = new WindowContainerTransaction();
                    }
                    }
                    mDisplayController.onDisplayRotateRequested(wct, change.getDisplayId(),
                    mDisplayController.onDisplayChangeRequested(wct, change.getDisplayId(),
                            change.getStartAbsBounds(), change.getEndAbsBounds(),
                            change.getStartRotation(), change.getEndRotation());
                            change.getStartRotation(), change.getEndRotation());
                }
                }
            }
            }