• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MANAGER_H
17 #define FACE_AUTH_MANAGER_H
18 
19 #include "face_auth_query_callback.h"
20 #include "face_auth_executor_callback.h"
21 #include "face_auth_event.h"
22 #include "face_auth_ca.h"
23 #include "output/video_output.h"
24 #include "surface.h"
25 #include "surface_buffer.h"
26 
27 namespace OHOS {
28 namespace UserIAM {
29 namespace FaceAuth {
30 class FaceAuthSequence;
31 class FaceAuthManager {
32 public:
33     static std::shared_ptr<FaceAuthManager> GetInstance();
34     ~FaceAuthManager()=default;
35     FaceAuthManager()=default;
36     int32_t Init();
37     int32_t Release();
38     void RegisterExecutor();
39     void VerifyAuthInfo();
40     // about authenticate
41     ResultCodeForCoAuth AddAuthenticationRequest(const AuthParam &param);
42     void DoAuthenticate(const AuthParam &param);
43     int32_t CancelAuth(const AuthParam &param);
44     // about enroll
45     ResultCodeForCoAuth AddEnrollmentRequest(const EnrollParam &param);
46     void DoEnroll(const EnrollParam &param);
47     int32_t CancelEnrollment(const EnrollParam &param);
48     // about remove
49     int32_t AddRemoveRequest(const RemoveParam &param);
50     void DoRemove(const RemoveParam &param);
51     // about algorithm
52     FIRetCode InitAlgorithm(std::string bundleName);
53     FIRetCode DoWaitInitAlgorithm(std::future<int32_t> futureobj);
54     FIRetCode ReleaseAlgorithm(std::string bundleName);
55     void QueryRegStatus();
56     // about messager
57     void SetExecutorMessenger(const sptr<AuthResPool::IExecutorMessenger> &messager);
58     void UnfreezeTemplates(std::vector<uint64_t> templateIdList);
59     void FreezeTemplates(std::vector<uint64_t> templateIdList);
60 private:
61     static std::shared_ptr<FaceAuthManager> manager_;
62     static std::mutex mutex_;
63     static sptr<AuthResPool::IExecutorMessenger> executorMessenger_;
64     static std::shared_ptr<FaceAuthEventHandler> handler_;
65     static std::shared_ptr<AppExecFwk::EventRunner> runner_;
66     static std::shared_ptr<AuthResPool::QueryCallback> queryCallback_;
67     static std::shared_ptr<FaceAuthExecutorCallback> executorCallback_;
68     std::map<std::string, int32_t> bundleNameList_;
69 private:
70     FaceAuthManager(const FaceAuthManager&)=delete;
71     FaceAuthManager &operator=(const FaceAuthManager&)=delete;
72     bool IsAlgorithmInited();
73     AlgoResult IsNeedAlgoLoad(std::string bundleName);
74     AlgoResult IsNeedAlgoRelease(std::string bundleName);
75     int32_t GenerateEventId();
76     void SendData(uint64_t scheduleId, uint64_t transNum, int32_t srcType, int32_t dstType, pAuthMessage msg);
77     void Finish(uint64_t scheduleId, int32_t srcType, int32_t resultCode, pAuthAttributes finalResult);
78     FIRetCode OperForAlgorithm(uint64_t scheduleID, FaceOperateType type);
79     void HandleAlgoResult(uint64_t scheduleID, FaceOperateType type);
80     int32_t OpenCamera(sptr<IBufferProducer> producer);
81     int32_t WaitAlgorithmProcessDone(uint64_t scheduleID, FaceOperateType type);
82     bool GetRandomNum(int32_t *randomNum);
83 };
84 } // namespace FaceAuth
85 } // namespace UserIAM
86 } // namespace OHOS
87 #endif // FACE_AUTH_MANAGER_H
88