diff options
5 files changed, 57 insertions, 27 deletions
diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/AidlTestUtils.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/AidlTestUtils.java index f3d4ccfcb4d7..3fb1554fe3a7 100644 --- a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/AidlTestUtils.java +++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/AidlTestUtils.java @@ -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; - hwInfo.logicallyTunedTo = logicallyTunedTo; - hwInfo.physicallyTunedTo = physicallyTunedTo; + if (logicallyTunedTo != null) { + hwInfo.logicallyTunedTo = logicallyTunedTo; + } + if (physicallyTunedTo != null) { + hwInfo.physicallyTunedTo = physicallyTunedTo; + } hwInfo.signalQuality = hwSignalQuality; hwInfo.relatedContent = relatedContent; hwInfo.metadata = metadata; diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsTest.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsTest.java index 5a08acdf6271..bdc4d2540bae 100644 --- a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsTest.java +++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsTest.java @@ -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); @@ -575,6 +576,21 @@ public final class ConversionUtilsTest extends ExtendedRadioMockitoTestCase { } @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", TEST_DAB_SELECTOR).that(ConversionUtils diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ProgramInfoCacheTest.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ProgramInfoCacheTest.java index d64fcaf865f2..b18567192657 100644 --- a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ProgramInfoCacheTest.java +++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ProgramInfoCacheTest.java @@ -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, diff --git a/services/core/java/com/android/server/broadcastradio/aidl/ConversionUtils.java b/services/core/java/com/android/server/broadcastradio/aidl/ConversionUtils.java index 9467d6f6fd92..a3c68f9dc827 100644 --- a/services/core/java/com/android/server/broadcastradio/aidl/ConversionUtils.java +++ b/services/core/java/com/android/server/broadcastradio/aidl/ConversionUtils.java @@ -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(); diff --git a/services/core/java/com/android/server/broadcastradio/aidl/RadioModule.java b/services/core/java/com/android/server/broadcastradio/aidl/RadioModule.java index 03e347a903b5..4edd4417c0aa 100644 --- a/services/core/java/com/android/server/broadcastradio/aidl/RadioModule.java +++ b/services/core/java/com/android/server/broadcastradio/aidl/RadioModule.java @@ -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) { |