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

Commit 911851b9 authored by Hyunyoung Song's avatar Hyunyoung Song
Browse files

Fix isProjected and setAlpha method inside AdaptiveIconDrawable

Test: atest AdaptiveIconDrawableTest (in coretests and cts)
Bug: 119755247
Bug: 118503770

Some contexts regarding why setAlpha was misbehaving before and after
setBounds: mPaint object which is used to setAlpha was shared between
mLayerBitmpa and mMaskBitmap. When bounds changed, mMaskBitmap alpha was
never properly refreshed. To fix this issue AND to optimize memory
footprint, the drawable no longer make use of the mMaskBitmap object.

CtsGraphicsTestCases (21 Tests)
------------------------------
[1/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testInflateNull: PASSED (1ms)
[2/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testSetVisible: PASSED (1ms)
[3/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testDraw: PASSED (1ms)
[4/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testGetOpacity: PASSED (0ms)
[5/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testGetForegroundBackground: PASSED (25ms)
[6/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testGetConstantState: PASSED (0ms)
[7/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testIsStateful: PASSED (0ms)
[8/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testDrawNull: PASSED (1ms)
[9/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testDrawWithoutSetBounds: PASSED (0ms)
[10/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testGetIntrinsicHeight: PASSED (25ms)
[11/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testScheduleDrawable: PASSED (1ms)
[12/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testGetIntrinsicWidth: PASSED (1ms)
[13/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testSetColorFilter: PASSED (1ms)
[14/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testInflate: PASSED (1ms)
[15/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testMutate: PASSED (1ms)
[16/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testGetChangingConfigurations: PASSED (1ms)
[17/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testInvalidateDrawable: PASSED (0ms)
[18/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testUnscheduleDrawable: PASSED (25ms)
[19/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testConstructor: PASSED (0ms)
[20/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testSetAlpha: PASSED (0ms)
[21/21] android.graphics.drawable.cts.AdaptiveIconDrawableTest#testDrawSetBounds: PASSED (478ms)

Summary
-------
CtsGraphicsTestCases: Passed: 21, Failed: 0

FrameworksCoreTests (6 Tests)
----------------------------
[1/6] android.graphics.drawable.AdaptiveIconDrawableTest#testDraw_withBounds: PASSED (454ms)
[2/6] android.graphics.drawable.AdaptiveIconDrawableTest#testDraw_withoutBounds: PASSED (0ms)
[3/6] android.graphics.drawable.AdaptiveIconDrawableTest#testGetIconMaskAfterSetBounds: PASSED (1ms)
[4/6] android.graphics.drawable.AdaptiveIconDrawableTest#testGetIconMask_withoutBounds: PASSED (1ms)
[5/6] android.graphics.drawable.AdaptiveIconDrawableTest#testGetOutline_withBounds: PASSED (0ms)
[6/6] android.graphics.drawable.AdaptiveIconDrawableTest#testSetAlpha: PASSED (0ms)

Summary
-------
FrameworksCoreTests: Passed: 6, Failed: 0

Change-Id: Ie52019f14159e06b957760cb33118cb74f58415e
parent 3389e5b5
Loading
Loading
Loading
Loading
+15 −19
Original line number Diff line number Diff line
@@ -108,11 +108,10 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback
     * Scaled mask based on the view bounds.
     */
    private final Path mMask;
    private final Path mMaskScaleOnly;
    private final Matrix mMaskMatrix;
    private final Region mTransparentRegion;

    private Bitmap mMaskBitmap;

    /**
     * Indices used to access {@link #mLayerState.mChildDrawable} array for foreground and
     * background layer.
@@ -156,8 +155,8 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback
            sMask = PathParser.createPathFromPathData(
                Resources.getSystem().getString(R.string.config_icon_mask));
        }
        mMask = PathParser.createPathFromPathData(
            Resources.getSystem().getString(R.string.config_icon_mask));
        mMask = new Path(sMask);
        mMaskScaleOnly = new Path(mMask);
        mMaskMatrix = new Matrix();
        mCanvas = new Canvas();
        mTransparentRegion = new Region();
@@ -329,24 +328,19 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback
    }

    private void updateMaskBoundsInternal(Rect b) {
        // reset everything that depends on the view bounds
        mMaskMatrix.setScale(b.width() / MASK_SIZE, b.height() / MASK_SIZE);
        sMask.transform(mMaskMatrix, mMaskScaleOnly);

        mMaskMatrix.postTranslate(b.left, b.top);
        sMask.transform(mMaskMatrix, mMask);

        if (mMaskBitmap == null || mMaskBitmap.getWidth() != b.width() ||
            mMaskBitmap.getHeight() != b.height()) {
            mMaskBitmap = Bitmap.createBitmap(b.width(), b.height(), Bitmap.Config.ALPHA_8);
        if (mLayersBitmap == null || mLayersBitmap.getWidth() != b.width()
                || mLayersBitmap.getHeight() != b.height()) {
            mLayersBitmap = Bitmap.createBitmap(b.width(), b.height(), Bitmap.Config.ARGB_8888);
        }
        // mMaskBitmap bound [0, w] x [0, h]
        mCanvas.setBitmap(mMaskBitmap);
        mPaint.setShader(null);
        mCanvas.drawPath(mMask, mPaint);

        // mMask bound [left, top, right, bottom]
        mMaskMatrix.postTranslate(b.left, b.top);
        mMask.reset();
        sMask.transform(mMaskMatrix, mMask);
        // reset everything that depends on the view bounds
        mPaint.setShader(null);
        mTransparentRegion.setEmpty();
        mLayersShader = null;
    }
@@ -371,9 +365,11 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback
            mLayersShader = new BitmapShader(mLayersBitmap, TileMode.CLAMP, TileMode.CLAMP);
            mPaint.setShader(mLayersShader);
        }
        if (mMaskBitmap != null) {
        if (mMaskScaleOnly != null) {
            Rect bounds = getBounds();
            canvas.drawBitmap(mMaskBitmap, bounds.left, bounds.top, mPaint);
            canvas.translate(bounds.left, bounds.top);
            canvas.drawPath(mMaskScaleOnly, mPaint);
            canvas.translate(-bounds.left, -bounds.top);
        }
    }

@@ -549,7 +545,7 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback

        final ChildDrawable[] layers = mLayerState.mChildren;
        for (int i = 0; i < mLayerState.N_CHILDREN; i++) {
            if (layers[i].mDrawable.isProjected()) {
            if (layers[i].mDrawable != null && layers[i].mDrawable.isProjected()) {
                return true;
            }
        }