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

Commit 675c606a authored by Mateusz Cicheński's avatar Mateusz Cicheński Committed by Android (Google) Code Review
Browse files

Merge "Validate aspect ratio if source rect hint is provided" into main

parents c6e5b9ea aebde404
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.util.Rational;
import android.view.Choreographer;
import android.view.Display;
import android.view.Surface;
@@ -126,6 +127,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
            SystemProperties.getInt(
                    "persist.wm.debug.extra_content_overlay_fade_out_delay_ms", 400);

    private static final float PIP_ASPECT_RATIO_MISMATCH_THRESHOLD = 0.005f;

    private final Context mContext;
    private final SyncTransactionQueue mSyncTransactionQueue;
    private final PipBoundsState mPipBoundsState;
@@ -767,6 +770,37 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
                    mPictureInPictureParams.getTitle());
            mPipParamsChangedForwarder.notifySubtitleChanged(
                    mPictureInPictureParams.getSubtitle());

            if (mPictureInPictureParams.hasSourceBoundsHint()
                    && mPictureInPictureParams.hasSetAspectRatio()) {
                Rational sourceRectHintAspectRatio = new Rational(
                        mPictureInPictureParams.getSourceRectHint().width(),
                        mPictureInPictureParams.getSourceRectHint().height());
                if (sourceRectHintAspectRatio.compareTo(
                        mPictureInPictureParams.getAspectRatio()) != 0) {
                    ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                            "Aspect ratio of source rect hint (%d/%d) does not match the provided "
                                    + "aspect ratio value (%d/%d). Consider matching them for "
                                    + "improved animation. Future releases might override the "
                                    + "value to match.",
                            mPictureInPictureParams.getSourceRectHint().width(),
                            mPictureInPictureParams.getSourceRectHint().height(),
                            mPictureInPictureParams.getAspectRatio().getNumerator(),
                            mPictureInPictureParams.getAspectRatio().getDenominator());
                }
                if (Math.abs(sourceRectHintAspectRatio.floatValue()
                        - mPictureInPictureParams.getAspectRatioFloat())
                        > PIP_ASPECT_RATIO_MISMATCH_THRESHOLD) {
                    ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                            "Aspect ratio of source rect hint (%f) does not match the provided "
                                    + "aspect ratio value (%f) and is above threshold of %f. "
                                    + "Consider matching them for improved animation. Future "
                                    + "releases might override the value to match.",
                            sourceRectHintAspectRatio.floatValue(),
                            mPictureInPictureParams.getAspectRatioFloat(),
                            PIP_ASPECT_RATIO_MISMATCH_THRESHOLD);
                }
            }
        }

        mPipUiEventLoggerLogger.setTaskInfo(mTaskInfo);