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

Commit 9d3e5eec authored by Weilin Xu's avatar Weilin Xu
Browse files

Add tuner session and conversion utils unit tests

Added missing unit tests for tuner session and methods related to
HAL result conversion, radio metadata, vendor key/value parameters
and related contents in broadcast radio service.

Bug: 282031772
Test: atest BroadcastRadioTests
Flag: TEST_ONLY
Change-Id: I88353fe91eb253c31eecd6be311cccfea021f13a
parent 39a325f4
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -112,13 +112,21 @@ final class AidlTestUtils {
            android.hardware.broadcastradio.ProgramSelector hwSel,
            ProgramIdentifier logicallyTunedTo, ProgramIdentifier physicallyTunedTo,
            int hwSignalQuality) {
        return makeHalProgramInfo(hwSel, logicallyTunedTo, physicallyTunedTo, hwSignalQuality,
                new ProgramIdentifier[]{}, new Metadata[]{});
    }

    static ProgramInfo makeHalProgramInfo(
            android.hardware.broadcastradio.ProgramSelector hwSel,
            ProgramIdentifier logicallyTunedTo, ProgramIdentifier physicallyTunedTo,
            int hwSignalQuality, ProgramIdentifier[] relatedContent, Metadata[] metadata) {
        ProgramInfo hwInfo = new ProgramInfo();
        hwInfo.selector = hwSel;
        hwInfo.logicallyTunedTo = logicallyTunedTo;
        hwInfo.physicallyTunedTo = physicallyTunedTo;
        hwInfo.signalQuality = hwSignalQuality;
        hwInfo.relatedContent = new ProgramIdentifier[]{};
        hwInfo.metadata = new Metadata[]{};
        hwInfo.relatedContent = relatedContent;
        hwInfo.metadata = metadata;
        return hwInfo;
    }

+213 −8
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.hardware.radio.RadioMetadata;
import android.hardware.radio.UniqueProgramIdentifier;
import android.os.ServiceSpecificException;
import android.platform.test.flag.junit.SetFlagsRule;
import android.util.ArrayMap;
import android.util.ArraySet;

import com.android.dx.mockito.inline.extended.StaticMockitoSessionBuilder;
@@ -54,6 +55,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.mockito.stubbing.Answer;

import java.util.List;
import java.util.Map;
import java.util.Set;

@@ -86,6 +88,7 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {

    private static final int TEST_SIGNAL_QUALITY = 1;
    private static final long TEST_DAB_DMB_SID_EXT_VALUE = 0xA000000111L;
    private static final long TEST_DAB_SID_EXT_LEGACY_VALUE = 0xA00111L;
    private static final long TEST_DAB_ENSEMBLE_VALUE = 0x1001;
    private static final long TEST_DAB_FREQUENCY_VALUE = 220_352;
    private static final long TEST_FM_FREQUENCY_VALUE = 92_100;
@@ -103,6 +106,9 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
    private static final ProgramSelector.Identifier TEST_DAB_SID_EXT_ID =
            new ProgramSelector.Identifier(
                    ProgramSelector.IDENTIFIER_TYPE_DAB_DMB_SID_EXT, TEST_DAB_DMB_SID_EXT_VALUE);
    private static final ProgramSelector.Identifier TEST_DAB_SID_EXT_LEGACY_ID =
            new ProgramSelector.Identifier(
                    ProgramSelector.IDENTIFIER_TYPE_DAB_SID_EXT, TEST_DAB_SID_EXT_LEGACY_VALUE);
    private static final ProgramSelector.Identifier TEST_DAB_ENSEMBLE_ID =
            new ProgramSelector.Identifier(
                    ProgramSelector.IDENTIFIER_TYPE_DAB_ENSEMBLE, TEST_DAB_ENSEMBLE_VALUE);
@@ -125,6 +131,10 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
            ProgramSelector.PROGRAM_TYPE_DAB, TEST_DAB_SID_EXT_ID,
            new ProgramSelector.Identifier[]{TEST_DAB_FREQUENCY_ID, TEST_DAB_ENSEMBLE_ID},
            /* vendorIds= */ null);
    private static final ProgramSelector TEST_DAB_SELECTOR_LEGACY = new ProgramSelector(
            ProgramSelector.PROGRAM_TYPE_DAB, TEST_DAB_SID_EXT_LEGACY_ID,
            new ProgramSelector.Identifier[]{TEST_DAB_FREQUENCY_ID, TEST_DAB_ENSEMBLE_ID},
            /* vendorIds= */ null);
    private static final ProgramSelector TEST_FM_SELECTOR =
            AidlTestUtils.makeFmSelector(TEST_FM_FREQUENCY_VALUE);

