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/BasePipManager.java b/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java
index adee7f23..38744fe 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java
@@ -18,6 +18,8 @@
import android.content.res.Configuration;
+import com.android.systemui.shared.recents.IPinnedStackAnimationListener;
+
import java.io.PrintWriter;
@@ -27,5 +29,7 @@
default void hidePipMenu(Runnable onStartCallback, Runnable onEndCallback) {}
void onConfigurationChanged(Configuration newConfig);
default void setShelfHeight(boolean visible, int height) {}
+ default void setPinnedStackAnimationType(int animationType) {}
+ default void setPinnedStackAnimationListener(IPinnedStackAnimationListener listener) {}
default void dump(PrintWriter pw) {}
}
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipAnimationController.java b/packages/SystemUI/src/com/android/systemui/pip/PipAnimationController.java
new file mode 100644
index 0000000..b5fd406
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipAnimationController.java
@@ -0,0 +1,317 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.pip;
+
+import android.animation.Animator;
+import android.animation.ValueAnimator;
+import android.annotation.IntDef;
+import android.annotation.MainThread;
+import android.content.Context;
+import android.graphics.Rect;
+import android.os.RemoteException;
+import android.view.IWindowContainer;
+import android.view.SurfaceControl;
+import android.view.animation.AnimationUtils;
+import android.view.animation.Interpolator;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Controller class of PiP animations (both from and to PiP mode).
+ */
+public class PipAnimationController {
+ private static final float FRACTION_START = 0f;
+ private static final float FRACTION_END = 1f;
+
+ public static final int DURATION_NONE = 0;
+ public static final int DURATION_DEFAULT_MS = 425;
+ public static final int ANIM_TYPE_BOUNDS = 0;
+ public static final int ANIM_TYPE_ALPHA = 1;
+
+ @IntDef(prefix = { "ANIM_TYPE_" }, value = {
+ ANIM_TYPE_BOUNDS,
+ ANIM_TYPE_ALPHA
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface AnimationType {}
+
+ private final Interpolator mFastOutSlowInInterpolator;
+
+ private PipTransitionAnimator mCurrentAnimator;
+
+ PipAnimationController(Context context) {
+ mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
+ com.android.internal.R.interpolator.fast_out_slow_in);
+ }
+
+ @MainThread
+ PipTransitionAnimator getAnimator(IWindowContainer wc, boolean scheduleFinishPip,
+ Rect destinationBounds, float alphaStart, float alphaEnd) {
+ if (mCurrentAnimator == null) {
+ mCurrentAnimator = setupPipTransitionAnimator(
+ PipTransitionAnimator.ofAlpha(wc, scheduleFinishPip,
+ destinationBounds, alphaStart, alphaEnd));
+ } else if (mCurrentAnimator.getAnimationType() == ANIM_TYPE_ALPHA
+ && mCurrentAnimator.isRunning()) {
+ mCurrentAnimator.updateEndValue(alphaEnd);
+ } else {
+ mCurrentAnimator.cancel();
+ mCurrentAnimator = setupPipTransitionAnimator(
+ PipTransitionAnimator.ofAlpha(wc, scheduleFinishPip,
+ destinationBounds, alphaStart, alphaEnd));
+ }
+ return mCurrentAnimator;
+ }
+
+ @MainThread
+ PipTransitionAnimator getAnimator(IWindowContainer wc, boolean scheduleFinishPip,
+ Rect startBounds, Rect endBounds) {
+ if (mCurrentAnimator == null) {
+ mCurrentAnimator = setupPipTransitionAnimator(
+ PipTransitionAnimator.ofBounds(wc, scheduleFinishPip, startBounds, endBounds));
+ } else if (mCurrentAnimator.getAnimationType() == ANIM_TYPE_BOUNDS
+ && mCurrentAnimator.isRunning()) {
+ mCurrentAnimator.setDestinationBounds(endBounds);
+ // construct new Rect instances in case they are recycled
+ mCurrentAnimator.updateEndValue(new Rect(endBounds));
+ } else {
+ mCurrentAnimator.cancel();
+ mCurrentAnimator = setupPipTransitionAnimator(
+ PipTransitionAnimator.ofBounds(wc, scheduleFinishPip, startBounds, endBounds));
+ }
+ return mCurrentAnimator;
+ }
+
+ private PipTransitionAnimator setupPipTransitionAnimator(PipTransitionAnimator animator) {
+ animator.setInterpolator(mFastOutSlowInInterpolator);
+ animator.setFloatValues(FRACTION_START, FRACTION_END);
+ return animator;
+ }
+
+ /**
+ * Additional callback interface for PiP animation
+ */
+ public static class PipAnimationCallback {
+ /**
+ * Called when PiP animation is started.
+ */
+ public void onPipAnimationStart(IWindowContainer wc, PipTransitionAnimator animator) {}
+
+ /**
+ * Called when PiP animation is ended.
+ */
+ public void onPipAnimationEnd(IWindowContainer wc, SurfaceControl.Transaction tx,
+ PipTransitionAnimator animator) {}
+
+ /**
+ * Called when PiP animation is cancelled.
+ */
+ public void onPipAnimationCancel(IWindowContainer wc, PipTransitionAnimator animator) {}
+ }
+
+ /**
+ * Animator for PiP transition animation which supports both alpha and bounds animation.
+ * @param <T> Type of property to animate, either alpha (float) or bounds (Rect)
+ */
+ public abstract static class PipTransitionAnimator<T> extends ValueAnimator implements
+ ValueAnimator.AnimatorUpdateListener,
+ ValueAnimator.AnimatorListener {
+ private final IWindowContainer mWindowContainer;
+ private final boolean mScheduleFinishPip;
+ private final SurfaceControl mLeash;
+ private final @AnimationType int mAnimationType;
+ private final Rect mDestinationBounds = new Rect();
+
+ private T mStartValue;
+ private T mEndValue;
+ private T mCurrentValue;
+ private PipAnimationCallback mPipAnimationCallback;
+ private SurfaceControlTransactionFactory mSurfaceControlTransactionFactory;
+
+ private PipTransitionAnimator(IWindowContainer wc, boolean scheduleFinishPip,
+ @AnimationType int animationType, Rect destinationBounds,
+ T startValue, T endValue) {
+ mWindowContainer = wc;
+ mScheduleFinishPip = scheduleFinishPip;
+ try {
+ mLeash = wc.getLeash();
+ mAnimationType = animationType;
+ mDestinationBounds.set(destinationBounds);
+ mStartValue = startValue;
+ mEndValue = endValue;
+ addListener(this);
+ addUpdateListener(this);
+ mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void onAnimationStart(Animator animation) {
+ mCurrentValue = mStartValue;
+ applySurfaceControlTransaction(mLeash, newSurfaceControlTransaction(), FRACTION_START);
+ if (mPipAnimationCallback != null) {
+ mPipAnimationCallback.onPipAnimationStart(mWindowContainer, this);
+ }
+ }
+
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ applySurfaceControlTransaction(mLeash, newSurfaceControlTransaction(),
+ animation.getAnimatedFraction());
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mCurrentValue = mEndValue;
+ final SurfaceControl.Transaction tx = newSurfaceControlTransaction();
+ applySurfaceControlTransaction(mLeash, tx, FRACTION_END);
+ if (mPipAnimationCallback != null) {
+ mPipAnimationCallback.onPipAnimationEnd(mWindowContainer, tx, this);
+ }
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ if (mPipAnimationCallback != null) {
+ mPipAnimationCallback.onPipAnimationCancel(mWindowContainer, this);
+ }
+ }
+
+ @Override public void onAnimationRepeat(Animator animation) {}
+
+ @AnimationType int getAnimationType() {
+ return mAnimationType;
+ }
+
+ PipTransitionAnimator<T> setPipAnimationCallback(PipAnimationCallback callback) {
+ mPipAnimationCallback = callback;
+ return this;
+ }
+
+ boolean shouldScheduleFinishPip() {
+ return mScheduleFinishPip;
+ }
+
+ T getStartValue() {
+ return mStartValue;
+ }
+
+ T getEndValue() {
+ return mEndValue;
+ }
+
+ Rect getDestinationBounds() {
+ return mDestinationBounds;
+ }
+
+ void setDestinationBounds(Rect destinationBounds) {
+ mDestinationBounds.set(destinationBounds);
+ }
+
+ void setCurrentValue(T value) {
+ mCurrentValue = value;
+ }
+
+ /**
+ * Updates the {@link #mEndValue}.
+ *
+ * NOTE: Do not forget to call {@link #setDestinationBounds(Rect)} for bounds animation.
+ * This is typically used when we receive a shelf height adjustment during the bounds
+ * animation. In which case we can update the end bounds and keep the existing animation
+ * running instead of cancelling it.
+ */
+ void updateEndValue(T endValue) {
+ mEndValue = endValue;
+ mStartValue = mCurrentValue;
+ }
+
+ SurfaceControl.Transaction newSurfaceControlTransaction() {
+ return mSurfaceControlTransactionFactory.getTransaction();
+ }
+
+ @VisibleForTesting
+ void setSurfaceControlTransactionFactory(SurfaceControlTransactionFactory factory) {
+ mSurfaceControlTransactionFactory = factory;
+ }
+
+ abstract void applySurfaceControlTransaction(SurfaceControl leash,
+ SurfaceControl.Transaction tx, float fraction);
+
+ static PipTransitionAnimator<Float> ofAlpha(IWindowContainer wc, boolean scheduleFinishPip,
+ Rect destinationBounds, float startValue, float endValue) {
+ return new PipTransitionAnimator<Float>(wc, scheduleFinishPip, ANIM_TYPE_ALPHA,
+ destinationBounds, startValue, endValue) {
+ @Override
+ void applySurfaceControlTransaction(SurfaceControl leash,
+ SurfaceControl.Transaction tx, float fraction) {
+ final float alpha = getStartValue() * (1 - fraction) + getEndValue() * fraction;
+ setCurrentValue(alpha);
+ tx.setAlpha(leash, alpha);
+ if (Float.compare(fraction, FRACTION_START) == 0) {
+ // Ensure the start condition
+ final Rect bounds = getDestinationBounds();
+ tx.setPosition(leash, bounds.left, bounds.top)
+ .setWindowCrop(leash, bounds.width(), bounds.height());
+ }
+ tx.apply();
+ }
+ };
+ }
+
+ static PipTransitionAnimator<Rect> ofBounds(IWindowContainer wc, boolean scheduleFinishPip,
+ Rect startValue, Rect endValue) {
+ // construct new Rect instances in case they are recycled
+ return new PipTransitionAnimator<Rect>(wc, scheduleFinishPip, ANIM_TYPE_BOUNDS,
+ endValue, new Rect(startValue), new Rect(endValue)) {
+ private final Rect mTmpRect = new Rect();
+
+ private int getCastedFractionValue(float start, float end, float fraction) {
+ return (int) (start * (1 - fraction) + end * fraction + .5f);
+ }
+
+ @Override
+ void applySurfaceControlTransaction(SurfaceControl leash,
+ SurfaceControl.Transaction tx, float fraction) {
+ final Rect start = getStartValue();
+ final Rect end = getEndValue();
+ mTmpRect.set(
+ getCastedFractionValue(start.left, end.left, fraction),
+ getCastedFractionValue(start.top, end.top, fraction),
+ getCastedFractionValue(start.right, end.right, fraction),
+ getCastedFractionValue(start.bottom, end.bottom, fraction));
+ setCurrentValue(mTmpRect);
+ tx.setPosition(leash, mTmpRect.left, mTmpRect.top)
+ .setWindowCrop(leash, mTmpRect.width(), mTmpRect.height());
+ if (Float.compare(fraction, FRACTION_START) == 0) {
+ // Ensure the start condition
+ tx.setAlpha(leash, 1f);
+ }
+ tx.apply();
+ }
+ };
+ }
+ }
+
+ interface SurfaceControlTransactionFactory {
+ SurfaceControl.Transaction getTransaction();
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java
index 41b3130..8c3ccaa 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java
@@ -36,7 +36,6 @@
import android.util.TypedValue;
import android.view.DisplayInfo;
import android.view.Gravity;
-import android.view.IPinnedStackController;
import android.view.IWindowManager;
import android.view.WindowContainerTransaction;
import android.view.WindowManagerGlobal;
@@ -56,9 +55,7 @@
private final IWindowManager mWindowManager;
private final PipSnapAlgorithm mSnapAlgorithm;
private final DisplayInfo mDisplayInfo = new DisplayInfo();
- private final Rect mStableInsets = new Rect();
private final Rect mTmpInsets = new Rect();
- private final Point mTmpDisplaySize = new Point();
/**
* Tracks the destination bounds, used for any following
@@ -66,7 +63,6 @@
*/
private final Rect mLastDestinationBounds = new Rect();
- private IPinnedStackController mPinnedStackController;
private ComponentName mLastPipComponentName;
private float mReentrySnapFraction = INVALID_SNAP_FRACTION;
private Size mReentrySize = null;
@@ -80,7 +76,6 @@
private Point mScreenEdgeInsets;
private int mCurrentMinSize;
- private boolean mIsMinimized;
private boolean mIsImeShowing;
private int mImeHeight;
private boolean mIsShelfShowing;
@@ -123,10 +118,6 @@
com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio);
}
- public void setPinnedStackController(IPinnedStackController controller) {
- mPinnedStackController = controller;
- }
-
public void setMinEdgeSize(int minEdgeSize) {
mCurrentMinSize = minEdgeSize;
}
@@ -155,14 +146,6 @@
}
/**
- * Responds to IPinnedStackListener on minimized state change.
- */
- public void onMinimizedStateChanged(boolean minimized) {
- mIsMinimized = minimized;
- mSnapAlgorithm.setMinimized(minimized);
- }
-
- /**
* Responds to IPinnedStackListener on movement bounds change.
* Note that both inset and normal bounds will be calculated here rather than in the caller.
*/
@@ -238,9 +221,9 @@
}
/**
- * Responds to IPinnedStackListener on preparing the pinned stack animation.
+ * @return {@link Rect} of the destination PiP window bounds.
*/
- public void onPrepareAnimation(Rect sourceRectHint, float aspectRatio, Rect bounds) {
+ Rect getDestinationBounds(float aspectRatio, Rect bounds) {
final Rect destinationBounds;
final Rect defaultBounds = getDefaultBounds(mReentrySnapFraction, mReentrySize);
if (bounds == null) {
@@ -253,17 +236,16 @@
false /* useCurrentMinEdgeSize */);
}
if (destinationBounds.equals(bounds)) {
- return;
+ return bounds;
}
mAspectRatio = aspectRatio;
onResetReentryBoundsUnchecked();
- try {
- mPinnedStackController.startAnimation(destinationBounds, sourceRectHint,
- -1 /* animationDuration */);
- mLastDestinationBounds.set(destinationBounds);
- } catch (RemoteException e) {
- Log.e(TAG, "Failed to start PiP animation from SysUI", e);
- }
+ mLastDestinationBounds.set(destinationBounds);
+ return destinationBounds;
+ }
+
+ float getDefaultAspectRatio() {
+ return mDefaultAspectRatio;
}
/**
@@ -307,18 +289,10 @@
false /* adjustForIme */);
mSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
snapFraction);
- if (mIsMinimized) {
- applyMinimizedOffset(postChangeStackBounds, postChangeMovementBounds);
- }
- try {
- outBounds.set(postChangeStackBounds);
- mLastDestinationBounds.set(outBounds);
- mPinnedStackController.resetBoundsAnimation(outBounds);
- t.setBounds(pinnedStackInfo.stackToken, outBounds);
- } catch (RemoteException e) {
- Log.e(TAG, "Failed to resize PiP on display rotation", e);
- }
+ outBounds.set(postChangeStackBounds);
+ mLastDestinationBounds.set(outBounds);
+ t.setBounds(pinnedStackInfo.stackToken, outBounds);
return true;
}
@@ -370,9 +344,6 @@
final int top = (int) (stackBounds.centerY() - size.getHeight() / 2f);
stackBounds.set(left, top, left + size.getWidth(), top + size.getHeight());
mSnapAlgorithm.applySnapFraction(stackBounds, getMovementBounds(stackBounds), snapFraction);
- if (mIsMinimized) {
- applyMinimizedOffset(stackBounds, getMovementBounds(stackBounds));
- }
}
/**
@@ -436,20 +407,6 @@
}
/**
- * Applies the minimized offsets to the given stack bounds.
- */
- private void applyMinimizedOffset(Rect stackBounds, Rect movementBounds) {
- mTmpDisplaySize.set(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
- try {
- mWindowManager.getStableInsets(mContext.getDisplayId(), mStableInsets);
- mSnapAlgorithm.applyMinimizedOffset(stackBounds, movementBounds, mTmpDisplaySize,
- mStableInsets);
- } catch (RemoteException e) {
- Log.e(TAG, "Failed to get stable insets from WM", e);
- }
- }
-
- /**
* @return the default snap fraction to apply instead of the default gravity when calculating
* the default stack bounds when first entering PiP.
*/
@@ -486,7 +443,6 @@
pw.println(innerPrefix + "mMaxAspectRatio=" + mMaxAspectRatio);
pw.println(innerPrefix + "mAspectRatio=" + mAspectRatio);
pw.println(innerPrefix + "mDefaultStackGravity=" + mDefaultStackGravity);
- pw.println(innerPrefix + "mIsMinimized=" + mIsMinimized);
pw.println(innerPrefix + "mIsImeShowing=" + mIsImeShowing);
pw.println(innerPrefix + "mImeHeight=" + mImeHeight);
pw.println(innerPrefix + "mIsShelfShowing=" + mIsShelfShowing);
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipSnapAlgorithm.java b/packages/SystemUI/src/com/android/systemui/pip/PipSnapAlgorithm.java
index f3e707c..6b89718 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/PipSnapAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipSnapAlgorithm.java
@@ -63,14 +63,9 @@
private int mOrientation = Configuration.ORIENTATION_UNDEFINED;
- private final int mMinimizedVisibleSize;
- private boolean mIsMinimized;
-
public PipSnapAlgorithm(Context context) {
Resources res = context.getResources();
mContext = context;
- mMinimizedVisibleSize = res.getDimensionPixelSize(
- com.android.internal.R.dimen.pip_minimized_visible_size);
mDefaultSizePercent = res.getFloat(
com.android.internal.R.dimen.config_pictureInPictureDefaultSizePercent);
mMaxAspectRatioForMinSize = res.getFloat(
@@ -92,13 +87,6 @@
}
/**
- * Sets the PIP's minimized state.
- */
- public void setMinimized(boolean isMinimized) {
- mIsMinimized = isMinimized;
- }
-
- /**
* @return the closest absolute snap stack bounds for the given {@param stackBounds} moving at
* the given {@param velocityX} and {@param velocityY}. The {@param movementBounds} should be
* those for the given {@param stackBounds}.
@@ -235,20 +223,6 @@
}
/**
- * Applies the offset to the {@param stackBounds} to adjust it to a minimized state.
- */
- public void applyMinimizedOffset(Rect stackBounds, Rect movementBounds, Point displaySize,
- Rect stableInsets) {
- if (stackBounds.left <= movementBounds.centerX()) {
- stackBounds.offsetTo(stableInsets.left + mMinimizedVisibleSize - stackBounds.width(),
- stackBounds.top);
- } else {
- stackBounds.offsetTo(displaySize.x - stableInsets.right - mMinimizedVisibleSize,
- stackBounds.top);
- }
- }
-
- /**
* @return returns a fraction that describes where along the {@param movementBounds} the
* {@param stackBounds} are. If the {@param stackBounds} are not currently on the
* {@param movementBounds} exactly, then they will be snapped to the movement bounds.
@@ -402,16 +376,11 @@
* the new bounds out to {@param boundsOut}.
*/
private void snapRectToClosestEdge(Rect stackBounds, Rect movementBounds, Rect boundsOut) {
- // If the stackBounds are minimized, then it should only be snapped back horizontally
final int boundedLeft = Math.max(movementBounds.left, Math.min(movementBounds.right,
stackBounds.left));
final int boundedTop = Math.max(movementBounds.top, Math.min(movementBounds.bottom,
stackBounds.top));
boundsOut.set(stackBounds);
- if (mIsMinimized) {
- boundsOut.offsetTo(boundedLeft, boundedTop);
- return;
- }
// Otherwise, just find the closest edge
final int fromLeft = Math.abs(stackBounds.left - movementBounds.left);
@@ -479,7 +448,5 @@
pw.println(prefix + PipSnapAlgorithm.class.getSimpleName());
pw.println(innerPrefix + "mSnapMode=" + mSnapMode);
pw.println(innerPrefix + "mOrientation=" + mOrientation);
- pw.println(innerPrefix + "mMinimizedVisibleSize=" + mMinimizedVisibleSize);
- pw.println(innerPrefix + "mIsMinimized=" + mIsMinimized);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
new file mode 100644
index 0000000..1555153
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
@@ -0,0 +1,291 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.pip;
+
+import static com.android.systemui.pip.PipAnimationController.ANIM_TYPE_ALPHA;
+import static com.android.systemui.pip.PipAnimationController.ANIM_TYPE_BOUNDS;
+import static com.android.systemui.pip.PipAnimationController.DURATION_NONE;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.app.ActivityManager;
+import android.app.ActivityTaskManager;
+import android.app.ITaskOrganizerController;
+import android.app.PictureInPictureParams;
+import android.content.Context;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.DisplayInfo;
+import android.view.ITaskOrganizer;
+import android.view.IWindowContainer;
+import android.view.SurfaceControl;
+import android.view.WindowContainerTransaction;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Manages PiP tasks such as resize and offset.
+ *
+ * This class listens on {@link ITaskOrganizer} callbacks for windowing mode change
+ * both to and from PiP and issues corresponding animation if applicable.
+ * Normally, we apply series of {@link SurfaceControl.Transaction} when the animator is running
+ * and files a final {@link WindowContainerTransaction} at the end of the transition.
+ *
+ * This class is also responsible for general resize/offset PiP operations within SysUI component,
+ * see also {@link com.android.systemui.pip.phone.PipMotionHelper}.
+ */
+public class PipTaskOrganizer extends ITaskOrganizer.Stub {
+ private static final String TAG = PipTaskOrganizer.class.getSimpleName();
+
+ private final Handler mMainHandler;
+ private final ITaskOrganizerController mTaskOrganizerController;
+ private final PipBoundsHandler mPipBoundsHandler;
+ private final PipAnimationController mPipAnimationController;
+ private final List<PipTransitionCallback> mPipTransitionCallbacks = new ArrayList<>();
+ private final Rect mDisplayBounds = new Rect();
+ private final Rect mLastReportedBounds = new Rect();
+
+ private final PipAnimationController.PipAnimationCallback mPipAnimationCallback =
+ new PipAnimationController.PipAnimationCallback() {
+ @Override
+ public void onPipAnimationStart(IWindowContainer wc,
+ PipAnimationController.PipTransitionAnimator animator) {
+ mMainHandler.post(() -> {
+ for (int i = mPipTransitionCallbacks.size() - 1; i >= 0; i--) {
+ final PipTransitionCallback callback = mPipTransitionCallbacks.get(i);
+ callback.onPipTransitionStarted();
+ }
+ });
+ }
+
+ @Override
+ public void onPipAnimationEnd(IWindowContainer wc, SurfaceControl.Transaction tx,
+ PipAnimationController.PipTransitionAnimator animator) {
+ mMainHandler.post(() -> {
+ for (int i = mPipTransitionCallbacks.size() - 1; i >= 0; i--) {
+ final PipTransitionCallback callback = mPipTransitionCallbacks.get(i);
+ callback.onPipTransitionFinished();
+ }
+ });
+ final Rect destinationBounds = animator.getDestinationBounds();
+ mLastReportedBounds.set(destinationBounds);
+ try {
+ final WindowContainerTransaction wct = new WindowContainerTransaction();
+ if (animator.shouldScheduleFinishPip()) {
+ wct.scheduleFinishEnterPip(wc, destinationBounds);
+ } else {
+ wct.setBounds(wc, destinationBounds);
+ }
+ wct.setBoundsChangeTransaction(wc, tx);
+ mTaskOrganizerController.applyContainerTransaction(wct, null /* ITaskOrganizer */);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to apply container transaction", e);
+ }
+ }
+
+ @Override
+ public void onPipAnimationCancel(IWindowContainer wc,
+ PipAnimationController.PipTransitionAnimator animator) {
+ mMainHandler.post(() -> {
+ for (int i = mPipTransitionCallbacks.size() - 1; i >= 0; i--) {
+ final PipTransitionCallback callback = mPipTransitionCallbacks.get(i);
+ callback.onPipTransitionCanceled();
+ }
+ });
+ }
+ };
+
+ private ActivityManager.RunningTaskInfo mTaskInfo;
+ private @PipAnimationController.AnimationType int mOneShotAnimationType = ANIM_TYPE_BOUNDS;
+
+ public PipTaskOrganizer(Context context, @NonNull PipBoundsHandler boundsHandler) {
+ mMainHandler = new Handler(Looper.getMainLooper());
+ mTaskOrganizerController = ActivityTaskManager.getTaskOrganizerController();
+ mPipBoundsHandler = boundsHandler;
+ mPipAnimationController = new PipAnimationController(context);
+ }
+
+ /**
+ * Resize the PiP window, animate if the given duration is not {@link #DURATION_NONE}
+ */
+ public void resizePinnedStack(Rect destinationBounds, int durationMs) {
+ Objects.requireNonNull(mTaskInfo, "Requires valid IWindowContainer");
+ resizePinnedStackInternal(mTaskInfo.token, false /* scheduleFinishPip */,
+ mLastReportedBounds, destinationBounds, durationMs);
+ }
+
+ /**
+ * Offset the PiP window, animate if the given duration is not {@link #DURATION_NONE}
+ */
+ public void offsetPinnedStack(Rect originalBounds, int xOffset, int yOffset, int durationMs) {
+ if (mTaskInfo == null) {
+ Log.w(TAG, "mTaskInfo is not set");
+ return;
+ }
+ final Rect destinationBounds = new Rect(originalBounds);
+ destinationBounds.offset(xOffset, yOffset);
+ resizePinnedStackInternal(mTaskInfo.token, false /* scheduleFinishPip*/,
+ originalBounds, destinationBounds, durationMs);
+ }
+
+ /**
+ * Registers {@link PipTransitionCallback} to receive transition callbacks.
+ */
+ public void registerPipTransitionCallback(PipTransitionCallback callback) {
+ mPipTransitionCallbacks.add(callback);
+ }
+
+ /**
+ * Sets the preferred animation type for one time.
+ * This is typically used to set the animation type to {@link #ANIM_TYPE_ALPHA}.
+ */
+ public void setOneShotAnimationType(@PipAnimationController.AnimationType int animationType) {
+ mOneShotAnimationType = animationType;
+ }
+
+ /**
+ * Updates the display dimension with given {@link DisplayInfo}
+ */
+ public void onDisplayInfoChanged(DisplayInfo displayInfo) {
+ mDisplayBounds.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
+ }
+
+ /**
+ * Callback to issue the final {@link WindowContainerTransaction} on end of movements.
+ * @param destinationBounds the final bounds.
+ */
+ public void onMotionMovementEnd(Rect destinationBounds) {
+ try {
+ mLastReportedBounds.set(destinationBounds);
+ final WindowContainerTransaction wct = new WindowContainerTransaction();
+ wct.setBounds(mTaskInfo.token, destinationBounds);
+ mTaskOrganizerController.applyContainerTransaction(wct, null /* ITaskOrganizer */);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to apply window container transaction", e);
+ }
+ }
+
+ @Override
+ public void taskAppeared(ActivityManager.RunningTaskInfo info) {
+ Objects.requireNonNull(info, "Requires RunningTaskInfo");
+ final Rect destinationBounds = mPipBoundsHandler.getDestinationBounds(
+ getAspectRatioOrDefault(info.pictureInPictureParams), null /* bounds */);
+ Objects.requireNonNull(destinationBounds, "Missing destination bounds");
+ mTaskInfo = info;
+ if (mOneShotAnimationType == ANIM_TYPE_BOUNDS) {
+ final Rect currentBounds = mTaskInfo.configuration.windowConfiguration.getBounds();
+ resizePinnedStackInternal(mTaskInfo.token, true /* scheduleFinishPip */,
+ currentBounds, destinationBounds,
+ PipAnimationController.DURATION_DEFAULT_MS);
+ } else if (mOneShotAnimationType == ANIM_TYPE_ALPHA) {
+ mMainHandler.post(() -> mPipAnimationController
+ .getAnimator(mTaskInfo.token, true /* scheduleFinishPip */,
+ destinationBounds, 0f, 1f)
+ .setPipAnimationCallback(mPipAnimationCallback)
+ .setDuration(PipAnimationController.DURATION_DEFAULT_MS)
+ .start());
+ mOneShotAnimationType = ANIM_TYPE_BOUNDS;
+ } else {
+ throw new RuntimeException("Unrecognized animation type: " + mOneShotAnimationType);
+ }
+ }
+
+ @Override
+ public void taskVanished(IWindowContainer token) {
+ Objects.requireNonNull(token, "Requires valid IWindowContainer");
+ if (token.asBinder() != mTaskInfo.token.asBinder()) {
+ Log.wtf(TAG, "Unrecognized token: " + token);
+ return;
+ }
+ resizePinnedStackInternal(token, false /* scheduleFinishPip */,
+ mLastReportedBounds, mDisplayBounds,
+ PipAnimationController.DURATION_DEFAULT_MS);
+ }
+
+ @Override
+ public void transactionReady(int id, SurfaceControl.Transaction t) {
+ }
+
+ @Override
+ public void onTaskInfoChanged(ActivityManager.RunningTaskInfo info) {
+ final Rect destinationBounds = mPipBoundsHandler.getDestinationBounds(
+ getAspectRatioOrDefault(info.pictureInPictureParams), null /* bounds */);
+ Objects.requireNonNull(destinationBounds, "Missing destination bounds");
+ resizePinnedStack(destinationBounds, PipAnimationController.DURATION_DEFAULT_MS);
+ }
+
+ private void resizePinnedStackInternal(IWindowContainer wc, boolean scheduleFinishPip,
+ Rect currentBounds, Rect destinationBounds, int animationDurationMs) {
+ try {
+ // Could happen when dismissPip
+ if (wc == null || wc.getLeash() == null) {
+ Log.w(TAG, "Abort animation, invalid leash");
+ return;
+ }
+ final SurfaceControl leash = wc.getLeash();
+ if (animationDurationMs == DURATION_NONE) {
+ // Directly resize if no animation duration is set. When fling, wait for final
+ // callback to issue the proper WindowContainerTransaction with destination bounds.
+ new SurfaceControl.Transaction()
+ .setPosition(leash, destinationBounds.left, destinationBounds.top)
+ .setWindowCrop(leash, destinationBounds.width(), destinationBounds.height())
+ .apply();
+ } else {
+ mMainHandler.post(() -> mPipAnimationController
+ .getAnimator(wc, scheduleFinishPip, currentBounds, destinationBounds)
+ .setPipAnimationCallback(mPipAnimationCallback)
+ .setDuration(animationDurationMs)
+ .start());
+ }
+ } catch (RemoteException e) {
+ Log.w(TAG, "Abort animation, invalid window container", e);
+ } catch (Exception e) {
+ Log.e(TAG, "Should not reach here, terrible thing happened", e);
+ }
+ }
+
+ private float getAspectRatioOrDefault(@Nullable PictureInPictureParams params) {
+ return params == null
+ ? mPipBoundsHandler.getDefaultAspectRatio()
+ : params.getAspectRatio();
+ }
+
+ /**
+ * Callback interface for PiP transitions (both from and to PiP mode)
+ */
+ public interface PipTransitionCallback {
+ /**
+ * Callback when the pip transition is started.
+ */
+ void onPipTransitionStarted();
+
+ /**
+ * Callback when the pip transition is finished.
+ */
+ void onPipTransitionFinished();
+
+ /**
+ * Callback when the pip transition is cancelled.
+ */
+ void onPipTransitionCanceled();
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipUI.java b/packages/SystemUI/src/com/android/systemui/pip/PipUI.java
index 599c845..4fb675e 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/PipUI.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipUI.java
@@ -25,6 +25,7 @@
import android.os.UserManager;
import com.android.systemui.SystemUI;
+import com.android.systemui.shared.recents.IPinnedStackAnimationListener;
import com.android.systemui.statusbar.CommandQueue;
import java.io.FileDescriptor;
@@ -98,6 +99,18 @@
mPipManager.setShelfHeight(visible, height);
}
+ public void setPinnedStackAnimationType(int animationType) {
+ if (mPipManager != null) {
+ mPipManager.setPinnedStackAnimationType(animationType);
+ }
+ }
+
+ public void setPinnedStackAnimationListener(IPinnedStackAnimationListener listener) {
+ if (mPipManager != null) {
+ mPipManager.setPinnedStackAnimationListener(listener);
+ }
+ }
+
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (mPipManager == null) {
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.
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java
index c7bfc06..d660b67 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java
@@ -22,7 +22,6 @@
import android.app.ActivityManager.StackInfo;
import android.app.ActivityOptions;
import android.app.ActivityTaskManager;
-import android.app.IActivityManager;
import android.app.RemoteAction;
import android.content.Context;
import android.content.Intent;
@@ -68,11 +67,8 @@
public static final int MESSAGE_MENU_STATE_CHANGED = 100;
public static final int MESSAGE_EXPAND_PIP = 101;
- public static final int MESSAGE_MINIMIZE_PIP = 102;
public static final int MESSAGE_DISMISS_PIP = 103;
public static final int MESSAGE_UPDATE_ACTIVITY_CALLBACK = 104;
- public static final int MESSAGE_REGISTER_INPUT_CONSUMER = 105;
- public static final int MESSAGE_UNREGISTER_INPUT_CONSUMER = 106;
public static final int MESSAGE_SHOW_MENU = 107;
public static final int MENU_STATE_NONE = 0;
@@ -100,11 +96,6 @@
void onPipExpand();
/**
- * Called when the PIP requested to be minimized.
- */
- void onPipMinimize();
-
- /**
* Called when the PIP requested to be dismissed.
*/
void onPipDismiss();
@@ -116,7 +107,6 @@
}
private Context mContext;
- private IActivityManager mActivityManager;
private PipMediaController mMediaController;
private InputConsumerController mInputConsumerController;
@@ -146,10 +136,6 @@
mListeners.forEach(l -> l.onPipExpand());
break;
}
- case MESSAGE_MINIMIZE_PIP: {
- mListeners.forEach(l -> l.onPipMinimize());
- break;
- }
case MESSAGE_DISMISS_PIP: {
mListeners.forEach(l -> l.onPipDismiss());
break;
@@ -194,10 +180,9 @@
}
};
- public PipMenuActivityController(Context context, IActivityManager activityManager,
+ public PipMenuActivityController(Context context,
PipMediaController mediaController, InputConsumerController inputConsumerController) {
mContext = context;
- mActivityManager = activityManager;
mMediaController = mediaController;
mInputConsumerController = inputConsumerController;
}
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java
index c6e2852..91f539c 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java
@@ -22,7 +22,6 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager.StackInfo;
-import android.app.IActivityManager;
import android.app.IActivityTaskManager;
import android.content.Context;
import android.graphics.Point;
@@ -39,7 +38,9 @@
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
import com.android.internal.os.SomeArgs;
+import com.android.systemui.pip.PipAnimationController;
import com.android.systemui.pip.PipSnapAlgorithm;
+import com.android.systemui.pip.PipTaskOrganizer;
import com.android.systemui.shared.system.WindowManagerWrapper;
import com.android.systemui.statusbar.FlingAnimationUtils;
import com.android.systemui.util.FloatingContentCoordinator;
@@ -65,8 +66,6 @@
/** Friction to use for PIP when it moves via physics fling animations. */
private static final float DEFAULT_FRICTION = 2f;
- // The fraction of the stack width that the user has to drag offscreen to minimize the PiP
- private static final float MINIMIZE_OFFSCREEN_FRACTION = 0.3f;
// The fraction of the stack height that the user has to drag offscreen to dismiss the PiP
private static final float DISMISS_OFFSCREEN_FRACTION = 0.3f;
@@ -74,10 +73,10 @@
private static final int MSG_RESIZE_ANIMATE = 2;
private static final int MSG_OFFSET_ANIMATE = 3;
- private Context mContext;
- private IActivityManager mActivityManager;
- private IActivityTaskManager mActivityTaskManager;
- private Handler mHandler;
+ private final Context mContext;
+ private final IActivityTaskManager mActivityTaskManager;
+ private final PipTaskOrganizer mPipTaskOrganizer;
+ private final Handler mHandler;
private PipMenuActivityController mMenuController;
private PipSnapAlgorithm mSnapAlgorithm;
@@ -139,14 +138,14 @@
new PhysicsAnimator.SpringConfig(
SpringForce.STIFFNESS_LOW, SpringForce.DAMPING_RATIO_LOW_BOUNCY);
- public PipMotionHelper(Context context, IActivityManager activityManager,
- IActivityTaskManager activityTaskManager, PipMenuActivityController menuController,
+ public PipMotionHelper(Context context, IActivityTaskManager activityTaskManager,
+ PipTaskOrganizer pipTaskOrganizer, PipMenuActivityController menuController,
PipSnapAlgorithm snapAlgorithm, FlingAnimationUtils flingAnimationUtils,
FloatingContentCoordinator floatingContentCoordinator) {
mContext = context;
mHandler = new Handler(ForegroundThread.get().getLooper(), this);
- mActivityManager = activityManager;
mActivityTaskManager = activityTaskManager;
+ mPipTaskOrganizer = pipTaskOrganizer;
mMenuController = menuController;
mSnapAlgorithm = snapAlgorithm;
mFlingAnimationUtils = flingAnimationUtils;
@@ -285,35 +284,6 @@
}
/**
- * @return the closest minimized PiP bounds.
- */
- Rect getClosestMinimizedBounds(Rect stackBounds) {
- Point displaySize = new Point();
- mContext.getDisplay().getRealSize(displaySize);
- Rect toBounds = mSnapAlgorithm.findClosestSnapBounds(mMovementBounds, stackBounds);
- mSnapAlgorithm.applyMinimizedOffset(toBounds, mMovementBounds, displaySize, mStableInsets);
- return toBounds;
- }
-
- /**
- * @return whether the PiP at the current bounds should be minimized.
- */
- boolean shouldMinimizePip() {
- Point displaySize = new Point();
- mContext.getDisplay().getRealSize(displaySize);
- if (mBounds.left < 0) {
- float offscreenFraction = (float) -mBounds.left / mBounds.width();
- return offscreenFraction >= MINIMIZE_OFFSCREEN_FRACTION;
- } else if (mBounds.right > displaySize.x) {
- float offscreenFraction = (float) (mBounds.right - displaySize.x) /
- mBounds.width();
- return offscreenFraction >= MINIMIZE_OFFSCREEN_FRACTION;
- } else {
- return false;
- }
- }
-
- /**
* @return whether the PiP at the current bounds should be dismissed.
*/
boolean shouldDismissPip() {
@@ -328,25 +298,6 @@
}
/**
- * Animates the PiP to the minimized state, slightly offscreen.
- */
- void animateToClosestMinimizedState(@Nullable Runnable updateAction) {
- final Rect toBounds = getClosestMinimizedBounds(mBounds);
-
- mAnimatedBounds.set(mBounds);
- mAnimatedBoundsPhysicsAnimator
- .spring(FloatProperties.RECT_X, toBounds.left, mSpringConfig)
- .spring(FloatProperties.RECT_Y, toBounds.top, mSpringConfig);
-
- if (updateAction != null) {
- mAnimatedBoundsPhysicsAnimator.addUpdateListener(
- (target, values) -> updateAction.run());
- }
-
- startBoundsAnimation();
- }
-
- /**
* Flings the PiP to the closest snap target.
*/
void flingToSnapTarget(
@@ -436,8 +387,7 @@
* Animates the PiP from the expanded state to the normal state after the menu is hidden.
*/
void animateToUnexpandedState(Rect normalBounds, float savedSnapFraction,
- Rect normalMovementBounds, Rect currentMovementBounds, boolean minimized,
- boolean immediate) {
+ Rect normalMovementBounds, Rect currentMovementBounds, boolean immediate) {
if (savedSnapFraction < 0f) {
// If there are no saved snap fractions, then just use the current bounds
savedSnapFraction = mSnapAlgorithm.getSnapFraction(new Rect(mBounds),
@@ -445,10 +395,6 @@
}
mSnapAlgorithm.applySnapFraction(normalBounds, normalMovementBounds, savedSnapFraction);
- if (minimized) {
- normalBounds = getClosestMinimizedBounds(normalBounds);
- }
-
if (immediate) {
movePip(normalBounds);
} else {
@@ -503,6 +449,7 @@
cancelAnimations();
mAnimatedBoundsPhysicsAnimator
+ .withEndActions(() -> mPipTaskOrganizer.onMotionMovementEnd(mAnimatedBounds))
.addUpdateListener(mResizePipVsyncUpdateListener)
.start();
}
@@ -594,13 +541,6 @@
}
/**
- * @return the distance between points {@param p1} and {@param p2}.
- */
- private float distanceBetweenRectOffsets(Rect r1, Rect r2) {
- return PointF.length(r1.left - r2.left, r1.top - r2.top);
- }
-
- /**
* Handles messages to be processed on the background thread.
*/
public boolean handleMessage(Message msg) {
@@ -608,13 +548,8 @@
case MSG_RESIZE_IMMEDIATE: {
SomeArgs args = (SomeArgs) msg.obj;
Rect toBounds = (Rect) args.arg1;
- try {
- mActivityTaskManager.resizePinnedStack(
- toBounds, null /* tempPinnedTaskBounds */);
- mBounds.set(toBounds);
- } catch (RemoteException e) {
- Log.e(TAG, "Could not resize pinned stack to bounds: " + toBounds, e);
- }
+ mPipTaskOrganizer.resizePinnedStack(toBounds, PipAnimationController.DURATION_NONE);
+ mBounds.set(toBounds);
return true;
}
@@ -631,8 +566,7 @@
return true;
}
- mActivityTaskManager.animateResizePinnedStack(stackInfo.stackId, toBounds,
- duration);
+ mPipTaskOrganizer.resizePinnedStack(toBounds, duration);
mBounds.set(toBounds);
} catch (RemoteException e) {
Log.e(TAG, "Could not animate resize pinned stack to bounds: " + toBounds, e);
@@ -654,8 +588,8 @@
return true;
}
- mActivityTaskManager.offsetPinnedStackBounds(stackInfo.stackId, originalBounds,
- 0/* xOffset */, offset, duration);
+ mPipTaskOrganizer.offsetPinnedStack(originalBounds,
+ 0 /* xOffset */, offset, duration);
Rect toBounds = new Rect(originalBounds);
toBounds.offset(0, offset);
mBounds.set(toBounds);
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 8e588e6..79a25b2 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
@@ -45,6 +45,7 @@
import com.android.systemui.R;
import com.android.systemui.pip.PipBoundsHandler;
import com.android.systemui.pip.PipSnapAlgorithm;
+import com.android.systemui.pip.PipTaskOrganizer;
import com.android.systemui.shared.system.InputConsumerController;
import com.android.systemui.statusbar.FlingAnimationUtils;
import com.android.systemui.util.FloatingContentCoordinator;
@@ -58,8 +59,6 @@
public class PipTouchHandler {
private static final String TAG = "PipTouchHandler";
- // Allow the PIP to be dragged to the edge of the screen to be minimized.
- private static final boolean ENABLE_MINIMIZE = false;
// Allow the PIP to be flung from anywhere on the screen to the bottom to be dismissed.
private static final boolean ENABLE_FLING_DISMISS = false;
@@ -67,12 +66,9 @@
private static final int BOTTOM_OFFSET_BUFFER_DP = 1;
// Allow dragging the PIP to a location to close it
- private final boolean mEnableDimissDragToEdge;
+ private final boolean mEnableDismissDragToEdge;
private final Context mContext;
private final IActivityManager mActivityManager;
- private final IActivityTaskManager mActivityTaskManager;
- private final ViewConfiguration mViewConfig;
- private final PipMenuListener mMenuListener = new PipMenuListener();
private final PipBoundsHandler mPipBoundsHandler;
private final PipResizeGestureHandler mPipResizeGestureHandler;
private IPinnedStackController mPinnedStackController;
@@ -104,7 +100,7 @@
private Runnable mShowDismissAffordance = new Runnable() {
@Override
public void run() {
- if (mEnableDimissDragToEdge) {
+ if (mEnableDismissDragToEdge) {
mDismissViewController.showDismissTarget();
}
}
@@ -112,7 +108,6 @@
// Behaviour states
private int mMenuState = MENU_STATE_NONE;
- private boolean mIsMinimized;
private boolean mIsImeShowing;
private int mImeHeight;
private int mImeOffset;
@@ -121,7 +116,6 @@
private int mMovementBoundsExtraOffsets;
private float mSavedSnapFraction = -1f;
private boolean mSendingHoverAccessibilityEvents;
- private boolean mMovementWithinMinimize;
private boolean mMovementWithinDismiss;
private PipAccessibilityInteractionConnection mConnection;
@@ -146,15 +140,7 @@
@Override
public void onPipExpand() {
- if (!mIsMinimized) {
- mMotionHelper.expandPip();
- }
- }
-
- @Override
- public void onPipMinimize() {
- setMinimizedStateInternal(true);
- mMotionHelper.animateToClosestMinimizedState(null /* updateAction */);
+ mMotionHelper.expandPip();
}
@Override
@@ -175,26 +161,24 @@
IActivityTaskManager activityTaskManager, PipMenuActivityController menuController,
InputConsumerController inputConsumerController,
PipBoundsHandler pipBoundsHandler,
+ PipTaskOrganizer pipTaskOrganizer,
FloatingContentCoordinator floatingContentCoordinator) {
-
// Initialize the Pip input consumer
mContext = context;
mActivityManager = activityManager;
- mActivityTaskManager = activityTaskManager;
mAccessibilityManager = context.getSystemService(AccessibilityManager.class);
- mViewConfig = ViewConfiguration.get(context);
mMenuController = menuController;
- mMenuController.addListener(mMenuListener);
+ mMenuController.addListener(new PipMenuListener());
mDismissViewController = new PipDismissViewController(context);
mSnapAlgorithm = new PipSnapAlgorithm(mContext);
mFlingAnimationUtils = new FlingAnimationUtils(context.getResources().getDisplayMetrics(),
2.5f);
mGesture = new DefaultPipTouchGesture();
- mMotionHelper = new PipMotionHelper(mContext, mActivityManager, mActivityTaskManager,
+ mMotionHelper = new PipMotionHelper(mContext, activityTaskManager, pipTaskOrganizer,
mMenuController, mSnapAlgorithm, mFlingAnimationUtils, floatingContentCoordinator);
mPipResizeGestureHandler =
new PipResizeGestureHandler(context, pipBoundsHandler, this, mMotionHelper);
- mTouchState = new PipTouchState(mViewConfig, mHandler,
+ mTouchState = new PipTouchState(ViewConfiguration.get(context), mHandler,
() -> mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
mMovementBounds, true /* allowMenuTimeout */, willResizeMenu()));
@@ -203,7 +187,7 @@
R.dimen.pip_expanded_shortest_edge_size);
mImeOffset = res.getDimensionPixelSize(R.dimen.pip_ime_offset);
- mEnableDimissDragToEdge = res.getBoolean(R.bool.config_pipEnableDismissDragToEdge);
+ mEnableDismissDragToEdge = res.getBoolean(R.bool.config_pipEnableDismissDragToEdge);
// Register the listener for input consumer touch events
inputConsumerController.setInputListener(this::handleTouchEvent);
@@ -339,8 +323,7 @@
// If we have a deferred resize, apply it now
if (mDeferResizeToNormalBoundsUntilRotation == displayRotation) {
mMotionHelper.animateToUnexpandedState(normalBounds, mSavedSnapFraction,
- mNormalMovementBounds, mMovementBounds, mIsMinimized,
- true /* immediate */);
+ mNormalMovementBounds, mMovementBounds, true /* immediate */);
mSavedSnapFraction = -1f;
mDeferResizeToNormalBoundsUntilRotation = -1;
}
@@ -482,44 +465,6 @@
}
/**
- * Sets the minimized state.
- */
- private void setMinimizedStateInternal(boolean isMinimized) {
- if (!ENABLE_MINIMIZE) {
- return;
- }
- setMinimizedState(isMinimized, false /* fromController */);
- }
-
- /**
- * Sets the minimized state.
- */
- void setMinimizedState(boolean isMinimized, boolean fromController) {
- if (!ENABLE_MINIMIZE) {
- return;
- }
- if (mIsMinimized != isMinimized) {
- MetricsLoggerWrapper.logPictureInPictureMinimize(mContext,
- isMinimized, PipUtils.getTopPinnedActivity(mContext, mActivityManager));
- }
- mIsMinimized = isMinimized;
- mSnapAlgorithm.setMinimized(isMinimized);
-
- if (fromController) {
- if (isMinimized) {
- // Move the PiP to the new bounds immediately if minimized
- mMotionHelper.movePip(mMotionHelper.getClosestMinimizedBounds(mNormalBounds));
- }
- } else if (mPinnedStackController != null) {
- try {
- mPinnedStackController.setIsMinimized(isMinimized);
- } catch (RemoteException e) {
- Log.e(TAG, "Could not set minimized state", e);
- }
- }
- }
-
- /**
* Sets the menu visibility.
*/
private void setMenuState(int menuState, boolean resize) {
@@ -562,8 +507,7 @@
if (mDeferResizeToNormalBoundsUntilRotation == -1) {
Rect normalBounds = new Rect(mNormalBounds);
mMotionHelper.animateToUnexpandedState(normalBounds, mSavedSnapFraction,
- mNormalMovementBounds, mMovementBounds, mIsMinimized,
- false /* immediate */);
+ mNormalMovementBounds, mMovementBounds, false /* immediate */);
mSavedSnapFraction = -1f;
}
} else {
@@ -601,8 +545,6 @@
* Gesture controlling normal movement of the PIP.
*/
private class DefaultPipTouchGesture extends PipTouchGesture {
- // Whether the PiP was on the left side of the screen at the start of the gesture
- private boolean mStartedOnLeft;
private final Point mStartPosition = new Point();
private final PointF mDelta = new PointF();
@@ -615,17 +557,15 @@
Rect bounds = mMotionHelper.getBounds();
mDelta.set(0f, 0f);
mStartPosition.set(bounds.left, bounds.top);
- mStartedOnLeft = bounds.left < mMovementBounds.centerX();
- mMovementWithinMinimize = true;
mMovementWithinDismiss = touchState.getDownTouchPosition().y >= mMovementBounds.bottom;
- // If the menu is still visible, and we aren't minimized, then just poke the menu
+ // If the menu is still visible then just poke the menu
// so that it will timeout after the user stops touching it
- if (mMenuState != MENU_STATE_NONE && !mIsMinimized) {
+ if (mMenuState != MENU_STATE_NONE) {
mMenuController.pokeMenu();
}
- if (mEnableDimissDragToEdge) {
+ if (mEnableDismissDragToEdge) {
mDismissViewController.createDismissTarget();
mHandler.postDelayed(mShowDismissAffordance, SHOW_DISMISS_AFFORDANCE_DELAY);
}
@@ -640,7 +580,7 @@
if (touchState.startedDragging()) {
mSavedSnapFraction = -1f;
- if (mEnableDimissDragToEdge) {
+ if (mEnableDismissDragToEdge) {
mHandler.removeCallbacks(mShowDismissAffordance);
mDismissViewController.showDismissTarget();
}
@@ -662,17 +602,11 @@
mTmpBounds.offsetTo((int) left, (int) top);
mMotionHelper.movePip(mTmpBounds, true /* isDragging */);
- if (mEnableDimissDragToEdge) {
+ if (mEnableDismissDragToEdge) {
updateDismissFraction();
}
final PointF curPos = touchState.getLastTouchPosition();
- if (mMovementWithinMinimize) {
- // Track if movement remains near starting edge to identify swipes to minimize
- mMovementWithinMinimize = mStartedOnLeft
- ? curPos.x <= mMovementBounds.left + mTmpBounds.width()
- : curPos.x >= mMovementBounds.right;
- }
if (mMovementWithinDismiss) {
// Track if movement remains near the bottom edge to identify swipe to dismiss
mMovementWithinDismiss = curPos.y >= mMovementBounds.bottom;
@@ -684,7 +618,7 @@
@Override
public boolean onUp(PipTouchState touchState) {
- if (mEnableDimissDragToEdge) {
+ if (mEnableDismissDragToEdge) {
// Clean up the dismiss target regardless of the touch state in case the touch
// enabled state changes while the user is interacting
cleanUpDismissTarget();
@@ -704,7 +638,7 @@
vel.y, isFling);
final boolean isFlingToBot = isFling && vel.y > 0 && !isHorizontal
&& (mMovementWithinDismiss || isUpWithinDimiss);
- if (mEnableDimissDragToEdge) {
+ if (mEnableDismissDragToEdge) {
// Check if the user dragged or flung the PiP offscreen to dismiss it
if (mMotionHelper.shouldDismissPip() || isFlingToBot) {
MetricsLoggerWrapper.logPictureInPictureDismissByDrag(mContext,
@@ -717,33 +651,10 @@
}
if (touchState.isDragging()) {
- final boolean isFlingToEdge = isFling && isHorizontal && mMovementWithinMinimize
- && (mStartedOnLeft ? vel.x < 0 : vel.x > 0);
- if (ENABLE_MINIMIZE &&
- !mIsMinimized && (mMotionHelper.shouldMinimizePip() || isFlingToEdge)) {
- // Pip should be minimized
- setMinimizedStateInternal(true);
- if (mMenuState == MENU_STATE_FULL) {
- // If the user dragged the expanded PiP to the edge, then hiding the menu
- // will trigger the PiP to be scaled back to the normal size with the
- // minimize offset adjusted
- mMenuController.hideMenu();
- } else {
- mMotionHelper.animateToClosestMinimizedState(
- PipTouchHandler.this::updateDismissFraction /* updateAction */);
- }
- return true;
- }
- if (mIsMinimized) {
- // If we're dragging and it wasn't a minimize gesture then we shouldn't be
- // minimized.
- setMinimizedStateInternal(false);
- }
-
Runnable endAction = null;
if (mMenuState != MENU_STATE_NONE) {
- // If the menu is still visible, and we aren't minimized, then just poke the
- // menu so that it will timeout after the user stops touching it
+ // If the menu is still visible, then just poke the menu so that
+ // it will timeout after the user stops touching it
mMenuController.showMenu(mMenuState, mMotionHelper.getBounds(),
mMovementBounds, true /* allowMenuTimeout */, willResizeMenu());
} else {
@@ -759,10 +670,6 @@
} else {
mMotionHelper.animateToClosestSnapTarget();
}
- } else if (mIsMinimized) {
- // This was a tap, so no longer minimized
- mMotionHelper.animateToClosestSnapTarget();
- setMinimizedStateInternal(false);
} else if (mTouchState.isDoubleTap()) {
// Expand to fullscreen if this is a double tap
mMotionHelper.expandPip();
@@ -821,14 +728,12 @@
pw.println(innerPrefix + "mExpandedBounds=" + mExpandedBounds);
pw.println(innerPrefix + "mExpandedMovementBounds=" + mExpandedMovementBounds);
pw.println(innerPrefix + "mMenuState=" + mMenuState);
- pw.println(innerPrefix + "mIsMinimized=" + mIsMinimized);
pw.println(innerPrefix + "mIsImeShowing=" + mIsImeShowing);
pw.println(innerPrefix + "mImeHeight=" + mImeHeight);
pw.println(innerPrefix + "mIsShelfShowing=" + mIsShelfShowing);
pw.println(innerPrefix + "mShelfHeight=" + mShelfHeight);
pw.println(innerPrefix + "mSavedSnapFraction=" + mSavedSnapFraction);
- pw.println(innerPrefix + "mEnableDragToEdgeDismiss=" + mEnableDimissDragToEdge);
- pw.println(innerPrefix + "mEnableMinimize=" + ENABLE_MINIMIZE);
+ pw.println(innerPrefix + "mEnableDragToEdgeDismiss=" + mEnableDismissDragToEdge);
mSnapAlgorithm.dump(pw, innerPrefix);
mTouchState.dump(pw, innerPrefix);
mMotionHelper.dump(pw, innerPrefix);
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 487c253..cb1a218 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
@@ -50,7 +50,9 @@
import com.android.systemui.UiOffloadThread;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.pip.BasePipManager;
+import com.android.systemui.pip.PipAnimationController;
import com.android.systemui.pip.PipBoundsHandler;
+import com.android.systemui.pip.PipTaskOrganizer;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.PinnedStackListenerForwarder.PinnedStackListener;
import com.android.systemui.shared.system.TaskStackChangeListener;
@@ -66,7 +68,7 @@
* Manages the picture-in-picture (PIP) UI and states.
*/
@Singleton
-public class PipManager implements BasePipManager {
+public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitionCallback {
private static final String TAG = "PipManager";
static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -91,7 +93,6 @@
private static final int INVALID_RESOURCE_TYPE = -1;
public static final int SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH = 0x1;
- public static final int SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_OVERLAY_ACTIVITY_FINISH = 0x2;
/**
* PIPed activity is playing a media and it can be paused.
@@ -112,6 +113,7 @@
private Context mContext;
private PipBoundsHandler mPipBoundsHandler;
+ private PipTaskOrganizer mPipTaskOrganizer;
private IActivityTaskManager mActivityTaskManager;
private MediaSessionManager mMediaSessionManager;
private int mState = STATE_NO_PIP;
@@ -205,8 +207,7 @@
}
@Override
- public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment,
- boolean fromShelfAdjustment) {
+ public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment) {
mHandler.post(() -> {
// Populate the inset / normal bounds and DisplayInfo from mPipBoundsHandler first.
mPipBoundsHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds,
@@ -234,6 +235,8 @@
mInitialized = true;
mContext = context;
mPipBoundsHandler = new PipBoundsHandler(context);
+ mPipTaskOrganizer = new PipTaskOrganizer(mContext, mPipBoundsHandler);
+ mPipTaskOrganizer.registerPipTransitionCallback(this);
mActivityTaskManager = ActivityTaskManager.getService();
ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
IntentFilter intentFilter = new IntentFilter();
@@ -279,9 +282,12 @@
mMediaSessionManager =
(MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE);
+ mPipTaskOrganizer.registerPipTransitionCallback(this);
try {
WindowManagerWrapper.getInstance().addPinnedStackListener(mPinnedStackListener);
+ ActivityTaskManager.getTaskOrganizerController().registerTaskOrganizer(
+ mPipTaskOrganizer, WINDOWING_MODE_PINNED);
} catch (RemoteException e) {
Log.e(TAG, "Failed to register pinned stack listener", e);
}
@@ -422,20 +428,13 @@
case STATE_PIP_MENU:
mCurrentPipBounds = mMenuModePipBounds;
break;
- case STATE_PIP:
- mCurrentPipBounds = mPipBounds;
- break;
+ case STATE_PIP: // fallthrough
default:
mCurrentPipBounds = mPipBounds;
break;
}
- try {
- int animationDurationMs = -1;
- mActivityTaskManager.animateResizePinnedStack(mPinnedStackId, mCurrentPipBounds,
- animationDurationMs);
- } catch (RemoteException e) {
- Log.e(TAG, "resizeStack failed", e);
- }
+ mPipTaskOrganizer.resizePinnedStack(
+ mCurrentPipBounds, PipAnimationController.DURATION_DEFAULT_MS);
}
/**
@@ -449,13 +448,6 @@
}
/**
- * Returns the default PIP bound.
- */
- public Rect getPipBounds() {
- return mPipBounds;
- }
-
- /**
* Shows PIP menu UI by launching {@link PipMenuActivity}. It also locates the pinned
* stack to the centered PIP bound {@link R.config_centeredPictureInPictureBounds}.
*/
@@ -692,19 +684,28 @@
// If PIPed activity is launched again by Launcher or intent, make it fullscreen.
movePipToFullscreen();
}
-
- @Override
- public void onPinnedStackAnimationEnded() {
- if (DEBUG) Log.d(TAG, "onPinnedStackAnimationEnded()");
-
- switch (getState()) {
- case STATE_PIP_MENU:
- showPipMenu();
- break;
- }
- }
};
+ @Override
+ public void onPipTransitionStarted() { }
+
+ @Override
+ public void onPipTransitionFinished() {
+ onPipTransitionFinishedOrCanceled();
+ }
+
+ @Override
+ public void onPipTransitionCanceled() {
+ onPipTransitionFinishedOrCanceled();
+ }
+
+ private void onPipTransitionFinishedOrCanceled() {
+ if (DEBUG) Log.d(TAG, "onPipTransitionFinishedOrCanceled()");
+ if (getState() == STATE_PIP_MENU) {
+ showPipMenu();
+ }
+ }
+
/**
* A listener interface to receive notification on changes in PIP.
*/
diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
index 34cad51..1cd6388 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
@@ -61,9 +61,11 @@
import com.android.internal.util.ScreenshotHelper;
import com.android.systemui.Dumpable;
import com.android.systemui.model.SysUiState;
+import com.android.systemui.pip.PipAnimationController;
import com.android.systemui.pip.PipUI;
import com.android.systemui.recents.OverviewProxyService.OverviewProxyListener;
import com.android.systemui.shared.recents.IOverviewProxy;
+import com.android.systemui.shared.recents.IPinnedStackAnimationListener;
import com.android.systemui.shared.recents.ISystemUiProxy;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.QuickStepContract;
@@ -388,6 +390,32 @@
}
}
+ @Override
+ public void notifySwipeToHomeFinished() {
+ if (!verifyCaller("notifySwipeToHomeFinished")) {
+ return;
+ }
+ long token = Binder.clearCallingIdentity();
+ try {
+ mPipUI.setPinnedStackAnimationType(PipAnimationController.ANIM_TYPE_ALPHA);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public void setPinnedStackAnimationListener(IPinnedStackAnimationListener listener) {
+ if (!verifyCaller("setPinnedStackAnimationListener")) {
+ return;
+ }
+ long token = Binder.clearCallingIdentity();
+ try {
+ mPipUI.setPinnedStackAnimationListener(listener);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
private boolean verifyCaller(String reason) {
final int callerId = Binder.getCallingUserHandle().getIdentifier();
if (callerId != mCurrentBoundedUserId) {