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