Move utils lib out from implementation namespace.
RadioService may benefit from it too.
Also, fix subchannel base, as I found a tiny comment about it in the 1.0 HAL.
Bug: b/32621193
Test: instrumentalization
Change-Id: I11939025b72bdeab4cc6393e25159f53164e22ed
diff --git a/broadcastradio/1.1/utils/Utils.cpp b/broadcastradio/1.1/utils/Utils.cpp
index 9dc0a53..270aabb 100644
--- a/broadcastradio/1.1/utils/Utils.cpp
+++ b/broadcastradio/1.1/utils/Utils.cpp
@@ -24,7 +24,6 @@
namespace hardware {
namespace broadcastradio {
namespace V1_1 {
-namespace implementation {
namespace utils {
using V1_0::Band;
@@ -166,26 +165,31 @@
sel.primaryId.type = static_cast<uint32_t>(IdentifierType::AMFM_FREQUENCY);
sel.primaryId.value = channel;
if (subChannel > 0) {
- // stating sub channel for AM/FM channel does not give any guarantees,
- // but we can't do much more without HD station ID
+ /* stating sub channel for AM/FM channel does not give any guarantees,
+ * but we can't do much more without HD station ID
+ *
+ * The legacy APIs had 1-based subChannels, while ProgramSelector is 0-based.
+ */
sel.secondaryIds = hidl_vec<ProgramIdentifier>{
- {static_cast<uint32_t>(IdentifierType::HD_SUBCHANNEL), subChannel},
+ {static_cast<uint32_t>(IdentifierType::HD_SUBCHANNEL), subChannel - 1},
};
}
return sel;
}
-bool getLegacyChannel(const ProgramSelector& sel, uint32_t& channelOut, uint32_t& subChannelOut) {
+bool getLegacyChannel(const ProgramSelector& sel, uint32_t* channelOut, uint32_t* subChannelOut) {
+ if (channelOut) *channelOut = 0;
+ if (subChannelOut) *subChannelOut = 0;
if (isAmFm(getType(sel))) {
- channelOut = getId(sel, IdentifierType::AMFM_FREQUENCY);
- subChannelOut = getId(sel, IdentifierType::HD_SUBCHANNEL, 0);
+ if (channelOut) *channelOut = getId(sel, IdentifierType::AMFM_FREQUENCY);
+ if (subChannelOut && hasId(sel, IdentifierType::HD_SUBCHANNEL)) {
+ // The legacy APIs had 1-based subChannels, while ProgramSelector is 0-based.
+ *subChannelOut = getId(sel, IdentifierType::HD_SUBCHANNEL) + 1;
+ }
return true;
- } else {
- channelOut = 0;
- subChannelOut = 0;
- return false;
}
+ return false;
}
bool isDigital(const ProgramSelector& sel) {
@@ -200,7 +204,6 @@
}
} // namespace utils
-} // namespace implementation
} // namespace V1_1
} // namespace broadcastradio
} // namespace hardware