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

Commit ce298705 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Make sure Bitmap for PiP overlay being recycled

- In this change

Add a last resort as to recycle the bitmap being used in
PipAppIconOverlay. Currently, we rely on the creator of
PipAppIconOverlay to call detach and that practice is not strictedly
followed in both Launcher and PiP1 implementation.

- What's next

We will evaluate if a proper fix is worthwhile in PiP1 and meanwhile,
make sure PiP2 implementation does the recycle properly.

Flag: EXEMPT bugfix
Bug: 393584443
Test: Enter PiP with app icon overlay, make sure bitmap is recycled
Change-Id: Ie8981bd1e52f53bfe010aa5c9bd3ff6f69f30c33
parent 0c5555eb
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -169,6 +169,8 @@ public abstract class PipContentOverlay {
        // The maximum size for app icon in pixel.
        private static final int MAX_APP_ICON_SIZE_DP = 72;

        private static final long RECYCLE_BITMAP_TIMEOUT_MILLIS = 2_000;

        private final Context mContext;
        private final int mAppIconSizePx;
        /**
@@ -231,6 +233,12 @@ public abstract class PipContentOverlay {
            tx.setAlpha(mLeash, 0f);
            tx.reparent(mLeash, parentLeash);
            tx.apply();

            // Recycle the mBitmap as a last resort.
            if (mContext.getMainThreadHandler() != null) {
                mContext.getMainThreadHandler().postDelayed(
                        this::safeRecycle, RECYCLE_BITMAP_TIMEOUT_MILLIS);
            }
        }

        @Override
@@ -256,6 +264,10 @@ public abstract class PipContentOverlay {
        @Override
        public void detach(SurfaceControl.Transaction tx) {
            super.detach(tx);
            safeRecycle();
        }

        private void safeRecycle() {
            if (mBitmap != null && !mBitmap.isRecycled()) {
                mBitmap.recycle();
            }