Deprecates the animatingBounds from WM to SysUI
PipTouchHandler, similar to other components in SysUI, should be in-sync
with the destination bounds calculated within SysUI rather than WM.
Fixed also the empty movement bounds upon the first call to
PipTouchHandler#onMovementBoundsChanged. Together, this change should
fix the PIP not being lifted on IME show up. PipTouchHandlerTest is
updated correspondingly.
Bug: 153352899
Test: manually enter/exit PiP
Test: atest PipTouchHandlerTest
Change-Id: I2912af2a181b7fb57c6d90751744d46c6b3366d2
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/PinnedStackListenerForwarder.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/PinnedStackListenerForwarder.java
index 34a0268..4794847 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/PinnedStackListenerForwarder.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/PinnedStackListenerForwarder.java
@@ -18,7 +18,6 @@
import android.content.ComponentName;
import android.content.pm.ParceledListSlice;
-import android.graphics.Rect;
import android.view.DisplayInfo;
import android.view.IPinnedStackController;
import android.view.IPinnedStackListener;
@@ -53,9 +52,9 @@
}
@Override
- public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment) {
+ public void onMovementBoundsChanged(boolean fromImeAdjustment) {
for (PinnedStackListener listener : mListeners) {
- listener.onMovementBoundsChanged(animatingBounds, fromImeAdjustment);
+ listener.onMovementBoundsChanged(fromImeAdjustment);
}
}
@@ -108,7 +107,7 @@
public static class PinnedStackListener {
public void onListenerRegistered(IPinnedStackController controller) {}
- public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment) {}
+ public void onMovementBoundsChanged(boolean fromImeAdjustment) {}
public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) {}
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
index d2994ae..a95d6b7 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
@@ -317,17 +317,22 @@
/**
* TODO(b/152809058): consolidate the display info handling logic in SysUI
+ *
+ * @param destinationBoundsOut the current destination bounds will be populated to this param
*/
@SuppressWarnings("unchecked")
- public void onMovementBoundsChanged(boolean fromImeAdjustment, boolean fromShelfAdjustment) {
+ public void onMovementBoundsChanged(Rect destinationBoundsOut,
+ boolean fromImeAdjustment, boolean fromShelfAdjustment) {
final PipAnimationController.PipTransitionAnimator animator =
mPipAnimationController.getCurrentAnimator();
+ destinationBoundsOut.set(mLastReportedBounds);
if (animator == null || !animator.isRunning()
|| animator.getTransitionDirection() != TRANSITION_DIRECTION_TO_PIP) {
return;
}
final Rect currentDestinationBounds = animator.getDestinationBounds();
+ destinationBoundsOut.set(currentDestinationBounds);
if (!fromImeAdjustment && !fromShelfAdjustment
&& mPipBoundsHandler.getDisplayBounds().contains(currentDestinationBounds)) {
// no need to update the destination bounds, bail early
@@ -342,6 +347,7 @@
animator.updateEndValue(newDestinationBounds);
}
animator.setDestinationBounds(newDestinationBounds);
+ destinationBoundsOut.set(newDestinationBounds);
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
index 918c45b..a2667d9 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
@@ -21,6 +21,7 @@
import static com.android.systemui.pip.PipAnimationController.TRANSITION_DIRECTION_TO_FULLSCREEN;
+import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.app.IActivityManager;
@@ -160,9 +161,9 @@
}
@Override
- public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment) {
- mHandler.post(() -> updateMovementBounds(animatingBounds, fromImeAdjustment,
- false /* fromShelfAdjustment */));
+ public void onMovementBoundsChanged(boolean fromImeAdjustment) {
+ mHandler.post(() -> updateMovementBounds(null /* toBounds */,
+ fromImeAdjustment, false /* fromShelfAdjustment */));
}
@Override
@@ -352,17 +353,19 @@
mMenuController.onPinnedStackAnimationEnded();
}
- private void updateMovementBounds(Rect animatingBounds, boolean fromImeAdjustment,
- boolean fromShelfAdjustment) {
+ private void updateMovementBounds(@Nullable Rect toBounds,
+ boolean fromImeAdjustment, boolean fromShelfAdjustment) {
// Populate inset / normal bounds and DisplayInfo from mPipBoundsHandler before
- // passing to mTouchHandler, mTouchHandler would rely on the bounds calculated by
- // mPipBoundsHandler with up-to-dated information
+ // passing to mTouchHandler/mPipTaskOrganizer
+ final Rect outBounds = new Rect(toBounds);
mPipBoundsHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds,
- animatingBounds, mTmpDisplayInfo);
+ outBounds, mTmpDisplayInfo);
+ // mTouchHandler would rely on the bounds populated from mPipTaskOrganizer
+ mPipTaskOrganizer.onMovementBoundsChanged(outBounds,
+ fromImeAdjustment, fromShelfAdjustment);
mTouchHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds,
- animatingBounds, fromImeAdjustment, fromShelfAdjustment,
+ outBounds, fromImeAdjustment, fromShelfAdjustment,
mTmpDisplayInfo.rotation);
- mPipTaskOrganizer.onMovementBoundsChanged(fromImeAdjustment, fromShelfAdjustment);
}
public void dump(PrintWriter pw) {
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
index 1e9daab..ddba9ea 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
@@ -380,11 +380,18 @@
}
// Re-calculate the expanded bounds
- mNormalBounds = normalBounds;
+ mNormalBounds.set(normalBounds);
Rect normalMovementBounds = new Rect();
mSnapAlgorithm.getMovementBounds(mNormalBounds, insetBounds, normalMovementBounds,
bottomOffset);
+ if (mMovementBounds.isEmpty()) {
+ // mMovementBounds is not initialized yet and a clean movement bounds without
+ // bottom offset shall be used later in this function.
+ mSnapAlgorithm.getMovementBounds(curBounds, insetBounds, mMovementBounds,
+ 0 /* bottomOffset */);
+ }
+
// Calculate the expanded size
float aspectRatio = (float) normalBounds.width() / normalBounds.height();
Point displaySize = new Point();
@@ -430,8 +437,8 @@
// Update the movement bounds after doing the calculations based on the old movement bounds
// above
- mNormalMovementBounds = normalMovementBounds;
- mExpandedMovementBounds = expandedMovementBounds;
+ mNormalMovementBounds.set(normalMovementBounds);
+ mExpandedMovementBounds.set(expandedMovementBounds);
mDisplayRotation = displayRotation;
mInsetBounds.set(insetBounds);
updateMovementBounds();
diff --git a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
index 99a01d3..6779479 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
@@ -208,12 +208,13 @@
}
@Override
- public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment) {
+ public void onMovementBoundsChanged(boolean fromImeAdjustment) {
mHandler.post(() -> {
// Populate the inset / normal bounds and DisplayInfo from mPipBoundsHandler first.
+ final Rect destinationBounds = new Rect();
mPipBoundsHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds,
- animatingBounds, mTmpDisplayInfo);
- mDefaultPipBounds.set(animatingBounds);
+ destinationBounds, mTmpDisplayInfo);
+ mDefaultPipBounds.set(destinationBounds);
});
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/pip/phone/PipTouchHandlerTest.java b/packages/SystemUI/tests/src/com/android/systemui/pip/phone/PipTouchHandlerTest.java
index 4d7e6ae..7211254 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/pip/phone/PipTouchHandlerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/pip/phone/PipTouchHandlerTest.java
@@ -29,7 +29,6 @@
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.Size;
-import android.view.DisplayInfo;
import androidx.test.filters.SmallTest;
@@ -59,12 +58,8 @@
@SmallTest
@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class PipTouchHandlerTest extends SysuiTestCase {
- private static final int ROUNDING_ERROR_MARGIN = 10;
- private static final float DEFAULT_ASPECT_RATIO = 1f;
- private static final Rect EMPTY_CURRENT_BOUNDS = null;
private PipTouchHandler mPipTouchHandler;
- private DisplayInfo mDefaultDisplayInfo;
@Mock
private IActivityManager mActivityManager;
@@ -90,18 +85,17 @@
@Mock
private DeviceConfigProxy mDeviceConfigProxy;
-
private PipSnapAlgorithm mPipSnapAlgorithm;
private PipMotionHelper mMotionHelper;
private PipResizeGestureHandler mPipResizeGestureHandler;
- Rect mInsetBounds;
- Rect mMinBounds;
- Rect mCurBounds;
- boolean mFromImeAdjustment;
- boolean mFromShelfAdjustment;
- int mDisplayRotation;
-
+ private Rect mInsetBounds;
+ private Rect mMinBounds;
+ private Rect mCurBounds;
+ private boolean mFromImeAdjustment;
+ private boolean mFromShelfAdjustment;
+ private int mDisplayRotation;
+ private int mImeHeight;
@Before
public void setUp() throws Exception {
@@ -121,10 +115,11 @@
mInsetBounds = new Rect(10, 10, 990, 990);
// minBounds of 100x100 bottom right corner
mMinBounds = new Rect(890, 890, 990, 990);
- mCurBounds = new Rect();
+ mCurBounds = new Rect(mMinBounds);
mFromImeAdjustment = false;
mFromShelfAdjustment = false;
mDisplayRotation = 0;
+ mImeHeight = 100;
}
@Test
@@ -162,6 +157,8 @@
@Test
public void updateMovementBounds_withImeAdjustment_movesPip() {
mFromImeAdjustment = true;
+ mPipTouchHandler.onImeVisibilityChanged(true /* imeVisible */, mImeHeight);
+
mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mMinBounds, mCurBounds,
mFromImeAdjustment, mFromShelfAdjustment, mDisplayRotation);