using V1_0::Band;
using V1_0::BandConfig;
using V1_0::Direction;
+using utils::HalRevision;
using std::chrono::milliseconds;
using std::lock_guard;
: mCallback(callback),
mCallback1_1(ITunerCallback::castFrom(callback).withDefault(nullptr)),
mVirtualFm(make_fm_radio()),
- mIsAnalogForced(false) {
- // TODO (b/36864090): inject this data in a more elegant way
- setCompatibilityLevel(mCallback1_1 == nullptr ? 1 : 2);
-}
+ mIsAnalogForced(false) {}
void Tuner::forceClose() {
lock_guard<mutex> lk(mMut);
return info11;
}
+HalRevision Tuner::getHalRev() const {
+ if (mCallback1_1 != nullptr) {
+ return HalRevision::V1_1;
+ } else {
+ return HalRevision::V1_0;
+ }
+}
+
bool Tuner::isFmLocked() {
if (!utils::isAmFm(utils::getType(mCurrentProgram))) return false;
return mAmfmConfig.type == Band::FM_HD || mAmfmConfig.type == Band::FM;
VirtualProgram virtualProgram;
if (virtualRadio != nullptr && virtualRadio->getProgram(sel, virtualProgram)) {
mCurrentProgram = virtualProgram.selector;
- mCurrentProgramInfo = static_cast<ProgramInfo>(virtualProgram);
+ mCurrentProgramInfo = virtualProgram.getProgramInfo(getHalRev());
} else {
mCurrentProgram = sel;
mCurrentProgramInfo = makeDummyProgramInfo(sel);
auto list = virtualRadio.getProgramList();
ALOGD("returning a list of %zu programs", list.size());
- _hidl_cb(ProgramListResult::OK, hidl_vec<ProgramInfo>(list.begin(), list.end()));
+ _hidl_cb(ProgramListResult::OK, getProgramInfoVector(list, getHalRev()));
return {};
}
ProgramInfo mCurrentProgramInfo = {};
std::atomic<bool> mIsAnalogForced;
+ utils::HalRevision getHalRev() const;
void tuneInternalLocked(const ProgramSelector& sel);
bool isFmLocked(); // TODO(b/36864090): make it generic, not FM only
};
namespace V1_1 {
namespace implementation {
+using std::vector;
+
using V1_0::MetaData;
using V1_0::MetadataKey;
using V1_0::MetadataType;
+using utils::HalRevision;
-// TODO (b/36864090): inject this data in a more elegant way
-static int gHalVersion = 2; // 1 = 1.0, 2 = 1.1
-
-void setCompatibilityLevel(int halversion) {
- gHalVersion = halversion;
-}
-
-static MetaData createDemoBitmap(MetadataKey key) {
+static MetaData createDemoBitmap(MetadataKey key, HalRevision halRev) {
MetaData bmp = {MetadataType::INT, key, resources::demoPngId, {}, {}, {}};
- if (gHalVersion < 2) {
+ if (halRev < HalRevision::V1_1) {
bmp.type = MetadataType::RAW;
bmp.intValue = 0;
bmp.rawValue = hidl_vec<uint8_t>(resources::demoPng, std::end(resources::demoPng));
return bmp;
}
-VirtualProgram::operator ProgramInfo() const {
+ProgramInfo VirtualProgram::getProgramInfo(HalRevision halRev) const {
ProgramInfo info11 = {};
auto& info10 = info11.base;
{MetadataType::TEXT, MetadataKey::RDS_PS, {}, {}, programName, {}},
{MetadataType::TEXT, MetadataKey::TITLE, {}, {}, songTitle, {}},
{MetadataType::TEXT, MetadataKey::ARTIST, {}, {}, songArtist, {}},
- createDemoBitmap(MetadataKey::ICON),
- createDemoBitmap(MetadataKey::ART),
+ createDemoBitmap(MetadataKey::ICON, halRev),
+ createDemoBitmap(MetadataKey::ART, halRev),
});
return info11;
return false;
}
+vector<ProgramInfo> getProgramInfoVector(const vector<VirtualProgram>& vec, HalRevision halRev) {
+ vector<ProgramInfo> out;
+ out.reserve(vec.size());
+ for (auto&& program : vec) {
+ out.push_back(program.getProgramInfo(halRev));
+ }
+ return out;
+}
+
} // namespace implementation
} // namespace V1_1
} // namespace broadcastradio
#define ANDROID_HARDWARE_BROADCASTRADIO_V1_1_VIRTUALPROGRAM_H
#include <android/hardware/broadcastradio/1.1/types.h>
-#include <cstdint>
+#include <broadcastradio-utils/Utils.h>
namespace android {
namespace hardware {
namespace V1_1 {
namespace implementation {
-// TODO (b/36864090): inject this data in a more elegant way
-void setCompatibilityLevel(int halversion);
-
struct VirtualProgram {
ProgramSelector selector;
std::string songArtist = "";
std::string songTitle = "";
- explicit operator ProgramInfo() const;
+ ProgramInfo getProgramInfo(utils::HalRevision halRev) const;
+
friend bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs);
};
+std::vector<ProgramInfo> getProgramInfoVector(const std::vector<VirtualProgram>& vec,
+ utils::HalRevision halRev);
+
} // namespace implementation
} // namespace V1_1
} // namespace broadcastradio
namespace V1_1 {
namespace utils {
+// TODO(b/64115813): move it out from frameworks/base/services/core/jni/BroadcastRadio/types.h
+enum class HalRevision : uint32_t {
+ V1_0 = 1,
+ V1_1,
+};
+
/**
* Checks, if {@code pointer} tunes to {@channel}.
*