• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 USER_AUTH_INSTANCE_V10_H
17 #define USER_AUTH_INSTANCE_V10_H
18 
19 #include <mutex>
20 
21 #include "nocopyable.h"
22 
23 #include "ability.h"
24 
25 #include "auth_common.h"
26 #include "auth_instance_v9.h"
27 #include "user_auth_callback_v10.h"
28 #include "user_auth_modal_callback.h"
29 #include "user_auth_napi_client_impl.h"
30 
31 namespace OHOS {
32 namespace UserIam {
33 namespace UserAuth {
34 class UserAuthInstanceV10 : public NoCopyable {
35 public:
36     explicit UserAuthInstanceV10(napi_env env);
37     ~UserAuthInstanceV10() override = default;
38 
39     UserAuthResultCode Init(napi_env env, napi_callback_info info);
40     UserAuthResultCode On(napi_env env, napi_callback_info info);
41     UserAuthResultCode Off(napi_env env, napi_callback_info info);
42     UserAuthResultCode Start(napi_env env, napi_callback_info info);
43     UserAuthResultCode Cancel(napi_env env, napi_callback_info info);
44     static napi_value GetEnrolledState(napi_env env, napi_callback_info info);
45 
46 private:
47     UserAuthResultCode InitChallenge(napi_env env, napi_value value);
48     UserAuthResultCode InitAuthType(napi_env env, napi_value value);
49     UserAuthResultCode InitAuthTrustLevel(napi_env env, napi_value value);
50     UserAuthResultCode InitReuseUnlockResult(napi_env env, napi_value value);
51     UserAuthResultCode InitUserId(napi_env env, napi_value value);
52     UserAuthResultCode ProcessAuthTrustLevelAndUserId(napi_env env, napi_value value);
53     UserAuthResultCode ProcessReuseUnlockResult(napi_env env, napi_value value);
54     UserAuthResultCode InitAuthParam(napi_env env, napi_value value);
55     UserAuthResultCode ProcessWindowMode(napi_env env, napi_value value);
56     UserAuthResultCode InitWidgetParam(napi_env env, napi_value value);
57     std::shared_ptr<JsRefHolder> GetCallback(napi_env env, napi_value value);
58     static napi_value DoGetEnrolledStateResult(napi_env env, EnrolledState enrolledState);
59     UserAuthResultCode ProcessContext(napi_env env, napi_value value);
60     bool CheckUIContext(const std::shared_ptr<OHOS::AbilityRuntime::Context> context);
61 
62     AuthParamInner authParam_ = {};
63     UserAuthNapiClientImpl::WidgetParamNapi widgetParam_ = {};
64 
65     uint64_t contextId_ = 0;
66     bool isAuthStarted_ = false;
67     std::mutex mutex_;
68     std::shared_ptr<UserAuthCallbackV10> callback_ = nullptr;
69     std::shared_ptr<UserAuthModalCallback> modalCallback_ = nullptr;
70     std::shared_ptr<AbilityRuntime::Context> context_ = nullptr;
71 };
72 } // namespace UserAuth
73 } // namespace UserIam
74 } // namespace OHOS
75 #endif // USER_AUTH_INSTANCE_V10_H
76