diff options
author | Reda ZAITI <reda.zaiti@thalesgroup.com> | 2023-10-03 12:09:12 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-10-03 12:09:12 +0000 |
commit | 6cbc132a861ce9a474e3a37547bd51cf77f339a5 (patch) | |
tree | e195a2f3f4a9f04aa5e4698c503e75a2662f4489 | |
parent | e8eb04b7f6c3fc09c3df9d4c2553e55731692b19 (diff) | |
parent | bcd012cdd0b7b2daf777bae7428628d213a15da1 (diff) | |
download | secure_element2-6cbc132a861ce9a474e3a37547bd51cf77f339a5.tar.gz |
Fix HIDL/AIDL status not checked am: 50072bdd17 am: 8db21d8678 am: a6d4c29fe2 am: 0c350cc916 am: bcd012cdd0
Original change: https://android-review.googlesource.com/c/platform/hardware/st/secure_element2/+/2752261
Change-Id: I60e3fe7577607754c2302edb8715978c36f12eac
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | secure_element/1.2/SecureElement.cpp | 74 | ||||
-rw-r--r-- | secure_element/1.2/SecureElement.h | 1 | ||||
-rw-r--r-- | secure_element/aidl/SecureElement.cpp | 25 | ||||
-rw-r--r-- | secure_element/aidl/SecureElement.h | 1 |
4 files changed, 57 insertions, 44 deletions
diff --git a/secure_element/1.2/SecureElement.cpp b/secure_element/1.2/SecureElement.cpp index d835e88..08e4dfb 100644 --- a/secure_element/1.2/SecureElement.cpp +++ b/secure_element/1.2/SecureElement.cpp @@ -151,10 +151,16 @@ Return<void> SecureElement::init(const sp<::android::hardware::secure_element::V if (initializeSE() != EXIT_SUCCESS) { ALOGE("SecureElement:%s initializeSE Failed", __func__); - clientCallback->onStateChange(false); + auto ret = clientCallback->onStateChange(false); + if (!ret.isOk()) { + ALOGW("failed to send onStateChange event!"); + } } else { ALOGD("SecureElement:%s initializeSE Success", __func__); - clientCallback->onStateChange(true); + auto ret = clientCallback->onStateChange(true); + if (!ret.isOk()) { + ALOGW("failed to send onStateChange event!"); + } } ALOGD("SecureElement:%s end", __func__); @@ -178,10 +184,16 @@ Return<void> SecureElement::init_1_1(const sp<::android::hardware::secure_elemen if (initializeSE() != EXIT_SUCCESS) { ALOGE("SecureElement:%s initializeSE Failed", __func__); - clientCallback->onStateChange_1_1(false, "SE Initialized failed"); + auto ret = clientCallback->onStateChange_1_1(false, "SE Initialized failed"); + if (!ret.isOk()) { + ALOGW("failed to send onStateChange event!"); + } } else { ALOGD("SecureElement:%s initializeSE Success", __func__); - clientCallback->onStateChange_1_1(true, "SE Initialized"); + auto ret = clientCallback->onStateChange_1_1(true, "SE Initialized"); + if (!ret.isOk()) { + ALOGW("failed to send onStateChange event!"); + } } ALOGD("SecureElement:%s end", __func__); @@ -250,12 +262,7 @@ Return<void> SecureElement::openLogicalChannel(const hidl_vec<uint8_t>& aid, uin if (!checkSeUp) { if (initializeSE() != EXIT_SUCCESS) { ALOGE("SecureElement:%s: Failed to re-initialise the eSE HAL", __func__); - if(internalClientCallback_v1_1 != nullptr) { - internalClientCallback_v1_1->onStateChange_1_1(false, "SE Initialized failed"); - } - else { - internalClientCallback->onStateChange(false); - } + notify(false, "SE Initialized failed"); _hidl_cb(resApduBuff, SecureElementStatus::IOERROR); return Void(); } @@ -450,12 +457,7 @@ Return<void> SecureElement::openBasicChannel(const hidl_vec<uint8_t>& aid, uint8 if (!checkSeUp) { if (initializeSE() != EXIT_SUCCESS) { ALOGE("SecureElement:%s: Failed to re-initialise the eSE HAL", __func__); - if(internalClientCallback_v1_1 != nullptr) { - internalClientCallback_v1_1->onStateChange_1_1(false, "SE Initialized failed"); - } - else { - internalClientCallback->onStateChange(false); - } + notify(false, "SE Initialized failed"); _hidl_cb(result, SecureElementStatus::IOERROR); return Void(); } @@ -616,6 +618,22 @@ Return<::android::hardware::secure_element::V1_0::SecureElementStatus> SecureEle } void +SecureElement::notify(bool state, const char *message) +{ + if (internalClientCallback_v1_1 != nullptr) { + auto ret = internalClientCallback_v1_1->onStateChange_1_1(state, message); + if (!ret.isOk()) { + ALOGW("failed to send onStateChange event!"); + } + } else { + auto ret = internalClientCallback->onStateChange(state); + if (!ret.isOk()) { + ALOGW("failed to send onStateChange event!"); + } + } +} + +void SecureElement::dump_bytes(const char *pf, char sep, const uint8_t *p, int n, FILE *out) { const uint8_t *s = p; @@ -784,11 +802,7 @@ SecureElement::deinitializeSE() { if(checkSeUp){ if (se_gto_close(ctx) < 0) { mSecureElementStatus = SecureElementStatus::FAILED; - if (internalClientCallback_v1_1 != nullptr) { - internalClientCallback_v1_1->onStateChange_1_1(false, "SE Initialized failed"); - } else { - internalClientCallback->onStateChange(false); - } + notify(false, "SE Initialized failed"); } else { ctx = NULL; mSecureElementStatus = SecureElementStatus::SUCCESS; @@ -821,11 +835,7 @@ SecureElement::reset() { ALOGE("SecureElement:%s deinitializeSE Failed", __func__); } - if (internalClientCallback_v1_1 != nullptr) { - internalClientCallback_v1_1->onStateChange_1_1(false, "reset the SE"); - } else { - internalClientCallback->onStateChange(false); - } + notify(false, "reset the SE"); if (eSE1ResetToolStr.length() > 0) { typedef int (*STEseReset)(); @@ -839,11 +849,7 @@ SecureElement::reset() { ALOGD("SecureElement:%s STResetTool Success", __func__); if (initializeSE() == EXIT_SUCCESS) { status = SecureElementStatus::SUCCESS; - if (internalClientCallback_v1_1 != nullptr) { - internalClientCallback_v1_1->onStateChange_1_1(true, "SE Initialized"); - } else { - internalClientCallback->onStateChange(true); - } + notify(true, "SE Initialized"); } } else { ALOGE("SecureElement:%s STResetTool Failed!", __func__); @@ -852,11 +858,7 @@ SecureElement::reset() { dlclose(stdll); } else { if (initializeSE() == EXIT_SUCCESS) { - if (internalClientCallback_v1_1 != nullptr) { - internalClientCallback_v1_1->onStateChange_1_1(true, "SE Initialized"); - } else { - internalClientCallback->onStateChange(true); - } + notify(true, "SE Initialized"); status = SecureElementStatus::SUCCESS; } } diff --git a/secure_element/1.2/SecureElement.h b/secure_element/1.2/SecureElement.h index 4c4bc05..b6142ec 100644 --- a/secure_element/1.2/SecureElement.h +++ b/secure_element/1.2/SecureElement.h @@ -68,6 +68,7 @@ struct SecureElement : public ISecureElement , public hidl_death_recipient { int resetSE(); int openConfigFile(int verbose); int parseConfigFile(FILE *f, int verbose); + void notify(bool state, const char *message); }; diff --git a/secure_element/aidl/SecureElement.cpp b/secure_element/aidl/SecureElement.cpp index 7a34242..79450f8 100644 --- a/secure_element/aidl/SecureElement.cpp +++ b/secure_element/aidl/SecureElement.cpp @@ -145,10 +145,10 @@ ScopedAStatus SecureElement::init(const std::shared_ptr<ISecureElementCallback>& if (initializeSE() != EXIT_SUCCESS) { ALOGE("SecureElement:%s initializeSE Failed", __func__); - clientCallback->onStateChange(false, "SE Initialized failed"); + notify(false, "SE Initialized failed"); } else { ALOGD("SecureElement:%s initializeSE Success", __func__); - clientCallback->onStateChange(true, "SE Initialized"); + notify(true, "SE Initialized"); } ALOGD("SecureElement:%s end", __func__); @@ -224,7 +224,7 @@ ScopedAStatus SecureElement::openLogicalChannel(const std::vector<uint8_t>& aid, if (!checkSeUp) { if (initializeSE() != EXIT_SUCCESS) { ALOGE("SecureElement:%s: Failed to re-initialise the eSE HAL", __func__); - internalClientCallback->onStateChange(false, "SE Initialized failed"); + notify(false, "SE Initialized failed"); return ScopedAStatus::fromServiceSpecificError(IOERROR); } } @@ -421,7 +421,7 @@ ScopedAStatus SecureElement::openBasicChannel(const std::vector<uint8_t>& aid, i if (!checkSeUp) { if (initializeSE() != EXIT_SUCCESS) { ALOGE("SecureElement:%s: Failed to re-initialise the eSE HAL", __func__); - internalClientCallback->onStateChange(false, "SE Initialized failed"); + notify(false, "SE Initialized failed"); return ScopedAStatus::fromServiceSpecificError(IOERROR); } } @@ -582,6 +582,15 @@ ScopedAStatus SecureElement::closeChannel(int8_t channelNumber) { } void +SecureElement::notify(bool state, const char *message) +{ + auto ret = internalClientCallback->onStateChange(state, message); + if (!ret.isOk()) { + ALOGW("failed to send onStateChange event!"); + } +} + +void SecureElement::dump_bytes(const char *pf, char sep, const uint8_t *p, int n, FILE *out) { const uint8_t *s = p; @@ -733,7 +742,7 @@ int SecureElement::deinitializeSE() { if(checkSeUp){ if (se_gto_close(ctx) < 0) { mSecureElementStatus = FAILED; - internalClientCallback->onStateChange(false, "SE Initialized failed"); + notify(false, "SE Initialized failed"); } else { ctx = NULL; mSecureElementStatus = SUCCESS; @@ -769,7 +778,7 @@ ScopedAStatus SecureElement::reset() { return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); } - internalClientCallback->onStateChange(false, "reset the SE"); + notify(false, "reset the SE"); if (eSE1ResetToolStr.length() > 0) { typedef int (*STEseReset)(); @@ -783,7 +792,7 @@ ScopedAStatus SecureElement::reset() { ALOGD("SecureElement:%s STResetTool Success", __func__); if (initializeSE() == EXIT_SUCCESS) { status = SUCCESS; - internalClientCallback->onStateChange(true, "SE Initialized"); + notify(true, "SE Initialized"); } } else { ALOGE("SecureElement:%s STResetTool Failed!", __func__); @@ -792,7 +801,7 @@ ScopedAStatus SecureElement::reset() { dlclose(stdll); } else { if (initializeSE() == EXIT_SUCCESS) { - internalClientCallback->onStateChange(true, "SE Initialized"); + notify(true, "SE Initialized"); status = SUCCESS; } } diff --git a/secure_element/aidl/SecureElement.h b/secure_element/aidl/SecureElement.h index dc85042..86a3539 100644 --- a/secure_element/aidl/SecureElement.h +++ b/secure_element/aidl/SecureElement.h @@ -56,6 +56,7 @@ struct SecureElement : public BnSecureElement { int resetSE(); int openConfigFile(int verbose); int parseConfigFile(FILE *f, int verbose); + void notify(bool state, const char *message); }; } //se |