Merge "Fix missing finish callback to fix running animation leak" into rvc-dev am: 526632d15f am: d49d6f502c

Change-Id: I76af5c10d68ee7aa4f11c6bcea4026f2673d8c30
This commit is contained in:
Jorim Jaggi
2020-04-01 16:38:43 +00:00
committed by Automerger Merge Worker
3 changed files with 25 additions and 3 deletions

View File

@@ -140,7 +140,12 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
@Override
public void setInsetsAndAlpha(Insets insets, float alpha, float fraction) {
if (mFinished) {
setInsetsAndAlpha(insets, alpha, fraction, false /* allowWhenFinished */);
}
private void setInsetsAndAlpha(Insets insets, float alpha, float fraction,
boolean allowWhenFinished) {
if (!allowWhenFinished && mFinished) {
throw new IllegalStateException(
"Can't change insets on an animation that is finished.");
}
@@ -201,8 +206,9 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
return;
}
mShownOnFinish = shown;
setInsetsAndAlpha(shown ? mShownInsets : mHiddenInsets, 1f /* alpha */, 1f /* fraction */);
mFinished = true;
setInsetsAndAlpha(shown ? mShownInsets : mHiddenInsets, 1f /* alpha */, 1f /* fraction */,
true /* allowWhenFinished */);
mListener.onFinished(this);
}

View File

@@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -222,6 +223,22 @@ public class InsetsAnimationControlImplTest {
verify(mMockListener, never()).onFinished(any());
}
@Test
public void testFinish_immediately() {
when(mMockController.getState()).thenReturn(mInsetsState);
doAnswer(invocation -> {
mController.applyChangeInsets(mInsetsState);
return null;
}).when(mMockController).scheduleApplyChangeInsets();
mController.finish(true /* shown */);
assertEquals(Insets.of(0, 100, 100, 0), mController.getCurrentInsets());
verify(mMockController).notifyFinished(eq(mController), eq(true /* shown */));
assertFalse(mController.isReady());
assertTrue(mController.isFinished());
assertFalse(mController.isCancelled());
verify(mMockListener).onFinished(mController);
}
private void assertPosition(Matrix m, Rect original, Rect transformed) {
RectF rect = new RectF(original);
rect.offsetTo(0, 0);

View File

@@ -367,7 +367,6 @@ class InsetsPolicy {
@Override
protected void onAnimationFinish() {
super.onAnimationFinish();
mControlCallbacks.mAnimationControl.finish(mAnimatingShown);
DisplayThread.getHandler().post(mFinishCallback);
}