From 8e8a8ae5675261f4af586ad5585d89aaea761223 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Tue, 3 Mar 2020 11:06:56 -0800 Subject: [PATCH] Schedule new transition on aspect ratio change only When we receive TaskOrganizer#onTaskInfoChanged callback, there is no need to schedule new transition if the aspect ratio remains same since no other parameters in PictureInPictureParams affect bounds. Bug: 150606166 Test: Next/Prev on expanded YouTube PiP Change-Id: I69d269f379308d0d3a333ce56acd3976b4a54983 --- .../android/systemui/pip/PipTaskOrganizer.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java index 1566877c7204b..836485a46e365 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java +++ b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java @@ -219,12 +219,28 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub { @Override public void onTaskInfoChanged(ActivityManager.RunningTaskInfo info) { + final PictureInPictureParams newParams = info.pictureInPictureParams; + if (!shouldUpdateDestinationBounds(newParams)) { + Log.d(TAG, "Ignored onTaskInfoChanged with PiP param: " + newParams); + return; + } final Rect destinationBounds = mPipBoundsHandler.getDestinationBounds( - getAspectRatioOrDefault(info.pictureInPictureParams), null /* bounds */); + getAspectRatioOrDefault(newParams), null /* bounds */); Objects.requireNonNull(destinationBounds, "Missing destination bounds"); animateResizePip(destinationBounds, DURATION_DEFAULT_MS); } + /** + * @return {@code true} if the aspect ratio is changed since no other parameters within + * {@link PictureInPictureParams} would affect the bounds. + */ + private boolean shouldUpdateDestinationBounds(PictureInPictureParams params) { + if (params == null || mTaskInfo.pictureInPictureParams == null) { + return params != mTaskInfo.pictureInPictureParams; + } + return !Objects.equals(mTaskInfo.pictureInPictureParams.getAspectRatioRational(), + params.getAspectRatioRational()); + } /** * Directly perform manipulation/resize on the leash. This will not perform any