Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b90b26cb authored by Fan Wu's avatar Fan Wu
Browse files

Make AppIconCacheManager instance volatile to prevent thread caching

issue

Bug: 378525195
Test: atest
Flag: EXEMPT bug fix
Change-Id: I09c8eedfe05ef17affa910d6cfbc940bb4e29115
parent d44e0ba4
Loading
Loading
Loading
Loading
+14 −6
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.UserHandle;
import android.util.Log;
import android.util.Log;
import android.util.LruCache;
import android.util.LruCache;


import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.VisibleForTesting;


/**
/**
@@ -33,7 +34,7 @@ public class AppIconCacheManager {
    @VisibleForTesting
    @VisibleForTesting
    static final int MAX_CACHE_SIZE_IN_KB = getMaxCacheInKb();
    static final int MAX_CACHE_SIZE_IN_KB = getMaxCacheInKb();
    private static final String DELIMITER = ":";
    private static final String DELIMITER = ":";
    private static AppIconCacheManager sAppIconCacheManager;
    private static volatile AppIconCacheManager sAppIconCacheManager;
    private final LruCache<String, Drawable> mDrawableCache;
    private final LruCache<String, Drawable> mDrawableCache;


    private AppIconCacheManager() {
    private AppIconCacheManager() {
@@ -52,11 +53,18 @@ public class AppIconCacheManager {
    /**
    /**
     * Get an {@link AppIconCacheManager} instance.
     * Get an {@link AppIconCacheManager} instance.
     */
     */
    public static synchronized AppIconCacheManager getInstance() {
    public static @NonNull AppIconCacheManager getInstance() {
        if (sAppIconCacheManager == null) {
        AppIconCacheManager result = sAppIconCacheManager;
            sAppIconCacheManager = new AppIconCacheManager();
        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)
     * @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) {
        if (level >= android.content.ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) {
            // Time to clear everything
            // Time to clear everything
            if (sAppIconCacheManager != null) {
            if (sAppIconCacheManager != null) {