Use TransactionCommittedListener to enable resizes

Use addTransactionCommittedListener to reset PiP pinch
resizing instead of using applySyncTransaction with a callback.

Bug: 277652545
Bug: 274682042
Test: manually pinch resized PiP window
Change-Id: I3ca9c2ebed559ae19fe722a3e3b8a4093a6f89e5
This commit is contained in:
Ikram Gabiyev
2023-04-18 18:46:57 +00:00
parent f8942d91cc
commit 47a1285cbe
2 changed files with 16 additions and 23 deletions

View File

@@ -72,7 +72,6 @@ import android.window.TaskOrganizer;
import android.window.TaskSnapshot;
import android.window.WindowContainerToken;
import android.window.WindowContainerTransaction;
import android.window.WindowContainerTransactionCallback;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.common.ProtoLog;
@@ -139,17 +138,6 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
// the runnable to execute after WindowContainerTransactions is applied to finish resizing pip
private Runnable mPipFinishResizeWCTRunnable;
private final WindowContainerTransactionCallback mPipFinishResizeWCTCallback =
new WindowContainerTransactionCallback() {
@Override
public void onTransactionReady(int id, SurfaceControl.Transaction t) {
t.apply();
// execute the runnable if non-null after WCT is applied to finish resizing pip
maybePerformFinishResizeCallback();
}
};
private void maybePerformFinishResizeCallback() {
if (mPipFinishResizeWCTRunnable != null) {
mPipFinishResizeWCTRunnable.run();
@@ -175,6 +163,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
final int direction = animator.getTransitionDirection();
if (mIsCancelled) {
sendOnPipTransitionFinished(direction);
maybePerformFinishResizeCallback();
return;
}
final int animationType = animator.getAnimationType();
@@ -199,6 +188,10 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
|| isRemovePipDirection(direction);
if (mPipTransitionState.getTransitionState() != PipTransitionState.EXITING_PIP
|| isExitPipDirection) {
// execute the finish resize callback if needed after the transaction is committed
tx.addTransactionCommittedListener(mMainExecutor,
PipTaskOrganizer.this::maybePerformFinishResizeCallback);
// Finish resize as long as we're not exiting PIP, or, if we are, only if this is
// the end of an exit PIP animation.
// This is necessary in case there was a resize animation ongoing when exit PIP
@@ -1614,12 +1607,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
if (direction == TRANSITION_DIRECTION_LEAVE_PIP_TO_SPLIT_SCREEN) {
mSplitScreenOptional.ifPresent(splitScreenController ->
splitScreenController.enterSplitScreen(mTaskInfo.taskId, wasPipTopLeft, wct));
} else if (direction == TRANSITION_DIRECTION_LEAVE_PIP) {
// when leaving PiP we can call the callback without sync
maybePerformFinishResizeCallback();
mTaskOrganizer.applyTransaction(wct);
} else {
mTaskOrganizer.applySyncTransaction(wct, mPipFinishResizeWCTCallback);
mTaskOrganizer.applyTransaction(wct);
}
}

View File

@@ -105,6 +105,7 @@ public class PipResizeGestureHandler {
private boolean mAllowGesture;
private boolean mIsAttached;
private boolean mIsEnabled;
private boolean mEnableTouch;
private boolean mEnablePinchResize;
private boolean mEnableDragCornerResize;
private boolean mIsSysUiStateValid;
@@ -139,6 +140,7 @@ public class PipResizeGestureHandler {
mPhonePipMenuController = menuActivityController;
mPipUiEventLogger = pipUiEventLogger;
mPinchResizingAlgorithm = new PipPinchResizingAlgorithm();
mEnableTouch = true;
mUpdateResizeBoundsCallback = (rect) -> {
mUserResizeBounds.set(rect);
@@ -244,13 +246,16 @@ public class PipResizeGestureHandler {
@VisibleForTesting
void onInputEvent(InputEvent ev) {
// TODO: remove logging once b/269505548 is resolved
Log.d(TAG, "onInputEvent: " + ev);
if (!mEnableDragCornerResize && !mEnablePinchResize) {
// No need to handle anything if neither form of resizing is enabled.
return;
}
if (!mEnableTouch) {
// No need to handle anything if touches are not enabled for resizing.
return;
}
// Don't allow resize when PiP is stashed.
if (mPipBoundsState.isStashed()) {
return;
@@ -589,14 +594,13 @@ public class PipResizeGestureHandler {
mLastResizeBounds, movementBounds);
mPipBoundsAlgorithm.applySnapFraction(mLastResizeBounds, snapFraction);
// disable the pinch resizing until the final bounds are updated
final boolean prevEnablePinchResize = mEnablePinchResize;
mEnablePinchResize = false;
// disable the resizing until the final bounds are updated
mEnableTouch = false;
mPipTaskOrganizer.scheduleAnimateResizePip(startBounds, mLastResizeBounds,
PINCH_RESIZE_SNAP_DURATION, mAngle, mUpdateResizeBoundsCallback, () -> {
// reset the pinch resizing to its default state
mEnablePinchResize = prevEnablePinchResize;
mEnableTouch = true;
});
} else {
mPipTaskOrganizer.scheduleFinishResizePip(mLastResizeBounds,