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

Commit 4579fbb4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Broaden exception criteria for failed image URI resolution" am: ca52c5d3

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1573373

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I423411434ac4891d8452e101fd9e295aa5bcbd6a
parents a43f22ee ca52c5d3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

@@ -189,7 +188,8 @@ public class Image {
            if (mContext == null) return null;
            input = mContext.getContentResolver().openInputStream(uri);
            art = BitmapFactory.decodeStream(input);
        } catch (FileNotFoundException e) {
        } catch (Exception e) {
            Log.w("Failed to fetch image at uri=" + uri, e);
            art = null;
        }
        try {
+19 −0
Original line number Diff line number Diff line
@@ -67,6 +67,11 @@ public class ImageTest {
            .build();
    private static final String IMAGE_STRING_1 = IMAGE_URI_1.toString();

    private static final String IMAGE_HANDLE_SECURITY_ERROR = "sec_error";
    private static final Uri IMAGE_URI_SECURITY_ERROR = TEST_CONTENT_URI.buildUpon()
            .appendQueryParameter("handle", IMAGE_HANDLE_SECURITY_ERROR)
            .build();

    private Bitmap mTestBitmap = null;

    @Before
@@ -91,6 +96,8 @@ public class ImageTest {
                if (IMAGE_URI_1.equals(url)) {
                    return mTestResources.openRawResourceFd(
                            com.android.bluetooth.tests.R.raw.image_200_200);
                } else if (IMAGE_URI_SECURITY_ERROR.equals(url)) {
                    throw new SecurityException();
                }
                return null;
            }
@@ -443,6 +450,18 @@ public class ImageTest {
        assertThat(artwork.getImageHandle()).isEqualTo(IMAGE_HANDLE_1);
    }

    /**
     * Make sure image URI resolution with erroneous resources doesn't crash and results in a null
     * image.
     */
    @Test
    public void testLoadImageFromUriWithSecurityException() {
        Image artwork = new Image(mMockContext, IMAGE_URI_SECURITY_ERROR);
        assertThat(artwork.getImageHandle()).isNull();
        assertThat(artwork.getSource()).isEqualTo(Image.SOURCE_NONE);
        assertThat(artwork.getImage()).isNull();
    }

    /**
     * Make sure you can get a string representation of this Image
     */