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

Commit 5f358680 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Handle NPE in LocalImageResolver to avoid crashing systemui" into...

Merge "Handle NPE in LocalImageResolver to avoid crashing systemui" into rvc-qpr-dev am: 6bf25fdf am: 8517455d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12421224

Change-Id: I42f1a691785b5476e3f8957440c80656e8c54e8a
parents 25f8bcad 8517455d
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Log;

import java.io.IOException;
import java.io.InputStream;
@@ -31,6 +32,7 @@ import java.io.InputStream;
 * A class to extract Bitmaps from a MessagingStyle message.
 */
public class LocalImageResolver {
    private static final String TAG = LocalImageResolver.class.getSimpleName();

    private static final int MAX_SAFE_ICON_SIZE_PX = 480;

@@ -60,11 +62,18 @@ public class LocalImageResolver {

    private static BitmapFactory.Options getBoundsOptionsForImage(Uri uri, Context context)
            throws IOException {
        InputStream input = context.getContentResolver().openInputStream(uri);
        BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
        try (InputStream input = context.getContentResolver().openInputStream(uri)) {
            if (input == null) {
                throw new IllegalArgumentException();
            }
            onlyBoundsOptions.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(input, null, onlyBoundsOptions);
        input.close();
        } catch (IllegalArgumentException iae) {
            onlyBoundsOptions.outWidth = -1;
            onlyBoundsOptions.outHeight = -1;
            Log.e(TAG, "error loading image", iae);
        }
        return onlyBoundsOptions;
    }