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

Commit 866858b8 authored by Garfield, Tan's avatar Garfield, Tan Committed by Garfield Tan
Browse files

Recycle after return to avoid returning an invalid value.

Also add some main thread assertions.

Change-Id: Id6314d6e92d530ce57a01902b5570381fa20044d
(cherry picked from commit 1a1b9148a2094b4365ff5e65372b1a1eb0282a0a)
parent e3c4e48b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.ComponentCallbacks2;
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 @@ public class ThumbnailCache {

        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 @@ public class ThumbnailCache {
        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;
+21 −17
Original line number Diff line number Diff line
@@ -258,11 +258,13 @@ public class IconHelper {
            ImageView iconThumb, ImageView iconMime) {
        final Result result = mThumbnailCache.getThumbnail(uri, mCurrentSize);

        try {
            final Bitmap cachedThumbnail = result.getThumbnail();
            iconThumb.setImageBitmap(cachedThumbnail);

            boolean stale = (docLastModified > result.getLastModified());
        if (DEBUG) Log.d(TAG, String.format("Load thumbnail for %s, got result %d and stale %b.",
            if (DEBUG) Log.d(TAG,
                    String.format("Load thumbnail for %s, got result %d and stale %b.",
                            uri.toString(), result.getStatus(), stale));
            if (!result.isExactHit() || stale) {
                final BiConsumer<View, View> animator =
@@ -274,9 +276,11 @@ public class IconHelper {

                ProviderExecutor.forAuthority(docAuthority).execute(task);
            }
        result.recycle();

            return result.isHit();
        } finally {
            result.recycle();
        }
    }

    private void setMimeIcon(ImageView view, Drawable icon) {