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

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

Fix invalid program info check in bcradio client

Fixed invalid program info check in AIDL broadcast radio service
client by allowing identifiers physically and logically tuned to
invalid according to AIDL broadcast radio HAL definition.

Bug: 342335147
Flag: EXEMPT bugfix
Test: atest com.android.server.broadcastradio.aidl
Change-Id: Ifbf201808f6d91f05d5bdf02f2c3f587008c130a
parent fed81b23
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.server.broadcastradio.aidl;

import android.annotation.Nullable;
import android.hardware.broadcastradio.IdentifierType;
import android.hardware.broadcastradio.Metadata;
import android.hardware.broadcastradio.ProgramIdentifier;
@@ -110,20 +111,25 @@ final class AidlTestUtils {

    static ProgramInfo makeHalProgramInfo(
            android.hardware.broadcastradio.ProgramSelector hwSel,
            ProgramIdentifier logicallyTunedTo, ProgramIdentifier physicallyTunedTo,
            int hwSignalQuality) {
            @Nullable ProgramIdentifier logicallyTunedTo,
            @Nullable 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) {
            @Nullable ProgramIdentifier logicallyTunedTo,
            @Nullable ProgramIdentifier physicallyTunedTo, int hwSignalQuality,
            ProgramIdentifier[] relatedContent, Metadata[] metadata) {
        ProgramInfo hwInfo = new ProgramInfo();
        hwInfo.selector = hwSel;
        if (logicallyTunedTo != null) {
            hwInfo.logicallyTunedTo = logicallyTunedTo;
        }
        if (physicallyTunedTo != null) {
            hwInfo.physicallyTunedTo = physicallyTunedTo;
        }
        hwInfo.signalQuality = hwSignalQuality;
        hwInfo.relatedContent = relatedContent;
        hwInfo.metadata = metadata;
+19 −3
Original line number Diff line number Diff line
@@ -562,10 +562,11 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
    @Test
    public void programInfoFromHalProgramInfo_withInvalidDabProgramInfo() {
        android.hardware.broadcastradio.ProgramSelector invalidHalDabSelector =
                AidlTestUtils.makeHalSelector(TEST_HAL_DAB_SID_EXT_ID,
                new ProgramIdentifier[]{TEST_HAL_DAB_ENSEMBLE_ID, TEST_HAL_DAB_FREQUENCY_ID});
                AidlTestUtils.makeHalSelector(TEST_HAL_DAB_ENSEMBLE_ID,
                        new ProgramIdentifier[]{TEST_HAL_DAB_FREQUENCY_ID});
        ProgramInfo halProgramInfo = AidlTestUtils.makeHalProgramInfo(invalidHalDabSelector,
                TEST_HAL_DAB_SID_EXT_ID, TEST_HAL_DAB_ENSEMBLE_ID, TEST_SIGNAL_QUALITY);
                /* logicallyTunedTo= */ null, /* physicallyTunedTo= */ null,
                TEST_SIGNAL_QUALITY);

        RadioManager.ProgramInfo programInfo =
                ConversionUtils.programInfoFromHalProgramInfo(halProgramInfo);
@@ -574,6 +575,21 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase {
                .that(programInfo).isNull();
    }

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

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

        expect.withMessage("Invalid DAB program info with incorrect type of physically tuned to id")
                .that(programInfo).isNull();
    }

    @Test
    public void programSelectorMeetsSdkVersionRequirement_withLowerVersionPrimaryId_returnsFalse() {
        expect.withMessage("Selector %s with primary id requiring higher-version SDK version",
+11 −8
Original line number Diff line number Diff line
@@ -189,13 +189,16 @@ public class ProgramInfoCacheTest {

    @Test
    public void updateFromHalProgramListChunk_withInvalidChunk() {
        RadioManager.ProgramInfo invalidDabInfo = AidlTestUtils.makeProgramInfo(TEST_DAB_SELECTOR,
                TEST_DAB_DMB_SID_EXT_ID, TEST_DAB_ENSEMBLE_ID, TEST_SIGNAL_QUALITY);
        ProgramInfo invalidHalDabInfo = AidlTestUtils.makeHalProgramInfo(
                AidlTestUtils.makeHalSelector(
                        ConversionUtils.identifierToHalProgramIdentifier(TEST_DAB_ENSEMBLE_ID),
                        new ProgramIdentifier[]{}), /* logicallyTunedTo= */ null,
                /* physicallyTunedTo= */ null, TEST_SIGNAL_QUALITY);
        ProgramInfoCache cache = new ProgramInfoCache(/* filter= */ null,
                /* complete= */ false);
        ProgramListChunk chunk = AidlTestUtils.makeHalChunk(/* purge= */ false,
                /* complete= */ true, new ProgramInfo[]{AidlTestUtils.programInfoToHalProgramInfo(
                        invalidDabInfo)}, new ProgramIdentifier[]{});
                /* complete= */ true, new ProgramInfo[]{invalidHalDabInfo},
                new ProgramIdentifier[]{});

        cache.updateFromHalProgramListChunk(chunk);

@@ -447,10 +450,10 @@ public class ProgramInfoCacheTest {
                /* complete= */ false, TEST_FM_INFO, TEST_RDS_INFO, TEST_DAB_INFO);
        ProgramInfo[] halModified = new android.hardware.broadcastradio.ProgramInfo[1];
        halModified[0] = AidlTestUtils.makeHalProgramInfo(
                ConversionUtils.programSelectorToHalProgramSelector(TEST_DAB_SELECTOR_ALTERNATIVE),
                ConversionUtils.identifierToHalProgramIdentifier(TEST_DAB_FREQUENCY_ID_ALTERNATIVE),
                ConversionUtils.identifierToHalProgramIdentifier(TEST_DAB_FREQUENCY_ID_ALTERNATIVE),
                TEST_SIGNAL_QUALITY);
                AidlTestUtils.makeHalSelector(
                        ConversionUtils.identifierToHalProgramIdentifier(TEST_DAB_ENSEMBLE_ID),
                        new ProgramIdentifier[]{}), /* logicallyTunedTo= */ null,
                /* physicallyTunedTo= */ null, TEST_SIGNAL_QUALITY);
        ProgramIdentifier[] halRemoved = new android.hardware.broadcastradio.ProgramIdentifier[1];
        halRemoved[0] = new android.hardware.broadcastradio.ProgramIdentifier();
        ProgramListChunk halChunk = AidlTestUtils.makeHalChunk(/* purge= */ false,
+14 −9
Original line number Diff line number Diff line
@@ -590,15 +590,9 @@ final class ConversionUtils {
                || isVendorIdentifierType(id.type);
    }

    private static boolean isValidHalProgramInfo(ProgramInfo info) {
        return isValidHalProgramSelector(info.selector)
                && isValidLogicallyTunedTo(info.logicallyTunedTo)
                && isValidPhysicallyTunedTo(info.physicallyTunedTo);
    }

    @Nullable
    static RadioManager.ProgramInfo programInfoFromHalProgramInfo(ProgramInfo info) {
        if (!isValidHalProgramInfo(info)) {
        if (!isValidHalProgramSelector(info.selector)) {
            return null;
        }
        Collection<ProgramSelector.Identifier> relatedContent = new ArrayList<>();
@@ -624,6 +618,15 @@ final class ConversionUtils {
        );
    }

    @Nullable
    static RadioManager.ProgramInfo tunedProgramInfoFromHalProgramInfo(ProgramInfo info) {
        if (!isValidLogicallyTunedTo(info.logicallyTunedTo)
                || !isValidPhysicallyTunedTo(info.physicallyTunedTo)) {
            return null;
        }
        return programInfoFromHalProgramInfo(info);
    }

    static ProgramFilter filterToHalProgramFilter(@Nullable ProgramList.Filter filter) {
        if (filter == null) {
            filter = new ProgramList.Filter();
@@ -686,8 +689,10 @@ final class ConversionUtils {
        if (!programSelectorMeetsSdkVersionRequirement(info.getSelector(), uid)) {
            return false;
        }
        if (!identifierMeetsSdkVersionRequirement(info.getLogicallyTunedTo(), uid)
                || !identifierMeetsSdkVersionRequirement(info.getPhysicallyTunedTo(), uid)) {
        if ((info.getLogicallyTunedTo() != null
                && !identifierMeetsSdkVersionRequirement(info.getLogicallyTunedTo(), uid))
                || (info.getPhysicallyTunedTo() != null
                && !identifierMeetsSdkVersionRequirement(info.getPhysicallyTunedTo(), uid))) {
            return false;
        }
        Iterator<ProgramSelector.Identifier> relatedContentIt = info.getRelatedContent().iterator();
+1 −1
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ final class RadioModule {
        public void onCurrentProgramInfoChanged(ProgramInfo halProgramInfo) {
            fireLater(() -> {
                RadioManager.ProgramInfo currentProgramInfo =
                        ConversionUtils.programInfoFromHalProgramInfo(halProgramInfo);
                        ConversionUtils.tunedProgramInfoFromHalProgramInfo(halProgramInfo);
                Objects.requireNonNull(currentProgramInfo,
                        "Program info from AIDL HAL is invalid");
                synchronized (mLock) {