diff --git a/services/faceauth/src/face_auth_camera.cpp b/services/faceauth/src/face_auth_camera.cpp index bcb52c9af69335bfe52ff2e2e46cef36a48cc4f6..57c9de67dbabba10a24ea37e9beafa7b3b8a1e93 100644 --- a/services/faceauth/src/face_auth_camera.cpp +++ b/services/faceauth/src/face_auth_camera.cpp @@ -53,8 +53,11 @@ sptr FaceAuthCamera::CreatePreviewOutput( { FACEAUTH_HILOGI(MODULE_SERVICE, "CreatePreviewOutput."); sptr previewBuffer = Surface::CreateSurfaceAsConsumer(); + // Tianshi: 判空?? previewBuffer->SetDefaultWidthAndHeight(PREVIEW_DEFAULT_WIDTH, PREVIEW_DEFAULT_HEIGHT); + // Tianshi: shared ptr 使用make shared创建? sptr listener = new FaceAuthCameraBufferListener(); + // Tianshi: 判空?? listener->cameraBuffer_ = previewBuffer; previewBuffer->RegisterConsumerListener((sptr &) listener); sptr previewOutput = camManagerObj->CreatePreviewOutput(previewBuffer); diff --git a/services/faceauth/src/face_auth_camera_buffer_listener.cpp b/services/faceauth/src/face_auth_camera_buffer_listener.cpp index 679753d8827ac5a4f3e0a5f0c8e777ea8668ea47..62a1f0849b5d91842b0c87f70687f178fe7090b8 100644 --- a/services/faceauth/src/face_auth_camera_buffer_listener.cpp +++ b/services/faceauth/src/face_auth_camera_buffer_listener.cpp @@ -25,6 +25,7 @@ int32_t FaceAuthCameraBufferListener::SendCameraImage(OHOS::sptr faceAuthCA = FaceAuthCA::GetInstance(); if (faceAuthCA == nullptr) { + // tianshi: 异常分支要加日志 + // 请排查修改 return -1; } faceAuthCA->TransferImageToAlgorithm(image); diff --git a/services/faceauth/src/face_auth_event.cpp b/services/faceauth/src/face_auth_event.cpp index 941c2fc48fd6dad7b992e88d042534ebb4c192e2..1661f2d7cd0252f3a461aa47d5a2795ce690bd8f 100644 --- a/services/faceauth/src/face_auth_event.cpp +++ b/services/faceauth/src/face_auth_event.cpp @@ -55,6 +55,8 @@ void FaceAuthEvent::HandleTask(const AppExecFwk::InnerEvent::Pointer &event) FACEAUTH_HILOGI(MODULE_SERVICE,"operateType is %{public}d", operateType); switch (operateType) { case FACE_OPERATE_TYPE_LOCAL_AUTH: { + // tianshi: 动词开头,AuthenticateTask等等 + // 排查 AuthenticateTask(event); break; } diff --git a/services/faceauth/src/face_auth_executor_callback.cpp b/services/faceauth/src/face_auth_executor_callback.cpp index 8475c5fcbc9f8a07b898eac190b4715d1cbd5538..82714e5d8dbbac5a433526a329936ed55aa5a8f3 100644 --- a/services/faceauth/src/face_auth_executor_callback.cpp +++ b/services/faceauth/src/face_auth_executor_callback.cpp @@ -42,6 +42,8 @@ int32_t ExecutorCallback::OnBeginExecute(uint64_t scheduleId, std::vectorGetUint64Value(AUTH_TEMPLATE_ID, templateID); diff --git a/services/faceauth/src/face_auth_manager.cpp b/services/faceauth/src/face_auth_manager.cpp index cdf9fd46439c10123b72a43fdd608e447f3cd4a8..7a3c95f6d002a67ba02f2032143b6d8c9fb60f1f 100755 --- a/services/faceauth/src/face_auth_manager.cpp +++ b/services/faceauth/src/face_auth_manager.cpp @@ -49,6 +49,8 @@ int32_t FaceAuthManager::Init() // run event handler std::string threadName("FaceAuthEventRunner"); runner_ = AppExecFwk::EventRunner::Create(threadName); + // tianshi: 改成 == null 直接点 + // 排查 if (!runner_) { FACEAUTH_HILOGE(MODULE_SERVICE, "failed to create a runner."); return FA_RET_ERROR; @@ -149,6 +151,8 @@ int32_t FaceAuthManager::Release() return FA_RET_OK; } +// tianshi: 改下名吧 这里是 ProcessAuthenticationRequest +// 其他请求处理函数同理 int32_t FaceAuthManager::Authenticate(const AuthParam ¶m) { FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); @@ -164,6 +168,8 @@ int32_t FaceAuthManager::Authenticate(const AuthParam ¶m) FACEAUTH_HILOGE(MODULE_SERVICE,"FaceAuthManager::Auth Need Init."); return FA_RET_ERROR; } + // tianshi: 变量和结构体,使用前必须用 = {} 清零 + // 请排查修改 FaceReqType reqType; reqType.reqId = param.scheduleID; reqType.operateType = FACE_OPERATE_TYPE_LOCAL_AUTH; @@ -181,12 +187,15 @@ int32_t FaceAuthManager::Authenticate(const AuthParam ¶m) handler_->SendEvent(faceInfo.eventId, std::move(authInfo), priority); return FA_RET_OK; } + +// tianshi: 改下名吧 这里是 DoAuthenticate void FaceAuthManager::HandleCallAuthenticate(const AuthParam ¶m) { //remove require info FaceReqType reqType; reqType.reqId = param.scheduleID; reqType.operateType = FACE_OPERATE_TYPE_LOCAL_AUTH; + // tianshi 在这里删除过早,移到StartAlgorithmOperation后面 FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); //check param if (param.templateID < 0) { @@ -207,12 +216,16 @@ void FaceAuthManager::HandleCallAuthenticate(const AuthParam ¶m) AlgorithmParam algorithmParam; algorithmParam.scheduleId = param.scheduleID; algorithmParam.templateId = param.templateID; + // tianshi: 如果在StartAlgorithmOperation调用faceAuthCA cancel算法不会处理cancel事件 + // 因此要在StartAlgorithmOperation后,再次判断是否cancel,此后才能RemoveRequireInfo + // Enroll 流程同理 int32_t iRet = faceAuthCA->StartAlgorithmOperation(algorithmOperation, algorithmParam); if (iRet != FA_RET_OK) { FACEAUTH_HILOGE(MODULE_SERVICE,"StartAlgorithmOperation failed"); return; } // receive algorithm message and handle algorithm result + // tianshi: 这个函数实际上是在等待认证流程结束,换个名字吧,返回值要打日志 if(GetAuthMessage(param.scheduleID) != FA_RET_OK) { return; } @@ -234,6 +247,7 @@ int32_t FaceAuthManager::Enrollment(const EnrollParam ¶m) return FA_RET_ERROR; } //check algorithm init + // tianshi: IsAlgorithmInited 放到执行时判断 if (IsAlgorithmInited()) { FACEAUTH_HILOGE(MODULE_SERVICE,"FaceAuthManager::Enroll Need Init."); return FA_RET_ERROR; @@ -262,6 +276,7 @@ void FaceAuthManager::HandleCallEnroll(const EnrollParam ¶m) reqType.reqId = param.scheduleID; reqType.operateType = FACE_OPERATE_TYPE_ENROLL; FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); + // tianshi: 在这里检查下算法 //check param if (param.templateID < 0) { FACEAUTH_HILOGI(MODULE_SERVICE, "Parameter check error."); @@ -307,7 +322,7 @@ int32_t FaceAuthManager::Remove(const RemoveParam ¶m) FACEAUTH_HILOGI(MODULE_SERVICE, "Parameter check error."); return FA_RET_ERROR; } - //check algorithm init + // tianshi: remove 不需要检查算法是否初始化 if (IsAlgorithmInited()) { FACEAUTH_HILOGE(MODULE_SERVICE,"FaceAuthManager::Remove Need Init."); return FA_RET_ERROR; @@ -346,6 +361,7 @@ void FaceAuthManager::HandleCallRemove(const RemoveParam ¶m) FACEAUTH_HILOGE(MODULE_SERVICE, "faceAuthCA instance is null."); return; } + // tianshi: 拼写错误 int32_t iRet = faceAuthCA->DeleteTemplete(param.templateID); if (FA_RET_OK == iRet) { FACEAUTH_HILOGI(MODULE_SERVICE, "Remove success."); @@ -362,6 +378,8 @@ FIRetCode FaceAuthManager::OperForAlgorithm(uint64_t scheduleID) } int32_t retCode = 0; std::vector retCoauthMsg; + // tianshi: 同一个类是不是直接 this-> 就可以了 + // 排查 std::shared_ptr manager = FaceAuthManager::GetInstance(); if (manager == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "init manager failed."); @@ -415,17 +433,22 @@ int32_t FaceAuthManager::CancelAuth(const AuthParam ¶m) reqType.reqId = param.scheduleID; reqType.operateType = FACE_OPERATE_TYPE_LOCAL_AUTH; int32_t uId = param.callerUID; + // tianshi:改为setCancelFlagSuccess ? + // 这里的逻辑没看懂,是不是如果还在队列里存在,就setFlag,不在说明已经处理中,调CancelAlogrithmOperation? + // CancelEnroll也要改下 bool isSuccess = FaceAuthReq::GetInstance()->SetCancelFlag(reqType, uId); if (!isSuccess) { FACEAUTH_HILOGE(MODULE_SERVICE,"CancelAuth failed,reqId: xxxx%04llu, ", reqType.reqId); result = FA_RET_ERROR; } + // tianshi: else ? if (isSuccess) { std::shared_ptr faceAuthCA = FaceAuthCA::GetInstance(); if (faceAuthCA == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE,"FaceAuthCA instance is null"); return result; } + // tianshi 拼写错误 result = faceAuthCA->CancelAlogrithmOperation(); if(result == FA_RET_OK) { FACEAUTH_HILOGI(MODULE_SERVICE,"CancelAlogrithmOperation success"); @@ -507,6 +530,7 @@ FIRetCode FaceAuthManager::InitAlgorithm(std::string bundleName) FaceAuthThreadPool::GetInstance()->AddTask( [&promiseobj]() { promiseobj.set_value(FaceAuthCA::GetInstance()->LoadAlgorithm()); }); std::chrono::microseconds span(INIT_DYNAMIC_TIME_OUT); + // tianshi: 加载算法有可能很耗时,需要起个IMMEDIATE级别的Request,不能在这里等 while (futureobj.wait_for(span) == std::future_status::timeout) { FACEAUTH_HILOGI(MODULE_SERVICE,"LoadAlgorithm TimeOut"); return FI_RC_ERROR; @@ -519,6 +543,7 @@ FIRetCode FaceAuthManager::InitAlgorithm(std::string bundleName) FIRetCode FaceAuthManager::ReleaseAlgorithm(std::string bundleName) { FACEAUTH_HILOGI(MODULE_SERVICE,"Release ,bundleName:%{public}s", bundleName.c_str()); + // tianshi: 因为INIT是Request,Release也需要是Task AlgoResult result = IsNeedAlgoRelease(bundleName); if (result == AR_EMPTY) { if(FA_RET_OK == FaceAuthCA::GetInstance()->ReleaseAlgorithm()) { @@ -581,6 +606,9 @@ uint32_t FaceAuthManager::GenerateEventId() t.tv_sec = 0; t.tv_nsec = 0; clock_gettime(CLOCK_REALTIME, &t); + // tianshi: + // 用时间作为随机数种子,eventId有可能被构造成重复的 + // 1. 建议使用openssl等安全随机数生成方式 int64_t elapsedTime { ((t.tv_sec) * SEC_TO_NANOSEC + t.tv_nsec) }; size_t elapsedHash = std::hash()(std::to_string(elapsedTime)); uint32_t eventId = static_cast(elapsedHash); diff --git a/services/faceauth/src/face_auth_req.cpp b/services/faceauth/src/face_auth_req.cpp index ea181155918162549b4785f1ffef15cda855aa8b..cc56edbf9a863194de46d4cb8b7d276df38a7ba3 100644 --- a/services/faceauth/src/face_auth_req.cpp +++ b/services/faceauth/src/face_auth_req.cpp @@ -44,6 +44,7 @@ std::shared_ptr FaceAuthReq::GetInstance() bool FaceAuthReq::IsReqNumReachedMax(FaceOperateType type) { std::lock_guard lock_l(mutex_); + // tianshi: 打印全部Request提取个函数吧 for (auto iterinfo = reqInfoList_.begin(); iterinfo != reqInfoList_.end(); ++iterinfo) { FACEAUTH_HILOGI(MODULE_SERVICE, "ListInfo:reqId:xxxx%04llu,Type:%{public}d,eventId:%{public}u,uId:%{public}d,isCanceled:%{public}d", @@ -51,6 +52,7 @@ bool FaceAuthReq::IsReqNumReachedMax(FaceOperateType type) iterinfo->second.isCanceled); } FACEAUTH_HILOGI(MODULE_SERVICE,"type is %{public}d", type); + // tianshi: type <= FACE_INVALID_OPERATE_TYPE ?? if (type > FACE_OPERATE_TYPE_MAX || type < FACE_INVALID_OPERATE_TYPE) { FACEAUTH_HILOGE(MODULE_SERVICE,"Parameter check error.type is %{public}d", type); return true; @@ -62,6 +64,7 @@ bool FaceAuthReq::IsReqNumReachedMax(FaceOperateType type) count++; } } + // tianshi: 新增一个后超过CO_AUTH_MAX_NUM,是不是要count >= CO_AUTH_MAX_NUM - 1 ? if (count >= CO_AUTH_MAX_NUM) { return true; } @@ -80,15 +83,18 @@ bool FaceAuthReq::IsReqNumReachedMax(FaceOperateType type) void FaceAuthReq::AddReqInfo(FaceReqType reqType, FaceInfo reqInfo) { std::lock_guard lock_l(mutex_); + // tianshi: 在一行打印吧 FACEAUTH_HILOGI(MODULE_SERVICE,"reqType.reqId is xxxx%04llu", reqType.reqId); FACEAUTH_HILOGI(MODULE_SERVICE,"reqType.operateType is %{public}d", reqType.operateType); FACEAUTH_HILOGI(MODULE_SERVICE,"reqInfo.eventId is %{public}u", reqInfo.eventId); FACEAUTH_HILOGI(MODULE_SERVICE,"reqInfo.uId is %{public}d", reqInfo.uId); FACEAUTH_HILOGI(MODULE_SERVICE,"reqInfo.isCanceled is %{public}d", reqInfo.isCanceled); + // tianshi: type <= FACE_INVALID_OPERATE_TYPE ?? if (reqType.operateType < FACE_INVALID_OPERATE_TYPE || reqType.operateType > FACE_OPERATE_TYPE_MAX) { FACEAUTH_HILOGE(MODULE_SERVICE,"Parameter check error.reqInfo.operateType is %{public}d", reqType.operateType); return; } + // tianshi: 添加前判断是否有重复key reqInfoList_.insert(std::pair(reqType, reqInfo)); return; } @@ -96,18 +102,22 @@ void FaceAuthReq::AddReqInfo(FaceReqType reqType, FaceInfo reqInfo) void FaceAuthReq::RemoveRequireInfo(FaceReqType reqType) { std::lock_guard lock_l(mutex_); + // tianshi: 打印全部Request提取个函数吧 for (auto iter = reqInfoList_.begin(); iter != reqInfoList_.end(); ++iter) { FACEAUTH_HILOGI(MODULE_SERVICE, "Remove before reqId:xxxx%04llu,Type:%{public}d,eventId:%{public}d,uId:%{public}d,isCanceled:%{public}d", iter->first.reqId, iter->first.operateType, iter->second.eventId, iter->second.uId, iter->second.isCanceled); } + // tianshi: 在一行打印吧 FACEAUTH_HILOGI(MODULE_SERVICE,"Remove reqType.reqId is xxxx%04llu", reqType.reqId); FACEAUTH_HILOGI(MODULE_SERVICE,"Remove reqType.operateType is %{public}d", reqType.operateType); + // tianshi: iterrm 小驼峰如:req2Rm auto iterrm = reqInfoList_.find(reqType); if (iterrm != reqInfoList_.end()) { reqInfoList_.erase(reqType); } + // tianshi: 找不到打个日志 return; } diff --git a/services/faceauth/src/face_auth_service.cpp b/services/faceauth/src/face_auth_service.cpp index d89c1f1672c369f3a1a051854e40ab1ca1e2e753..e6f6a687bd243656bf2a6b45b9e141b01090866e 100755 --- a/services/faceauth/src/face_auth_service.cpp +++ b/services/faceauth/src/face_auth_service.cpp @@ -20,6 +20,7 @@ namespace OHOS { namespace UserIAM { namespace FaceAuth { +// tianshi: 24 25 两行定义的变量,疑似无使用?? std::mutex FaceAuthService::mutex_; std::shared_ptr FaceAuthService::instance_ = nullptr; std::shared_ptr FaceAuthService::manager_ = nullptr; diff --git a/services/temp/include/face_auth_ca.h b/services/temp/include/face_auth_ca.h index b03ee7fb33560e325cdd2647c86385b6d24f26cd..bbabe84aab2fc11b962f84b81d0a82410b7681e6 100644 --- a/services/temp/include/face_auth_ca.h +++ b/services/temp/include/face_auth_ca.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +// tianshi: 这里是CA的mock实现,文件夹名称不要叫tmp, 可以叫ca_mock #ifndef FACE_AUTH_CA_H #define FACE_AUTH_CA_H #include "face_auth_defines.h" diff --git a/services/temp/src/adaptor_memory.cpp b/services/temp/src/adaptor_memory.cpp index f9efe83bf22ea5959edd9af5cf5976ebbf3b9db3..cd59d1a9ff4a7d8981bdb49fc2c1396ca9f33d13 100644 --- a/services/temp/src/adaptor_memory.cpp +++ b/services/temp/src/adaptor_memory.cpp @@ -18,6 +18,8 @@ namespace OHOS { namespace UserIAM { namespace FaceAuth { +// tianshi: 自定义的函数不要和原版只有大小写差异,可以叫SafeMalloc +// 排查 void *Malloc(const size_t size) { if (size == 0) { diff --git a/services/temp/src/face_auth_ca.cpp b/services/temp/src/face_auth_ca.cpp index e8d3ced512d2e059de2192abdb56b088b92a9f03..cf14a04fcc5952c0a9d5d8d559e63870dfefd4fc 100644 --- a/services/temp/src/face_auth_ca.cpp +++ b/services/temp/src/face_auth_ca.cpp @@ -21,6 +21,7 @@ std::shared_ptr FaceAuthCA::GetInstance() { int32_t FaceAuthCA::Init() { FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); GenerateKeyPair(); + // tianshi: 返回值不要用魔术字 引用/定义个 宏 return 0; } @@ -53,6 +54,8 @@ int32_t FaceAuthCA::TransferImageToAlgorithm(CameraImage images) { } void FaceAuthCA::GetAlgorithmState(int32_t &retCode, std::vector &retCoauthMsg) { + // tianshi: GetAlgorithmState 需要有桩实现,从文件中读取acquireInfo,编码签名后返回给上层 + // 以验证 GetAlgorithmState -> onAcquire 流程OK,便于UX调试 retCode = 1; (void)(retCoauthMsg); return ; diff --git a/services/temp/src/face_auth_func.cpp b/services/temp/src/face_auth_func.cpp index 66ecb746719c7c3e88183707a7a90d738be127f6..4f8f22889607cf6669ba295d4380bd8ef2208557 100644 --- a/services/temp/src/face_auth_func.cpp +++ b/services/temp/src/face_auth_func.cpp @@ -89,6 +89,7 @@ static Buffer *GetDataTlvContent(uint32_t result, uint64_t scheduleId, uint64_t ResultCode GenerateRetTlv(uint32_t result, uint64_t scheduleId, uint64_t subType, uint64_t templatedId, Buffer *retTlv) { + // tianshi: IsEd25519KeyPairValid(g_keyPair) 并不是入参,请单独判断 if (!IsBufferValid(retTlv) || !IsEd25519KeyPairValid(g_keyPair)) { FACEAUTH_HILOGE(MODULE_SERVICE,"param is invalid."); return RESULT_BAD_PARAM; @@ -134,6 +135,7 @@ ResultCode DoGetExecutorInfo(std::vector &vPubKey, uint32_t &esl, uint6 } uint32_t pubKeyLen = CONST_PUB_KEY_LEN; uint8_t pubKey[CONST_PUB_KEY_LEN]; + // tianshi: 用SetResultTlv里的方式效率更高,可以提取一个copy buffer to vector 的函数 if (GetBufferData(g_keyPair->pubKey, pubKey, &pubKeyLen) != RESULT_SUCCESS) { FACEAUTH_HILOGE(MODULE_SERVICE,"GetBufferData fail!"); return RESULT_UNKNOWN; @@ -144,6 +146,7 @@ ResultCode DoGetExecutorInfo(std::vector &vPubKey, uint32_t &esl, uint6 vPubKey.push_back(pubKey[index]); } esl = FACE_EXECUTOR_SECURITY_LEVEL; + // tianshi: 拼写错误,使用工具排查 authAbility = FACE_AUTH_AIBNILITY; return RESULT_SUCCESS; }