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

Commit 884a4caf authored by Jay Shrauner's avatar Jay Shrauner
Browse files

Fix NPE in decodedBitmapDrawable

Check for whether bitmap was successfully decoded from byte array.

Bug:18508529
Change-Id: If5c1bb3f0b726be5891d5b33d8bc7073cf40b108
parent 5e5ce873
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -97,9 +97,10 @@ public class ImageViewDrawableSetter {
            return previousBitmap();
        }

        final Drawable newDrawable = (compressed == null)
                ? defaultDrawable()
                : decodedBitmapDrawable(compressed);
        Drawable newDrawable = decodedBitmapDrawable(compressed);
        if (newDrawable == null) {
            newDrawable = defaultDrawable();
        }

        // Remember this for next time, so that we can check if it changed.
        mCompressed = compressed;
@@ -159,8 +160,14 @@ public class ImageViewDrawableSetter {
    }

    private BitmapDrawable decodedBitmapDrawable(byte[] compressed) {
        if (compressed == null) {
            return null;
        }
        final Resources rsrc = mTarget.getResources();
        Bitmap bitmap = BitmapFactory.decodeByteArray(compressed, 0, compressed.length);
        if (bitmap == null) {
            return null;
        }
        if (bitmap.getHeight() != bitmap.getWidth()) {
            // Crop the bitmap into a square.
            final int size = Math.min(bitmap.getWidth(), bitmap.getHeight());