• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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     bool UpdateOhosAccountInfo(
45         const std::string &accountName, const std::string &uid, const std::string &eventStr) override;
46     std::int32_t SetOhosAccountInfo(const OhosAccountInfo &ohosAccountInfo,
47         const std::string &eventStr) override;
48     std::int32_t SetOhosAccountInfoByUserId(
49         const int32_t userId, const OhosAccountInfo &ohosAccountInfo, const std::string &eventStr) override;
50     std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo(void) override;
51     std::pair<bool, OhosAccountInfo> QueryOhosAccountInfoByUserId(std::int32_t userId) override;
52     ErrCode GetOhosAccountInfo(OhosAccountInfo &info) override;
53     ErrCode GetOhosAccountInfoByUserId(int32_t userId, OhosAccountInfo &info) override;
54     std::int32_t QueryDeviceAccountId(std::int32_t &accountId) override;
55     sptr<IRemoteObject> GetAppAccountService() override;
56     sptr<IRemoteObject> GetOsAccountService() override;
57     sptr<IRemoteObject> GetAccountIAMService() override;
58     sptr<IRemoteObject> GetDomainAccountService() override;
59 
60     void OnStart() override;
61     void OnStop() override;
62     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
63     bool IsServiceStarted(void) const override;
GetInstance()64     static AccountMgrService &GetInstance()
65     {
66         return DelayedRefSingleton<AccountMgrService>::GetInstance();
67     }
68     std::int32_t Dump(std::int32_t fd, const std::vector<std::u16string> &args) override;
69     void HandleNotificationEvents(const std::string &eventStr) override;
70     std::int32_t GetCallingUserID();
71 
72 private:
73     bool Init();
74     void SelfClean();
75     std::int32_t GetDeviceAccountIdFromCurrentProcess();
76     bool CreateOsAccountService();
77     bool CreateAppAccountService();
78     bool CreateIAMService();
79     bool CreateDomainService();
80 
81     bool registerToService_ = false;
82     ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START;
83     std::unique_ptr<AccountDumpHelper> dumpHelper_{};
84 
85     sptr<IRemoteObject> appAccountManagerService_ = nullptr;
86     sptr<OsAccountManagerService> osAccountManagerService_ = nullptr;
87     sptr<IRemoteObject> accountIAMService_ = nullptr;
88     sptr<IRemoteObject> domainAccountMgrService_ = nullptr;
89 
90     std::mutex statusMutex_;
91     bool isStorageReady_ = false;
92     bool isAmsReady_ = false;
93     bool isBmsReady_ = false;
94 };
95 }  // namespace AccountSA
96 }  // namespace OHOS
97 
98 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_ACCOUNT_MGR_SERVICE_H
99