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