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

Commit 9b0594af authored by Etienne Ruffieux's avatar Etienne Ruffieux Committed by Gerrit Code Review
Browse files

Merge "Disable URI images for CoverArt, modify corresponding tests"

parents 31fcf4ce d5576aef
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -56,13 +56,19 @@ public class Image {
    public Image(Context context, MediaMetadata metadata) {
        mContext = context;

        String uri_art = metadata.getString(MediaMetadata.METADATA_KEY_ART_URI);
        String uri_album_art = metadata.getString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI);
        String uri_icon = metadata.getString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI);
        String uri_art = null;
        String uri_album_art = null;
        String uri_icon = null;
        Bitmap bmp_art = metadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
        Bitmap bmp_album_art = metadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
        Bitmap bmp_icon = metadata.getBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON);

        if (mContext != null && Util.areUriImagesSupported(mContext)) {
            uri_art = metadata.getString(MediaMetadata.METADATA_KEY_ART_URI);
            uri_album_art = metadata.getString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI);
            uri_icon = metadata.getString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI);
        }

        if (bmp_art != null) {
            setImage(bmp_art);
        } else if (bmp_album_art != null) {
@@ -84,13 +90,19 @@ public class Image {
    public Image(Context context, Bundle bundle) {
        mContext = context;

        String uri_art = bundle.getString(MediaMetadata.METADATA_KEY_ART_URI);
        String uri_album_art = bundle.getString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI);
        String uri_icon = bundle.getString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI);
        String uri_art = null;
        String uri_album_art = null;
        String uri_icon = null;
        Bitmap bmp_art = bundle.getParcelable(MediaMetadata.METADATA_KEY_ART);
        Bitmap bmp_album_art = bundle.getParcelable(MediaMetadata.METADATA_KEY_ALBUM_ART);
        Bitmap bmp_icon = bundle.getParcelable(MediaMetadata.METADATA_KEY_DISPLAY_ICON);

        if (mContext != null && Util.areUriImagesSupported(mContext)) {
            uri_art = bundle.getString(MediaMetadata.METADATA_KEY_ART_URI);
            uri_album_art = bundle.getString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI);
            uri_icon = bundle.getString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI);
        }

        if (bmp_art != null) {
            setImage(bmp_art);
        } else if (bmp_album_art != null) {
+100 −0
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ import android.test.mock.MockContentResolver;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.R;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -52,6 +54,7 @@ public class ImageTest {
    private Context mTargetContext;

    private @Mock Context mMockContext;
    private @Mock Resources mMockResources;
    private Resources mTestResources;
    private MockContentResolver mTestContentResolver;

@@ -104,6 +107,8 @@ public class ImageTest {
        });

        when(mMockContext.getContentResolver()).thenReturn(mTestContentResolver);
        when(mMockContext.getResources()).thenReturn(mMockResources);
        when(mMockResources.getBoolean(R.bool.avrcp_target_cover_art_uri_images)).thenReturn(true);
    }

    @After
