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() {