From 1fc214bdfc6253be161581cf159a7ab28988f26e Mon Sep 17 00:00:00 2001 From: Arthur Hung Date: Mon, 20 May 2019 11:12:53 +0800 Subject: [PATCH] Fix a deadlock between WindowManagerGlobal and WindowManagerService When a new display added, would first lock WMS then create a new DisplayContent, that would also create the corresponding SystemGesturesPointerEventListener, GestureDetector, ViewConfiguration, and WindowManagerImpl, and it would also temporarily lock WindowManagerGlobal in WindowManagerImpl's constructor. This patch would post creating GestureDetector to avoid the deadlock caused by other thread also lock WMS/WindowMaagerGlobal at same time. Bug: 132746553 Test: create a app with splash screen and connect to new display at same time. Change-Id: I246e596dff387923356bbc579f785b634d3d2468 --- .../server/wm/SystemGesturesPointerEventListener.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java b/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java index 854537b4618fb..fb781b06f05f3 100644 --- a/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java +++ b/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java @@ -113,7 +113,12 @@ class SystemGesturesPointerEventListener implements PointerEventListener { // statistics because it passes every touch event though a GestureDetector. By creating an // anonymous subclass of GestureDetector, these statistics will be recorded with a unique // source name that can be filtered. - mGestureDetector = new GestureDetector(mContext, new FlingGestureDetector(), mHandler) {}; + + // GestureDetector would get a ViewConfiguration instance by context, that may also + // create a new WindowManagerImpl for the new display, and lock WindowManagerGlobal + // temporarily in the constructor that would make a deadlock. + mHandler.post(() -> mGestureDetector = + new GestureDetector(mContext, new FlingGestureDetector(), mHandler) {}); } @Override