From a28af297d370fa3bcea14e0b6883343433a35d9c Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 23 Dec 2022 02:14:45 +0000 Subject: [PATCH] Fix deadlock by not acquiring lock when reporting proximity There is a deadlock situation from AttentionManagerService acquiring lock before callings back to its clients with the proximity update. This can cause a deadlock because the clients, while holding their own locks, can call AttentionManagerService again. Thread 1: Acquires attention lock -> AttentionManager Service reports proximityUpdate to VoiceInteraction -> tries to acquire voice lock Thread 2: Acquires voice lock -> VoiceService tries to cancel proximity updates -> tries to acquire attention lock The deadlock can be fixed by removing the acquiring attention lock step before reporting proximityUpdates to the clients. Bug: 261143716 Test: atest CtsAttentionServiceDeviceTestCases Change-Id: I9f7d520cbcfd57032a9476853acad025fd7a6b95 --- .../com/android/server/attention/AttentionManagerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/attention/AttentionManagerService.java b/services/core/java/com/android/server/attention/AttentionManagerService.java index d4ef638d08181..658e38b969ee0 100644 --- a/services/core/java/com/android/server/attention/AttentionManagerService.java +++ b/services/core/java/com/android/server/attention/AttentionManagerService.java @@ -668,8 +668,8 @@ public class AttentionManagerService extends SystemService { mIProximityUpdateCallback = new IProximityUpdateCallback.Stub() { @Override public void onProximityUpdate(double distance) { + mCallbackInternal.onProximityUpdate(distance); synchronized (mLock) { - mCallbackInternal.onProximityUpdate(distance); freeIfInactiveLocked(); } }