Fix transfer splash screen view been called twice from onDraw

postOnAnimation is not robust enough from remove the onDrawListener
before next traversal, add a flag to to ensure that transfer splash
screen view only been called once.

Bug: 204125440
Test: atest SplashscreenTests
Test: verify SplashScreenTests and SplashscreenParametrizedTest pass
Change-Id: Id0e6d57b901b2dae45f5aa77e5571f9cf81b6e29
This commit is contained in:
wilsonshih
2022-01-05 20:18:02 +08:00
parent cfba62de35
commit 4ee97aa498

View File

@@ -4178,15 +4178,20 @@ public final class ActivityThread extends ClientTransactionHandler
view.requestLayout();
view.getViewTreeObserver().addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
private boolean mHandled = false;
@Override
public void onDraw() {
if (mHandled) {
return;
}
mHandled = true;
// Transfer the splash screen view from shell to client.
// Call syncTransferSplashscreenViewTransaction at the first onDraw so we can ensure
// the client view is ready to show and we can use applyTransactionOnDraw to make
// all transitions happen at the same frame.
syncTransferSplashscreenViewTransaction(
view, r.token, decorView, startingWindowLeash);
view.postOnAnimation(() -> view.getViewTreeObserver().removeOnDrawListener(this));
view.post(() -> view.getViewTreeObserver().removeOnDrawListener(this));
}
});
}