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

Commit ed717bcd authored by Hyunyoung Song's avatar Hyunyoung Song Committed by Android (Google) Code Review
Browse files

Merge "Fix last bit of WidgetTray jank issue b/21133230" into ub-launcher3-burnaby

parents 383c507c e98f4a4d
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -56,6 +56,8 @@ public class WidgetPreviewLoader {
    /**
     * Weak reference objects, do not prevent their referents from being made finalizable,
     * finalized, and then reclaimed.
     * Note: synchronized block used for this variable is expensive and the block should always
     * be posted to a background thread.
     */
    @Thunk Set<Bitmap> mUnusedBitmaps =
            Collections.newSetFromMap(new WeakHashMap<Bitmap, Boolean>());
@@ -555,11 +557,16 @@ public class WidgetPreviewLoader {
            // in the tasks's onCancelled() call, and if cancelled while the task is writing to
            // disk, it will be cancelled in the task's onPostExecute() call.
            if (mTask.mBitmapToRecycle != null) {
                mWorkerHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        synchronized (mUnusedBitmaps) {
                            mUnusedBitmaps.add(mTask.mBitmapToRecycle);
                        }
                        mTask.mBitmapToRecycle = null;
                    }
                });
            }
        }
    }

@@ -661,15 +668,20 @@ public class WidgetPreviewLoader {
        }

        @Override
        protected void onCancelled(Bitmap preview) {
        protected void onCancelled(final Bitmap preview) {
            // If we've cancelled while the task is running, then can return the bitmap to the
            // recycled set immediately. Otherwise, it will be recycled after the preview is written
            // to disk.
            if (preview != null) {
                mWorkerHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        synchronized (mUnusedBitmaps) {
                            mUnusedBitmaps.add(preview);
                        }
                    }
                });
            }
        }
    }