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

Commit 49f1404c authored by Sal Savage's avatar Sal Savage Committed by Myles Watson
Browse files

Broaden exception criteria for failed image URI resolution

Tag: #stability
Fixes: 179179898
Test: atest BluetoothInstrumentationTests
Change-Id: Ibfada77c343bfe69954cc9c9fb2e9c34ec9730d6
parent 07f9aae1
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Bundle;
import android.util.Log;
import android.util.Log;


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


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


    @Before
    @Before
@@ -91,6 +96,8 @@ public class ImageTest {
                if (IMAGE_URI_1.equals(url)) {
                if (IMAGE_URI_1.equals(url)) {
                    return mTestResources.openRawResourceFd(
                    return mTestResources.openRawResourceFd(
                            com.android.bluetooth.tests.R.raw.image_200_200);
                            com.android.bluetooth.tests.R.raw.image_200_200);
                } else if (IMAGE_URI_SECURITY_ERROR.equals(url)) {
                    throw new SecurityException();
                }
                }
                return null;
                return null;
            }
            }
@@ -443,6 +450,18 @@ public class ImageTest {
        assertThat(artwork.getImageHandle()).isEqualTo(IMAGE_HANDLE_1);
        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
     * Make sure you can get a string representation of this Image
     */
     */