diff options
Diffstat (limited to 'packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java')
-rw-r--r-- | packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java b/packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java index ecde685d29c4..639d4fb4feb3 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java +++ b/packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java @@ -111,6 +111,13 @@ public class ThumbnailCache { return Result.obtainMiss(); } + /** + * Puts a thumbnail for the given uri and size in to the cache. + * @param uri the uri of the thumbnail + * @param size the size of the thumbnail + * @param thumbnail the thumbnail to put in cache + * @param lastModified last modified value of the thumbnail to track its validity + */ public void putThumbnail(Uri uri, Point size, Bitmap thumbnail, long lastModified) { Pair<Uri, Point> cacheKey = Pair.create(uri, size); @@ -130,14 +137,33 @@ public class ThumbnailCache { } } + /** + * Removes all thumbnail cache associated to the given uri. + * @param uri the uri which thumbnail cache to remove + */ + public void removeUri(Uri uri) { + TreeMap<Point, Pair<Uri, Point>> sizeMap; + synchronized (mSizeIndex) { + sizeMap = mSizeIndex.get(uri); + } + + if (sizeMap != null) { + // Create an array to hold all values to avoid ConcurrentModificationException because + // removeKey() will be called by LruCache but we can't modify the map while we're + // iterating over the collection of values. + for (Pair<Uri, Point> index : sizeMap.values().toArray(new Pair[0])) { + mCache.remove(index); + } + } + } + private void removeKey(Uri uri, Point size) { TreeMap<Point, Pair<Uri, Point>> sizeMap; synchronized (mSizeIndex) { sizeMap = mSizeIndex.get(uri); } - // LruCache tells us to remove a key, which should exist, so sizeMap can't be null. - assert (sizeMap != null); + assert(sizeMap != null); synchronized (sizeMap) { sizeMap.remove(size); } |