Implement default radio HAL stopProgramListUpdates
Implemented stopProgramListUpdates method in default AIDL broadcast
radio HAL. Created a separate thread for program list updates, so
that canceling pending tuning operations and canceling pending
program list updates are independent.
Bug: 243681584
Test: atest VtsHalBroadcastradioAidlTargetTest
Change-Id: I9e09f267a2264fa0cbc280d0d6ea71037db519ac
diff --git a/broadcastradio/aidl/default/BroadcastRadio.cpp b/broadcastradio/aidl/default/BroadcastRadio.cpp
index 4d097c1..8584921 100644
--- a/broadcastradio/aidl/default/BroadcastRadio.cpp
+++ b/broadcastradio/aidl/default/BroadcastRadio.cpp
@@ -115,7 +115,8 @@
}
BroadcastRadio::~BroadcastRadio() {
- mThread.reset();
+ mTuningThread.reset();
+ mProgramListThread.reset();
}
ScopedAStatus BroadcastRadio::getAmFmRegionConfig(bool full, AmFmRegionConfig* returnConfigs) {
@@ -239,7 +240,7 @@
callback->onCurrentProgramInfoChanged(programInfo);
};
auto cancelTask = [program, callback]() { callback->onTuneFailed(Result::CANCELED, program); };
- mThread->schedule(task, cancelTask, kTuneDelayTimeMs);
+ mTuningThread->schedule(task, cancelTask, kTuneDelayTimeMs);
return ScopedAStatus::ok();
}
@@ -267,7 +268,7 @@
callback->onTuneFailed(Result::TIMEOUT, {});
};
- mThread->schedule(task, cancelTask, kSeekDelayTimeMs);
+ mTuningThread->schedule(task, cancelTask, kSeekDelayTimeMs);
return ScopedAStatus::ok();
}
@@ -300,7 +301,7 @@
}
callback->onCurrentProgramInfoChanged(programInfo);
};
- mThread->schedule(task, cancelTask, kSeekDelayTimeMs);
+ mTuningThread->schedule(task, cancelTask, kSeekDelayTimeMs);
return ScopedAStatus::ok();
}
@@ -355,15 +356,15 @@
callback->onCurrentProgramInfoChanged(programInfo);
};
auto cancelTask = [callback]() { callback->onTuneFailed(Result::CANCELED, {}); };
- mThread->schedule(task, cancelTask, kStepDelayTimeMs);
+ mTuningThread->schedule(task, cancelTask, kStepDelayTimeMs);
return ScopedAStatus::ok();
}
void BroadcastRadio::cancelLocked() {
- LOG(DEBUG) << __func__ << ": cancelling current operations...";
+ LOG(DEBUG) << __func__ << ": cancelling current tuning operations...";
- mThread->cancelAll();
+ mTuningThread->cancelAll();
if (mCurrentProgram.primaryId.type != IdentifierType::INVALID) {
mIsTuneCompleted = true;
}
@@ -388,6 +389,8 @@
lock_guard<mutex> lk(mMutex);
+ cancelProgramListUpdateLocked();
+
const auto& list = mVirtualRadio.getProgramList();
vector<VirtualProgram> filteredList;
std::copy_if(list.begin(), list.end(), std::back_inserter(filteredList), filterCb);
@@ -410,14 +413,20 @@
callback->onProgramListUpdated(chunk);
};
- mThread->schedule(task, kListDelayTimeS);
+ mProgramListThread->schedule(task, kListDelayTimeS);
return ScopedAStatus::ok();
}
+void BroadcastRadio::cancelProgramListUpdateLocked() {
+ LOG(DEBUG) << __func__ << ": cancelling current program list update operations...";
+ mProgramListThread->cancelAll();
+}
+
ScopedAStatus BroadcastRadio::stopProgramListUpdates() {
LOG(DEBUG) << __func__ << ": requested program list updates to stop...";
- // TODO(b/243681584) Implement stop program list updates method
+ lock_guard<mutex> lk(mMutex);
+ cancelProgramListUpdateLocked();
return ScopedAStatus::ok();
}
diff --git a/broadcastradio/aidl/default/BroadcastRadio.h b/broadcastradio/aidl/default/BroadcastRadio.h
index 092776f..0f818ce 100644
--- a/broadcastradio/aidl/default/BroadcastRadio.h
+++ b/broadcastradio/aidl/default/BroadcastRadio.h
@@ -68,7 +68,9 @@
const VirtualRadio& mVirtualRadio;
std::mutex mMutex;
AmFmRegionConfig mAmFmConfig GUARDED_BY(mMutex);
- std::unique_ptr<::android::WorkerThread> mThread GUARDED_BY(mMutex) =
+ std::unique_ptr<::android::WorkerThread> mTuningThread GUARDED_BY(mMutex) =
+ std::unique_ptr<::android::WorkerThread>(new ::android::WorkerThread());
+ std::unique_ptr<::android::WorkerThread> mProgramListThread GUARDED_BY(mMutex) =
std::unique_ptr<::android::WorkerThread>(new ::android::WorkerThread());
bool mIsTuneCompleted GUARDED_BY(mMutex) = true;
Properties mProperties GUARDED_BY(mMutex);
@@ -81,6 +83,7 @@
std::optional<AmFmBandRange> getAmFmRangeLocked() const;
void cancelLocked();
ProgramInfo tuneInternalLocked(const ProgramSelector& sel);
+ void cancelProgramListUpdateLocked();
binder_status_t cmdHelp(int fd) const;
binder_status_t cmdTune(int fd, const char** args, uint32_t numArgs);