Validate aspect ratio on PiP params change.

If the params do not provide the aspect ratio we will return 0f, which
impacts further computations on e.g. pinch resize gesture.

Bug: 276455406
Test: manually modify ApiDemos to not provide aspect ratio, enter PiP
and verify that aspect ratio is set to default value instead of 0

Change-Id: Ie734a4e35ccbccdad5a2bee0f0e1bd507dcc1025
This commit is contained in:
Mateusz Cicheński
2023-04-04 21:28:32 +00:00
parent b3d0060102
commit 86edc8c525
2 changed files with 11 additions and 2 deletions

View File

@@ -198,7 +198,7 @@ public class PipBoundsAlgorithm {
/**
* @return whether the given {@param aspectRatio} is valid.
*/
private boolean isValidPictureInPictureAspectRatio(float aspectRatio) {
public boolean isValidPictureInPictureAspectRatio(float aspectRatio) {
return Float.compare(mMinAspectRatio, aspectRatio) <= 0
&& Float.compare(aspectRatio, mMaxAspectRatio) <= 0;
}

View File

@@ -1230,7 +1230,16 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
protected void applyNewPictureInPictureParams(@NonNull PictureInPictureParams params) {
if (mDeferredTaskInfo != null || PipUtils.aspectRatioChanged(params.getAspectRatioFloat(),
mPictureInPictureParams.getAspectRatioFloat())) {
mPipParamsChangedForwarder.notifyAspectRatioChanged(params.getAspectRatioFloat());
if (mPipBoundsAlgorithm.isValidPictureInPictureAspectRatio(
params.getAspectRatioFloat())) {
mPipParamsChangedForwarder.notifyAspectRatioChanged(params.getAspectRatioFloat());
} else {
ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
"%s: New aspect ratio is not valid."
+ " hasAspectRatio=%b"
+ " aspectRatio=%f",
TAG, params.hasSetAspectRatio(), params.getAspectRatioFloat());
}
}
if (mDeferredTaskInfo != null
|| PipUtils.remoteActionsChanged(params.getActions(),