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 USERIDM_CLIENT_H 17 #define USERIDM_CLIENT_H 18 19 #include <iremote_object.h> 20 #include <singleton.h> 21 #include "iuser_idm.h" 22 #include "useridm_callback.h" 23 24 namespace OHOS { 25 namespace UserIAM { 26 namespace UserIDM { 27 class UserIDMClient : public DelayedRefSingleton<UserIDM::UserIDMClient> { 28 DECLARE_DELAYED_REF_SINGLETON(UserIDMClient); 29 public: 30 DISALLOW_COPY_AND_MOVE(UserIDMClient); 31 32 /** 33 * the user id that can be used for getting all credential info 34 */ 35 static const int32_t ALL_INFO_GET_USER_ID = -1; 36 uint64_t OpenSession(); 37 void CloseSession(); 38 int32_t GetAuthInfo(AuthType authType, const std::shared_ptr<GetInfoCallback>& callback); 39 int32_t GetAuthInfo(int32_t userId, AuthType authType, const std::shared_ptr<GetInfoCallback>& callback); 40 int32_t GetSecInfo(int32_t userId, const std::shared_ptr<GetSecInfoCallback>& callback); 41 void AddCredential(AddCredInfo& credInfo, const std::shared_ptr<IDMCallback>& callback); 42 void UpdateCredential(AddCredInfo& credInfo, const std::shared_ptr<IDMCallback>& callback); 43 int32_t Cancel(uint64_t challenge); 44 int32_t EnforceDelUser(int32_t userId, const std::shared_ptr<IDMCallback>& callback); 45 void DelUser(std::vector<uint8_t> authToken, const std::shared_ptr<IDMCallback>& callback); 46 void DelCred(uint64_t credentialId, std::vector<uint8_t> authToken, const std::shared_ptr<IDMCallback>& callback); 47 48 private: 49 class UserIDMDeathRecipient : public IRemoteObject::DeathRecipient { 50 public: 51 UserIDMDeathRecipient() = default; 52 ~UserIDMDeathRecipient() = default; 53 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 54 55 private: 56 DISALLOW_COPY_AND_MOVE(UserIDMDeathRecipient); 57 }; 58 59 void ResetUserIDMProxy(const wptr<IRemoteObject>& remote); 60 sptr<IUserIDM> GetUserIDMProxy(); 61 62 std::mutex mutex_; 63 sptr<IUserIDM> proxy_ {nullptr}; 64 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 65 }; 66 } // namespace UserIDM 67 } // namespace UserIAM 68 } // namespace OHOS 69 70 #endif // USERIDM_CLIENT_H 71