Loading core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/AidlTestUtils.java +12 −6 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsTest.java +19 −3 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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", Loading core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ProgramInfoCacheTest.java +11 −8 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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, Loading services/core/java/com/android/server/broadcastradio/aidl/ConversionUtils.java +14 −9 Original line number Diff line number Diff line Loading @@ -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<>(); Loading @@ -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(); Loading Loading @@ -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(); Loading services/core/java/com/android/server/broadcastradio/aidl/RadioModule.java +1 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading
core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/AidlTestUtils.java +12 −6 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading
core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsTest.java +19 −3 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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", Loading
core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ProgramInfoCacheTest.java +11 −8 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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, Loading
services/core/java/com/android/server/broadcastradio/aidl/ConversionUtils.java +14 −9 Original line number Diff line number Diff line Loading @@ -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<>(); Loading @@ -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(); Loading Loading @@ -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(); Loading
services/core/java/com/android/server/broadcastradio/aidl/RadioModule.java +1 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading