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

Commit b46cbdac authored by wilsonshih's avatar wilsonshih
Browse files

Attemp to release bitmap resource for ImmobileIconDrawable

Which should remove the bitmap reference between splash screen window,
so the bitmap memory should be removed more quickly.

Bug: 336531014
Test: Check heap dump of bitmap memory usage.
Change-Id: Ide96349aaf09b3aab28e44663c77dcfb238d4db7
parent 4250dc6f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -56,6 +56,8 @@ import com.android.internal.R;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.policy.DecorView;

import java.io.Closeable;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.function.Consumer;
@@ -568,6 +570,12 @@ public final class SplashScreenView extends FrameLayout {
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        releaseAnimationSurfaceHost();
        if (mIconView instanceof ImageView imageView
                && imageView.getDrawable() instanceof Closeable closeableDrawable) {
            try {
                closeableDrawable.close();
            } catch (IOException ignore) { }
        }
    }

    @Override
+12 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.window.SplashScreenView;

import com.android.internal.R;

import java.io.Closeable;
import java.util.function.LongConsumer;

/**
@@ -100,7 +101,7 @@ public class SplashscreenIconDrawableFactory {
     * Drawable pre-drawing the scaled icon in a separate thread to increase the speed of the
     * final drawing.
     */
    private static class ImmobileIconDrawable extends Drawable {
    private static class ImmobileIconDrawable extends Drawable implements Closeable {
        private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG
                | Paint.FILTER_BITMAP_FLAG);
        private final Matrix mMatrix = new Matrix();
@@ -154,6 +155,16 @@ public class SplashscreenIconDrawableFactory {
        public int getOpacity() {
            return 1;
        }

        @Override
        public void close() {
            synchronized (mPaint) {
                if (mIconBitmap != null) {
                    mIconBitmap.recycle();
                    mIconBitmap = null;
                }
            }
        }
    }

    /**