mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Improve current program info validation.
Bug: 74022658 Test: atest VtsHalBroadcastradioV2_0TargetTest Change-Id: Ifee19249a9033363df863480e8a5da24334f5e59
This commit is contained in:
@@ -137,29 +137,30 @@ TunerCallbackMock::TunerCallbackMock() {
|
||||
}
|
||||
|
||||
Return<void> TunerCallbackMock::onCurrentProgramInfoChanged(const ProgramInfo& info) {
|
||||
auto logically = utils::getType(info.logicallyTunedTo);
|
||||
if (logically != IdentifierType::INVALID) {
|
||||
EXPECT_TRUE(logically == IdentifierType::AMFM_FREQUENCY ||
|
||||
logically == IdentifierType::RDS_PI ||
|
||||
logically == IdentifierType::HD_STATION_ID_EXT ||
|
||||
logically == IdentifierType::DAB_SID_EXT ||
|
||||
logically == IdentifierType::DRMO_SERVICE_ID ||
|
||||
logically == IdentifierType::SXM_SERVICE_ID ||
|
||||
(logically >= IdentifierType::VENDOR_START &&
|
||||
logically <= IdentifierType::VENDOR_END) ||
|
||||
logically > IdentifierType::SXM_CHANNEL);
|
||||
for (auto&& id : info.selector) {
|
||||
EXPECT_NE(IdentifierType::INVALID, utils::getType(id));
|
||||
}
|
||||
|
||||
auto logically = utils::getType(info.logicallyTunedTo);
|
||||
/* This field is required for currently tuned program and should be INVALID
|
||||
* for entries from the program list.
|
||||
*/
|
||||
EXPECT_TRUE(
|
||||
logically == IdentifierType::AMFM_FREQUENCY || logically == IdentifierType::RDS_PI ||
|
||||
logically == IdentifierType::HD_STATION_ID_EXT ||
|
||||
logically == IdentifierType::DAB_SID_EXT || logically == IdentifierType::DRMO_SERVICE_ID ||
|
||||
logically == IdentifierType::SXM_SERVICE_ID ||
|
||||
(logically >= IdentifierType::VENDOR_START && logically <= IdentifierType::VENDOR_END) ||
|
||||
logically > IdentifierType::SXM_CHANNEL);
|
||||
|
||||
auto physically = utils::getType(info.physicallyTunedTo);
|
||||
if (physically != IdentifierType::INVALID) {
|
||||
EXPECT_TRUE(physically == IdentifierType::AMFM_FREQUENCY ||
|
||||
physically == IdentifierType::DAB_ENSEMBLE ||
|
||||
physically == IdentifierType::DRMO_FREQUENCY ||
|
||||
physically == IdentifierType::SXM_CHANNEL ||
|
||||
(physically >= IdentifierType::VENDOR_START &&
|
||||
physically <= IdentifierType::VENDOR_END) ||
|
||||
physically > IdentifierType::SXM_CHANNEL);
|
||||
}
|
||||
// ditto (see "logically" above)
|
||||
EXPECT_TRUE(
|
||||
physically == IdentifierType::AMFM_FREQUENCY ||
|
||||
physically == IdentifierType::DAB_ENSEMBLE ||
|
||||
physically == IdentifierType::DRMO_FREQUENCY || physically == IdentifierType::SXM_CHANNEL ||
|
||||
(physically >= IdentifierType::VENDOR_START && physically <= IdentifierType::VENDOR_END) ||
|
||||
physically > IdentifierType::SXM_CHANNEL);
|
||||
|
||||
if (logically == IdentifierType::AMFM_FREQUENCY) {
|
||||
auto ps = utils::getMetadataString(info, MetadataKey::RDS_PS);
|
||||
|
||||
@@ -33,8 +33,8 @@ TEST(IdentifierIteratorTest, singleSecondary) {
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
auto it = utils::begin(sel);
|
||||
auto end = utils::end(sel);
|
||||
auto it = V2_0::begin(sel);
|
||||
auto end = V2_0::end(sel);
|
||||
|
||||
ASSERT_NE(end, it);
|
||||
EXPECT_EQ(sel.primaryId, *it);
|
||||
@@ -46,8 +46,8 @@ TEST(IdentifierIteratorTest, singleSecondary) {
|
||||
TEST(IdentifierIteratorTest, empty) {
|
||||
V2_0::ProgramSelector sel{};
|
||||
|
||||
auto it = utils::begin(sel);
|
||||
auto end = utils::end(sel);
|
||||
auto it = V2_0::begin(sel);
|
||||
auto end = V2_0::end(sel);
|
||||
|
||||
ASSERT_NE(end, it++); // primary id is always present
|
||||
ASSERT_EQ(end, it);
|
||||
@@ -57,8 +57,8 @@ TEST(IdentifierIteratorTest, twoSelectors) {
|
||||
V2_0::ProgramSelector sel1{};
|
||||
V2_0::ProgramSelector sel2{};
|
||||
|
||||
auto it1 = utils::begin(sel1);
|
||||
auto it2 = utils::begin(sel2);
|
||||
auto it1 = V2_0::begin(sel1);
|
||||
auto it2 = V2_0::begin(sel2);
|
||||
|
||||
EXPECT_NE(it1, it2);
|
||||
}
|
||||
@@ -66,8 +66,8 @@ TEST(IdentifierIteratorTest, twoSelectors) {
|
||||
TEST(IdentifierIteratorTest, increments) {
|
||||
V2_0::ProgramSelector sel{{}, {{}, {}}};
|
||||
|
||||
auto it = utils::begin(sel);
|
||||
auto end = utils::end(sel);
|
||||
auto it = V2_0::begin(sel);
|
||||
auto end = V2_0::end(sel);
|
||||
auto pre = it;
|
||||
auto post = it;
|
||||
|
||||
@@ -102,8 +102,8 @@ TEST(IdentifierIteratorTest, findType) {
|
||||
auto isRdsPi = std::bind(typeEquals, _1, IdentifierType::RDS_PI);
|
||||
auto isFreq = std::bind(typeEquals, _1, IdentifierType::AMFM_FREQUENCY);
|
||||
|
||||
auto end = utils::end(sel);
|
||||
auto it = std::find_if(utils::begin(sel), end, isRdsPi);
|
||||
auto end = V2_0::end(sel);
|
||||
auto it = std::find_if(V2_0::begin(sel), end, isRdsPi);
|
||||
ASSERT_NE(end, it);
|
||||
EXPECT_EQ(rds_pi1, it->value);
|
||||
|
||||
@@ -111,7 +111,7 @@ TEST(IdentifierIteratorTest, findType) {
|
||||
ASSERT_NE(end, it);
|
||||
EXPECT_EQ(rds_pi2, it->value);
|
||||
|
||||
it = std::find_if(utils::begin(sel), end, isFreq);
|
||||
it = std::find_if(V2_0::begin(sel), end, isFreq);
|
||||
ASSERT_NE(end, it);
|
||||
EXPECT_EQ(freq1, it->value);
|
||||
|
||||
@@ -120,4 +120,17 @@ TEST(IdentifierIteratorTest, findType) {
|
||||
EXPECT_EQ(freq2, it->value);
|
||||
}
|
||||
|
||||
TEST(IdentifierIteratorTest, rangeLoop) {
|
||||
V2_0::ProgramSelector sel{{}, {{}, {}, {}}};
|
||||
|
||||
unsigned count = 0;
|
||||
for (auto&& id : sel) {
|
||||
ASSERT_EQ(0u, id.type);
|
||||
count++;
|
||||
}
|
||||
|
||||
const auto expectedCount = 1 + sel.secondaryIds.size();
|
||||
ASSERT_EQ(expectedCount, count);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
@@ -81,14 +81,6 @@ bool IdentifierIterator::operator==(const IdentifierIterator& rhs) const {
|
||||
return mPos == rhs.mPos;
|
||||
}
|
||||
|
||||
IdentifierIterator begin(const V2_0::ProgramSelector& sel) {
|
||||
return IdentifierIterator(sel);
|
||||
}
|
||||
|
||||
IdentifierIterator end(const V2_0::ProgramSelector& sel) {
|
||||
return IdentifierIterator(sel) + 1 /* primary id */ + sel.secondaryIds.size();
|
||||
}
|
||||
|
||||
FrequencyBand getBand(uint64_t freq) {
|
||||
// keep in sync with
|
||||
// frameworks/base/services/core/java/com/android/server/broadcastradio/hal2/Utils.java
|
||||
@@ -411,6 +403,18 @@ V2_0::ProgramIdentifier make_hdradio_station_name(const std::string& name) {
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
||||
namespace V2_0 {
|
||||
|
||||
utils::IdentifierIterator begin(const ProgramSelector& sel) {
|
||||
return utils::IdentifierIterator(sel);
|
||||
}
|
||||
|
||||
utils::IdentifierIterator end(const ProgramSelector& sel) {
|
||||
return utils::IdentifierIterator(sel) + 1 /* primary id */ + sel.secondaryIds.size();
|
||||
}
|
||||
|
||||
} // namespace V2_0
|
||||
} // namespace broadcastradio
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
@@ -69,9 +69,6 @@ class IdentifierIterator
|
||||
size_t mPos = 0;
|
||||
};
|
||||
|
||||
IdentifierIterator begin(const V2_0::ProgramSelector& sel);
|
||||
IdentifierIterator end(const V2_0::ProgramSelector& sel);
|
||||
|
||||
/**
|
||||
* Guesses band from the frequency value.
|
||||
*
|
||||
@@ -153,6 +150,13 @@ std::optional<std::string> getMetadataString(const V2_0::ProgramInfo& info,
|
||||
V2_0::ProgramIdentifier make_hdradio_station_name(const std::string& name);
|
||||
|
||||
} // namespace utils
|
||||
|
||||
namespace V2_0 {
|
||||
|
||||
utils::IdentifierIterator begin(const ProgramSelector& sel);
|
||||
utils::IdentifierIterator end(const ProgramSelector& sel);
|
||||
|
||||
} // namespace V2_0
|
||||
} // namespace broadcastradio
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
Reference in New Issue
Block a user