summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fan Wu <cechkahn@google.com> 2024-11-14 06:56:23 +0000
committer Fan Wu <cechkahn@google.com> 2024-11-14 09:04:37 +0000
commitb90b26cbd66597d9bb167cf490dff677286a91bd (patch)
tree9904773ef5ab278acb83d5ae34c25ba36f8e37ae
parentd44e0ba4134bc001826210c366a3bd2b4f2ededc (diff)
Make AppIconCacheManager instance volatile to prevent thread caching
issue Bug: 378525195 Test: atest Flag: EXEMPT bug fix Change-Id: I09c8eedfe05ef17affa910d6cfbc940bb4e29115
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/applications/AppIconCacheManager.java20
1 files changed, 14 insertions, 6 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/AppIconCacheManager.java b/packages/SettingsLib/src/com/android/settingslib/applications/AppIconCacheManager.java
index c0117b952beb..30ce13bf3b00 100644
--- a/packages/SettingsLib/src/com/android/settingslib/applications/AppIconCacheManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/applications/AppIconCacheManager.java
@@ -22,6 +22,7 @@ import android.os.UserHandle;
import android.util.Log;
import android.util.LruCache;
+import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
/**
@@ -33,7 +34,7 @@ public class AppIconCacheManager {
@VisibleForTesting
static final int MAX_CACHE_SIZE_IN_KB = getMaxCacheInKb();
private static final String DELIMITER = ":";
- private static AppIconCacheManager sAppIconCacheManager;
+ private static volatile AppIconCacheManager sAppIconCacheManager;
private final LruCache<String, Drawable> mDrawableCache;
private AppIconCacheManager() {
@@ -52,11 +53,18 @@ public class AppIconCacheManager {
/**
* Get an {@link AppIconCacheManager} instance.
*/
- public static synchronized AppIconCacheManager getInstance() {
- if (sAppIconCacheManager == null) {
- sAppIconCacheManager = new AppIconCacheManager();
+ public static @NonNull AppIconCacheManager getInstance() {
+ AppIconCacheManager result = sAppIconCacheManager;
+ if (result == null) {
+ synchronized (AppIconCacheManager.class) {
+ result = sAppIconCacheManager;
+ if (result == null) {
+ result = new AppIconCacheManager();
+ sAppIconCacheManager = result;
+ }
+ }
}
- return sAppIconCacheManager;
+ return result;
}
/**
@@ -118,7 +126,7 @@ public class AppIconCacheManager {
*
* @see android.content.ComponentCallbacks2#onTrimMemory(int)
*/
- public void trimMemory(int level) {
+ public static void trimMemory(int level) {
if (level >= android.content.ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) {
// Time to clear everything
if (sAppIconCacheManager != null) {