[Bugfix][RemoteAnimation] Fix IndexOutOfBoundsException in onAnimationFinished of
RemoteAnimationController
Sometimes mPendingAnimations.remove will be called more than once in one cycle (line 255 - 270) of
onAnimationFinished, e.g., mPendingAnimations.remove being called again in
adapters.mAdapter.mCapturedFinishCallback.onAnimationFinished, resulting in
IndexOutOfBoundsException.
Bug:237989368
Change-Id: Ica771f1ae4cb4ddddb7684bd964504ca9f31ea12
Test: Monkey test
diff --git a/services/core/java/com/android/server/wm/RemoteAnimationController.java b/services/core/java/com/android/server/wm/RemoteAnimationController.java
index eeac230..027f3ae 100644
--- a/services/core/java/com/android/server/wm/RemoteAnimationController.java
+++ b/services/core/java/com/android/server/wm/RemoteAnimationController.java
@@ -68,6 +68,7 @@
final ArrayList<NonAppWindowAnimationAdapter> mPendingNonAppAnimations = new ArrayList<>();
private final Handler mHandler;
private final Runnable mTimeoutRunnable = () -> cancelAnimation("timeoutRunnable");
+ private boolean mIsFinishing;
private FinishedCallback mFinishedCallback;
private boolean mCanceled;
@@ -246,6 +247,7 @@
mPendingAnimations.size());
mHandler.removeCallbacks(mTimeoutRunnable);
synchronized (mService.mGlobalLock) {
+ mIsFinishing = true;
unlinkToDeathOfRunner();
releaseFinishedCallback();
mService.openSurfaceTransaction();
@@ -290,6 +292,7 @@
throw e;
} finally {
mService.closeSurfaceTransaction("RemoteAnimationController#finished");
+ mIsFinishing = false;
}
}
setRunningRemoteAnimation(false);
@@ -501,6 +504,9 @@
@Override
public void onAnimationCancelled(SurfaceControl animationLeash) {
+ if (mIsFinishing) {
+ return;
+ }
if (mRecord.mAdapter == this) {
mRecord.mAdapter = null;
} else {