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 USER_AUTH_CLIENT_IMPL_H 17 #define USER_AUTH_CLIENT_IMPL_H 18 19 #include <mutex> 20 21 #include "nocopyable.h" 22 23 #include "user_auth_client.h" 24 #include "user_auth_interface.h" 25 #include "iuser_auth_widget_callback.h" 26 27 namespace OHOS { 28 namespace UserIam { 29 namespace UserAuth { 30 class UserAuthClientImpl final : public UserAuthClient, NoCopyable { 31 public: 32 static UserAuthClientImpl& Instance(); 33 int32_t GetAvailableStatus(AuthType authType, AuthTrustLevel authTrustLevel); 34 int32_t GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel); 35 void GetProperty(int32_t userId, const GetPropertyRequest &request, 36 const std::shared_ptr<GetPropCallback> &callback) override; 37 void SetProperty(int32_t userId, const SetPropertyRequest &request, 38 const std::shared_ptr<SetPropCallback> &callback) override; 39 uint64_t BeginAuthentication(int32_t userId, const std::vector<uint8_t> &challenge, AuthType authType, 40 AuthTrustLevel atl, const std::shared_ptr<AuthenticationCallback> &callback) override; 41 uint64_t BeginNorthAuthentication(int32_t apiVersion, const std::vector<uint8_t> &challenge, AuthType authType, 42 AuthTrustLevel atl, const std::shared_ptr<AuthenticationCallback> &callback); 43 int32_t CancelAuthentication(uint64_t contextId) override; 44 uint64_t BeginIdentification(const std::vector<uint8_t> &challenge, AuthType authType, 45 const std::shared_ptr<IdentificationCallback> &callback) override; 46 int32_t CancelIdentification(uint64_t contextId) override; 47 int32_t GetVersion(int32_t &version); 48 uint64_t BeginWidgetAuth(int32_t apiVersion, const AuthParam &authParam, 49 const WidgetParam &widgetParam, const std::shared_ptr<AuthenticationCallback> &callback); 50 int32_t SetWidgetCallback(int32_t version, const std::shared_ptr<IUserAuthWidgetCallback> &callback); 51 int32_t Notice(NoticeType noticeType, const std::string &eventData); 52 53 private: 54 ResultCode SetPropertyInner(int32_t userId, const SetPropertyRequest &request, 55 const std::shared_ptr<SetPropCallback> &callback); 56 57 friend class UserAuthClient; 58 UserAuthClientImpl() = default; 59 ~UserAuthClientImpl() 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 constexpr static uint64_t INVALID_SESSION_ID {0}; 72 std::mutex mutex_; 73 }; 74 } // namespace UserAuth 75 } // namespace UserIam 76 } // namespace OHOS 77 #endif // USER_AUTH_CLIENT_IMPL_H