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 OS_ACCOUNT_INTERFACES_INNERKITS_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_CLIENT_H 17 #define OS_ACCOUNT_INTERFACES_INNERKITS_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_CLIENT_H 18 19 #include <mutex> 20 #include "account_error_no.h" 21 #include "domain_account_plugin.h" 22 #include "idomain_account.h" 23 #include "singleton.h" 24 25 namespace OHOS { 26 namespace AccountSA { 27 class DomainAccountClient : public DelayedRefSingleton<DomainAccountClient> { 28 public: 29 ErrCode RegisterPlugin(const std::shared_ptr<DomainAccountPlugin> &plugin); 30 ErrCode UnregisterPlugin(); 31 ErrCode Auth(const DomainAccountInfo &info, const std::vector<uint8_t> &password, 32 const std::shared_ptr<DomainAuthCallback> &callback); 33 ErrCode AuthUser(int32_t userId, const std::vector<uint8_t> &password, 34 const std::shared_ptr<DomainAuthCallback> &callback); 35 36 private: 37 class DomainAccountDeathRecipient : public IRemoteObject::DeathRecipient { 38 public: 39 DomainAccountDeathRecipient() = default; 40 ~DomainAccountDeathRecipient() = default; 41 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 42 43 private: 44 DISALLOW_COPY_AND_MOVE(DomainAccountDeathRecipient); 45 }; 46 sptr<IDomainAccount> GetDomainAccountProxy(); 47 void ResetDomainAccountProxy(const wptr<IRemoteObject>& remote); 48 49 private: 50 std::mutex mutex_; 51 sptr<IDomainAccount> proxy_ = nullptr; 52 sptr<DomainAccountDeathRecipient> deathRecipient_ = nullptr; 53 }; 54 } // namespace AccountSA 55 } // namespace OHOS 56 #endif // OS_ACCOUNT_INTERFACES_INNERKITS_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_CLIENT_H