Prepare a best-effort workaround for HD Radio station id abuse.
In theory, 32bit HD Radio station ID + subchannel index (parts of
HD_STATION_ID_EXT) is a globally unique identifier. It allows broadcast
radio framework to determine which programs are the same and allow the
application to match entries from favourite list and the program list
provided by the tuner.
However, some broadcasters don't perform equipment setup correctly and
don't set station ID. As a result, there are some stations with
conflicting IDs.
As a workaround to treat these stations separately in a given location,
FM frequency was added as a part of HD_STATION_ID_EXT. This still doesn't
solve the global uniqueness problem: user might save KCQW 105.5 (sid=0) in
California, travel to Nevada and find KNAB 105.5 (sid=0). It turns out
there is no reliable identifier that might identify the station globally.
As a workaround, shortened station name is added for double-checking.
This is a best-effort fix, so it's not required for such misbehaving
stations to get correctly identified in every corner case.
Bug: 69958777
Test: VTS
Change-Id: Id11243096f1cde7fdda5cb70a7248d1831985cdd
diff --git a/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp b/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
index 87ac934..151e089 100644
--- a/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
+++ b/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
@@ -30,6 +30,7 @@
#include <gmock/gmock.h>
#include <chrono>
+#include <optional>
#include <regex>
namespace android {
@@ -96,6 +97,7 @@
bool openSession();
bool getAmFmRegionConfig(bool full, AmFmRegionConfig* config);
+ std::optional<utils::ProgramInfoSet> getProgramList();
sp<IBroadcastRadio> mModule;
Properties mProperties;
@@ -178,6 +180,25 @@
return halResult == Result::OK;
}
+std::optional<utils::ProgramInfoSet> BroadcastRadioHalTest::getProgramList() {
+ EXPECT_TIMEOUT_CALL(*mCallback, onProgramListReady).Times(AnyNumber());
+
+ auto startResult = mSession->startProgramListUpdates({});
+ if (startResult == Result::NOT_SUPPORTED) {
+ printSkipped("Program list not supported");
+ return nullopt;
+ }
+ EXPECT_EQ(Result::OK, startResult);
+ if (startResult != Result::OK) return nullopt;
+
+ EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onProgramListReady, timeout::programListScan);
+
+ auto stopResult = mSession->stopProgramListUpdates();
+ EXPECT_TRUE(stopResult.isOk());
+
+ return mCallback->mProgramList;
+}
+
/**
* Test session opening.
*
@@ -645,19 +666,35 @@
TEST_F(BroadcastRadioHalTest, GetProgramList) {
ASSERT_TRUE(openSession());
- EXPECT_TIMEOUT_CALL(*mCallback, onProgramListReady).Times(AnyNumber());
+ getProgramList();
+}
- auto startResult = mSession->startProgramListUpdates({});
- if (startResult == Result::NOT_SUPPORTED) {
- printSkipped("Program list not supported");
- return;
+/**
+ * Test HD_STATION_NAME correctness.
+ *
+ * Verifies that if a program on the list contains HD_STATION_NAME identifier:
+ * - the program provides station name in its metadata;
+ * - the identifier matches the name;
+ * - there is only one identifier of that type.
+ */
+TEST_F(BroadcastRadioHalTest, HdRadioStationNameId) {
+ ASSERT_TRUE(openSession());
+
+ auto list = getProgramList();
+ if (!list) return;
+
+ for (auto&& program : *list) {
+ auto nameIds = utils::getAllIds(program.selector, IdentifierType::HD_STATION_NAME);
+ EXPECT_LE(nameIds.size(), 1u);
+ if (nameIds.size() == 0) continue;
+
+ auto name = utils::getMetadataString(program, MetadataKey::PROGRAM_NAME);
+ if (!name) name = utils::getMetadataString(program, MetadataKey::RDS_PS);
+ ASSERT_TRUE(name.has_value());
+
+ auto expectedId = utils::make_hdradio_station_name(*name);
+ EXPECT_EQ(expectedId.value, nameIds[0]);
}
- ASSERT_EQ(Result::OK, startResult);
-
- EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onProgramListReady, timeout::programListScan);
-
- auto stopResult = mSession->stopProgramListUpdates();
- EXPECT_TRUE(stopResult.isOk());
}
// TODO(b/70939328): test ProgramInfo's currentlyTunedId and