• 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_OSACCOUNT_IINNER_OS_ACCOUNT_MANAGER_H
17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_IINNER_OS_ACCOUNT_MANAGER_H
18 
19 #include <memory>
20 #include "iinner_os_account.h"
21 #include "inner_domain_account_manager.h"
22 #include "ios_account_control.h"
23 #include "ios_account_subscribe.h"
24 #include "ohos_account_manager.h"
25 #include "os_account_interface.h"
26 #include "singleton.h"
27 
28 namespace OHOS {
29 namespace AccountSA {
30 class IInnerOsAccountManager : public IInnerOsAccount {
31 public:
32     static IInnerOsAccountManager &GetInstance();
33     void Init() override;
34     ErrCode CreateOsAccount(
35         const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo) override;
36     ErrCode CreateOsAccount(const std::string &localName, const std::string &shortName,
37         const OsAccountType &type, OsAccountInfo &osAccountInfo, const CreateOsAccountOptions &options = {}) override;
38     ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override;
39     ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override;
40     ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
41         const sptr<IDomainAccountCallback> &callback) override;
42     ErrCode RemoveOsAccount(const int id) override;
43     ErrCode IsOsAccountExists(const int id, bool &isOsAccountExits) override;
44     ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) override;
45     ErrCode IsOsAccountConstraintEnable(
46         const int id, const std::string &constraint, bool &isOsAccountConstraintEnable) override;
47     ErrCode IsOsAccountVerified(const int id, bool &isVerified) override;
48     ErrCode GetCreatedOsAccountsCount(unsigned int &createdOsAccountCount) override;
49     ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber) override;
50     ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints) override;
51     ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos) override;
52     ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo) override;
53     ErrCode GetOsAccountShortName(const int id, std::string &shortName) override;
54     ErrCode GetOsAccountType(const int id, OsAccountType &type) override;
55     ErrCode GetOsAccountProfilePhoto(const int id, std::string &photo) override;
56     ErrCode IsMultiOsAccountEnable(bool &isMultiOsAccountEnable) override;
57     ErrCode SetOsAccountName(const int id, const std::string &name) override;
58     ErrCode SetOsAccountConstraints(
59         const int id, const std::vector<std::string> &constraints, const bool enable) override;
60     ErrCode SetOsAccountProfilePhoto(const int id, const std::string &photo) override;
61     ErrCode ActivateOsAccount(const int id) override;
62     ErrCode DeactivateOsAccount(const int id) override;
63     ErrCode StartOsAccount(const int id) override;
64     ErrCode StopOsAccount(const int id) override;
65     ErrCode GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id) override;
66     ErrCode GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber) override;
67     ErrCode SubscribeOsAccount(
68         const OsAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override;
69     ErrCode UnsubscribeOsAccount(const sptr<IRemoteObject> &eventListener) override;
70     OS_ACCOUNT_SWITCH_MOD GetOsAccountSwitchMod() override;
71     ErrCode IsOsAccountCompleted(const int id, bool &isOsAccountCompleted) override;
72     ErrCode SetOsAccountIsVerified(const int id, const bool isVerified) override;
73     ErrCode GetOsAccountCredentialId(const int id, uint64_t &credentialId) override;
74     ErrCode SetOsAccountCredentialId(const int id, uint64_t credentialId) override;
75     ErrCode IsAllowedCreateAdmin(bool &isAllowedCreateAdmin) override;
76     ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id) override;
77     ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID,
78         int &createdOsAccountNum) override;
79     ErrCode GetSerialNumberFromDatabase(const std::string& storeID, int64_t &serialNumber) override;
80     ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id) override;
81     ErrCode GetOsAccountFromDatabase(const std::string& storeID, const int id,
82         OsAccountInfo &osAccountInfo) override;
83     ErrCode GetOsAccountListFromDatabase(const std::string& storeID,
84         std::vector<OsAccountInfo> &osAccountList) override;
85     ErrCode QueryActiveOsAccountIds(std::vector<int32_t>& ids) override;
86     ErrCode QueryOsAccountConstraintSourceTypes(const int32_t id,
87         const std::string &constraint, std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos) override;
88     ErrCode SetBaseOsAccountConstraints(const int32_t id,
89         const std::vector<std::string> &constraints, const bool enable) override;
90     ErrCode SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints,
91         const bool enable, const int32_t enforcerId, const bool isDeviceOwner) override;
92     ErrCode SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints,
93         const bool enable, const int32_t targetId, const int32_t enforcerId, const bool isDeviceOwner) override;
94 
95     ErrCode SetDefaultActivatedOsAccount(const int32_t id) override;
96     ErrCode GetDefaultActivatedOsAccount(int32_t &id) override;
97     ErrCode BindDomainAccount(const OsAccountType &type, const DomainAccountInfo &domainAccountInfo,
98         const sptr<IDomainAccountCallback> &callback);
99     ErrCode SendMsgForAccountCreate(OsAccountInfo &osAccountInfo, const CreateOsAccountOptions &options = {});
100     ErrCode GetOsAccountInfoById(const int id, OsAccountInfo &osAccountInfo);
101     ErrCode UpdateAccountStatusForDomain(const int id, DomainAccountStatus status);
102 
103 private:
104     IInnerOsAccountManager();
105     ~IInnerOsAccountManager() = default;
106     DISALLOW_COPY_AND_MOVE(IInnerOsAccountManager);
107     void SetOsAccountControl(std::shared_ptr<IOsAccountControl> ptr);
108     void StartAccount();
109     void RestartActiveAccount();
110     void CreateBaseAdminAccount();
111     void CreateBaseStandardAccount();
112     void ResetAccountStatus(void);
113     ErrCode RemoveOsAccountOperate(
114         const int id, OsAccountInfo &osAccountInfo, const DomainAccountInfo &domainAccountInfo);
115     ErrCode DeactivateOsAccountById(const int id);
116     ErrCode DeactivateOsAccountByInfo(OsAccountInfo &osAccountInfo);
117     ErrCode PrepareOsAccountInfo(const std::string &name, const OsAccountType &type,
118         const DomainAccountInfo &domainAccount, OsAccountInfo &osAccountInfo);
119     ErrCode PrepareOsAccountInfo(const std::string &localName, const std::string &shortName, const OsAccountType &type,
120         const DomainAccountInfo &domainAccount, OsAccountInfo &osAccountInfo);
121     ErrCode FillOsAccountInfo(const std::string &localName, const std::string &shortName, const OsAccountType &type,
122         const DomainAccountInfo &domainAccount, OsAccountInfo &osAccountInfo);
123     ErrCode PrepareOsAccountInfoWithFullInfo(OsAccountInfo &osAccountInfo);
124     ErrCode SendMsgForAccountActivate(OsAccountInfo &osAccountInfo);
125     ErrCode SendMsgForAccountDeactivate(OsAccountInfo &osAccountInfo);
126     ErrCode SendMsgForAccountStop(OsAccountInfo &osAccountInfo);
127     ErrCode SendMsgForAccountRemove(OsAccountInfo &osAccountInfo);
128     ErrCode ValidateOsAccount(const OsAccountInfo &osAccountInfo);
129     void RemoveLocalIdToOperating(int32_t localId);
130     bool CheckAndAddLocalIdOperating(int32_t localId);
131     void CleanGarbageAccounts();
132     ErrCode DealWithDeviceOwnerId(const bool isDeviceOwner, const int32_t localId);
133     void CheckAndRefreshLocalIdRecord(const int id);
134     ErrCode ValidateShortName(const std::string &shortName);
135 
136     // operations for active list
137     void PushIdIntoActiveList(int32_t id);
138     void EraseIdFromActiveList(int32_t id);
139     bool IsOsAccountIDInActiveList(int32_t id);
140     void CopyFromActiveList(std::vector<int32_t>& idList);
141     void RefreshActiveList(int32_t newId);
142     bool CheckDomainAccountBound(const std::vector<OsAccountInfo> &osAccountInfos, const DomainAccountInfo &info);
143     void WatchStartUser(std::int32_t id);
144     void RetryToGetAccount(OsAccountInfo &osAccountInfo);
145 
146 private:
147     std::shared_ptr<IOsAccountControl> osAccountControl_;
148     std::vector<int32_t> activeAccountId_;
149     std::vector<int32_t> operatingId_;
150     IOsAccountSubscribe &subscribeManager_;
151     std::int32_t deviceOwnerId_ = -1;
152     std::int32_t defaultActivatedId_ = -1;
153     mutable std::mutex ativeMutex_;
154     mutable std::mutex operatingMutex_;
155 };
156 }  // namespace AccountSA
157 }  // namespace OHOS
158 
159 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_IINNER_OS_ACCOUNT_MANAGER_H
160