1 /* 2 * Copyright (c) 2021-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 BASE_ACCOUNT_OHOS_ACCOUNT_KITS_IMPL_H 17 #define BASE_ACCOUNT_OHOS_ACCOUNT_KITS_IMPL_H 18 19 #include <mutex> 20 #include "iaccount.h" 21 #include "ipc_skeleton.h" 22 #include "ohos_account_kits.h" 23 24 namespace OHOS { 25 namespace AccountSA { 26 using DomainAccountSubscribeSACallbackFunc = std::function<void(int32_t, const std::string)>; 27 class OhosAccountKitsImpl final : public OhosAccountKits { 28 public: 29 DISALLOW_COPY_AND_MOVE(OhosAccountKitsImpl); 30 static OhosAccountKitsImpl &GetInstance(); 31 bool UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid, 32 const std::string& eventStr) final; 33 std::int32_t SetOhosAccountInfo(const OhosAccountInfo &ohosAccountInfo, 34 const std::string &eventStr) final; 35 ErrCode SetOhosAccountInfoByUserId( 36 const int32_t userId, const OhosAccountInfo& ohosAccountInfo, const std::string& eventStr) final; 37 std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo() final; 38 ErrCode GetOhosAccountInfo(OhosAccountInfo &accountInfo) final; 39 ErrCode GetOhosAccountInfoByUserId(int32_t userId, OhosAccountInfo &accountInfo) final; 40 std::pair<bool, OhosAccountInfo> QueryOhosAccountInfoByUserId(std::int32_t userId) final; 41 ErrCode QueryDeviceAccountId(std::int32_t& accountId) final; 42 std::int32_t GetDeviceAccountIdByUID(std::int32_t& uid) final; 43 ErrCode SubscribeSystemAbility(const DomainAccountSubscribeSACallbackFunc& callbackFunc); 44 sptr<IRemoteObject> GetOsAccountService(); 45 sptr<IRemoteObject> GetDomainAccountService(); 46 sptr<IRemoteObject> GetAppAccountService(); 47 sptr<IRemoteObject> GetAccountIAMService(); 48 49 private: 50 OhosAccountKitsImpl() = default; 51 ~OhosAccountKitsImpl() = default; 52 // For death event procession 53 class DeathRecipient final : public IRemoteObject::DeathRecipient { 54 public: 55 DeathRecipient() = default; 56 ~DeathRecipient() final = default; 57 DISALLOW_COPY_AND_MOVE(DeathRecipient); 58 59 void OnRemoteDied(const wptr<IRemoteObject>& remote) final; 60 }; 61 62 void ResetService(const wptr<IRemoteObject>& remote); 63 sptr<IAccount> GetService(); 64 65 sptr<IRemoteObject::DeathRecipient> deathRecipient_{}; 66 std::mutex accountProxyLock_; 67 sptr<IAccount> accountProxy_{}; 68 }; 69 } // namespace AccountSA 70 } // namespace OHOS 71 72 #endif // BASE_ACCOUNT_OHOS_ACCOUNT_KITS_IMPL_H 73