• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_NAPI_CLIENT_IMPL_H
17 #define USER_AUTH_NAPI_CLIENT_IMPL_H
18 
19 #include <mutex>
20 
21 #include "nocopyable.h"
22 
23 #include "user_auth_client_callback.h"
24 #include "user_auth_client_defines.h"
25 #include "iuser_auth.h"
26 #include "user_auth_modal_client_callback.h"
27 #include "user_auth_types.h"
28 #include "user_auth_common_defines.h"
29 
30 namespace OHOS {
31 namespace UserIam {
32 namespace UserAuth {
33 class UserAuthNapiClientImpl final : public NoCopyable {
34 public:
35     /**
36      * @brief Auth widget parameter.
37      */
38     struct WidgetParamNapi {
39         /** Title of widget. */
40         std::string title;
41         /** The description text of navigation button. */
42         std::string navigationButtonText;
43         /** Full screen or not. */
44         WindowModeType windowMode;
45         /** Default has't context. */
46         bool hasContext {false};
47     };
48 
49     static UserAuthNapiClientImpl& Instance();
50     uint64_t BeginWidgetAuth(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParamNapi &widgetParam,
51         const std::shared_ptr<AuthenticationCallback> &callback,
52         const std::shared_ptr<UserAuthModalClientCallback> &modalCallback);
53     int32_t CancelAuthentication(uint64_t contextId, int32_t cancelReason);
54 
55 private:
56     uint64_t BeginWidgetAuthInner(int32_t apiVersion, const AuthParamInner &authParam,
57         const WidgetParamInner &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback,
58         const std::shared_ptr<UserAuthModalClientCallback> &modalCallback);
59     void InitIpcAuthParam(const AuthParamInner &authParam, IpcAuthParamInner &ipcWidgetParamInner);
60     void InitIpcWidgetParam(const WidgetParamInner &widgetParam, IpcWidgetParamInner &ipcWidgetParamInner);
61 
62     UserAuthNapiClientImpl() = default;
63     ~UserAuthNapiClientImpl() override = default;
64     class UserAuthImplDeathRecipient : public IRemoteObject::DeathRecipient, public NoCopyable {
65     public:
66         UserAuthImplDeathRecipient() = default;
67         ~UserAuthImplDeathRecipient() override = default;
68         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
69     };
70     void ResetProxy(const wptr<IRemoteObject> &remote);
71     sptr<IUserAuth> GetProxy();
72     sptr<IUserAuth> proxy_ {nullptr};
73     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
74     constexpr static int32_t MINIMUM_VERSION {0};
75     std::mutex mutex_;
76 };
77 } // namespace UserAuth
78 } // namespace UserIam
79 } // namespace OHOS
80 #endif // USER_AUTH_NAPI_CLIENT_IMPL_H