• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 IAM_CONTEXT_FACTORY_H
17 #define IAM_CONTEXT_FACTORY_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <memory>
22 #include <string>
23 
24 #include "singleton.h"
25 #include "authentication_impl.h"
26 #include "delete_impl.h"
27 #include "enrollment_impl.h"
28 #include "context.h"
29 #include "context_callback.h"
30 #include "local_remote_auth_context.h"
31 #include "identification_impl.h"
32 #include "imodal_callback.h"
33 #include "remote_auth_context.h"
34 #include "remote_auth_invoker_context.h"
35 
36 namespace OHOS {
37 namespace UserIam {
38 namespace UserAuth {
39 class ContextFactory : public DelayedSingleton<ContextFactory> {
40 public:
41     struct AuthProfile {
42         int32_t pinSubType {0};
43         std::string sensorInfo {""};
44         int32_t remainTimes {0};
45         int32_t freezingTime {0};
46     };
47 
48     struct AuthWidgetContextPara {
49         int32_t userId {INVALID_USER_ID};
50         int32_t sdkVersion {0};
51         uint32_t tokenId {0};
52         std::string callerName {""};
53         std::vector<uint8_t> challenge {};
54         std::vector<AuthType> authTypeList {};
55         AuthTrustLevel atl {ATL1};
56         WidgetParamInner widgetParam {};
57         std::map<AuthType, AuthProfile> authProfileMap {};
58         int32_t callerType {0};
59         std::string callingAppID {""};
60         bool isPinExpired {false};
61         bool isOsAccountVerified {false};
62         bool isBackgroundApplication {false};
63         bool skipLockedBiometricAuth {false};
64     };
65 
66     static std::shared_ptr<Context> CreateSimpleAuthContext(const Authentication::AuthenticationPara &para,
67         const std::shared_ptr<ContextCallback> &callback, bool needSubscribeAppState);
68     static std::shared_ptr<Context> CreateRemoteAuthContext(const Authentication::AuthenticationPara &para,
69         RemoteAuthContextParam &remoteAuthContextParam, const std::shared_ptr<ContextCallback> &callback);
70     static std::shared_ptr<Context> CreateRemoteAuthInvokerContext(AuthParamInner authParam,
71         RemoteAuthInvokerContextParam param, std::shared_ptr<ContextCallback> callback);
72     static std::shared_ptr<Context> CreateLocalRemoteAuthContext(const Authentication::AuthenticationPara &para,
73         LocalRemoteAuthContextParam &localRemoteAuthContextParam, const std::shared_ptr<ContextCallback> &callback);
74     static std::shared_ptr<Context> CreateIdentifyContext(const Identification::IdentificationPara &para,
75         const std::shared_ptr<ContextCallback> &callback);
76     static std::shared_ptr<Context> CreateEnrollContext(const Enrollment::EnrollmentPara &para,
77         const std::shared_ptr<ContextCallback> &callback, bool needSubscribeAppState);
78     static std::shared_ptr<Context> CreateWidgetAuthContext(std::shared_ptr<ContextCallback> callback);
79     static std::shared_ptr<Context> CreateWidgetContext(const AuthWidgetContextPara &para,
80         std::shared_ptr<ContextCallback> callback, const sptr<IModalCallback> &modalCallback);
81     static std::shared_ptr<Context> CreateScheduleHolderContext(std::shared_ptr<ScheduleNode> scheduleNode);
82     static std::shared_ptr<Context> CreateDeleteContext(const Deletion::DeleteParam &para,
83         const std::shared_ptr<ContextCallback> &callback);
84 };
85 } // namespace UserAuth
86 } // namespace UserIam
87 } // namespace OHOS
88 #endif // IAM_CONTEXT_FACTORY_H