From 5971d8a0ce8eb4f4567bf9c326c6eacba83bbb64 Mon Sep 17 00:00:00 2001 From: "Su, Weihua" Date: Wed, 18 Jan 2017 14:35:13 +0800 Subject: [PATCH] Fix crash issue on Storage Manager app StorageManager app Start/Exit many times occur crash if there are over 100 unused app. Because ApplicationsState.BackgroundHandler will update AppEntry'Size during the ApplicationsState.MainHandler sort all AppEntry with SIZE_COMPARATOR. In this case, SIZE_COMPARATOR will occur "IllegalArgumentException Comparison method violates its general contract!". In ordre to fix the crash, add mEntriesMap synchronized during the AppEntry sort operation. Bug: 34800804 Change-Id: Ic670df01fadde648a79c0d01820efe772a898958 --- .../android/settingslib/applications/ApplicationsState.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java index f0ec107865075..a803e60e18206 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java @@ -649,7 +649,11 @@ public class ApplicationsState { } if (comparator != null) { - Collections.sort(filteredApps, comparator); + synchronized (mEntriesMap) { + // Locking to ensure that the background handler does not mutate + // the size of AppEntries used for ordering while sorting. + Collections.sort(filteredApps, comparator); + } } synchronized (mRebuildSync) {