@@ -269,6 +274,55 @@ public class ImageTest {
        assertThat(artwork.getImageHandle()).isNull();
    }

    /**
     * Make sure no image is set when you create an Image from a MediaMetadata object that contains
     * cover artwork as an Art Uri and Bluetooth is not configured to support URI images.
     */
    @Test
    public void testCreateImageFromMediaMetadataWithArtUriDisabled() {
        when(mMockResources.getBoolean(R.bool.avrcp_target_cover_art_uri_images))
                .thenReturn(false);
        MediaMetadata metadata =
                getMediaMetadataWithUri(MediaMetadata.METADATA_KEY_ART_URI, IMAGE_STRING_1);
        Image artwork = new Image(mMockContext, metadata);
        assertThat(artwork.getImage()).isNull();
        assertThat(artwork.getSource()).isEqualTo(Image.SOURCE_NONE);
        assertThat(artwork.getImageHandle()).isNull();
    }

    /**
     * Make sure no image is set when you create an Image from a MediaMetadata object that contains
     * cover artwork as an Album Art Uri and Bluetooth is not configured to support URI images.
     */
    @Test
    public void testCreateImageFromMediaMetadataWithAlbumArtUriDisabled() {
        when(mMockResources.getBoolean(R.bool.avrcp_target_cover_art_uri_images))
                .thenReturn(false);
        MediaMetadata metadata =
                getMediaMetadataWithUri(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, IMAGE_STRING_1);
        Image artwork = new Image(mMockContext, metadata);
        assertThat(artwork.getImage()).isNull();
        assertThat(artwork.getSource()).isEqualTo(Image.SOURCE_NONE);
        assertThat(artwork.getImageHandle()).isNull();
    }

    /**
     * Make sure no image is set when you create an Image from a MediaMetadata object that contains
     * cover artwork as a Display Icon Uri and Bluetooth is not configured to support URI images.
     */
    @Test
    public void testCreateImageFromMediaMetadataWithDisplayIconUriDisabled() {
        when(mMockResources.getBoolean(R.bool.avrcp_target_cover_art_uri_images))
                .thenReturn(false);
        MediaMetadata metadata =
                getMediaMetadataWithUri(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI,
                        IMAGE_STRING_1);
        Image artwork = new Image(mMockContext, metadata);
        assertThat(artwork.getImage()).isNull();
        assertThat(artwork.getSource()).isEqualTo(Image.SOURCE_NONE);
        assertThat(artwork.getImageHandle()).isNull();
    }

    /**
     * Make sure you can create an Image from a MediaMetadata object that contains no cover artwork
     */
@@ -397,6 +451,52 @@ public class ImageTest {
        assertThat(artwork.getImageHandle()).isNull();
    }

    /**
     * Make sure no image is set when you create an Image from a Bundle that contains cover artwork
     * as an Art Uri and Bluetooth is not configured to support URI images.
     */
    @Test
    public void testCreateImageFromBundleWithArtUriDisabled() {
        when(mMockResources.getBoolean(R.bool.avrcp_target_cover_art_uri_images))
                .thenReturn(false);
        Bundle bundle = getBundleWithUri(MediaMetadata.METADATA_KEY_ART_URI, IMAGE_STRING_1);
        Image artwork = new Image(mMockContext, bundle);
        assertThat(artwork.getImage()).isNull();
        assertThat(artwork.getSource()).isEqualTo(Image.SOURCE_NONE);
        assertThat(artwork.getImageHandle()).isNull();
    }

    /**
     * Make sure no image is set when you create an Image from a Bundle that contains cover artwork
     * as an Album Art Uri and Bluetooth is not configured to support URI images.
     */
    @Test
    public void testCreateImageFromBundleWithAlbumArtUriDisabled() {
        when(mMockResources.getBoolean(R.bool.avrcp_target_cover_art_uri_images))
                .thenReturn(false);
        Bundle bundle = getBundleWithUri(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, IMAGE_STRING_1);
        Image artwork = new Image(mMockContext, bundle);
        assertThat(artwork.getImage()).isNull();
        assertThat(artwork.getSource()).isEqualTo(Image.SOURCE_NONE);
        assertThat(artwork.getImageHandle()).isNull();
    }

    /**
     * Make sure no image is set when you create an Image from a Bundle that contains cover artwork
     * as a Display Icon Uri and Bluetooth is not configured to support URI images.
     */
    @Test
    public void testCreateImageFromBundleWithDisplayIconUriDisabled() {
        when(mMockResources.getBoolean(R.bool.avrcp_target_cover_art_uri_images))
                .thenReturn(false);
        Bundle bundle =
                getBundleWithUri(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, IMAGE_STRING_1);
        Image artwork = new Image(mMockContext, bundle);
        assertThat(artwork.getImage()).isNull();
        assertThat(artwork.getSource()).isEqualTo(Image.SOURCE_NONE);
        assertThat(artwork.getImageHandle()).isNull();
    }

    /**
     * Make sure you can create an Image from a Bundle that contains no cover artwork
     */