@@ -132,6 +142,9 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
            new ProgramSelector.Identifier(ProgramSelector.IDENTIFIER_TYPE_HD_STATION_ID_EXT,
                    TEST_HD_STATION_ID_EXT_VALUE);

    private static final ProgramIdentifier TEST_HAL_HD_STATION_EXT_ID =
            AidlTestUtils.makeHalIdentifier(IdentifierType.HD_STATION_ID_EXT,
                    TEST_HD_STATION_ID_EXT_VALUE);
    private static final ProgramIdentifier TEST_HAL_HD_STATION_LOCATION_ID =
            AidlTestUtils.makeHalIdentifier(IdentifierType.HD_STATION_LOCATION,
                    TEST_HD_LOCATION_VALUE);
@@ -220,6 +233,27 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
                .hasMessageThat().contains("tune: CANCELED");
    }

    @Test
    public void throwOnError_withInvalidArgumentException() {
        ServiceSpecificException halException = new ServiceSpecificException(
                Result.INVALID_ARGUMENTS);

        RuntimeException thrown = ConversionUtils.throwOnError(halException, "tune");

        expect.withMessage("Exception thrown for invalid argument error")
                .that(thrown).hasMessageThat().contains("tune: INVALID_ARGUMENTS");
    }

    @Test
    public void throwOnError_withTimeoutException() {
        ServiceSpecificException halException = new ServiceSpecificException(Result.TIMEOUT);

        RuntimeException thrown = ConversionUtils.throwOnError(halException, "seek");

        expect.withMessage("Exception thrown for timeout error")
                .that(thrown).hasMessageThat().contains("seek: TIMEOUT");
    }

    @Test
    public void propertiesFromHalProperties_idsMatch() {
        expect.withMessage("Properties id")
@@ -300,7 +334,7 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
    @Test
    public void propertiesFromHalProperties_withoutAmFmAndDabConfigs() {
        RadioManager.ModuleProperties properties = createModuleProperties(/* amFmConfig= */ null,
                new DabTableEntry[]{});
                /* dabTableEntries= */ null);

        expect.withMessage("Empty AM/FM config")
                .that(properties.getBands()).asList().isEmpty();
@@ -498,6 +532,22 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
                .that(programInfo.getSignalStrength()).isEqualTo(TEST_SIGNAL_QUALITY);
    }

    @Test
    public void programInfoFromHalProgramInfo_withRelatedContent() {
        android.hardware.broadcastradio.ProgramSelector halDabSelector =
                AidlTestUtils.makeHalSelector(TEST_HAL_DAB_SID_EXT_ID, new ProgramIdentifier[]{
                        TEST_HAL_DAB_ENSEMBLE_ID, TEST_HAL_DAB_FREQUENCY_ID});
        ProgramInfo halProgramInfo = AidlTestUtils.makeHalProgramInfo(halDabSelector,
                TEST_HAL_DAB_SID_EXT_ID, TEST_HAL_DAB_FREQUENCY_ID, TEST_SIGNAL_QUALITY,
                new ProgramIdentifier[]{TEST_HAL_HD_STATION_EXT_ID}, new Metadata[]{});

        RadioManager.ProgramInfo programInfo =
                ConversionUtils.programInfoFromHalProgramInfo(halProgramInfo);

        expect.withMessage("Related content of converted program info")
                .that(programInfo.getRelatedContent()).containsExactly(TEST_HD_STATION_EXT_ID);
    }

    @Test
    public void programInfoFromHalProgramInfo_withInvalidDabProgramInfo() {
        android.hardware.broadcastradio.ProgramSelector invalidHalDabSelector =
@@ -557,6 +607,29 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
                        T_APP_UID)).isFalse();
    }

    @Test
    public void programInfoMeetsSdkVersionRequirement_withLowerVersionIdForLogicallyTunedTo() {
        RadioManager.ProgramInfo dabProgramInfo = AidlTestUtils.makeProgramInfo(
                TEST_DAB_SELECTOR_LEGACY, TEST_DAB_SID_EXT_ID, TEST_DAB_FREQUENCY_ID,
                TEST_SIGNAL_QUALITY);

        expect.withMessage("Program info %s with logically tuned to ID not of required SDK version",
                        dabProgramInfo).that(ConversionUtils.programInfoMeetsSdkVersionRequirement(
                                dabProgramInfo, T_APP_UID)).isFalse();
    }

    @Test
    public void programInfoMeetsSdkVersionRequirement_withLowerVersionIdForRelatedContent() {
        RadioManager.ProgramInfo dabProgramInfo = new RadioManager.ProgramInfo(
                TEST_DAB_SELECTOR_LEGACY, TEST_DAB_SID_EXT_ID, TEST_DAB_FREQUENCY_ID,
                List.of(TEST_DAB_SID_EXT_ID), /* infoFlags= */ 0, TEST_SIGNAL_QUALITY,
                new RadioMetadata.Builder().build(), new ArrayMap<>());

        expect.withMessage("Program info %s with related content not of required SDK version",
                dabProgramInfo).that(ConversionUtils.programInfoMeetsSdkVersionRequirement(
                dabProgramInfo, T_APP_UID)).isFalse();
    }

    @Test
    public void programInfoMeetsSdkVersionRequirement_withRequiredVersionId_returnsTrue() {
        RadioManager.ProgramInfo fmProgramInfo = AidlTestUtils.makeProgramInfo(TEST_FM_SELECTOR,
@@ -675,20 +748,122 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
    }

    @Test
    public void radioMetadataFromHalMetadata_withFlagEnabled() {
        mSetFlagsRule.enableFlags(Flags.FLAG_HD_RADIO_IMPROVED);

    public void radioMetadataFromHalMetadata() {
        int rdsPtyValue = 3;
        int rbdsPtyValue = 4;
        String rdsRtValue = "rdsRtTest";
        String songAlbumValue = "songAlbumTest";
        String programNameValue = "programNameTest";
        RadioMetadata convertedMetadata = ConversionUtils.radioMetadataFromHalMetadata(
                new Metadata[]{TEST_HAL_SONG_TITLE, TEST_HAL_HD_SUBCHANNELS, TEST_HAL_ALBUM_ART});
                new Metadata[]{TEST_HAL_SONG_TITLE, TEST_HAL_ALBUM_ART,
                        Metadata.rdsPty(rdsPtyValue), Metadata.rbdsPty(rbdsPtyValue),
                        Metadata.rdsRt(rdsRtValue), Metadata.songAlbum(songAlbumValue),
                        Metadata.programName(programNameValue)});

        expect.withMessage("Metadata with flag enabled").that(convertedMetadata.size())
                .isEqualTo(3);
        expect.withMessage("Song title with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_TITLE))
                .isEqualTo(TEST_SONG_TITLE);
        expect.withMessage("Album art with flag enabled")
                .that(convertedMetadata.getInt(RadioMetadata.METADATA_KEY_ART))
                .isEqualTo(TEST_ALBUM_ART);
        expect.withMessage("RDS PTY with flag enabled")
                .that(convertedMetadata.getInt(RadioMetadata.METADATA_KEY_RDS_PTY))
                .isEqualTo(rdsPtyValue);
        expect.withMessage("RBDS PTY with flag enabled")
                .that(convertedMetadata.getInt(RadioMetadata.METADATA_KEY_RBDS_PTY))
                .isEqualTo(rbdsPtyValue);
        expect.withMessage("RDS RT with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_RDS_RT))
                .isEqualTo(rdsRtValue);
        expect.withMessage("Album with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_ALBUM))
                .isEqualTo(songAlbumValue);
        expect.withMessage("Program name with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_PROGRAM_NAME))
                .isEqualTo(programNameValue);
    }

    @Test
    public void radioMetadataFromHalMetadata_withDabMetadata() {
        String dabEnsembleNameValue = "dabEnsembleNameTest";
        String dabEnsembleNameShortValue = "dabEnsembleNameShortTest";
        String dabServiceNameValue = "dabServiceNameTest";
        String dabServiceNameShortValue = "dabServiceNameShortTest";
        String dabComponentNameValue = "dabComponentNameTest";
        String dabComponentNameShortValue = "dabComponentNameShortTest";
        RadioMetadata convertedMetadata = ConversionUtils.radioMetadataFromHalMetadata(
                new Metadata[]{Metadata.dabEnsembleName(dabEnsembleNameValue),
                        Metadata.dabEnsembleNameShort(dabEnsembleNameShortValue),
                        Metadata.dabServiceName(dabServiceNameValue),
                        Metadata.dabServiceNameShort(dabServiceNameShortValue),
                        Metadata.dabComponentName(dabComponentNameValue),
                        Metadata.dabComponentNameShort(dabComponentNameShortValue)});

        expect.withMessage("DAB Ensemble name with flag enabled")
                .that(convertedMetadata.getString(
                        RadioMetadata.METADATA_KEY_DAB_ENSEMBLE_NAME))
                .isEqualTo(dabEnsembleNameValue);
        expect.withMessage("DAB Ensemble short name with flag enabled")
                .that(convertedMetadata.getString(
                        RadioMetadata.METADATA_KEY_DAB_ENSEMBLE_NAME_SHORT))
                .isEqualTo(dabEnsembleNameShortValue);
        expect.withMessage("DAB service service name with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_DAB_SERVICE_NAME))
                .isEqualTo(dabServiceNameValue);
        expect.withMessage("DAB service service short name with flag enabled")
                .that(convertedMetadata.getString(
                        RadioMetadata.METADATA_KEY_DAB_SERVICE_NAME_SHORT))
                .isEqualTo(dabServiceNameShortValue);
        expect.withMessage("DAB component name with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_DAB_COMPONENT_NAME))
                .isEqualTo(dabComponentNameValue);
        expect.withMessage("DAB component short name with flag enabled")
                .that(convertedMetadata.getString(
                        RadioMetadata.METADATA_KEY_DAB_COMPONENT_NAME_SHORT))
                .isEqualTo(dabComponentNameShortValue);
    }

    @Test
    public void radioMetadataFromHalMetadata_withHdMedatadataAndFlagEnabled() {
        mSetFlagsRule.enableFlags(Flags.FLAG_HD_RADIO_IMPROVED);
        String genreValue = "genreTest";
        String commentShortDescriptionValue = "commentShortDescriptionTest";
        String commentActualTextValue = "commentActualTextTest";
        String commercialValue = "commercialTest";
        List<String> ufidsValue = List.of("ufids1Test", "ufids2Test");
        String hdStationNameShortValue = "hdStationNameShortTest";
        String hdStationNameLongValue = "hdStationNameLongTest";
        RadioMetadata convertedMetadata = ConversionUtils.radioMetadataFromHalMetadata(
                new Metadata[]{TEST_HAL_HD_SUBCHANNELS, Metadata.genre(genreValue),
                        Metadata.commentShortDescription(commentShortDescriptionValue),
                        Metadata.commentActualText(commentActualTextValue),
                        Metadata.commercial(commercialValue),
                        Metadata.ufids(ufidsValue.toArray(new String[0])),
                        Metadata.hdStationNameShort(hdStationNameShortValue),
                        Metadata.hdStationNameLong(hdStationNameLongValue)});

        expect.withMessage("Genre with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_GENRE))
                .isEqualTo(genreValue);
        expect.withMessage("Short description of comment with flag enabled")
                .that(convertedMetadata.getString(
                        RadioMetadata.METADATA_KEY_COMMENT_SHORT_DESCRIPTION))
                .isEqualTo(commentShortDescriptionValue);
        expect.withMessage("Actual text of comment with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_COMMENT_ACTUAL_TEXT))
                .isEqualTo(commentActualTextValue);
        expect.withMessage("Commercial with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_COMMERCIAL))
                .isEqualTo(commercialValue);
        expect.withMessage("UFIDs with flag enabled")
                .that(convertedMetadata.getStringArray(RadioMetadata.METADATA_KEY_UFIDS)).asList()
                .containsExactlyElementsIn(ufidsValue);
        expect.withMessage("HD station short name with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_HD_STATION_NAME_SHORT))
                .isEqualTo(hdStationNameShortValue);
        expect.withMessage("HD station long name with flag enabled")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_HD_STATION_NAME_LONG))
                .isEqualTo(hdStationNameLongValue);
        expect.withMessage("HD sub-channels with flag enabled")
                .that(convertedMetadata.getInt(RadioMetadata
                        .METADATA_KEY_HD_SUBCHANNELS_AVAILABLE)).isEqualTo(TEST_HD_SUBCHANNELS);
@@ -742,6 +917,35 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
                        ConversionUtils.identifierToHalProgramIdentifier(TEST_DAB_SID_EXT_ID));
    }

    @Test
    public void vendorInfoToHalVendorKeyValues_withNull() {
        expect.withMessage("Null vendor info converted to HAL")
                .that(ConversionUtils.vendorInfoToHalVendorKeyValues(/* info= */ null)).asList()
                .isEmpty();
    }

    @Test
    public void vendorInfoToHalVendorKeyValues_withNullValue() {
        Map<String, String> vendorInfo = new ArrayMap<>();
        vendorInfo.put(VENDOR_INFO_KEY_1, null);

        expect.withMessage("Vendor info with null value converted to HAL")
                .that(ConversionUtils.vendorInfoToHalVendorKeyValues(vendorInfo)).asList()
                .isEmpty();
    }

    @Test
    public void vendorInfoFromHalVendorKeyValues_withNullElements() {
        VendorKeyValue halVendorInfo = new VendorKeyValue();
        halVendorInfo.key = null;
        halVendorInfo.value = VENDOR_INFO_VALUE_1;
        VendorKeyValue[] halVendorInfoArray = new VendorKeyValue[]{halVendorInfo};

        expect.withMessage("Null vendor info converted from HAL")
                .that(ConversionUtils.vendorInfoFromHalVendorKeyValues(halVendorInfoArray))
                .isEmpty();
    }

    private static RadioManager.ModuleProperties createModuleProperties() {
        AmFmRegionConfig amFmConfig = createAmFmRegionConfig();
        DabTableEntry[] dabTableEntries = new DabTableEntry[]{
@@ -785,7 +989,8 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
    private static Properties createHalProperties() {
        Properties halProperties = new Properties();
        halProperties.supportedIdentifierTypes = new int[]{IdentifierType.AMFM_FREQUENCY_KHZ,
                IdentifierType.RDS_PI, IdentifierType.DAB_SID_EXT};
                IdentifierType.RDS_PI, IdentifierType.DAB_SID_EXT, IdentifierType.HD_STATION_ID_EXT,
                IdentifierType.DRMO_SERVICE_ID};
        halProperties.maker = TEST_MAKER;
        halProperties.product = TEST_PRODUCT;
        halProperties.version = TEST_VERSION;
+14 −0
Original line number Diff line number Diff line
@@ -307,6 +307,20 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {
                .that(mTunerSessions[0].isClosed()).isTrue();
    }

    @Test
    public void close_forMultipleTimes() throws Exception {
        openAidlClients(/* numClients= */ 1);
        int errorCode = RadioTuner.ERROR_SERVER_DIED;
        mTunerSessions[0].close(errorCode);
        verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onError(errorCode);

        mTunerSessions[0].close(errorCode);

        verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onError(errorCode);
        expect.withMessage("Close state of broadcast radio service session for multiple times")
                .that(mTunerSessions[0].isClosed()).isTrue();
    }

    @Test
    public void closeSessions_withMultipleSessions_withError() throws Exception {
        int numSessions = 3;
+88 −1
Original line number Diff line number Diff line
@@ -16,14 +16,23 @@

package com.android.server.broadcastradio.hal2;

import static org.junit.Assert.assertThrows;

import android.hardware.broadcastradio.V2_0.AmFmBandRange;
import android.hardware.broadcastradio.V2_0.AmFmRegionConfig;
import android.hardware.broadcastradio.V2_0.DabTableEntry;
import android.hardware.broadcastradio.V2_0.IdentifierType;
import android.hardware.broadcastradio.V2_0.Metadata;
import android.hardware.broadcastradio.V2_0.MetadataKey;
import android.hardware.broadcastradio.V2_0.ProgramInfo;
import android.hardware.broadcastradio.V2_0.Properties;
import android.hardware.broadcastradio.V2_0.Result;
import android.hardware.broadcastradio.V2_0.VendorKeyValue;
import android.hardware.radio.Announcement;
import android.hardware.radio.ProgramSelector;
import android.hardware.radio.RadioManager;
import android.hardware.radio.RadioMetadata;
import android.util.ArrayMap;

import com.google.common.truth.Expect;

@@ -70,6 +79,15 @@ public final class ConvertTest {
    @Rule
    public final Expect expect = Expect.create();

    @Test
    public void throwOnError() {
        IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () ->
                Convert.throwOnError("tune", Result.INVALID_ARGUMENTS));

        expect.withMessage("Exception for illegeal argument").that(thrown)
                .hasMessageThat().contains("INVALID_ARGUMENTS");
    }

    @Test
    public void propertiesFromHalProperties_idsMatch() {
        expect.withMessage("Properties id")
@@ -198,6 +216,60 @@ public final class ConvertTest {
                .that(Utils.getBand(/* freq= */ 110000)).isEqualTo(FrequencyBand.UNKNOWN);
    }

    @Test
    public void vendorInfoToHal_withNull() {
        expect.withMessage("Null vendor info converted to HAL")
                .that(Convert.vendorInfoToHal(/* info= */ null)).isEmpty();
    }

    @Test
    public void vendorInfoToHal_withNullValue() {
        Map<String, String> vendorInfo = new ArrayMap<>();
        vendorInfo.put(VENDOR_INFO_KEY_1, null);

        expect.withMessage("Vendor info with null value converted to HAL")
                .that(Convert.vendorInfoToHal(vendorInfo)).isEmpty();
    }

    @Test
    public void vendorInfoFromHalVendorKeyValues_withNullElements() {
        VendorKeyValue halVendorInfo = new VendorKeyValue();
        halVendorInfo.key = null;
        halVendorInfo.value = "VendorValue";
        List<VendorKeyValue> halVendorInfoArray = List.of(halVendorInfo);

        expect.withMessage("Null vendor info converted from HAL")
                .that(Convert.vendorInfoFromHal(halVendorInfoArray)).isEmpty();
    }

    @Test
    public void programInfoFromHal_withMetadata() {
        int freq = 97900;
        int signalQuality = 90;
        String songTitle = "titleTest";
        int albumArt = 1;
        android.hardware.broadcastradio.V2_0.ProgramSelector halSelector =
                TestUtils.makeHalFmSelector(freq);
        ArrayList<Metadata> metadata = new ArrayList<>(List.of(
                createIntMetadata(MetadataKey.ALBUM_ART, albumArt),
                createStringMetadata(MetadataKey.SONG_TITLE, songTitle),
                createStringMetadata(/* key= */ 1000, "valueForInvalidMetadataType")));
        ProgramInfo halInfo = TestUtils.makeHalProgramInfo(halSelector, signalQuality,
                /* relatedContent= */ new ArrayList<>(), metadata);

        RadioManager.ProgramInfo info = Convert.programInfoFromHal(halInfo);

        RadioMetadata convertedMetadata = info.getMetadata();
        expect.withMessage("Metadata converted from HAL")
                .that(convertedMetadata.size()).isEqualTo(2);
        expect.withMessage("Song title")
                .that(convertedMetadata.getString(RadioMetadata.METADATA_KEY_TITLE))
                .isEqualTo(songTitle);
        expect.withMessage("Album art")
                .that(convertedMetadata.getInt(RadioMetadata.METADATA_KEY_ART))
                .isEqualTo(albumArt);
    }

    private static RadioManager.ModuleProperties convertToModuleProperties() {
        AmFmRegionConfig amFmConfig = createAmFmRegionConfig();
        List<DabTableEntry> dabTableEntries = Arrays.asList(
@@ -241,7 +313,8 @@ public final class ConvertTest {
    private static Properties createHalProperties() {
        Properties halProperties = new Properties();
        halProperties.supportedIdentifierTypes = new ArrayList<Integer>(Arrays.asList(
                IdentifierType.AMFM_FREQUENCY, IdentifierType.RDS_PI, IdentifierType.DAB_SID_EXT));
                IdentifierType.AMFM_FREQUENCY, IdentifierType.RDS_PI, IdentifierType.DAB_SID_EXT,
                IdentifierType.HD_STATION_ID_EXT, IdentifierType.DRMO_SERVICE_ID));
        halProperties.maker = TEST_MAKER;
        halProperties.product = TEST_PRODUCT;
        halProperties.version = TEST_VERSION;
@@ -251,4 +324,18 @@ public final class ConvertTest {
                TestUtils.makeVendorKeyValue(VENDOR_INFO_KEY_2, VENDOR_INFO_VALUE_2)));
        return halProperties;
    }

    private Metadata createStringMetadata(int key, String value) {
        Metadata metadata = new Metadata();
        metadata.key = key;
        metadata.stringValue = value;
        return metadata;
    }

    private Metadata createIntMetadata(int key, int value) {
        Metadata metadata = new Metadata();
        metadata.key = key;
        metadata.intValue = value;
        return metadata;
    }
}
+11 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.server.broadcastradio.hal2;

import android.hardware.broadcastradio.V2_0.IdentifierType;
import android.hardware.broadcastradio.V2_0.Metadata;
import android.hardware.broadcastradio.V2_0.ProgramIdentifier;
import android.hardware.broadcastradio.V2_0.ProgramInfo;
import android.hardware.broadcastradio.V2_0.VendorKeyValue;
@@ -127,13 +128,21 @@ final class TestUtils {

    static ProgramInfo makeHalProgramInfo(
            android.hardware.broadcastradio.V2_0.ProgramSelector hwSel, int hwSignalQuality) {
        return makeHalProgramInfo(hwSel, hwSignalQuality, /* relatedContent= */ new ArrayList<>(),
                /* metadata= */ new ArrayList<>());
    }

    @SuppressWarnings("NonApiType")
    static ProgramInfo makeHalProgramInfo(
            android.hardware.broadcastradio.V2_0.ProgramSelector hwSel, int hwSignalQuality,
            ArrayList<ProgramIdentifier> relatedContent, ArrayList<Metadata> metadata) {
        ProgramInfo hwInfo = new ProgramInfo();
        hwInfo.selector = hwSel;
        hwInfo.logicallyTunedTo = hwSel.primaryId;
        hwInfo.physicallyTunedTo = hwSel.primaryId;
        hwInfo.signalQuality = hwSignalQuality;
        hwInfo.relatedContent = new ArrayList<>();
        hwInfo.metadata = new ArrayList<>();
        hwInfo.relatedContent = relatedContent;
        hwInfo.metadata = metadata;
        return hwInfo;
    }

Loading