1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FACE_AUTH_EXECUTOR_HDI_H 17 #define FACE_AUTH_EXECUTOR_HDI_H 18 19 #include <cstdint> 20 #include <map> 21 #include <vector> 22 23 #include "nocopyable.h" 24 25 #include "ibuffer_producer.h" 26 27 #include "face_auth_hdi.h" 28 #include "iam_executor_framework_types.h" 29 #include "iam_executor_iauth_executor_hdi.h" 30 #include "iam_executor_iexecute_callback.h" 31 32 namespace OHOS { 33 namespace UserIam { 34 namespace FaceAuth { 35 namespace UserAuth = OHOS::UserIam::UserAuth; 36 class FaceAuthExecutorHdi : public std::enable_shared_from_this<FaceAuthExecutorHdi>, 37 public UserAuth::IAuthExecutorHdi, 38 public NoCopyable { 39 public: 40 explicit FaceAuthExecutorHdi(sptr<IExecutor> executorProxy); 41 ~FaceAuthExecutorHdi() override = default; 42 43 UserAuth::ResultCode GetExecutorInfo(UserAuth::ExecutorInfo &info) override; 44 UserAuth::ResultCode OnRegisterFinish(const std::vector<uint64_t> &templateIdList, 45 const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) override; 46 UserAuth::ResultCode Enroll(uint64_t scheduleId, const UserAuth::EnrollParam ¶m, 47 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override; 48 UserAuth::ResultCode Authenticate(uint64_t scheduleId, const UserAuth::AuthenticateParam ¶m, 49 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override; 50 UserAuth::ResultCode Identify(uint64_t scheduleId, const UserAuth::IdentifyParam ¶m, 51 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override; 52 UserAuth::ResultCode Delete(const std::vector<uint64_t> &templateIdList) override; 53 UserAuth::ResultCode Cancel(uint64_t scheduleId) override; 54 UserAuth::ResultCode SendCommand(UserAuth::PropertyMode commandId, const std::vector<uint8_t> &extraInfo, 55 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override; 56 UserAuth::ResultCode GetProperty(const std::vector<uint64_t> &templateIdList, 57 const std::vector<UserAuth::Attributes::AttributeKey> &keys, UserAuth::Property &property) override; 58 UserAuth::ResultCode SetCachedTemplates(const std::vector<uint64_t> &templateIdList) override; 59 int32_t SetBufferProducer(sptr<IBufferProducer> &producer); 60 void OnHdiDisconnect(); 61 62 private: 63 class SaCommandCallback; 64 65 UserAuth::ResultCode MoveHdiExecutorInfo(ExecutorInfo &in, UserAuth::ExecutorInfo &out); 66 void MoveHdiTemplateInfo(TemplateInfo &in, UserAuth::TemplateInfo &out); 67 void MoveHdiProperty(Property &in, UserAuth::Property &out); 68 UserAuth::ResultCode ConvertCommandId(const UserAuth::PropertyMode in, CommandId &out); 69 UserAuth::ResultCode ConvertAuthType(const AuthType in, UserAuth::AuthType &out); 70 UserAuth::ResultCode ConvertExecutorRole(const ExecutorRole in, UserAuth::ExecutorRole &out); 71 UserAuth::ResultCode ConvertExecutorSecureLevel(const ExecutorSecureLevel in, UserAuth::ExecutorSecureLevel &out); 72 UserAuth::ResultCode ConvertResultCode(const int32_t in); 73 UserAuth::ResultCode ConvertAttributeKeyToPropertyType(const UserAuth::Attributes::AttributeKey in, 74 GetPropertyType &out); 75 UserAuth::ResultCode ConvertAttributeKeyVectorToPropertyType( 76 const std::vector<UserAuth::Attributes::AttributeKey> inVector, std::vector<GetPropertyType> &outVector); 77 UserAuth::ResultCode RegisterSaCommandCallback(); 78 79 sptr<IExecutor> executorProxy_; 80 sptr<SaCommandCallback> saCommandCallback_; 81 }; 82 83 class FaceAuthExecutorHdi::SaCommandCallback : public ISaCommandCallback, public NoCopyable { 84 public: SaCommandCallback(std::shared_ptr<FaceAuthExecutorHdi> executorHdi)85 explicit SaCommandCallback(std::shared_ptr<FaceAuthExecutorHdi> executorHdi) : executorHdi_(executorHdi) {}; ~SaCommandCallback()86 ~SaCommandCallback() override {}; 87 int32_t OnSaCommands(const std::vector<SaCommand> &commands) override; 88 89 private: 90 std::shared_ptr<FaceAuthExecutorHdi> executorHdi_; 91 }; 92 } // namespace FaceAuth 93 } // namespace UserIam 94 } // namespace OHOS 95 96 #endif // FACE_AUTH_EXECUTOR_HDI_H