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

Commit a1b96b5d authored by Winson's avatar Winson
Browse files

Ensuring that we evict ActivityInfos from the cache.

- Once the data that we depend on the ActivityInfos for are evicted, 
  also remove them from the cache so that they are not stale the next
  time we might want to use them.

Bug: 27495264
Change-Id: I615842df4f48deb12a051ef241991a51a10cf383
parent a6516017
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -268,6 +268,14 @@ public class RecentsTaskLoader {
    BitmapDrawable mDefaultIcon;
    Bitmap mDefaultThumbnail;

    private TaskKeyLruCache.EvictionCallback mClearActivityInfoOnEviction =
            new TaskKeyLruCache.EvictionCallback() {
        @Override
        public void onEntryEvicted(Task.TaskKey key) {
            mActivityInfoCache.remove(key.getComponent());
        }
    };

    public RecentsTaskLoader(Context context) {
        Resources res = context.getResources();
        mDefaultTaskBarBackgroundColor =
@@ -292,10 +300,11 @@ public class RecentsTaskLoader {
        // Initialize the proxy, cache and loaders
        int numRecentTasks = ActivityManager.getMaxRecentTasksStatic();
        mLoadQueue = new TaskResourceLoadQueue();
        mIconCache = new TaskKeyLruCache<>(iconCacheSize);
        mIconCache = new TaskKeyLruCache<>(iconCacheSize, mClearActivityInfoOnEviction);
        mThumbnailCache = new TaskKeyLruCache<>(thumbnailCacheSize);
        mActivityLabelCache = new TaskKeyLruCache<>(numRecentTasks);
        mContentDescriptionCache = new TaskKeyLruCache<>(numRecentTasks);
        mActivityLabelCache = new TaskKeyLruCache<>(numRecentTasks, mClearActivityInfoOnEviction);
        mContentDescriptionCache = new TaskKeyLruCache<>(numRecentTasks,
                mClearActivityInfoOnEviction);
        mActivityInfoCache = new LruCache(numRecentTasks);
        mLoader = new BackgroundTaskLoader(mLoadQueue, mIconCache, mThumbnailCache,
                mDefaultThumbnail, mDefaultIcon);
@@ -375,7 +384,6 @@ public class RecentsTaskLoader {
        mIconCache.remove(t.key);
        mActivityLabelCache.remove(t.key);
        mContentDescriptionCache.remove(t.key);
        mActivityInfoCache.remove(t.key.getComponent());
        if (notifyTaskDataUnloaded) {
            t.notifyTaskDataUnloaded(null, mDefaultIcon);
        }
+15 −1
Original line number Diff line number Diff line
@@ -30,16 +30,29 @@ import android.util.SparseArray;
 */
public class TaskKeyLruCache<V> {

    public interface EvictionCallback {
        public void onEntryEvicted(Task.TaskKey key);
    }

    private static final String TAG = "TaskKeyLruCache";

    private final SparseArray<Task.TaskKey> mKeys = new SparseArray<>();
    private final LruCache<Integer, V> mCache;
    private final EvictionCallback mEvictionCallback;

    public TaskKeyLruCache(int cacheSize) {
        this(cacheSize, null);
    }

    public TaskKeyLruCache(int cacheSize, EvictionCallback evictionCallback) {
        mEvictionCallback = evictionCallback;
        mCache = new LruCache<Integer, V>(cacheSize) {

            @Override
            protected void entryRemoved(boolean evicted, Integer taskId, V oldV, V newV) {
                if (mEvictionCallback != null) {
                    mEvictionCallback.onEntryEvicted(mKeys.get(taskId));
                }
                mKeys.remove(taskId);
            }
        };
@@ -84,8 +97,9 @@ public class TaskKeyLruCache<V> {

    /** Removes a cache entry for a specific key. */
    final void remove(Task.TaskKey key) {
        mKeys.remove(key.id);
        // Remove the key after the cache value because we need it to make the callback
        mCache.remove(key.id);
        mKeys.remove(key.id);
    }

    /** Removes all the entries in the cache. */