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

Commit fa41f438 authored by Weilin Xu's avatar Weilin Xu
Browse files

Update unit tests for program cache with unique id

Updated unit tests for program list and program info caches for  AIDL
and HIDL broadcast radio service after unique program identifier is
used.

Bug: 273967346
Test: atest ProgramListTest com.android.server.broadcastradio.hal2
Change-Id: Ic40db07bd0ad7b14da412aa169a7c97a06e42a6f
parent 00f0fc4c
Loading
Loading
Loading
Loading
+113 −52
Original line number Diff line number Diff line
@@ -74,18 +74,45 @@ public final class ProgramListTest {
    private static final ProgramSelector.Identifier DAB_ENSEMBLE_IDENTIFIER =
            new ProgramSelector.Identifier(ProgramSelector.IDENTIFIER_TYPE_DAB_ENSEMBLE,
                    /* value= */ 0x1013);
    private static final ProgramSelector.Identifier DAB_FREQUENCY_IDENTIFIER_1 =
            new ProgramSelector.Identifier(ProgramSelector.IDENTIFIER_TYPE_DAB_FREQUENCY,
                    /* value= */ 222_064);
    private static final ProgramSelector.Identifier DAB_FREQUENCY_IDENTIFIER_2 =
            new ProgramSelector.Identifier(ProgramSelector.IDENTIFIER_TYPE_DAB_FREQUENCY,
                    /* value= */ 220_352);

    private static final ProgramSelector DAB_SELECTOR_1 = new ProgramSelector(
            ProgramSelector.PROGRAM_TYPE_DAB, DAB_DMB_SID_EXT_IDENTIFIER,
            new ProgramSelector.Identifier[]{DAB_ENSEMBLE_IDENTIFIER, DAB_FREQUENCY_IDENTIFIER_1},
            /* vendorIds= */ null);
    private static final ProgramSelector DAB_SELECTOR_2 = new ProgramSelector(
            ProgramSelector.PROGRAM_TYPE_DAB, DAB_DMB_SID_EXT_IDENTIFIER,
            new ProgramSelector.Identifier[]{DAB_ENSEMBLE_IDENTIFIER, DAB_FREQUENCY_IDENTIFIER_2},
            /* vendorIds= */ null);

    private static final UniqueProgramIdentifier RDS_UNIQUE_IDENTIFIER =
            new UniqueProgramIdentifier(RDS_IDENTIFIER);
    private static final UniqueProgramIdentifier DAB_UNIQUE_IDENTIFIER_1 =
            new UniqueProgramIdentifier(DAB_SELECTOR_1);
    private static final UniqueProgramIdentifier DAB_UNIQUE_IDENTIFIER_2 =
            new UniqueProgramIdentifier(DAB_SELECTOR_2);

    private static final RadioManager.ProgramInfo FM_PROGRAM_INFO = createFmProgramInfo(
            createProgramSelector(ProgramSelector.PROGRAM_TYPE_FM, FM_IDENTIFIER));
    private static final RadioManager.ProgramInfo RDS_PROGRAM_INFO = createFmProgramInfo(
            createProgramSelector(ProgramSelector.PROGRAM_TYPE_FM, RDS_IDENTIFIER));
    private static final RadioManager.ProgramInfo DAB_PROGRAM_INFO_1 = createDabProgramInfo(
            DAB_SELECTOR_1);
    private static final RadioManager.ProgramInfo DAB_PROGRAM_INFO_2 = createDabProgramInfo(
            DAB_SELECTOR_2);

    private static final Set<Integer> FILTER_IDENTIFIER_TYPES = Set.of(
            ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY, ProgramSelector.IDENTIFIER_TYPE_RDS_PI);
    private static final Set<ProgramSelector.Identifier> FILTER_IDENTIFIERS = Set.of(FM_IDENTIFIER);

    private static final ProgramList.Chunk FM_RDS_ADD_CHUNK = new ProgramList.Chunk(IS_PURGE,
            IS_COMPLETE, Set.of(FM_PROGRAM_INFO, RDS_PROGRAM_INFO),
            Set.of(DAB_DMB_SID_EXT_IDENTIFIER, DAB_ENSEMBLE_IDENTIFIER));
            ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY,
            ProgramSelector.IDENTIFIER_TYPE_DAB_DMB_SID_EXT);
    private static final Set<ProgramSelector.Identifier> FILTER_IDENTIFIERS = Set.of(
            FM_IDENTIFIER, DAB_DMB_SID_EXT_IDENTIFIER);

    private static final ProgramList.Chunk FM_DAB_ADD_CHUNK = new ProgramList.Chunk(IS_PURGE,
            IS_COMPLETE, Set.of(FM_PROGRAM_INFO, DAB_PROGRAM_INFO_1, DAB_PROGRAM_INFO_2),
            Set.of(RDS_UNIQUE_IDENTIFIER));
    private static final ProgramList.Chunk FM_ADD_INCOMPLETE_CHUNK = new ProgramList.Chunk(IS_PURGE,
            /* complete= */ false, Set.of(FM_PROGRAM_INFO), new ArraySet<>());
    private static final ProgramList.Filter TEST_FILTER = new ProgramList.Filter(
@@ -213,58 +240,44 @@ public final class ProgramListTest {

    @Test
    public void isPurge_forChunk() {
        ProgramList.Chunk chunk = new ProgramList.Chunk(IS_PURGE, IS_COMPLETE,
                Set.of(FM_PROGRAM_INFO, RDS_PROGRAM_INFO),
                Set.of(DAB_DMB_SID_EXT_IDENTIFIER, DAB_ENSEMBLE_IDENTIFIER));

        assertWithMessage("Puring chunk").that(chunk.isPurge()).isEqualTo(IS_PURGE);
        assertWithMessage("Puring chunk").that(FM_DAB_ADD_CHUNK.isPurge()).isEqualTo(IS_PURGE);
    }

    @Test
    public void isComplete_forChunk() {
        ProgramList.Chunk chunk = new ProgramList.Chunk(IS_PURGE, IS_COMPLETE,
                Set.of(FM_PROGRAM_INFO, RDS_PROGRAM_INFO),
                Set.of(DAB_DMB_SID_EXT_IDENTIFIER, DAB_ENSEMBLE_IDENTIFIER));

        assertWithMessage("Complete chunk").that(chunk.isComplete()).isEqualTo(IS_COMPLETE);
        assertWithMessage("Complete chunk").that(FM_DAB_ADD_CHUNK.isComplete())
                .isEqualTo(IS_COMPLETE);
    }

    @Test
    public void getModified_forChunk() {
        ProgramList.Chunk chunk = new ProgramList.Chunk(IS_PURGE, IS_COMPLETE,
                Set.of(FM_PROGRAM_INFO, RDS_PROGRAM_INFO),
                Set.of(DAB_DMB_SID_EXT_IDENTIFIER, DAB_ENSEMBLE_IDENTIFIER));

        assertWithMessage("Modified program info in chunk")
                .that(chunk.getModified()).containsExactly(FM_PROGRAM_INFO, RDS_PROGRAM_INFO);
                .that(FM_DAB_ADD_CHUNK.getModified())
                .containsExactly(FM_PROGRAM_INFO, DAB_PROGRAM_INFO_1, DAB_PROGRAM_INFO_2);
    }

    @Test
    public void getRemoved_forChunk() {
        ProgramList.Chunk chunk = new ProgramList.Chunk(IS_PURGE, IS_COMPLETE,
                Set.of(FM_PROGRAM_INFO, RDS_PROGRAM_INFO),
                Set.of(DAB_DMB_SID_EXT_IDENTIFIER, DAB_ENSEMBLE_IDENTIFIER));

        assertWithMessage("Removed program identifiers in chunk").that(chunk.getRemoved())
                .containsExactly(DAB_DMB_SID_EXT_IDENTIFIER, DAB_ENSEMBLE_IDENTIFIER);
        assertWithMessage("Removed program identifiers in chunk")
                .that(FM_DAB_ADD_CHUNK.getRemoved()).containsExactly(RDS_UNIQUE_IDENTIFIER);
    }

    @Test
    public void describeContents_forChunk() {
        assertWithMessage("Chunk contents").that(FM_RDS_ADD_CHUNK.describeContents()).isEqualTo(0);
        assertWithMessage("Chunk contents").that(FM_DAB_ADD_CHUNK.describeContents()).isEqualTo(0);
    }

    @Test
    public void writeToParcel_forChunk() {
        Parcel parcel = Parcel.obtain();

        FM_RDS_ADD_CHUNK.writeToParcel(parcel, /* flags= */ 0);
        FM_DAB_ADD_CHUNK.writeToParcel(parcel, /* flags= */ 0);
        parcel.setDataPosition(0);

        ProgramList.Chunk chunkFromParcel =
                ProgramList.Chunk.CREATOR.createFromParcel(parcel);
        assertWithMessage("Chunk created from parcel")
                .that(chunkFromParcel).isEqualTo(FM_RDS_ADD_CHUNK);
                .that(chunkFromParcel).isEqualTo(FM_DAB_ADD_CHUNK);
    }

    @Test
@@ -336,37 +349,78 @@ public final class ProgramListTest {
    }

    @Test
    public void onProgramListUpdated_withNewIdsAdded_invokesMockedCallbacks() throws Exception {
    public void onProgramListUpdated_withNewIdsAdded_invokesCallbacks() throws Exception {
        createRadioTuner();
        mProgramList = mRadioTuner.getDynamicProgramList(TEST_FILTER);
        registerListCallbacks(/* numCallbacks= */ 1);
        addOnCompleteListeners(/* numListeners= */ 1);

        mTunerCallback.onProgramListUpdated(FM_RDS_ADD_CHUNK);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);

        verify(mListCallbackMocks[0], CALLBACK_TIMEOUT).onItemChanged(FM_IDENTIFIER);
        verify(mListCallbackMocks[0], CALLBACK_TIMEOUT).onItemChanged(RDS_IDENTIFIER);
        verify(mListCallbackMocks[0], CALLBACK_TIMEOUT).onItemChanged(DAB_DMB_SID_EXT_IDENTIFIER);
        verify(mOnCompleteListenerMocks[0], CALLBACK_TIMEOUT).onComplete();
        assertWithMessage("Program info in program list after adding FM and RDS info")
                .that(mProgramList.toList()).containsExactly(FM_PROGRAM_INFO, RDS_PROGRAM_INFO);
        assertWithMessage("Program info in program list after adding FM and DAB info")
                .that(mProgramList.toList()).containsExactly(FM_PROGRAM_INFO, DAB_PROGRAM_INFO_1,
                        DAB_PROGRAM_INFO_2);
    }

    @Test
    public void onProgramListUpdated_withIdsRemoved_invokesMockedCallbacks() throws Exception {
    public void onProgramListUpdated_withFmIdsRemoved_invokesCallbacks() throws Exception {
        UniqueProgramIdentifier fmUniqueId = new UniqueProgramIdentifier(FM_IDENTIFIER);
        ProgramList.Chunk fmRemovedChunk = new ProgramList.Chunk(/* purge= */ false,
                /* complete= */ false, new ArraySet<>(), Set.of(FM_IDENTIFIER));
                /* complete= */ false, new ArraySet<>(), Set.of(fmUniqueId));
        createRadioTuner();
        mProgramList = mRadioTuner.getDynamicProgramList(TEST_FILTER);
        registerListCallbacks(/* numCallbacks= */ 1);
        mTunerCallback.onProgramListUpdated(FM_RDS_ADD_CHUNK);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);

        mTunerCallback.onProgramListUpdated(fmRemovedChunk);

        verify(mListCallbackMocks[0], CALLBACK_TIMEOUT).onItemRemoved(FM_IDENTIFIER);
        assertWithMessage("Program info in program list after removing FM id")
                .that(mProgramList.toList()).containsExactly(RDS_PROGRAM_INFO);
        assertWithMessage("Program info FM identifier")
                .that(mProgramList.get(RDS_IDENTIFIER)).isEqualTo(RDS_PROGRAM_INFO);
                .that(mProgramList.toList()).containsExactly(DAB_PROGRAM_INFO_1,
                        DAB_PROGRAM_INFO_2);
    }

    @Test
    public void onProgramListUpdated_withPartOfDabIdsRemoved_doesNotInvokeCallbacks()
            throws Exception {
        ProgramList.Chunk dabRemovedChunk1 = new ProgramList.Chunk(/* purge= */ false,
                /* complete= */ false, new ArraySet<>(), Set.of(DAB_UNIQUE_IDENTIFIER_1));
        createRadioTuner();
        mProgramList = mRadioTuner.getDynamicProgramList(TEST_FILTER);
        registerListCallbacks(/* numCallbacks= */ 1);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);

        mTunerCallback.onProgramListUpdated(dabRemovedChunk1);

        verify(mListCallbackMocks[0], after(TIMEOUT_MS).never()).onItemRemoved(
                DAB_DMB_SID_EXT_IDENTIFIER);
        assertWithMessage("Program info in program list after removing part of DAB ids")
                .that(mProgramList.toList()).containsExactly(FM_PROGRAM_INFO, DAB_PROGRAM_INFO_2);
    }

    @Test
    public void onProgramListUpdated_withAllDabIdsRemoved_invokesCallbacks()
            throws Exception {
        ProgramList.Chunk dabRemovedChunk1 = new ProgramList.Chunk(/* purge= */ false,
                /* complete= */ false, new ArraySet<>(), Set.of(DAB_UNIQUE_IDENTIFIER_1));
        ProgramList.Chunk dabRemovedChunk2 = new ProgramList.Chunk(/* purge= */ false,
                /* complete= */ false, new ArraySet<>(), Set.of(DAB_UNIQUE_IDENTIFIER_2));
        createRadioTuner();
        mProgramList = mRadioTuner.getDynamicProgramList(TEST_FILTER);
        registerListCallbacks(/* numCallbacks= */ 1);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);
        mTunerCallback.onProgramListUpdated(dabRemovedChunk1);
        verify(mListCallbackMocks[0], after(TIMEOUT_MS).never()).onItemRemoved(
                DAB_DMB_SID_EXT_IDENTIFIER);

        mTunerCallback.onProgramListUpdated(dabRemovedChunk2);

        verify(mListCallbackMocks[0], CALLBACK_TIMEOUT).onItemRemoved(DAB_DMB_SID_EXT_IDENTIFIER);
        assertWithMessage("Program info in program list after removing all DAB ids")
                .that(mProgramList.toList()).containsExactly(FM_PROGRAM_INFO);
    }

    @Test
