Merge "Hdmi CEC Mock : Clear the existing callback when new callback is set" into main am: ad148cc9f9

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2968206

Change-Id: Id150740e5f81a83f94af27d8913dcab3c27b5642
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2024-03-13 06:29:36 +00:00 committed by Automerger Merge Worker
commit 405001db74
2 changed files with 21 additions and 15 deletions

View file

@ -35,8 +35,7 @@ namespace implementation {
void HdmiCecMock::serviceDied(void* cookie) {
ALOGE("HdmiCecMock died");
auto hdmiCecMock = static_cast<HdmiCecMock*>(cookie);
hdmiCecMock->mCecThreadRun = false;
pthread_join(hdmiCecMock->mThreadId, NULL);
hdmiCecMock->closeCallback();
}
ScopedAStatus HdmiCecMock::addLogicalAddress(CecLogicalAddress addr, Result* _aidl_return) {
@ -86,10 +85,10 @@ ScopedAStatus HdmiCecMock::sendMessage(const CecMessage& message, SendMessageRes
}
ScopedAStatus HdmiCecMock::setCallback(const std::shared_ptr<IHdmiCecCallback>& callback) {
// If callback is null, mCallback is also set to null so we do not call the old callback.
mCallback = callback;
closeCallback();
if (callback != nullptr) {
mCallback = callback;
mDeathRecipient =
ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(serviceDied));
AIBinder_linkToDeath(callback->asBinder().get(), mDeathRecipient.get(), this /* cookie */);
@ -104,8 +103,8 @@ ScopedAStatus HdmiCecMock::setCallback(const std::shared_ptr<IHdmiCecCallback>&
ScopedAStatus HdmiCecMock::setLanguage(const std::string& language) {
if (language.size() != 3) {
LOG(ERROR) << "Wrong language code: expected 3 letters, but it was " << language.size()
<< ".";
ALOGE("[halimp_aidl] Wrong language code: expected 3 letters, but it was %zu",
language.size());
return ScopedAStatus::ok();
}
// TODO Validate if language is a valid language code
@ -169,7 +168,7 @@ int HdmiCecMock::sendMessageToFifo(const CecMessage& message) {
// Open the output pipe for writing outgoing cec message
mOutputFile = open(CEC_MSG_OUT_FIFO, O_WRONLY | O_CLOEXEC);
if (mOutputFile < 0) {
ALOGD("[halimp_aidl] file open failed for writing");
ALOGE("[halimp_aidl] file open failed for writing");
return -1;
}
@ -258,17 +257,24 @@ void HdmiCecMock::threadLoop() {
}
HdmiCecMock::HdmiCecMock() {
ALOGE("[halimp_aidl] Opening a virtual CEC HAL for testing and virtual machine.");
ALOGD("[halimp_aidl] Opening a virtual CEC HAL for testing and virtual machine.");
mCallback = nullptr;
mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr);
}
void HdmiCecMock::closeCallback() {
if (mCallback != nullptr) {
ALOGD("[halimp_aidl] HdmiCecMock close the current callback.");
mCallback = nullptr;
mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr);
mCecThreadRun = false;
pthread_join(mThreadId, NULL);
}
}
HdmiCecMock::~HdmiCecMock() {
ALOGE("[halimp_aidl] HdmiCecMock shutting down.");
mCallback = nullptr;
mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr);
mCecThreadRun = false;
pthread_join(mThreadId, NULL);
ALOGD("[halimp_aidl] HdmiCecMock shutting down.");
closeCallback();
}
} // namespace implementation

View file

@ -55,6 +55,7 @@ struct HdmiCecMock : public BnHdmiCec {
::ndk::ScopedAStatus enableCec(bool value) override;
::ndk::ScopedAStatus enableSystemCecControl(bool value) override;
void printCecMsgBuf(const char* msg_buf, int len);
void closeCallback();
private:
static void* __threadLoop(void* data);
@ -62,9 +63,8 @@ struct HdmiCecMock : public BnHdmiCec {
int readMessageFromFifo(unsigned char* buf, int msgCount);
int sendMessageToFifo(const CecMessage& message);
void handleCecMessage(unsigned char* msgBuf, int length);
private:
static void serviceDied(void* cookie);
std::shared_ptr<IHdmiCecCallback> mCallback;
// Variables for the virtual cec hal impl