Merge "Hdmi CEC Mock : Clear the existing callback when new callback is set" into main
This commit is contained in:
commit
ad148cc9f9
2 changed files with 21 additions and 15 deletions
|
@ -35,8 +35,7 @@ namespace implementation {
|
||||||
void HdmiCecMock::serviceDied(void* cookie) {
|
void HdmiCecMock::serviceDied(void* cookie) {
|
||||||
ALOGE("HdmiCecMock died");
|
ALOGE("HdmiCecMock died");
|
||||||
auto hdmiCecMock = static_cast<HdmiCecMock*>(cookie);
|
auto hdmiCecMock = static_cast<HdmiCecMock*>(cookie);
|
||||||
hdmiCecMock->mCecThreadRun = false;
|
hdmiCecMock->closeCallback();
|
||||||
pthread_join(hdmiCecMock->mThreadId, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedAStatus HdmiCecMock::addLogicalAddress(CecLogicalAddress addr, Result* _aidl_return) {
|
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) {
|
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.
|
closeCallback();
|
||||||
mCallback = callback;
|
|
||||||
|
|
||||||
if (callback != nullptr) {
|
if (callback != nullptr) {
|
||||||
|
mCallback = callback;
|
||||||
mDeathRecipient =
|
mDeathRecipient =
|
||||||
ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(serviceDied));
|
ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(serviceDied));
|
||||||
AIBinder_linkToDeath(callback->asBinder().get(), mDeathRecipient.get(), this /* cookie */);
|
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) {
|
ScopedAStatus HdmiCecMock::setLanguage(const std::string& language) {
|
||||||
if (language.size() != 3) {
|
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();
|
return ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
// TODO Validate if language is a valid language code
|
// 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
|
// Open the output pipe for writing outgoing cec message
|
||||||
mOutputFile = open(CEC_MSG_OUT_FIFO, O_WRONLY | O_CLOEXEC);
|
mOutputFile = open(CEC_MSG_OUT_FIFO, O_WRONLY | O_CLOEXEC);
|
||||||
if (mOutputFile < 0) {
|
if (mOutputFile < 0) {
|
||||||
ALOGD("[halimp_aidl] file open failed for writing");
|
ALOGE("[halimp_aidl] file open failed for writing");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,17 +257,24 @@ void HdmiCecMock::threadLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
HdmiCecMock::HdmiCecMock() {
|
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;
|
mCallback = nullptr;
|
||||||
mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(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() {
|
HdmiCecMock::~HdmiCecMock() {
|
||||||
ALOGE("[halimp_aidl] HdmiCecMock shutting down.");
|
ALOGD("[halimp_aidl] HdmiCecMock shutting down.");
|
||||||
mCallback = nullptr;
|
closeCallback();
|
||||||
mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr);
|
|
||||||
mCecThreadRun = false;
|
|
||||||
pthread_join(mThreadId, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
|
|
|
@ -55,6 +55,7 @@ struct HdmiCecMock : public BnHdmiCec {
|
||||||
::ndk::ScopedAStatus enableCec(bool value) override;
|
::ndk::ScopedAStatus enableCec(bool value) override;
|
||||||
::ndk::ScopedAStatus enableSystemCecControl(bool value) override;
|
::ndk::ScopedAStatus enableSystemCecControl(bool value) override;
|
||||||
void printCecMsgBuf(const char* msg_buf, int len);
|
void printCecMsgBuf(const char* msg_buf, int len);
|
||||||
|
void closeCallback();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void* __threadLoop(void* data);
|
static void* __threadLoop(void* data);
|
||||||
|
@ -62,9 +63,8 @@ struct HdmiCecMock : public BnHdmiCec {
|
||||||
int readMessageFromFifo(unsigned char* buf, int msgCount);
|
int readMessageFromFifo(unsigned char* buf, int msgCount);
|
||||||
int sendMessageToFifo(const CecMessage& message);
|
int sendMessageToFifo(const CecMessage& message);
|
||||||
void handleCecMessage(unsigned char* msgBuf, int length);
|
void handleCecMessage(unsigned char* msgBuf, int length);
|
||||||
|
|
||||||
private:
|
|
||||||
static void serviceDied(void* cookie);
|
static void serviceDied(void* cookie);
|
||||||
|
|
||||||
std::shared_ptr<IHdmiCecCallback> mCallback;
|
std::shared_ptr<IHdmiCecCallback> mCallback;
|
||||||
|
|
||||||
// Variables for the virtual cec hal impl
|
// Variables for the virtual cec hal impl
|
||||||
|
|
Loading…
Reference in a new issue