Move attach/detach PiP menu calls to onTaskAppear/Vanish.

In an ideal case, onActivityPinned should always be followed by
an onActivityUpinned call in a PiP session. However, there are
possible times where it doesn't happen; PIP can crash suddenly,
or some other calls force closes PiP without it
getting a chance to call on Unpinned. In that case, menu isn't properly
cleaned up, so let's just make sure it is before trying to re-attach.
At the same time, move the call to onTaskAppear/Vanish, which is
guaranteed to be called.

Bug: 172268911
Bug: 172258041
Bug: 170315895
Test: Manual; Pause PiP, unpause PiP, menu still showing
Test: Locally hack so that detach doesn't get called the first time
(simulate crash), start PiP again - doesn't crash

Change-Id: I76984de59515f4178561ba92ae692fcc3c5edcb9
This commit is contained in:
Ben Lin
2020-11-05 11:16:05 -08:00
parent dd6d27ec2b
commit d4459553dc
3 changed files with 16 additions and 7 deletions

View File

@@ -495,6 +495,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
mOnDisplayIdChangeCallback.accept(info.displayId);
}
mMenuActivityController.onTaskAppeared();
if (mShouldIgnoreEnteringPipTransition) {
final Rect destinationBounds = mPipBoundsState.getBounds();
// animation is finished in the Launcher and here we directly apply the final touch.
@@ -666,6 +668,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
mPictureInPictureParams = null;
mState = State.UNDEFINED;
mPipUiEventLoggerLogger.setTaskInfo(null);
mMenuActivityController.onTaskVanished();
}
@Override

View File

@@ -276,7 +276,6 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
mMainExecutor.execute(() -> {
mTouchHandler.onActivityPinned();
mMediaController.onActivityPinned();
mMenuController.onActivityPinned();
mAppOpsListener.onActivityPinned(packageName);
});
}
@@ -284,7 +283,6 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
@Override
public void onActivityUnpinned(ComponentName topActivity) {
mMainExecutor.execute(() -> {
mMenuController.onActivityUnpinned();
mTouchHandler.onActivityUnpinned(topActivity);
mAppOpsListener.onActivityUnpinned();
});

View File

@@ -134,15 +134,22 @@ public class PipMenuActivityController {
return mPipMenuView != null && mMenuState != MENU_STATE_NONE;
}
public void onActivityPinned() {
/**
* Attach the menu when the PiP task first appears.
*/
public void onTaskAppeared() {
attachPipMenuView();
}
public void onActivityUnpinned() {
/**
* Detach the menu when the PiP task is gone.
*/
public void onTaskVanished() {
hideMenu();
detachPipMenuView();
}
public void onPinnedStackAnimationEnded() {
if (isMenuVisible()) {
mPipMenuView.onPipAnimationEnded();
@@ -150,10 +157,11 @@ public class PipMenuActivityController {
}
private void attachPipMenuView() {
if (mPipMenuView == null) {
mPipMenuView = new PipMenuView(mContext, this);
// In case detach was not called (e.g. PIP unexpectedly closed)
if (mPipMenuView != null) {
detachPipMenuView();
}
mPipMenuView = new PipMenuView(mContext, this);
mSystemWindows.addView(mPipMenuView, getPipMenuLayoutParams(0, 0), 0, SHELL_ROOT_LAYER_PIP);
}