From 4a2d4ddf6ede7c5ccee353a4e0ada63a8cfd51dc Mon Sep 17 00:00:00 2001 From: Nate Myren Date: Fri, 13 Nov 2020 13:55:14 -0800 Subject: [PATCH] Fix potential deadlock in shutdown in HistoricalRegistry Ensure that the memory lock is released before calling persistPendingHistory in HistoricalRegistry. Bug: 172776374 Test: none Change-Id: I909de9f83cd43c695d0db99f82252ce36a0b972b (cherry picked from commit 42387ceaedd6d6d53706e799486161db7fffcce5) --- .../java/com/android/server/appop/HistoricalRegistry.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/appop/HistoricalRegistry.java b/services/core/java/com/android/server/appop/HistoricalRegistry.java index 3d22a156b91c6..f49b5dca2b086 100644 --- a/services/core/java/com/android/server/appop/HistoricalRegistry.java +++ b/services/core/java/com/android/server/appop/HistoricalRegistry.java @@ -669,10 +669,12 @@ final class HistoricalRegistry { void shutdown() { synchronized (mInMemoryLock) { - if (mMode != AppOpsManager.HISTORICAL_MODE_DISABLED) { - persistPendingHistory(); + if (mMode == AppOpsManager.HISTORICAL_MODE_DISABLED) { + return; } } + // Do not call persistPendingHistory inside the memory lock, due to possible deadlock + persistPendingHistory(); } void persistPendingHistory() {