@@ -388,18 +442,18 @@ public final class ProgramListTest {
        createRadioTuner();
        mProgramList = mRadioTuner.getDynamicProgramList(TEST_FILTER);
        registerListCallbacks(/* numCallbacks= */ 1);
        mTunerCallback.onProgramListUpdated(FM_RDS_ADD_CHUNK);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);

        mTunerCallback.onProgramListUpdated(purgeChunk);

        verify(mListCallbackMocks[0], CALLBACK_TIMEOUT).onItemRemoved(FM_IDENTIFIER);
        verify(mListCallbackMocks[0], CALLBACK_TIMEOUT).onItemRemoved(RDS_IDENTIFIER);
        verify(mListCallbackMocks[0], CALLBACK_TIMEOUT).onItemRemoved(DAB_DMB_SID_EXT_IDENTIFIER);
        assertWithMessage("Program list after purge chunk applied")
                .that(mProgramList.toList()).isEmpty();
    }

    @Test
    public void onProgramListUpdated_afterProgramListClosed_notInvokeMockedCallbacks()
    public void onProgramListUpdated_afterProgramListClosed_notInvokeCallbacks()
            throws Exception {
        createRadioTuner();
        mProgramList = mRadioTuner.getDynamicProgramList(TEST_FILTER);
@@ -407,7 +461,7 @@ public final class ProgramListTest {
        addOnCompleteListeners(/* numListeners= */ 1);
        mProgramList.close();

        mTunerCallback.onProgramListUpdated(FM_RDS_ADD_CHUNK);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);

        verify(mListCallbackMocks[0], after(TIMEOUT_MS).never()).onItemChanged(any());
        verify(mListCallbackMocks[0], never()).onItemChanged(any());
@@ -462,7 +516,7 @@ public final class ProgramListTest {
            throws Exception {
        createRadioTuner();
        mProgramList = mRadioTuner.getDynamicProgramList(TEST_FILTER);
        mTunerCallback.onProgramListUpdated(FM_RDS_ADD_CHUNK);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);

        mTunerCallback.onBackgroundScanComplete();

@@ -487,7 +541,7 @@ public final class ProgramListTest {
        mProgramList = mRadioTuner.getDynamicProgramList(TEST_FILTER);

        mTunerCallback.onBackgroundScanComplete();
        mTunerCallback.onProgramListUpdated(FM_RDS_ADD_CHUNK);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);

        verify(mTunerCallbackMock, CALLBACK_TIMEOUT).onBackgroundScanComplete();
    }
@@ -512,7 +566,7 @@ public final class ProgramListTest {
                mock(ProgramList.OnCompleteListener.class);

        mProgramList.addOnCompleteListener(mExecutor, onCompleteListenerMock);
        mTunerCallback.onProgramListUpdated(FM_RDS_ADD_CHUNK);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);

        verify(onCompleteListenerMock, CALLBACK_TIMEOUT).onComplete();
    }
