Implement closing default radio implementation by invalidating all future calls.

Also, use the new hidl_vec range constructor.

Bug: b/36864090
Test: VTS
Change-Id: I92a22ab7f263edd39e42abb65bc25b3d3dc33a1e
This commit is contained in:
Tomasz Wasilczyk 2017-07-25 14:55:49 -07:00
parent a86912c77b
commit 753c1d1ef2
4 changed files with 50 additions and 19 deletions

View file

@ -66,6 +66,8 @@ void Tuner::forceClose() {
Return<Result> Tuner::setConfiguration(const BandConfig& config) {
ALOGV("%s", __func__);
lock_guard<mutex> lk(mMut);
if (mIsClosed) return Result::NOT_INITIALIZED;
if (config.lowerLimit >= config.upperLimit) return Result::INVALID_ARGUMENTS;
@ -87,14 +89,14 @@ Return<Result> Tuner::setConfiguration(const BandConfig& config) {
Return<void> Tuner::getConfiguration(getConfiguration_cb _hidl_cb) {
ALOGV("%s", __func__);
lock_guard<mutex> lk(mMut);
if (mIsAmfmConfigSet) {
if (!mIsClosed && mIsAmfmConfigSet) {
_hidl_cb(Result::OK, mAmfmConfig);
} else {
_hidl_cb(Result::NOT_INITIALIZED, {});
}
return Void();
return {};
}
// makes ProgramInfo that points to no program
@ -140,6 +142,8 @@ void Tuner::tuneInternalLocked(const ProgramSelector& sel) {
Return<Result> Tuner::scan(Direction direction, bool skipSubChannel __unused) {
ALOGV("%s", __func__);
lock_guard<mutex> lk(mMut);
if (mIsClosed) return Result::NOT_INITIALIZED;
vector<VirtualProgram> list;
if (isFmLocked()) {
@ -196,9 +200,10 @@ Return<Result> Tuner::scan(Direction direction, bool skipSubChannel __unused) {
Return<Result> Tuner::step(Direction direction, bool skipSubChannel) {
ALOGV("%s", __func__);
ALOGW_IF(!skipSubChannel, "can't step to next frequency without ignoring subChannel");
lock_guard<mutex> lk(mMut);
if (mIsClosed) return Result::NOT_INITIALIZED;
ALOGW_IF(!skipSubChannel, "can't step to next frequency without ignoring subChannel");
if (!utils::isAmFm(utils::getType(mCurrentProgram))) {
ALOGE("Can't step in anything else than AM/FM");
@ -244,8 +249,8 @@ Return<Result> Tuner::tune(uint32_t channel, uint32_t subChannel) {
Return<Result> Tuner::tune_1_1(const ProgramSelector& sel) {
ALOGV("%s(%s)", __func__, toString(sel).c_str());
lock_guard<mutex> lk(mMut);
if (mIsClosed) return Result::NOT_INITIALIZED;
if (utils::isAmFm(utils::getType(mCurrentProgram))) {
ALOGW_IF(!mIsAmfmConfigSet, "AM/FM config not set");
@ -269,12 +274,18 @@ Return<Result> Tuner::tune_1_1(const ProgramSelector& sel) {
Return<Result> Tuner::cancel() {
ALOGV("%s", __func__);
lock_guard<mutex> lk(mMut);
if (mIsClosed) return Result::NOT_INITIALIZED;
mThread.cancelAll();
return Result::OK;
}
Return<Result> Tuner::cancelAnnouncement() {
ALOGV("%s", __func__);
lock_guard<mutex> lk(mMut);
if (mIsClosed) return Result::NOT_INITIALIZED;
return Result::OK;
}
@ -287,46 +298,64 @@ Return<void> Tuner::getProgramInformation(getProgramInformation_cb _hidl_cb) {
Return<void> Tuner::getProgramInformation_1_1(getProgramInformation_1_1_cb _hidl_cb) {
ALOGV("%s", __func__);
lock_guard<mutex> lk(mMut);
if (mIsTuneCompleted) {
if (mIsClosed) {
_hidl_cb(Result::NOT_INITIALIZED, {});
} else if (mIsTuneCompleted) {
_hidl_cb(Result::OK, mCurrentProgramInfo);
} else {
_hidl_cb(Result::NOT_INITIALIZED, makeDummyProgramInfo(mCurrentProgram));
}
return Void();
return {};
}
Return<ProgramListResult> Tuner::startBackgroundScan() {
ALOGV("%s", __func__);
lock_guard<mutex> lk(mMut);
if (mIsClosed) return ProgramListResult::NOT_INITIALIZED;
return ProgramListResult::UNAVAILABLE;
}
Return<void> Tuner::getProgramList(const hidl_string& filter __unused, getProgramList_cb _hidl_cb) {
ALOGV("%s", __func__);
Return<void> Tuner::getProgramList(const hidl_string& filter, getProgramList_cb _hidl_cb) {
ALOGV("%s(%s)", __func__, filter.c_str());
lock_guard<mutex> lk(mMut);
if (mIsClosed) {
_hidl_cb(ProgramListResult::NOT_INITIALIZED, {});
return {};
}
auto& virtualRadio = mVirtualFm;
if (!isFmLocked()) {
ALOGI("bands other than FM are not supported yet");
_hidl_cb(ProgramListResult::OK, {});
return Void();
return {};
}
auto list = virtualRadio.getProgramList();
ALOGD("returning a list of %zu programs", list.size());
_hidl_cb(ProgramListResult::OK, vector<ProgramInfo>(list.begin(), list.end()));
return Void();
_hidl_cb(ProgramListResult::OK, hidl_vec<ProgramInfo>(list.begin(), list.end()));
return {};
}
Return<void> Tuner::isAnalogForced(isAnalogForced_cb _hidl_cb) {
ALOGV("%s", __func__);
_hidl_cb(Result::OK, mIsAnalogForced);
return Void();
lock_guard<mutex> lk(mMut);
if (mIsClosed) {
_hidl_cb(Result::NOT_INITIALIZED, false);
} else {
_hidl_cb(Result::OK, mIsAnalogForced);
}
return {};
}
Return<Result> Tuner::setAnalogForced(bool isForced) {
ALOGV("%s", __func__);
lock_guard<mutex> lk(mMut);
if (mIsClosed) return Result::NOT_INITIALIZED;
mIsAnalogForced = isForced;
return Result::OK;
}

View file

@ -53,7 +53,7 @@ struct Tuner : public ITuner {
private:
std::mutex mMut;
WorkerThread mThread;
bool mIsClosed = false; // TODO(b/36864090): use it
bool mIsClosed = false;
const sp<V1_0::ITunerCallback> mCallback;
const sp<V1_1::ITunerCallback> mCallback1_1;

View file

@ -41,7 +41,7 @@ static MetaData createDemoBitmap(MetadataKey key) {
if (gHalVersion < 2) {
bmp.type = MetadataType::RAW;
bmp.intValue = 0;
bmp.rawValue = std::vector<uint8_t>(resources::demoPng, std::end(resources::demoPng));
bmp.rawValue = hidl_vec<uint8_t>(resources::demoPng, std::end(resources::demoPng));
}
return bmp;
}

View file

@ -53,7 +53,9 @@ static bool anyHaveId(const ProgramSelector& a, const ProgramSelector& b,
static bool haveEqualIds(const ProgramSelector& a, const ProgramSelector& b,
const IdentifierType type) {
if (!bothHaveId(a, b, type)) return false;
// TODO(b/36864090): we should check all Ids of a given type (ie. other AF), not just one
/* We should check all Ids of a given type (ie. other AF),
* but it doesn't matter for default implementation.
*/
auto aId = getId(a, type);
auto bId = getId(b, type);
return aId == bId;