From 045230a4329620eac05d439ecb96c0387a72b6a5 Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Thu, 4 Mar 2021 17:59:46 +0800 Subject: [PATCH] Fix deadlock between WMG and WMS The dealock happened while WM#addView and WMS holds lock and called onWindowTokenRemoved. WM#addView -> WMG#addView(holds WMG lock) -> ... -> WMS#addWindow(holds WMS lock) (holds WMS lock) ... -> WindowTokenClient#onWindowTokenRemoved ... -> WMG#closeAll(holds WMG lock) This CL calls to WMG#closeAll asynchronously to release WMG lock fixes: 181839758 Test: manual Change-Id: I0cf8a505043a4def4dcf346952873b1362a92084 --- core/java/android/app/WindowTokenClient.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/WindowTokenClient.java b/core/java/android/app/WindowTokenClient.java index 29792ac47a36d..2298e84d755ec 100644 --- a/core/java/android/app/WindowTokenClient.java +++ b/core/java/android/app/WindowTokenClient.java @@ -85,8 +85,10 @@ public class WindowTokenClient extends IWindowToken.Stub { context.destroy(); mContextRef.clear(); } - // If a secondary display is detached, release all views attached to this token. - WindowManagerGlobal.getInstance().closeAll(this, mContextRef.getClass().getName(), - "WindowContext"); + ActivityThread.currentActivityThread().getHandler().post(() -> { + // If the tracked window token is detached, release all views attached to this token. + WindowManagerGlobal.getInstance().closeAll(WindowTokenClient.this, + "#onWindowTokenRemoved()", "WindowTokenClient"); + }); } }