@@ -524,7 +578,7 @@ public final class ProgramListTest {
        mProgramList = mRadioTuner.getDynamicProgramList(TEST_FILTER);
        addOnCompleteListeners(numListeners);

        mTunerCallback.onProgramListUpdated(FM_RDS_ADD_CHUNK);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);

        for (int index = 0; index < numListeners; index++) {
            verify(mOnCompleteListenerMocks[index], CALLBACK_TIMEOUT).onComplete();
@@ -538,7 +592,7 @@ public final class ProgramListTest {
        addOnCompleteListeners(/* numListeners= */ 1);

        mProgramList.removeOnCompleteListener(mOnCompleteListenerMocks[0]);
        mTunerCallback.onProgramListUpdated(FM_RDS_ADD_CHUNK);
        mTunerCallback.onProgramListUpdated(FM_DAB_ADD_CHUNK);

        verify(mOnCompleteListenerMocks[0], after(TIMEOUT_MS).never()).onComplete();
    }
@@ -566,6 +620,13 @@ public final class ProgramListTest {
                /* vendorInfo= */ null);
    }

    private static RadioManager.ProgramInfo createDabProgramInfo(ProgramSelector selector) {
        return new RadioManager.ProgramInfo(selector, selector.getPrimaryId(),
                DAB_ENSEMBLE_IDENTIFIER, /* relatedContents= */ null, /* infoFlags= */ 0,
                /* signalQuality= */ 1, new RadioMetadata.Builder().build(),
                /* vendorInfo= */ null);
    }

    private void createRadioTuner() throws Exception {
        mApplicationInfo.targetSdkVersion = TEST_TARGET_SDK_VERSION;
        when(mContextMock.getApplicationInfo()).thenReturn(mApplicationInfo);
+3 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.hardware.radio.ProgramList;
import android.hardware.radio.ProgramSelector;
import android.hardware.radio.RadioManager;
import android.hardware.radio.RadioMetadata;
import android.hardware.radio.UniqueProgramIdentifier;
import android.os.RemoteException;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -149,12 +150,12 @@ final class AidlTestUtils {

    static ProgramList.Chunk makeChunk(boolean purge, boolean complete,
            List<RadioManager.ProgramInfo> modified,
            List<ProgramSelector.Identifier> removed) throws RemoteException {
            List<UniqueProgramIdentifier> removed) throws RemoteException {
        ArraySet<RadioManager.ProgramInfo> modifiedSet = new ArraySet<>();
        if (modified != null) {
            modifiedSet.addAll(modified);
        }
        ArraySet<ProgramSelector.Identifier> removedSet = new ArraySet<>();
        ArraySet<UniqueProgramIdentifier> removedSet = new ArraySet<>();
        if (removed != null) {
            removedSet.addAll(removed);
        }
+10 −62
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.hardware.broadcastradio.DabTableEntry;
import android.hardware.broadcastradio.IdentifierType;
import android.hardware.broadcastradio.ProgramIdentifier;
import android.hardware.broadcastradio.ProgramInfo;
import android.hardware.broadcastradio.ProgramListChunk;
import android.hardware.broadcastradio.Properties;
import android.hardware.broadcastradio.Result;
import android.hardware.broadcastradio.VendorKeyValue;
@@ -33,6 +32,7 @@ import android.hardware.radio.Announcement;
import android.hardware.radio.ProgramList;
import android.hardware.radio.ProgramSelector;
import android.hardware.radio.RadioManager;
import android.hardware.radio.UniqueProgramIdentifier;
import android.os.ServiceSpecificException;

import com.android.dx.mockito.inline.extended.StaticMockitoSessionBuilder;
@@ -103,12 +103,6 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
    private static final ProgramIdentifier TEST_HAL_DAB_FREQUENCY_ID =
            AidlTestUtils.makeHalIdentifier(IdentifierType.DAB_FREQUENCY_KHZ,
                    TEST_DAB_FREQUENCY_VALUE);
    private static final ProgramIdentifier TEST_HAL_FM_FREQUENCY_ID =
            AidlTestUtils.makeHalIdentifier(IdentifierType.AMFM_FREQUENCY_KHZ,
                    TEST_FM_FREQUENCY_VALUE);
    private static final ProgramIdentifier TEST_HAL_VENDOR_ID =
            AidlTestUtils.makeHalIdentifier(IdentifierType.VENDOR_START,
                    TEST_VENDOR_ID_VALUE);

    private static final ProgramSelector TEST_DAB_SELECTOR = new ProgramSelector(
            ProgramSelector.PROGRAM_TYPE_DAB, TEST_DAB_SID_EXT_ID,
@@ -117,6 +111,12 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
    private static final ProgramSelector TEST_FM_SELECTOR =
            AidlTestUtils.makeFmSelector(TEST_FM_FREQUENCY_VALUE);

    private static final UniqueProgramIdentifier TEST_DAB_UNIQUE_ID = new UniqueProgramIdentifier(
            TEST_DAB_SELECTOR);

    private static final UniqueProgramIdentifier TEST_VENDOR_UNIQUE_ID =
            new UniqueProgramIdentifier(TEST_VENDOR_ID);

    private static final int TEST_ENABLED_TYPE = Announcement.TYPE_EMERGENCY;
    private static final int TEST_ANNOUNCEMENT_FREQUENCY = FM_LOWER_LIMIT + FM_SPACING;

@@ -325,57 +325,6 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
                .that(programInfo).isNull();
    }

    @Test
    public void chunkFromHalProgramListChunk_withValidChunk() {
        boolean purge = false;
        boolean complete = true;
        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 halDabInfo = AidlTestUtils.makeHalProgramInfo(halDabSelector,
                TEST_HAL_DAB_SID_EXT_ID, TEST_HAL_DAB_FREQUENCY_ID, TEST_SIGNAL_QUALITY);
        RadioManager.ProgramInfo dabInfo =
                ConversionUtils.programInfoFromHalProgramInfo(halDabInfo);
        ProgramListChunk halChunk = AidlTestUtils.makeHalChunk(purge, complete,
                new ProgramInfo[]{halDabInfo},
                new ProgramIdentifier[]{TEST_HAL_VENDOR_ID, TEST_HAL_FM_FREQUENCY_ID});

        ProgramList.Chunk chunk = ConversionUtils.chunkFromHalProgramListChunk(halChunk);

        expect.withMessage("Purged state of the converted valid program list chunk")
                .that(chunk.isPurge()).isEqualTo(purge);
        expect.withMessage("Completion state of the converted valid program list chunk")
                .that(chunk.isComplete()).isEqualTo(complete);
        expect.withMessage("Modified program info in the converted valid program list chunk")
                .that(chunk.getModified()).containsExactly(dabInfo);
        expect.withMessage("Removed program ides in the converted valid program list chunk")
                .that(chunk.getRemoved()).containsExactly(TEST_VENDOR_ID, TEST_FM_FREQUENCY_ID);
    }

    @Test
    public void chunkFromHalProgramListChunk_withInvalidModifiedProgramInfo() {
        boolean purge = true;
        boolean complete = false;
        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 halDabInfo = AidlTestUtils.makeHalProgramInfo(halDabSelector,
                TEST_HAL_DAB_SID_EXT_ID, TEST_HAL_DAB_ENSEMBLE_ID, TEST_SIGNAL_QUALITY);
        ProgramListChunk halChunk = AidlTestUtils.makeHalChunk(purge, complete,
                new ProgramInfo[]{halDabInfo}, new ProgramIdentifier[]{TEST_HAL_FM_FREQUENCY_ID});

        ProgramList.Chunk chunk = ConversionUtils.chunkFromHalProgramListChunk(halChunk);

        expect.withMessage("Purged state of the converted invalid program list chunk")
                .that(chunk.isPurge()).isEqualTo(purge);
        expect.withMessage("Completion state of the converted invalid program list chunk")
                .that(chunk.isComplete()).isEqualTo(complete);
        expect.withMessage("Modified program info in the converted invalid program list chunk")
                .that(chunk.getModified()).isEmpty();
        expect.withMessage("Removed program ids in the converted invalid program list chunk")
                .that(chunk.getRemoved()).containsExactly(TEST_FM_FREQUENCY_ID);
    }

    @Test
    public void programSelectorMeetsSdkVersionRequirement_withLowerVersionId_returnsFalse() {
        expect.withMessage("Selector %s without required SDK version", TEST_DAB_SELECTOR)
@@ -418,7 +367,7 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
                TEST_SIGNAL_QUALITY);
        ProgramList.Chunk chunk = new ProgramList.Chunk(/* purge= */ true,
                /* complete= */ true, Set.of(dabProgramInfo, fmProgramInfo),
                Set.of(TEST_DAB_SID_EXT_ID, TEST_DAB_ENSEMBLE_ID, TEST_VENDOR_ID));
                Set.of(TEST_DAB_UNIQUE_ID, TEST_VENDOR_UNIQUE_ID));

        ProgramList.Chunk convertedChunk = ConversionUtils.convertChunkToTargetSdkVersion(chunk,
                T_APP_UID);
@@ -434,8 +383,7 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
                .that(convertedChunk.getModified()).containsExactly(fmProgramInfo);
        expect.withMessage(
                "Removed program ids in the converted program list chunk with lower SDK version")
                .that(convertedChunk.getRemoved())
                .containsExactly(TEST_DAB_ENSEMBLE_ID, TEST_VENDOR_ID);
                .that(convertedChunk.getRemoved()).containsExactly(TEST_VENDOR_UNIQUE_ID);
    }

    @Test
@@ -446,7 +394,7 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
                TEST_SIGNAL_QUALITY);
        ProgramList.Chunk chunk = new ProgramList.Chunk(/* purge= */ true,
                /* complete= */ true, Set.of(dabProgramInfo, fmProgramInfo),
                Set.of(TEST_DAB_SID_EXT_ID, TEST_DAB_ENSEMBLE_ID, TEST_VENDOR_ID));
                Set.of(TEST_DAB_UNIQUE_ID, TEST_VENDOR_UNIQUE_ID));

        ProgramList.Chunk convertedChunk = ConversionUtils.convertChunkToTargetSdkVersion(chunk,
                U_APP_UID);
