Improve DAB support in broadcast radio AIDL HAL
SID in DAB_SID_EXT was extended to 32-bit to support DMB radio.
The documatation for DAB program selector and program info was
updated to make a DAB station is uniquely specified. AIDL HAL
definition requirement for identifier, program selector and info
was enforced in the AIDL utils class. The default implementation
and VTS were also updated correspondingly.
Bug: 261912181
Test: atest VtsHalBroadcastradioAidlTargetTest
Change-Id: Ic420955340f0c77370106e736410d7125536e62d
diff --git a/broadcastradio/aidl/vts/src/VtsHalBroadcastradioAidlTargetTest.cpp b/broadcastradio/aidl/vts/src/VtsHalBroadcastradioAidlTargetTest.cpp
index 5a56846..356673f 100644
--- a/broadcastradio/aidl/vts/src/VtsHalBroadcastradioAidlTargetTest.cpp
+++ b/broadcastradio/aidl/vts/src/VtsHalBroadcastradioAidlTargetTest.cpp
@@ -46,6 +46,7 @@
using ::aidl::android::hardware::broadcastradio::utils::makeIdentifier;
using ::aidl::android::hardware::broadcastradio::utils::makeSelectorAmfm;
+using ::aidl::android::hardware::broadcastradio::utils::makeSelectorDab;
using ::aidl::android::hardware::broadcastradio::utils::resultToInt;
using ::ndk::ScopedAStatus;
using ::ndk::SharedRefBase;
@@ -110,8 +111,7 @@
class TunerCallbackMock : public BnTunerCallback {
public:
TunerCallbackMock();
-
- MOCK_METHOD2(onTuneFailed, ScopedAStatus(Result, const ProgramSelector&));
+ ScopedAStatus onTuneFailed(Result result, const ProgramSelector& selector) override;
MOCK_TIMEOUT_METHOD1(onCurrentProgramInfoChangedMock, ScopedAStatus(const ProgramInfo&));
ScopedAStatus onCurrentProgramInfoChanged(const ProgramInfo& info) override;
ScopedAStatus onProgramListUpdated(const ProgramListChunk& chunk) override;
@@ -154,6 +154,12 @@
EXPECT_CALL(*this, onAntennaStateChange(false)).Times(0);
}
+ScopedAStatus TunerCallbackMock::onTuneFailed(Result result, const ProgramSelector& selector) {
+ LOG(DEBUG) << "Tune failed for selector" << selector.toString();
+ EXPECT_TRUE(result == Result::CANCELED);
+ return ndk::ScopedAStatus::ok();
+}
+
ScopedAStatus TunerCallbackMock::onCurrentProgramInfoChanged(const ProgramInfo& info) {
for (const auto& id : info.selector) {
EXPECT_NE(id.type, IdentifierType::INVALID);
@@ -175,7 +181,7 @@
IdentifierType physically = info.physicallyTunedTo.type;
// ditto (see "logically" above)
EXPECT_TRUE(physically == IdentifierType::AMFM_FREQUENCY_KHZ ||
- physically == IdentifierType::DAB_ENSEMBLE ||
+ physically == IdentifierType::DAB_FREQUENCY_KHZ ||
physically == IdentifierType::DRMO_FREQUENCY_KHZ ||
physically == IdentifierType::SXM_CHANNEL ||
(physically >= IdentifierType::VENDOR_START &&
@@ -593,10 +599,43 @@
ASSERT_TRUE(halResult.isOk());
ASSERT_NE(config.size(), 0U);
- // TODO(245787803): use a DAB frequency that can actually be tuned to.
+ auto programList = getProgramList();
+
+ if (!programList) {
+ printSkipped("Empty DAB station list, tune cannot be performed");
+ return;
+ }
+
ProgramSelector sel = {};
- int64_t freq = config[config.size() / 2].frequencyKhz;
- sel.primaryId = makeIdentifier(IdentifierType::DAB_FREQUENCY_KHZ, freq);
+ uint64_t freq = 0;
+ bool dabStationPresent = false;
+ for (auto&& programInfo : *programList) {
+ if (!utils::hasId(programInfo.selector, IdentifierType::DAB_FREQUENCY_KHZ)) {
+ continue;
+ }
+ for (auto&& config_entry : config) {
+ if (config_entry.frequencyKhz ==
+ utils::getId(programInfo.selector, IdentifierType::DAB_FREQUENCY_KHZ, 0)) {
+ freq = config_entry.frequencyKhz;
+ break;
+ }
+ }
+ // Do not trigger a tune request if the programList entry does not contain
+ // a valid DAB frequency.
+ if (freq == 0) {
+ continue;
+ }
+ int64_t dabSidExt = utils::getId(programInfo.selector, IdentifierType::DAB_SID_EXT, 0);
+ int64_t dabEns = utils::getId(programInfo.selector, IdentifierType::DAB_ENSEMBLE, 0);
+ sel = makeSelectorDab(dabSidExt, (int32_t)dabEns, freq);
+ dabStationPresent = true;
+ break;
+ }
+
+ if (!dabStationPresent) {
+ printSkipped("No DAB stations in the list, tune cannot be performed");
+ return;
+ }
// try tuning
ProgramInfo infoCb = {};
@@ -623,7 +662,6 @@
vector<int> freqs = bcutils::getAllIds(infoCb.selector, IdentifierType::DAB_FREQUENCY_KHZ);
EXPECT_NE(freqs.end(), find(freqs.begin(), freqs.end(), freq))
<< "DAB freq " << freq << " kHz is not sent back by callback.";
- ;
}
/**