Loading android/app/src/com/android/bluetooth/audio_util/helpers/Image.java +2 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 { Loading android/app/tests/unit/src/com/android/bluetooth/audio_util/ImageTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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; } Loading Loading @@ -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 */ Loading Loading
android/app/src/com/android/bluetooth/audio_util/helpers/Image.java +2 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 { Loading
android/app/tests/unit/src/com/android/bluetooth/audio_util/ImageTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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; } Loading Loading @@ -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 */ Loading