Remove a hack for 1.0/1.1 bitmap compatibility.

Instead, implement it correctly.
This hack was a quick jury-rigging before O MR1 FC.

Bug: b/36864090
Test: VTS
Change-Id: Ia9caff9228518ec573a85437e9070db777057359
This commit is contained in:
Tomasz Wasilczyk 2017-07-27 13:17:07 -07:00
parent 753c1d1ef2
commit 5be4c2b6e3
5 changed files with 42 additions and 23 deletions

View file

@ -34,6 +34,7 @@ using namespace std::chrono_literals;
using V1_0::Band;
using V1_0::BandConfig;
using V1_0::Direction;
using utils::HalRevision;
using std::chrono::milliseconds;
using std::lock_guard;
@ -53,10 +54,7 @@ Tuner::Tuner(const sp<V1_0::ITunerCallback>& callback)
: 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);
@ -111,6 +109,14 @@ static ProgramInfo makeDummyProgramInfo(const ProgramSelector& selector) {
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;
@ -125,7 +131,7 @@ void Tuner::tuneInternalLocked(const ProgramSelector& sel) {
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);
@ -335,7 +341,7 @@ Return<void> Tuner::getProgramList(const hidl_string& filter, getProgramList_cb
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 {};
}

View file

@ -67,6 +67,7 @@ struct Tuner : public ITuner {
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
};

View file

@ -25,20 +25,16 @@ namespace broadcastradio {
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));
@ -46,7 +42,7 @@ static MetaData createDemoBitmap(MetadataKey key) {
return bmp;
}
VirtualProgram::operator ProgramInfo() const {
ProgramInfo VirtualProgram::getProgramInfo(HalRevision halRev) const {
ProgramInfo info11 = {};
auto& info10 = info11.base;
@ -61,8 +57,8 @@ VirtualProgram::operator ProgramInfo() const {
{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;
@ -89,6 +85,15 @@ bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) {
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

View file

@ -17,7 +17,7 @@
#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 {
@ -25,9 +25,6 @@ namespace broadcastradio {
namespace V1_1 {
namespace implementation {
// TODO (b/36864090): inject this data in a more elegant way
void setCompatibilityLevel(int halversion);
struct VirtualProgram {
ProgramSelector selector;
@ -35,10 +32,14 @@ struct VirtualProgram {
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

View file

@ -27,6 +27,12 @@ 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}.
*