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

Commit 69c66253 authored by John Reck's avatar John Reck
Browse files

Native crash -> ISE

Do some basic validation of the Bitmap given to
BitmapShader to avoid a subsequent native crash
in favor of a proper IllegalStateException

Fixes: 274860420
Test: BitmapShaderTest#testRecycledBitmapThrowsISE
Change-Id: I9ee64df5fc34909e5c91e979b1d21a4f94ca5e57
parent 9d1c9281
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -401,8 +401,9 @@ public final class Bitmap implements Parcelable {
    /**
     * This is called by methods that want to throw an exception if the bitmap
     * has already been recycled.
     * @hide
     */
    private void checkRecycled(String errorMessage) {
    void checkRecycled(String errorMessage) {
        if (mRecycled) {
            throw new IllegalStateException(errorMessage);
        }
+3 −0
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ public class BitmapShader extends Shader {
        if (bitmap == null) {
            throw new IllegalArgumentException("Bitmap must be non-null");
        }
        bitmap.checkRecycled("Cannot create BitmapShader for recycled bitmap");
        mBitmap = bitmap;
        mTileX = tileX;
        mTileY = tileY;
@@ -188,6 +189,8 @@ public class BitmapShader extends Shader {
    /** @hide */
    @Override
    protected long createNativeInstance(long nativeMatrix, boolean filterFromPaint) {
        mBitmap.checkRecycled("BitmapShader's bitmap has been recycled");

        boolean enableLinearFilter = mFilterMode == FILTER_MODE_LINEAR;
        if (mFilterMode == FILTER_MODE_DEFAULT) {
            mFilterFromPaint = filterFromPaint;