From febe3f029d8fdade050406786a7ff4a3e5bdce4c Mon Sep 17 00:00:00 2001 From: Iris Yang Date: Tue, 6 Sep 2022 10:29:43 +0800 Subject: Post callback onSecureWindowShown on the main thread onSecureWindowShown will trigger a toast showing and might cause deadlock since showing a toast will acquire ActivityManagerService lock. Post onSecureWindowShown on the main thread, so it doesn't block activity launching. Bug: 244139910 Test: Manually test with Exo on multi-display environment Change-Id: Idf29b534a3657a265a5f389e0b388bc3af19c04e --- .../server/companion/virtual/GenericWindowPolicyController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/companion/java/com/android/server/companion/virtual/GenericWindowPolicyController.java b/services/companion/java/com/android/server/companion/virtual/GenericWindowPolicyController.java index 593a63c2f0c9..fc628cfdced2 100644 --- a/services/companion/java/com/android/server/companion/virtual/GenericWindowPolicyController.java +++ b/services/companion/java/com/android/server/companion/virtual/GenericWindowPolicyController.java @@ -250,7 +250,9 @@ public class GenericWindowPolicyController extends DisplayWindowPolicyController // The callback is fired only when windowFlags are changed. To let VirtualDevice owner // aware that the virtual display has a secure window on top. if ((windowFlags & FLAG_SECURE) != 0) { - mSecureWindowCallback.onSecureWindowShown(mDisplayId, activityInfo.applicationInfo.uid); + // Post callback on the main thread, so it doesn't block activity launching. + mHandler.post(() -> mSecureWindowCallback.onSecureWindowShown(mDisplayId, + activityInfo.applicationInfo.uid)); } if (!canContainActivity(activityInfo, windowFlags, systemWindowFlags)) { -- cgit v1.2.3-59-g8ed1b