From b29b6aac05a15d49f182f108981847f20c06ca12 Mon Sep 17 00:00:00 2001 From: Tony Huang Date: Tue, 3 Aug 2021 14:12:50 +0800 Subject: Fix split caused apps ANR If mWindowDrawCountDown is set to non null when mReportNextDraw is false, it won't get cleared in performingDraw. If another draw occurs afterwards where mReportNextDraw is true, but requestDrawWindow doesn't get called, an ANR will occur. This is because performDraw will end up waiting forever since mWindowDrawCountDown was previously set to non null, but there will never be any calls reportDrawFinish to handle the countDown. We should only create latch and wait it when mReportNextDraw is true. Bug: 195262673 Test: Pass existing tests Test: Drag and drop split divider quickly Change-Id: I4ee81a41687c4f61a4828d4c61ba01abee795e89 --- core/java/android/view/ViewRootImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 27eb2a551898..7d75d998c253 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -9931,7 +9931,10 @@ public final class ViewRootImpl implements ViewParent, if (!mUseMTRenderer) { return; } - mWindowDrawCountDown = new CountDownLatch(mWindowCallbacks.size()); + // Only wait if it will report next draw. + if (mReportNextDraw) { + mWindowDrawCountDown = new CountDownLatch(mWindowCallbacks.size()); + } for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { mWindowCallbacks.get(i).onRequestDraw(mReportNextDraw); } -- cgit v1.2.3-59-g8ed1b