From 864a7f911751f984bd5cfdaaa04a5676ad4fdb91 Mon Sep 17 00:00:00 2001 From: Tianshi Liu Date: Fri, 4 Mar 2022 15:21:28 +0800 Subject: [PATCH] fix issue Change-Id: Iff69c36f5cc1e36f90a6d30c16280c0723cc0e82 --- LICENSE | 0 sa_profile/942.xml | 0 sa_profile/face_auth_service.rc | 0 services/BUILD.gn | 8 +-- services/ca_mock/include/buffer.h | 1 - services/ca_mock/include/defines.h | 2 +- services/ca_mock/include/face_auth_ca.h | 3 +- services/ca_mock/src/buffer.cpp | 45 +++---------- services/ca_mock/src/face_auth_ca.cpp | 22 ++++--- services/common/include/face_auth_defines.h | 8 +-- .../log/include/face_auth_log_wrapper.h | 12 ++-- services/faceauth/include/face_auth_event.h | 1 - .../include/face_auth_event_handler.h | 0 services/faceauth/include/face_auth_service.h | 0 .../src/face_auth_common_event_subscriber.cpp | 2 +- services/faceauth/src/face_auth_event.cpp | 10 --- .../faceauth/src/face_auth_event_handler.cpp | 0 services/faceauth/src/face_auth_manager.cpp | 63 ++++++++----------- services/faceauth/src/face_auth_service.cpp | 0 useriam.gni | 3 +- 20 files changed, 67 insertions(+), 113 deletions(-) mode change 100755 => 100644 LICENSE mode change 100755 => 100644 sa_profile/942.xml mode change 100755 => 100644 sa_profile/face_auth_service.rc mode change 100755 => 100644 services/faceauth/include/face_auth_event_handler.h mode change 100755 => 100644 services/faceauth/include/face_auth_service.h mode change 100755 => 100644 services/faceauth/src/face_auth_event_handler.cpp mode change 100755 => 100644 services/faceauth/src/face_auth_service.cpp mode change 100755 => 100644 useriam.gni diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/sa_profile/942.xml b/sa_profile/942.xml old mode 100755 new mode 100644 diff --git a/sa_profile/face_auth_service.rc b/sa_profile/face_auth_service.rc old mode 100755 new mode 100644 diff --git a/services/BUILD.gn b/services/BUILD.gn index 9d09be3..129fd28 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -35,6 +35,10 @@ ohos_shared_library("face_auth_service") { ] sources = [ + "//base/user_iam/face_auth/services/ca_mock/src/adaptor_algorithm.cpp", + "//base/user_iam/face_auth/services/ca_mock/src/buffer.cpp", + "//base/user_iam/face_auth/services/ca_mock/src/face_auth_ca.cpp", + "//base/user_iam/face_auth/services/ca_mock/src/face_auth_func.cpp", "//base/user_iam/face_auth/services/common/src/constant.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_camera.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_camera_buffer_listener.cpp", @@ -48,10 +52,6 @@ ohos_shared_library("face_auth_service") { "//base/user_iam/face_auth/services/faceauth/src/face_auth_req.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_service.cpp", "//base/user_iam/face_auth/services/faceauth/src/face_auth_thread_pool.cpp", - "//base/user_iam/face_auth/services/ca_mock/src/adaptor_algorithm.cpp", - "//base/user_iam/face_auth/services/ca_mock/src/buffer.cpp", - "//base/user_iam/face_auth/services/ca_mock/src/face_auth_ca.cpp", - "//base/user_iam/face_auth/services/ca_mock/src/face_auth_func.cpp", ] deps = [ diff --git a/services/ca_mock/include/buffer.h b/services/ca_mock/include/buffer.h index 49113ad..1684b14 100644 --- a/services/ca_mock/include/buffer.h +++ b/services/ca_mock/include/buffer.h @@ -34,7 +34,6 @@ ResultCode InitBuffer(Buffer *buffer, const uint8_t *buf, const uint32_t bufSize void DestoryBuffer(Buffer *buffer); Buffer *CopyBuffer(const Buffer *buffer); bool CompareBuffer(const Buffer *buffer1, const Buffer *buffer2); -Buffer *CreateBufferByData(const uint8_t *data, const uint32_t dataSize); ResultCode GetBufferData(const Buffer *buffer, uint8_t *data, uint32_t *dataSize); bool CheckBufferWithSize(const Buffer *buffer, const uint32_t size); } // namespace FaceAuth diff --git a/services/ca_mock/include/defines.h b/services/ca_mock/include/defines.h index fb18c2c..f0e2497 100644 --- a/services/ca_mock/include/defines.h +++ b/services/ca_mock/include/defines.h @@ -51,7 +51,7 @@ typedef enum AuthSubType { } AuthSubType; #define MAX_REMAIN_TIMES 5 -#define MAX_DULPLICATE_CHECK 100 +#define MAX_DUPLICATE_CHECK 100 } // namespace FaceAuth } // namespace UserIAM } // namespace OHOS diff --git a/services/ca_mock/include/face_auth_ca.h b/services/ca_mock/include/face_auth_ca.h index 8a84157..cb9cd42 100644 --- a/services/ca_mock/include/face_auth_ca.h +++ b/services/ca_mock/include/face_auth_ca.h @@ -52,6 +52,7 @@ typedef struct { uint64_t templateId = 0; std::vector coauthMsg; // coauth signed msg } AlgorithmResult; + typedef struct { int32_t resultCode; int32_t param[RESULT_MAX_SIZE]; @@ -101,7 +102,7 @@ private: private: void GetAuthResult(int32_t &result); FIRetCode GetAuthState(int32_t &authErrorCode, FICode &code, uint64_t reqId); - FIRetCode GetState(int32_t &resultCode, int32_t param[RESULT_MAX_SIZE]); + FIRetCode GetState(int32_t &resultCode, int32_t (¶m)[RESULT_MAX_SIZE]); void ReadFile(); int32_t SwitchAuthErrorCode(int32_t param); int32_t CheckIsCancel(int32_t &authErrorCode, FICode &code, uint64_t reqId); diff --git a/services/ca_mock/src/buffer.cpp b/services/ca_mock/src/buffer.cpp index e75dc94..925271e 100644 --- a/services/ca_mock/src/buffer.cpp +++ b/services/ca_mock/src/buffer.cpp @@ -48,22 +48,22 @@ Buffer *CreateBuffer(const uint32_t size) return nullptr; } - Buffer *buffer = new Buffer; + Buffer *buffer = (Buffer *)malloc(sizeof(Buffer)); if (buffer == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "Get buffer struct error"); return nullptr; } - buffer->buf = new uint8_t; + buffer->buf = (uint8_t *)malloc(size); if (buffer->buf == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "Get buffer error"); - delete buffer; + free(buffer); return nullptr; } if (memset_s(buffer->buf, size, 0, size) != EOK) { - delete buffer->buf; - delete buffer; + free(buffer->buf); + free(buffer); return nullptr; } buffer->maxSize = size; @@ -72,37 +72,6 @@ Buffer *CreateBuffer(const uint32_t size) return buffer; } -Buffer *CreateBufferByData(const uint8_t *data, const uint32_t dataSize) -{ - if ((data == nullptr) || (dataSize == 0) || (dataSize > MAX_BUFFER_SIZE)) { - FACEAUTH_HILOGE(MODULE_SERVICE, "Bad param size:%u", dataSize); - return nullptr; - } - - Buffer *buffer = new Buffer; - if (buffer == nullptr) { - FACEAUTH_HILOGE(MODULE_SERVICE, "Get buffer struct error"); - return nullptr; - } - - buffer->buf = new uint8_t; - if (buffer->buf == nullptr) { - FACEAUTH_HILOGE(MODULE_SERVICE, "Get buffer error"); - delete buffer; - return nullptr; - } - - if (memcpy_s(buffer->buf, dataSize, data, dataSize) != EOK) { - FACEAUTH_HILOGE(MODULE_SERVICE, "Cpy buffer error"); - DestoryBuffer(buffer); - return nullptr; - } - buffer->maxSize = dataSize; - buffer->contentSize = dataSize; - - return buffer; -} - ResultCode InitBuffer(Buffer *buffer, const uint8_t *buf, const uint32_t bufSize) { if (!IsBufferValid(buffer) || (buf == nullptr) || (bufSize == 0)) { @@ -126,12 +95,12 @@ void DestoryBuffer(Buffer *buffer) if (memset_s(buffer->buf, buffer->contentSize, 0, buffer->contentSize) != EOK) { FACEAUTH_HILOGE(MODULE_SERVICE, "DestoryBuffer memset fail!"); } - delete buffer->buf; + free(buffer->buf); buffer->buf = nullptr; buffer->contentSize = 0; buffer->maxSize = 0; } - delete buffer; + free(buffer); } } diff --git a/services/ca_mock/src/face_auth_ca.cpp b/services/ca_mock/src/face_auth_ca.cpp index 569aeb6..ddfbd0e 100644 --- a/services/ca_mock/src/face_auth_ca.cpp +++ b/services/ca_mock/src/face_auth_ca.cpp @@ -17,6 +17,7 @@ #include #include #include +#include "securec.h" #include "defines.h" #include "face_auth_func.h" @@ -50,7 +51,6 @@ static const char *RELEASE_FILENAME("/data/useriam/release.dat"); static const char *CONFIG_FILENAME("/data/useriam/config.dat"); static const char *FACEID_FILENAME("/data/useriam/faceId.dat"); static const char *AUTH_RESULT_FILENAME("/data/useriam/auth_result.dat"); -static const int32_t SLEEP_NUM = 2500; static const int32_t SLEEP_LONG_NUM = 2000; static const int32_t PARAM_RANGE = 10; static const int32_t TEST_ANGLT_START_NUM = 1000; @@ -196,12 +196,17 @@ int32_t FaceAuthCA::DeleteTemplate(uint64_t templateId) { FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); std::vector::const_iterator iter; - for (iter = templateIdList_.cbegin(); iter != templateIdList_.cend(); iter++) { + for (iter = templateIdList_.cbegin(); iter != templateIdList_.cend(); ++iter) { if (*iter == templateId) { - templateIdList_.erase(iter); - remainTimesMap_.erase(templateId); + break; } } + if (iter == templateIdList_.cend()) { + FACEAUTH_HILOGE(MODULE_SERVICE, "%{public}s template to delete not found.", __PRETTY_FUNCTION__); + return CA_RESULT_FAILED; + } + templateIdList_.erase(iter); + remainTimesMap_.erase(templateId); return CA_RESULT_SUCCESS; } @@ -245,6 +250,7 @@ int32_t FaceAuthCA::CancelAlgorithmOperation() Cancel(param_.scheduleId); return CA_RESULT_SUCCESS; } + void FaceAuthCA::SetAlgorithmParam(const AlgorithmParam ¶m) { param_ = param; @@ -325,17 +331,17 @@ FIRetCode FaceAuthCA::GetAuthState(int32_t &authErrorCode, FICode &code, uint64_ return result; } -FIRetCode FaceAuthCA::GetState(int32_t &resultCode, int32_t param[RESULT_MAX_SIZE]) +FIRetCode FaceAuthCA::GetState(int32_t &resultCode, int32_t (¶m)[RESULT_MAX_SIZE]) { - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_NUM)); ReadFile(); FACEAUTH_HILOGI(MODULE_SERVICE, "resultNum_ is %{public}d", resultNum_); FACEAUTH_HILOGI(MODULE_SERVICE, "resultInfos_.size() is %{public}d", resultInfos_.size()); if (resultNum_ < (int)resultInfos_.size()) { resultCode = resultInfos_[resultNum_].resultCode; FACEAUTH_HILOGI(MODULE_SERVICE, "memcpy length is %{public}d", sizeof(int32_t) * RESULT_MAX_SIZE); - if (memcpy(param, resultInfos_[resultNum_].param, - sizeof(int32_t) * RESULT_MAX_SIZE) != nullptr) { + if (memcpy_s(param, sizeof(param), resultInfos_[resultNum_].param, + sizeof(resultInfos_[resultNum_].param)) != EOK) { + FACEAUTH_HILOGE(MODULE_SERVICE, "memcpy_s fail"); return FIRetCode::FI_RC_ERROR; } if (resultNum_ >= 1 && resultInfos_[resultNum_ - 1].resultCode == FACE_DETECTED) { diff --git a/services/common/include/face_auth_defines.h b/services/common/include/face_auth_defines.h index df7fbcf..ec9d947 100644 --- a/services/common/include/face_auth_defines.h +++ b/services/common/include/face_auth_defines.h @@ -37,7 +37,6 @@ typedef enum { FACE_OPERATE_TYPE_LOCAL_AUTH, FACE_OPERATE_TYPE_CO_AUTH, FACE_OPERATE_TYPE_DEL, - FACE_OPERATE_TYPE_WAIT_INIT_ALGORITHM, FACE_OPERATE_TYPE_MAX, } FaceOperateType; @@ -75,6 +74,7 @@ static const int32_t UNUSED_PARAM_SIZE = 4; static const int32_t AUTH_FAIL_MAX_TIMES = 5; static const int32_t OPEN_CAMERA_TIME_OUT = 11000000; static const int32_t INIT_DYNAMIC_TIME_OUT = 5000000; +static const int32_t RELEASE_DYNAMIC_TIME_OUT = 5000000; static const int32_t GET_RESULT_TIME_OUT = 30000000; static const int32_t AUTH_FAIL_WAIT_TIME = 30; static const int32_t ALO_GETRESULT_PARAM_LEN = 10; @@ -104,9 +104,9 @@ static const int32_t FACE_COMMAND_INIT_ALGORITHM = 5; static const int32_t FACE_COMMAND_RELEASE_ALGORITHM = 6; // command from Co-Auth(OnGetProperty) static const int32_t FACE_COMMAND_GET = 1; -// alogrithm state from FaceAuth CA -static const int32_t FACE_ALOGRITHM_OPERATION_CONTINUE = 0; -static const int32_t FACE_ALOGRITHM_OPERATION_BREAK = 1; +// algorithm state from FaceAuth CA +static const int32_t FACE_ALGORITHM_OPERATION_CONTINUE = 0; +static const int32_t FACE_ALGORITHM_OPERATION_BREAK = 1; } typedef struct { uint64_t scheduleID = 0; diff --git a/services/common/log/include/face_auth_log_wrapper.h b/services/common/log/include/face_auth_log_wrapper.h index 65f1a50..8ba091d 100644 --- a/services/common/log/include/face_auth_log_wrapper.h +++ b/services/common/log/include/face_auth_log_wrapper.h @@ -25,7 +25,7 @@ namespace OHOS { namespace UserIAM { namespace FaceAuth { #define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) -#define FORMATED(fmt, ...) "[%{public}s] %{public}s# " fmt, FILENAME, __FUNCTION__, ##__VA_ARGS__ +#define FORMATTED(fmt, ...) "[%{public}s] %{public}s# " fmt, FILENAME, __FUNCTION__, ##__VA_ARGS__ #ifdef FACEAUTH_HILOGF #undef FACEAUTH_HILOGF @@ -66,15 +66,15 @@ static constexpr OHOS::HiviewDFX::HiLogLabel FACE_AUTH_LABEL[FACE_AUTH_MODULE_BU }; #define FACEAUTH_HILOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(FACE_AUTH_LABEL[module], \ - FORMATED(__VA_ARGS__)) + FORMATTED(__VA_ARGS__)) #define FACEAUTH_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(FACE_AUTH_LABEL[module], \ - FORMATED(__VA_ARGS__)) + FORMATTED(__VA_ARGS__)) #define FACEAUTH_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(FACE_AUTH_LABEL[module], \ - FORMATED(__VA_ARGS__)) + FORMATTED(__VA_ARGS__)) #define FACEAUTH_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(FACE_AUTH_LABEL[module], \ - FORMATED(__VA_ARGS__)) + FORMATTED(__VA_ARGS__)) #define FACEAUTH_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(FACE_AUTH_LABEL[module], \ - FORMATED(__VA_ARGS__)) + FORMATTED(__VA_ARGS__)) } // namespace FaceAuth } // namespace UserIAM } // namespace OHOS diff --git a/services/faceauth/include/face_auth_event.h b/services/faceauth/include/face_auth_event.h index f4cdb27..85fce3a 100644 --- a/services/faceauth/include/face_auth_event.h +++ b/services/faceauth/include/face_auth_event.h @@ -30,7 +30,6 @@ public: void ProcessAuthenticateTask(const AppExecFwk::InnerEvent::Pointer &event); void ProcessEnrollTask(const AppExecFwk::InnerEvent::Pointer &event); void ProcessRemoveTask(const AppExecFwk::InnerEvent::Pointer &event); - void ProcessWaitInitAlgorithmTask(const AppExecFwk::InnerEvent::Pointer &event); inline void SetEventHandler(const std::shared_ptr &handler) { eventHandler_ = handler; diff --git a/services/faceauth/include/face_auth_event_handler.h b/services/faceauth/include/face_auth_event_handler.h old mode 100755 new mode 100644 diff --git a/services/faceauth/include/face_auth_service.h b/services/faceauth/include/face_auth_service.h old mode 100755 new mode 100644 diff --git a/services/faceauth/src/face_auth_common_event_subscriber.cpp b/services/faceauth/src/face_auth_common_event_subscriber.cpp index 116101e..788c032 100644 --- a/services/faceauth/src/face_auth_common_event_subscriber.cpp +++ b/services/faceauth/src/face_auth_common_event_subscriber.cpp @@ -34,7 +34,7 @@ void FaceAuthCommonEventSubscriber::OnReceiveEvent(const CommonEventData &data) FACEAUTH_HILOGI(MODULE_SERVICE, "OnReceiveEvent enter"); OHOS::EventFwk::Want want = data.GetWant(); std::string action = want.GetAction(); - FACEAUTH_HILOGD(MODULE_SERVICE, "Recieved common event:%{public}s", action.c_str()); + FACEAUTH_HILOGD(MODULE_SERVICE, "Received common event:%{public}s", action.c_str()); if (action == REGISTER_NOTIFICATION) { callback_->Start(); return; diff --git a/services/faceauth/src/face_auth_event.cpp b/services/faceauth/src/face_auth_event.cpp index 6c310b9..e5449cf 100644 --- a/services/faceauth/src/face_auth_event.cpp +++ b/services/faceauth/src/face_auth_event.cpp @@ -67,10 +67,6 @@ void FaceAuthEvent::HandleTask(const AppExecFwk::InnerEvent::Pointer &event) ProcessRemoveTask(event); break; } - case FACE_OPERATE_TYPE_WAIT_INIT_ALGORITHM: { - ProcessWaitInitAlgorithmTask(event); - break; - } default: { FACEAUTH_HILOGI(MODULE_SERVICE, "operateType is invalid, %{public}d", operateType); break; @@ -119,12 +115,6 @@ void FaceAuthEvent::ProcessRemoveTask(const AppExecFwk::InnerEvent::Pointer &eve FaceAuthManager::GetInstance()->DoRemove(info); return; } -void FaceAuthEvent::ProcessWaitInitAlgorithmTask(const AppExecFwk::InnerEvent::Pointer &event) -{ - auto object = event->GetUniqueObject>(); - FaceAuthManager::GetInstance()->DoWaitInitAlgorithm(move(*object)); - return; -} } // namespace FaceAuth } // namespace UserIAM } // namespace OHOS diff --git a/services/faceauth/src/face_auth_event_handler.cpp b/services/faceauth/src/face_auth_event_handler.cpp old mode 100755 new mode 100644 diff --git a/services/faceauth/src/face_auth_manager.cpp b/services/faceauth/src/face_auth_manager.cpp index 34f0b42..5b9795a 100644 --- a/services/faceauth/src/face_auth_manager.cpp +++ b/services/faceauth/src/face_auth_manager.cpp @@ -19,6 +19,7 @@ #include #include #include +#include "securec.h" #include "face_auth_log_wrapper.h" #include "face_auth_event_handler.h" #include "auth_executor_registry.h" @@ -36,8 +37,8 @@ namespace OHOS { namespace UserIAM { namespace FaceAuth { const int RAND_NUM_BITS = 32; -const int TOP = 0; -const int BOTTOM = 1; +const int TOP = -1; +const int BOTTOM = 0; const int INVALID_EVENT_ID = -1; static const std::string FACE_LOCAL_INIT_ALGO_NAME = "face_auth_local_init"; std::shared_ptr FaceAuthManager::manager_ = nullptr; @@ -287,13 +288,10 @@ void FaceAuthManager::DoAuthenticate(const AuthParam ¶m) faceAuthCamera->CloseCamera(); this->ReleaseAlgorithm(FACE_LOCAL_INIT_ALGO_NAME); // remove require info - bool isCanceled = FaceAuthReq::GetInstance()->isCanceled(param.eventID, param.callerUID); - if (isCanceled) { - FaceReqType reqType = {}; - reqType.reqId = param.scheduleID; - reqType.operateType = FACE_OPERATE_TYPE_LOCAL_AUTH; - FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); - } + FaceReqType reqType = {}; + reqType.reqId = param.scheduleID; + reqType.operateType = FACE_OPERATE_TYPE_LOCAL_AUTH; + FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); } int32_t FaceAuthManager::AddEnrollmentRequest(const EnrollParam ¶m) { @@ -374,13 +372,10 @@ void FaceAuthManager::DoEnroll(const EnrollParam ¶m) faceAuthCamera->CloseCamera(); this->ReleaseAlgorithm(FACE_LOCAL_INIT_ALGO_NAME); // remove require info - bool isCanceled = FaceAuthReq::GetInstance()->isCanceled(param.eventID, param.callerUID); - if (isCanceled) { - FaceReqType reqType = {}; - reqType.reqId = param.scheduleID; - reqType.operateType = FACE_OPERATE_TYPE_ENROLL; - FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); - } + FaceReqType reqType = {}; + reqType.reqId = param.scheduleID; + reqType.operateType = FACE_OPERATE_TYPE_ENROLL; + FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); } int32_t FaceAuthManager::AddRemoveRequest(const RemoveParam ¶m) { @@ -455,11 +450,11 @@ FIRetCode FaceAuthManager::OperForAlgorithm(uint64_t scheduleID) while (1) { faceAuthCA->GetAlgorithmState(retCode, retCoauthMsg); FACEAUTH_HILOGI(MODULE_SERVICE, "receive new co auth message."); - uint32_t len; + uint32_t len = TOKEN_NUM; std::unique_ptr token_ptr = std::make_unique(TOKEN_NUM); GetAuthToken(token_ptr, len); uint8_t token[TOKEN_NUM]; - if (memcpy(token, token_ptr.get(), len) != nullptr) { + if (memcpy_s(token, sizeof(token), token_ptr.get(), len) != EOK) { FACEAUTH_HILOGE(MODULE_SERVICE, "GetAuthToken memcpy fail"); return FI_RC_ERROR; } @@ -470,8 +465,8 @@ FIRetCode FaceAuthManager::OperForAlgorithm(uint64_t scheduleID) if (msg != nullptr) { SendData(scheduleID, 0, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg); } - if (FACE_ALOGRITHM_OPERATION_BREAK == retCode) { - FACEAUTH_HILOGI(MODULE_SERVICE, "FACE_ALOGRITHM_OPERATION_BREAK."); + if (FACE_ALGORITHM_OPERATION_BREAK == retCode) { + FACEAUTH_HILOGI(MODULE_SERVICE, "FACE_ALGORITHM_OPERATION_BREAK."); break; } } @@ -586,20 +581,12 @@ FIRetCode FaceAuthManager::InitAlgorithm(std::string bundleName) std::future futureobj = promiseobj.get_future(); FaceAuthThreadPool::GetInstance()->AddTask( [&promiseobj]() { promiseobj.set_value(FaceAuthCA::GetInstance()->LoadAlgorithm()); }); - // send request - FaceReqType reqType = {}; - reqType.operateType = FACE_OPERATE_TYPE_WAIT_INIT_ALGORITHM; - FaceInfo faceInfo = {}; - faceInfo.eventId = GenerateEventId(); - if (faceInfo.eventId == INVALID_EVENT_ID) { - FACEAUTH_HILOGI(MODULE_SERVICE, "faceInfo.eventId is invalid."); + std::chrono::microseconds span(INIT_DYNAMIC_TIME_OUT); + while (futureobj.wait_for(span) == std::future_status::timeout) { + FACEAUTH_HILOGI(MODULE_SERVICE, "LoadAlgorithm TimeOut"); return FI_RC_ERROR; } - FaceAuthReq::GetInstance()->AddReqInfo(reqType, faceInfo); - auto info = std::make_unique>(move(futureobj)); - FaceAuthEventHandler::Priority priority = FaceAuthEventHandler::Priority::IMMEDIATE; - handler_->SendEvent(faceInfo.eventId, std::move(info), priority); - return FI_RC_OK; + return static_cast(futureobj.get()); } FACEAUTH_HILOGE(MODULE_SERVICE, "Init Fail %{public}d", result); return FI_RC_ERROR; @@ -613,10 +600,12 @@ FIRetCode FaceAuthManager::ReleaseAlgorithm(std::string bundleName) std::future futureobj = promiseobj.get_future(); FaceAuthThreadPool::GetInstance()->AddTask( [&promiseobj]() { promiseobj.set_value(FaceAuthCA::GetInstance()->ReleaseAlgorithm()); }); - if (futureobj.get() != FI_RC_OK) { - FACEAUTH_HILOGI(MODULE_SERVICE, "ReleaseAlgorithm Fail"); + std::chrono::microseconds span(RELEASE_DYNAMIC_TIME_OUT); + while (futureobj.wait_for(span) == std::future_status::timeout) { + FACEAUTH_HILOGI(MODULE_SERVICE, "ReleaseAlgorithm TimeOut"); return FI_RC_ERROR; } + return static_cast(futureobj.get()); } FACEAUTH_HILOGE(MODULE_SERVICE, "Release Fail %{public}d", result); return FI_RC_ERROR; @@ -727,13 +716,15 @@ bool FaceAuthManager::GetRandomNum(int32_t *randomNum) FACEAUTH_HILOGE(MODULE_SERVICE, "BN_new fail."); return false; } - if (BN_rand(bn, RAND_NUM_BITS, TOP, BOTTOM) != 0) { + if (BN_rand(bn, RAND_NUM_BITS, TOP, BOTTOM) == 0) { FACEAUTH_HILOGE(MODULE_SERVICE, "BN_rand fail."); + BN_free(bn); return false; } char *decVal = BN_bn2dec(bn); if (decVal == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "BN_bn2dec is nullptr."); + BN_free(bn); return false; } *randomNum = atoi(decVal); @@ -752,7 +743,7 @@ FIRetCode FaceAuthManager::DoWaitInitAlgorithm(std::future futureobj) int32_t FaceAuthManager::GetAuthToken(std::unique_ptr &authToken, uint32_t &len) { uint8_t at[] = {'A', 'u', 't', 'h', 'T', 'o', 'k', 'e', 'n', '\0'}; - if (memcpy(authToken.get(), at, sizeof(at)) != nullptr) { + if (memcpy_s(authToken.get(), len, at, sizeof(at)) != EOK) { FACEAUTH_HILOGE(MODULE_SERVICE, "GetAuthToken memcpy fail"); return FA_RET_ERROR; } diff --git a/services/faceauth/src/face_auth_service.cpp b/services/faceauth/src/face_auth_service.cpp old mode 100755 new mode 100644 diff --git a/useriam.gni b/useriam.gni old mode 100755 new mode 100644 index 0510be8..adc1bf4 --- a/useriam.gni +++ b/useriam.gni @@ -16,8 +16,7 @@ useriam_common_path = "${useriam_path}/common" face_auth_innerkits_path = "${useriam_path}/interfaces/innerkits/faceauth" useriam_auth_kits_path = "${useriam_path}/interfaces/kits" face_auth_services_path = "${useriam_path}/services/faceauth" -useriam_sa_path="${useriam_path}/sa_profile" +useriam_sa_path = "${useriam_path}/sa_profile" aafwk_path = "//foundation/aafwk/standard" appexecfwk_path = "//foundation/appexecfwk/standard" face_auth_test_app_path = "//test/xts/acts/user_iam/face_auth/cpp_api_scene_test/resource/faceauthtestability/abilitySrc" - -- Gitee