Reset PiP shadow radius in onTaskVanished

This is a follow-up of ag/17527240 in which we do not cover the case
that a Task in pinned mode is directly removed via Task#moveTaskToBack

Video: http://recall/-/aaaaaabFQoRHlzixHdtY/cMG5Uh1kLC7EyAs2EbDVkM
Bug: 228793904
Test: follow the reproduce step in bug, see video
Test: atest WMShellUnitTests:PipTaskOrganizerTest
Change-Id: Ib7472908a81d56d34216ca272afbd9f1a2668b89
This commit is contained in:
Hongwei Wang
2022-04-14 13:43:56 -07:00
parent 8e157c498c
commit e4f4f107f3
4 changed files with 88 additions and 46 deletions

View File

@@ -924,6 +924,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
removeContentOverlay(mSwipePipToHomeOverlay, null /* callback */);
mSwipePipToHomeOverlay = null;
}
resetShadowRadius();
mPipTransitionState.setInSwipePipToHomeTransition(false);
mPictureInPictureParams = null;
mPipTransitionState.setTransitionState(PipTransitionState.UNDEFINED);
@@ -1569,13 +1570,28 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
// Avoid double removal, which is fatal.
return;
}
final SurfaceControl.Transaction tx =
mSurfaceControlTransactionFactory.getTransaction();
final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
tx.remove(surface);
tx.apply();
if (callback != null) callback.run();
}
private void resetShadowRadius() {
if (mPipTransitionState.getTransitionState() == PipTransitionState.UNDEFINED) {
// mLeash is undefined when in PipTransitionState.UNDEFINED
return;
}
final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
tx.setShadowRadius(mLeash, 0f);
tx.apply();
}
@VisibleForTesting
public void setSurfaceControlTransactionFactory(
PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) {
mSurfaceControlTransactionFactory = factory;
}
/**
* Dumps internal states.
*/

View File

@@ -30,7 +30,6 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import android.app.TaskInfo;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -104,7 +103,7 @@ public class PipAnimationControllerTest extends ShellTestCase {
final PipAnimationController.PipTransitionAnimator oldAnimator = mPipAnimationController
.getAnimator(mTaskInfo, mLeash, baseValue, startValue, endValue1, null,
TRANSITION_DIRECTION_TO_PIP, 0, ROTATION_0);
oldAnimator.setSurfaceControlTransactionFactory(DummySurfaceControlTx::new);
oldAnimator.setSurfaceControlTransactionFactory(PipDummySurfaceControlTx::new);
oldAnimator.start();
final PipAnimationController.PipTransitionAnimator newAnimator = mPipAnimationController
@@ -134,7 +133,7 @@ public class PipAnimationControllerTest extends ShellTestCase {
@Test
public void pipTransitionAnimator_rotatedEndValue() {
final DummySurfaceControlTx tx = new DummySurfaceControlTx();
final PipDummySurfaceControlTx tx = new PipDummySurfaceControlTx();
final Rect startBounds = new Rect(200, 700, 400, 800);
final Rect endBounds = new Rect(0, 0, 500, 1000);
// Fullscreen to PiP.
@@ -184,7 +183,7 @@ public class PipAnimationControllerTest extends ShellTestCase {
final PipAnimationController.PipTransitionAnimator animator = mPipAnimationController
.getAnimator(mTaskInfo, mLeash, baseValue, startValue, endValue, null,
TRANSITION_DIRECTION_TO_PIP, 0, ROTATION_0);
animator.setSurfaceControlTransactionFactory(DummySurfaceControlTx::new);
animator.setSurfaceControlTransactionFactory(PipDummySurfaceControlTx::new);
animator.setPipAnimationCallback(mPipAnimationCallback);
@@ -201,44 +200,4 @@ public class PipAnimationControllerTest extends ShellTestCase {
verify(mPipAnimationCallback).onPipAnimationEnd(eq(mTaskInfo),
any(SurfaceControl.Transaction.class), eq(animator));
}
/**
* A dummy {@link SurfaceControl.Transaction} class.
* This is created as {@link Mock} does not support method chaining.
*/
public static class DummySurfaceControlTx extends SurfaceControl.Transaction {
@Override
public SurfaceControl.Transaction setAlpha(SurfaceControl leash, float alpha) {
return this;
}
@Override
public SurfaceControl.Transaction setPosition(SurfaceControl leash, float x, float y) {
return this;
}
@Override
public SurfaceControl.Transaction setWindowCrop(SurfaceControl leash, int w, int h) {
return this;
}
@Override
public SurfaceControl.Transaction setCornerRadius(SurfaceControl leash, float radius) {
return this;
}
@Override
public SurfaceControl.Transaction setMatrix(SurfaceControl leash, Matrix matrix,
float[] float9) {
return this;
}
@Override
public SurfaceControl.Transaction setFrameTimelineVsync(long frameTimelineVsyncId) {
return this;
}
@Override
public void apply() {}
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2022 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.wm.shell.pip;
import android.graphics.Matrix;
import android.view.SurfaceControl;
/**
* A dummy {@link SurfaceControl.Transaction} class for testing purpose and supports
* method chaining.
*/
public class PipDummySurfaceControlTx extends SurfaceControl.Transaction {
@Override
public SurfaceControl.Transaction setAlpha(SurfaceControl leash, float alpha) {
return this;
}
@Override
public SurfaceControl.Transaction setPosition(SurfaceControl leash, float x, float y) {
return this;
}
@Override
public SurfaceControl.Transaction setWindowCrop(SurfaceControl leash, int w, int h) {
return this;
}
@Override
public SurfaceControl.Transaction setCornerRadius(SurfaceControl leash, float radius) {
return this;
}
@Override
public SurfaceControl.Transaction setShadowRadius(SurfaceControl leash, float radius) {
return this;
}
@Override
public SurfaceControl.Transaction setMatrix(SurfaceControl leash, Matrix matrix,
float[] float9) {
return this;
}
@Override
public SurfaceControl.Transaction setFrameTimelineVsync(long frameTimelineVsyncId) {
return this;
}
@Override
public void apply() {}
}

View File

@@ -242,6 +242,7 @@ public class PipTaskOrganizerTest extends ShellTestCase {
mPipBoundsState.setDisplayLayout(new DisplayLayout(info,
mContext.getResources(), true, true));
mSpiedPipTaskOrganizer.setOneShotAnimationType(PipAnimationController.ANIM_TYPE_ALPHA);
mSpiedPipTaskOrganizer.setSurfaceControlTransactionFactory(PipDummySurfaceControlTx::new);
doNothing().when(mSpiedPipTaskOrganizer).enterPipWithAlphaAnimation(any(), anyLong());
doNothing().when(mSpiedPipTaskOrganizer).scheduleAnimateResizePip(any(), anyInt(), any());
}