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

Commit aebde404 authored by Mateusz Cicheński's avatar Mateusz Cicheński
Browse files

Validate aspect ratio if source rect hint is provided

This change simply adds a warning for the app developers and mentions
that this behavior might change in future releases.

Bug: 298529550
Bug: 326989052
Test: both log messages show for wide aspect ratio videos
Test: example of why animation is bad in those cases http://recall/-/ekEuGtt9d9HWqkUtAzpHx8/haMvMxYpHcxiNt9gkAbGbP
Flag: none

Change-Id: I5193a1d19d86e2ec4456d1366433e7316b469e22
parent af9ab323
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);