• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 <thread>
22 #include "account_dump_helper.h"
23 #include "account_event_provider.h"
24 #include "account_info.h"
25 #ifdef HAS_USER_AUTH_PART
26 #include "account_iam_service.h"
27 #endif
28 #include "account_stub.h"
29 #include "app_account_manager_service.h"
30 #include "domain_account_manager_service.h"
31 #include "os_account_manager_service.h"
32 #include "iaccount.h"
33 #include "iremote_object.h"
34 #include "ohos_account_manager.h"
35 #include "singleton.h"
36 #include "system_ability.h"
37 
38 namespace OHOS {
39 namespace AccountSA {
40 enum ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
41 
42 class AccountMgrService : public SystemAbility,
43                           public AccountStub,
44                           public OHOS::DelayedRefSingleton<AccountMgrService> {
45 public:
46     AccountMgrService();
47     ~AccountMgrService();
48     DISALLOW_COPY_AND_MOVE(AccountMgrService);
49     DECLARE_SYSTEM_ABILITY(AccountMgrService);
50     bool UpdateOhosAccountInfo(
51         const std::string &accountName, const std::string &uid, const std::string &eventStr) override;
52     std::int32_t SetOhosAccountInfo(const OhosAccountInfo &ohosAccountInfo,
53         const std::string &eventStr) override;
54     std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo(void) override;
55     std::pair<bool, OhosAccountInfo> QueryOhosAccountInfoByUserId(std::int32_t userId) override;
56     ErrCode GetOhosAccountInfo(OhosAccountInfo &accountInfo) override;
57     ErrCode GetOhosAccountInfoByUserId(int32_t userId, OhosAccountInfo &accountInfo) override;
58     std::int32_t QueryDeviceAccountId(std::int32_t &accountId) override;
59     sptr<IRemoteObject> GetAppAccountService() override;
60     sptr<IRemoteObject> GetOsAccountService() override;
61     sptr<IRemoteObject> GetAccountIAMService() override;
62     sptr<IRemoteObject> GetDomainAccountService() override;
63 
64     void OnStart() override;
65     void OnStop() override;
66     bool IsServiceStarted(void) const override;
GetInstance()67     static AccountMgrService &GetInstance()
68     {
69         return DelayedRefSingleton<AccountMgrService>::GetInstance();
70     }
71     std::int32_t Dump(std::int32_t fd, const std::vector<std::u16string> &args) override;
72     void HandleNotificationEvents(const std::string &eventStr) override;
73 
74 private:
75     bool Init();
76     void SelfClean();
77     std::int32_t GetDeviceAccountIdFromCurrentProcess();
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     std::shared_ptr<OhosAccountManager> ohosAccountMgr_{};
85 
86     sptr<AppAccountManagerService> appAccountManagerService_ = nullptr;
87     sptr<OsAccountManagerService> osAccountManagerService_ = nullptr;
88 #ifdef HAS_USER_AUTH_PART
89     sptr<AccountIAMService> accountIAMService_ = nullptr;
90 #endif
91     sptr<DomainAccountManagerService> domainAccountMgrService_ = nullptr;
92 };
93 }  // namespace AccountSA
94 }  // namespace OHOS
95 
96 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_ACCOUNT_MGR_SERVICE_H
97