Recycle after return to avoid returning an invalid value.
Also add some main thread assertions.
Change-Id: Id6314d6e92d530ce57a01902b5570381fa20044d
diff --git a/src/com/android/documentsui/ThumbnailCache.java b/src/com/android/documentsui/ThumbnailCache.java
index 53f5092..ee2f168 100644
--- a/src/com/android/documentsui/ThumbnailCache.java
+++ b/src/com/android/documentsui/ThumbnailCache.java
@@ -22,6 +22,7 @@
import android.graphics.Bitmap;
import android.graphics.Point;
import android.net.Uri;
+import android.os.Looper;
import android.util.LruCache;
import android.util.Pair;
import android.util.Pools;
@@ -195,6 +196,9 @@
private static Result obtain(@Status int status, @Nullable Bitmap thumbnail,
@Nullable Point size, long lastModified) {
+ // Make sure this method is only called from main thread.
+ assert(Looper.myLooper() == Looper.getMainLooper());
+
Result instance = sPool.acquire();
instance = (instance != null ? instance : new Result());
@@ -209,6 +213,9 @@
private Result() {}
public void recycle() {
+ // Make sure this method is only called from main thread.
+ assert(Looper.myLooper() == Looper.getMainLooper());
+
mStatus = -1;
mThumbnail = null;
mSize = null;