Move PiP animation to SysUI package
The bounds animation is cleaned up within window manager and it's now
the SysUI component listening on callbacks from TaskOrganizer for
entering to and exiting from PiP mode.
Additionally, the expand and move of the PiP window is now part of SysUI
as well.
Known issues:
- Black background when in transition from PiP to fullscreen. The
wallpaper gets into hidden state too early
- App gets into PiP mode too early when entering PiP, need to defer the
configuration change sent to app in this case
Bug: 146594635
Bug: 148198539
Bug: 138144750
Bug: 149569903
Test: atest PinnedStackTests
Test: atest PipAnimationControllerTest
Test: atest RecentsAnimationTest
Test: atest RecentTasksTest
Test: atest com.android.server.wm.ActivityStarterTests
Merged-In: Id0c8ce03fa26952daf5e3687b18b2eb2375b7d20
Change-Id: Id0c8ce03fa26952daf5e3687b18b2eb2375b7d20
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 cb94e28..e98dec0 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
@@ -41,6 +41,8 @@
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.pip.BasePipManager;
import com.android.systemui.pip.PipBoundsHandler;
+import com.android.systemui.pip.PipTaskOrganizer;
+import com.android.systemui.shared.recents.IPinnedStackAnimationListener;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.InputConsumerController;
import com.android.systemui.shared.system.PinnedStackListenerForwarder.PinnedStackListener;
@@ -59,12 +61,11 @@
* Manages the picture-in-picture (PIP) UI and states for Phones.
*/
@Singleton
-public class PipManager implements BasePipManager {
+public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitionCallback {
private static final String TAG = "PipManager";
private Context mContext;
private IActivityManager mActivityManager;
- private IActivityTaskManager mActivityTaskManager;
private Handler mHandler = new Handler();
private final PinnedStackListener mPinnedStackListener = new PipManagerPinnedStackListener();
@@ -78,7 +79,9 @@
private PipMenuActivityController mMenuController;
private PipMediaController mMediaController;
private PipTouchHandler mTouchHandler;
+ private PipTaskOrganizer mPipTaskOrganizer;
private PipAppOpsListener mAppOpsListener;
+ private IPinnedStackAnimationListener mPinnedStackAnimationRecentsListener;
/**
* Handler for display rotation changes.
@@ -124,20 +127,6 @@
}
@Override
- public void onPinnedStackAnimationStarted() {
- // Disable touches while the animation is running
- mTouchHandler.setTouchEnabled(false);
- }
-
- @Override
- public void onPinnedStackAnimationEnded() {
- // Re-enable touches after the animation completes
- mTouchHandler.setTouchEnabled(true);
- mTouchHandler.onPinnedStackAnimationEnded();
- mMenuController.onPinnedStackAnimationEnded();
- }
-
- @Override
public void onPinnedActivityRestartAttempt(boolean clearedTask) {
mTouchHandler.getMotionHelper().expandPip(clearedTask /* skipAnimation */);
}
@@ -149,10 +138,7 @@
private class PipManagerPinnedStackListener extends PinnedStackListener {
@Override
public void onListenerRegistered(IPinnedStackController controller) {
- mHandler.post(() -> {
- mPipBoundsHandler.setPinnedStackController(controller);
- mTouchHandler.setPinnedStackController(controller);
- });
+ mHandler.post(() -> mTouchHandler.setPinnedStackController(controller));
}
@Override
@@ -164,18 +150,9 @@
}
@Override
- public void onMinimizedStateChanged(boolean isMinimized) {
- mHandler.post(() -> {
- mPipBoundsHandler.onMinimizedStateChanged(isMinimized);
- mTouchHandler.setMinimizedState(isMinimized, true /* fromController */);
- });
- }
-
- @Override
- public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment,
- boolean fromShelfAdjustment) {
+ public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment) {
mHandler.post(() -> updateMovementBounds(animatingBounds, fromImeAdjustment,
- fromShelfAdjustment));
+ false /* fromShelfAdjustment */));
}
@Override
@@ -207,7 +184,10 @@
@Override
public void onDisplayInfoChanged(DisplayInfo displayInfo) {
- mHandler.post(() -> mPipBoundsHandler.onDisplayInfoChanged(displayInfo));
+ mHandler.post(() -> {
+ mPipBoundsHandler.onDisplayInfoChanged(displayInfo);
+ mPipTaskOrganizer.onDisplayInfoChanged(displayInfo);
+ });
}
@Override
@@ -219,13 +199,6 @@
public void onAspectRatioChanged(float aspectRatio) {
mHandler.post(() -> mPipBoundsHandler.onAspectRatioChanged(aspectRatio));
}
-
- @Override
- public void onPrepareAnimation(Rect sourceRectHint, float aspectRatio, Rect bounds) {
- mHandler.post(() -> {
- mPipBoundsHandler.onPrepareAnimation(sourceRectHint, aspectRatio, bounds);
- });
- }
}
@Inject
@@ -234,7 +207,6 @@
FloatingContentCoordinator floatingContentCoordinator) {
mContext = context;
mActivityManager = ActivityManager.getService();
- mActivityTaskManager = ActivityTaskManager.getService();
try {
WindowManagerWrapper.getInstance().addPinnedStackListener(mPinnedStackListener);
@@ -243,24 +215,29 @@
}
ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
+ final IActivityTaskManager activityTaskManager = ActivityTaskManager.getService();
mPipBoundsHandler = new PipBoundsHandler(context);
+ mPipTaskOrganizer = new PipTaskOrganizer(mContext, mPipBoundsHandler);
+ mPipTaskOrganizer.registerPipTransitionCallback(this);
mInputConsumerController = InputConsumerController.getPipInputConsumer();
mMediaController = new PipMediaController(context, mActivityManager, broadcastDispatcher);
- mMenuController = new PipMenuActivityController(context, mActivityManager, mMediaController,
+ mMenuController = new PipMenuActivityController(context, mMediaController,
mInputConsumerController);
- mTouchHandler = new PipTouchHandler(context, mActivityManager, mActivityTaskManager,
- mMenuController, mInputConsumerController, mPipBoundsHandler,
+ mTouchHandler = new PipTouchHandler(context, mActivityManager, activityTaskManager,
+ mMenuController, mInputConsumerController, mPipBoundsHandler, mPipTaskOrganizer,
floatingContentCoordinator);
mAppOpsListener = new PipAppOpsListener(context, mActivityManager,
mTouchHandler.getMotionHelper());
displayController.addDisplayChangingController(mRotationController);
- // If SystemUI restart, and it already existed a pinned stack,
- // register the pip input consumer to ensure touch can send to it.
try {
- ActivityManager.StackInfo stackInfo = mActivityTaskManager.getStackInfo(
+ ActivityTaskManager.getTaskOrganizerController().registerTaskOrganizer(
+ mPipTaskOrganizer, WINDOWING_MODE_PINNED);
+ ActivityManager.StackInfo stackInfo = activityTaskManager.getStackInfo(
WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED);
if (stackInfo != null) {
+ // If SystemUI restart, and it already existed a pinned stack,
+ // register the pip input consumer to ensure touch can send to it.
mInputConsumerController.registerInputConsumer();
}
} catch (RemoteException e) {
@@ -320,6 +297,46 @@
});
}
+ @Override
+ public void setPinnedStackAnimationType(int animationType) {
+ mHandler.post(() -> mPipTaskOrganizer.setOneShotAnimationType(animationType));
+ }
+
+ @Override
+ public void setPinnedStackAnimationListener(IPinnedStackAnimationListener listener) {
+ mHandler.post(() -> mPinnedStackAnimationRecentsListener = listener);
+ }
+
+ @Override
+ public void onPipTransitionStarted() {
+ // Disable touches while the animation is running
+ mTouchHandler.setTouchEnabled(false);
+ if (mPinnedStackAnimationRecentsListener != null) {
+ try {
+ mPinnedStackAnimationRecentsListener.onPinnedStackAnimationStarted();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to callback recents", e);
+ }
+ }
+ }
+
+ @Override
+ public void onPipTransitionFinished() {
+ onPipTransitionFinishedOrCanceled();
+ }
+
+ @Override
+ public void onPipTransitionCanceled() {
+ onPipTransitionFinishedOrCanceled();
+ }
+
+ private void onPipTransitionFinishedOrCanceled() {
+ // Re-enable touches after the animation completes
+ mTouchHandler.setTouchEnabled(true);
+ mTouchHandler.onPinnedStackAnimationEnded();
+ mMenuController.onPinnedStackAnimationEnded();
+ }
+
private void updateMovementBounds(Rect animatingBounds, boolean fromImeAdjustment,
boolean fromShelfAdjustment) {
// Populate inset / normal bounds and DisplayInfo from mPipBoundsHandler first.