1 /* 2 * Copyright (c) 2021-2024 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_SERVICES_ACCOUNTMGR_INCLUDE_ACCOUNT_MGR_SERVICE_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_ACCOUNT_MGR_SERVICE_H 18 19 #include <memory> 20 #include <mutex> 21 #include "account_dump_helper.h" 22 #include "account_event_provider.h" 23 #include "account_info.h" 24 #include "account_stub.h" 25 #include "os_account_manager_service.h" 26 #include "iaccount.h" 27 #include "iremote_object.h" 28 #include "ohos_account_manager.h" 29 #include "singleton.h" 30 #include "system_ability.h" 31 32 namespace OHOS { 33 namespace AccountSA { 34 enum ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; 35 36 class AccountMgrService : public SystemAbility, 37 public AccountStub, 38 public OHOS::DelayedRefSingleton<AccountMgrService> { 39 public: 40 AccountMgrService(); 41 ~AccountMgrService() override; 42 DISALLOW_COPY_AND_MOVE(AccountMgrService); 43 DECLARE_SYSTEM_ABILITY(AccountMgrService); 44 ErrCode UpdateOhosAccountInfo( 45 const std::string &accountName, const std::string &uid, const std::string &eventStr) override; 46 ErrCode SetOhosAccountInfo(const OhosAccountInfo &ohosAccountInfo, 47 const std::string &eventStr) override; 48 ErrCode SetOsAccountDistributedInfo( 49 const int32_t localId, const OhosAccountInfo &ohosAccountInfo, const std::string &eventStr) override; 50 ErrCode QueryOhosAccountInfo(OhosAccountInfo &accountInfo) override; 51 ErrCode QueryDistributedVirtualDeviceId(std::string &dvid) override; 52 ErrCode QueryDistributedVirtualDeviceId(const std::string &bundleName, int32_t localId, std::string &dvid) override; 53 ErrCode QueryOsAccountDistributedInfo(std::int32_t localId, OhosAccountInfo &accountInfo) override; 54 ErrCode GetOhosAccountInfo(OhosAccountInfo &info) override; 55 ErrCode GetOsAccountDistributedInfo(int32_t localId, OhosAccountInfo &info) override; 56 ErrCode QueryDeviceAccountId(std::int32_t &accountId) override; 57 ErrCode SubscribeDistributedAccountEvent(const DISTRIBUTED_ACCOUNT_SUBSCRIBE_TYPE type, 58 const sptr<IRemoteObject> &eventListener) override; 59 ErrCode UnsubscribeDistributedAccountEvent(const DISTRIBUTED_ACCOUNT_SUBSCRIBE_TYPE type, 60 const sptr<IRemoteObject> &eventListener) override; 61 sptr<IRemoteObject> GetAppAccountService() override; 62 sptr<IRemoteObject> GetOsAccountService() override; 63 sptr<IRemoteObject> GetAccountIAMService() override; 64 sptr<IRemoteObject> GetDomainAccountService() override; 65 66 void OnStart() override; 67 void OnStop() override; 68 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 69 bool IsServiceStarted(void) const override; GetInstance()70 static AccountMgrService &GetInstance() 71 { 72 return DelayedRefSingleton<AccountMgrService>::GetInstance(); 73 } 74 ErrCode Dump(std::int32_t fd, const std::vector<std::u16string> &args) override; 75 void HandleNotificationEvents(const std::string &eventStr) override; 76 std::int32_t GetCallingUserID(); 77 78 private: 79 bool Init(); 80 void SelfClean(); 81 std::int32_t GetDeviceAccountIdFromCurrentProcess(); 82 bool CreateOsAccountService(); 83 bool CreateAppAccountService(); 84 bool CreateIAMService(); 85 bool CreateDomainService(); 86 bool IsDefaultOsAccountVerified(); 87 #ifdef HAS_APP_ACCOUNT_PART 88 void MoveAppAccountData(); 89 #endif 90 91 bool registerToService_ = false; 92 ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START; 93 std::unique_ptr<AccountDumpHelper> dumpHelper_{}; 94 95 std::mutex serviceMutex_; 96 wptr<IRemoteObject> appAccountManagerService_ = nullptr; 97 wptr<OsAccountManagerService> osAccountManagerService_ = nullptr; 98 wptr<IRemoteObject> accountIAMService_ = nullptr; 99 wptr<IRemoteObject> domainAccountMgrService_ = nullptr; 100 101 std::mutex statusMutex_; 102 bool isStorageReady_ = false; 103 bool isAmsReady_ = false; 104 bool isBmsReady_ = false; 105 bool isDefaultOsAccountActivated_ = false; 106 }; 107 } // namespace AccountSA 108 } // namespace OHOS 109 110 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_ACCOUNT_MGR_SERVICE_H 111