Extend DAB primary identifier with SCIdS.
This replaces DAB_SIDECC with DAB_SID_EXT as primary DAB identifier.
Bug: 69308221
Test: it builds
Change-Id: I8d3c9628e7dc8a03c5aa0c04f136e60eccaa9940
diff --git a/broadcastradio/common/utils/Android.bp b/broadcastradio/common/utils/Android.bp
index d8bd125..d29d05c 100644
--- a/broadcastradio/common/utils/Android.bp
+++ b/broadcastradio/common/utils/Android.bp
@@ -29,6 +29,6 @@
],
export_include_dirs: ["include"],
shared_libs: [
- "android.hardware.broadcastradio@1.1",
+ "android.hardware.broadcastradio@1.2",
],
}
diff --git a/broadcastradio/common/utils/Utils.cpp b/broadcastradio/common/utils/Utils.cpp
index bdaf8e8..22a6970 100644
--- a/broadcastradio/common/utils/Utils.cpp
+++ b/broadcastradio/common/utils/Utils.cpp
@@ -26,10 +26,10 @@
namespace utils {
using V1_0::Band;
-using V1_1::IdentifierType;
using V1_1::ProgramIdentifier;
using V1_1::ProgramSelector;
using V1_1::ProgramType;
+using V1_2::IdentifierType;
static bool isCompatibleProgramType(const uint32_t ia, const uint32_t ib) {
auto a = static_cast<ProgramType>(ia);
@@ -88,7 +88,7 @@
return haveEqualIds(a, b, IdentifierType::AMFM_FREQUENCY);
case ProgramType::DAB:
- return haveEqualIds(a, b, IdentifierType::DAB_SIDECC);
+ return haveEqualIds(a, b, IdentifierType::DAB_SID_EXT);
case ProgramType::DRMO:
return haveEqualIds(a, b, IdentifierType::DRMO_SERVICE_ID);
case ProgramType::SXM:
@@ -126,23 +126,50 @@
return band == Band::FM || band == Band::FM_HD;
}
-bool hasId(const ProgramSelector& sel, const IdentifierType type) {
+static bool maybeGetId(const ProgramSelector& sel, const IdentifierType type, uint64_t* val) {
auto itype = static_cast<uint32_t>(type);
- if (sel.primaryId.type == itype) return true;
- // not optimal, but we don't care in default impl
- for (auto&& id : sel.secondaryIds) {
- if (id.type == itype) return true;
+ auto itypeAlt = itype;
+ if (type == IdentifierType::DAB_SIDECC) {
+ itypeAlt = static_cast<uint32_t>(IdentifierType::DAB_SID_EXT);
}
- return false;
+ if (type == IdentifierType::DAB_SID_EXT) {
+ itypeAlt = static_cast<uint32_t>(IdentifierType::DAB_SIDECC);
+ }
+
+ if (sel.primaryId.type == itype || sel.primaryId.type == itypeAlt) {
+ if (val) *val = sel.primaryId.value;
+ return true;
+ }
+
+ // not optimal, but we don't care in default impl
+ bool gotAlt = false;
+ for (auto&& id : sel.secondaryIds) {
+ if (id.type == itype) {
+ if (val) *val = id.value;
+ return true;
+ }
+ // alternative identifier is a backup, we prefer original value
+ if (id.type == itypeAlt) {
+ if (val) *val = id.value;
+ gotAlt = true;
+ continue;
+ }
+ }
+
+ return gotAlt;
+}
+
+bool hasId(const ProgramSelector& sel, const IdentifierType type) {
+ return maybeGetId(sel, type, nullptr);
}
uint64_t getId(const ProgramSelector& sel, const IdentifierType type) {
- auto itype = static_cast<uint32_t>(type);
- if (sel.primaryId.type == itype) return sel.primaryId.value;
- // not optimal, but we don't care in default impl
- for (auto&& id : sel.secondaryIds) {
- if (id.type == itype) return id.value;
+ uint64_t val;
+
+ if (maybeGetId(sel, type, &val)) {
+ return val;
}
+
ALOGW("Identifier %s not found", toString(type).c_str());
return 0;
}
diff --git a/broadcastradio/common/utils/include/broadcastradio-utils/Utils.h b/broadcastradio/common/utils/include/broadcastradio-utils/Utils.h
index b07ce79..9cdc629 100644
--- a/broadcastradio/common/utils/include/broadcastradio-utils/Utils.h
+++ b/broadcastradio/common/utils/include/broadcastradio-utils/Utils.h
@@ -16,7 +16,7 @@
#ifndef ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_H
#define ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_H
-#include <android/hardware/broadcastradio/1.1/types.h>
+#include <android/hardware/broadcastradio/1.2/types.h>
#include <chrono>
#include <queue>
#include <thread>
@@ -50,21 +50,21 @@
bool isAm(const V1_0::Band band);
bool isFm(const V1_0::Band band);
-bool hasId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);
+bool hasId(const V1_1::ProgramSelector& sel, const V1_2::IdentifierType type);
/**
* Returns ID (either primary or secondary) for a given program selector.
*
* If the selector does not contain given type, returns 0 and emits a warning.
*/
-uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);
+uint64_t getId(const V1_1::ProgramSelector& sel, const V1_2::IdentifierType type);
/**
* Returns ID (either primary or secondary) for a given program selector.
*
* If the selector does not contain given type, returns default value.
*/
-uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type, uint64_t defval);
+uint64_t getId(const V1_1::ProgramSelector& sel, const V1_2::IdentifierType type, uint64_t defval);
V1_1::ProgramSelector make_selector(V1_0::Band band, uint32_t channel, uint32_t subChannel = 0);