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_IDM_CLIENT_IMPL_H 17 #define USER_IDM_CLIENT_IMPL_H 18 19 #include <mutex> 20 21 #include "nocopyable.h" 22 23 #include "user_idm_client.h" 24 #include "user_idm_interface.h" 25 26 namespace OHOS { 27 namespace UserIam { 28 namespace UserAuth { 29 class UserIdmClientImpl final : public UserIdmClient, public NoCopyable { 30 public: 31 std::vector<uint8_t> OpenSession(int32_t userId) override; 32 void CloseSession(int32_t userId) override; 33 void AddCredential(int32_t userId, const CredentialParameters ¶, 34 const std::shared_ptr<UserIdmClientCallback> &callback) override; 35 void UpdateCredential(int32_t userId, const CredentialParameters ¶, 36 const std::shared_ptr<UserIdmClientCallback> &callback) override; 37 int32_t Cancel(int32_t userId) override; 38 void DeleteCredential(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, 39 const std::shared_ptr<UserIdmClientCallback> &callback) override; 40 void DeleteUser(int32_t userId, const std::vector<uint8_t> &authToken, 41 const std::shared_ptr<UserIdmClientCallback> &callback) override; 42 int32_t EraseUser(int32_t userId, const std::shared_ptr<UserIdmClientCallback> &callback) override; 43 int32_t GetCredentialInfo(int32_t userId, AuthType authType, 44 const std::shared_ptr<GetCredentialInfoCallback> &callback) override; 45 int32_t GetSecUserInfo(int32_t userId, const std::shared_ptr<GetSecUserInfoCallback> &callback) override; 46 void ClearRedundancyCredential(const std::shared_ptr<UserIdmClientCallback> &callback) override; 47 private: 48 friend class UserIdmClient; 49 UserIdmClientImpl() = default; 50 ~UserIdmClientImpl() override = default; 51 static UserIdmClientImpl &Instance(); 52 class UserIdmImplDeathRecipient : public IRemoteObject::DeathRecipient, public NoCopyable { 53 public: 54 UserIdmImplDeathRecipient() = default; 55 ~UserIdmImplDeathRecipient() override = default; 56 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 57 }; 58 void ResetProxy(const wptr<IRemoteObject> &remote); 59 sptr<UserIdmInterface> GetProxy(); 60 sptr<UserIdmInterface> proxy_ {nullptr}; 61 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 62 std::mutex mutex_; 63 }; 64 } // namespace UserAuth 65 } // namespace UserIam 66 } // namespace OHOS 67 #endif // USER_IDM_CLIENT_IMPL_H