+43 −18

File changed.

Preview size limit exceeded, changes collapsed.

+10 −5
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.hardware.radio.ProgramList;
import android.hardware.radio.ProgramSelector;
import android.hardware.radio.RadioManager;
import android.hardware.radio.RadioTuner;
import android.hardware.radio.UniqueProgramIdentifier;
import android.os.Binder;
import android.os.ParcelableException;
import android.os.RemoteException;
@@ -98,6 +99,9 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {
            new ProgramSelector.Identifier(ProgramSelector.IDENTIFIER_TYPE_RDS_PI,
                    /* value= */ 15_019);

    private static final UniqueProgramIdentifier TEST_RDS_PI_UNIQUE_ID =
            new UniqueProgramIdentifier(TEST_RDS_PI_ID);

    private static final RadioManager.ProgramInfo TEST_FM_INFO = AidlTestUtils.makeProgramInfo(
            AidlTestUtils.makeProgramSelector(ProgramSelector.PROGRAM_TYPE_FM,
                    TEST_FM_FREQUENCY_ID), TEST_FM_FREQUENCY_ID, TEST_FM_FREQUENCY_ID,
@@ -704,9 +708,10 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {
                /* includeCategories= */ true, /* excludeModifications= */ false);
        ProgramFilter halFilter = ConversionUtils.filterToHalProgramFilter(filter);
        List<RadioManager.ProgramInfo> modified = List.of(TEST_FM_INFO, TEST_RDS_INFO);
        List<ProgramSelector.Identifier> removed = new ArrayList<>();
        List<ProgramSelector.Identifier> halRemoved = new ArrayList<>();
        List<UniqueProgramIdentifier> removed = new ArrayList<>();
        ProgramListChunk halProgramList = AidlTestUtils.makeHalChunk(/* purge= */ true,
                /* complete= */ true, modified, removed);
                /* complete= */ true, modified, halRemoved);
        ProgramList.Chunk expectedProgramList =
                AidlTestUtils.makeChunk(/* purge= */ true, /* complete= */ true, modified, removed);

@@ -735,7 +740,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {

        verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onProgramListUpdated(
                AidlTestUtils.makeChunk(/* purge= */ false, /* complete= */ true,
                        List.of(TEST_FM_INFO_MODIFIED), List.of(TEST_RDS_PI_ID)));
                        List.of(TEST_FM_INFO_MODIFIED), List.of(TEST_RDS_PI_UNIQUE_ID)));
    }

    @Test
@@ -753,7 +758,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {
                /* complete= */ true, List.of(TEST_FM_INFO_MODIFIED), List.of(TEST_RDS_PI_ID)));
        verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onProgramListUpdated(
                AidlTestUtils.makeChunk(/* purge= */ false, /* complete= */ true,
                        List.of(TEST_FM_INFO_MODIFIED), List.of(TEST_RDS_PI_ID)));
                        List.of(TEST_FM_INFO_MODIFIED), List.of(TEST_RDS_PI_UNIQUE_ID)));

        mTunerSessions[0].startProgramListUpdates(filter);

@@ -781,7 +786,7 @@ public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {

        verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onProgramListUpdated(
                AidlTestUtils.makeChunk(/* purge= */ false, /* complete= */ true,
                        List.of(TEST_FM_INFO_MODIFIED), List.of(TEST_RDS_PI_ID)));
                        List.of(TEST_FM_INFO_MODIFIED), List.of(TEST_RDS_PI_UNIQUE_ID)));
    }

    @Test
Loading