• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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_OS_ACCOUNT_MANAGER_SERVICE_H
17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_MANAGER_SERVICE_H
18 
19 #include <stdint.h>
20 #include <sys/types.h>
21 #include <memory>
22 #include "account_permission_manager.h"
23 #include "os_account_constraint_manager.h"
24 #include "os_account_stub.h"
25 #include "idomain_account_callback.h"
26 #include "iinner_os_account_manager.h"
27 
28 namespace OHOS {
29 namespace AccountSA {
30 class OsAccountManagerService : public OsAccountStub {
31 public:
32     OsAccountManagerService();
33     ~OsAccountManagerService() override;
34 
35     ErrCode CreateOsAccount(
36         const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo);
37     ErrCode CreateOsAccount(const std::string &localName, const std::string &shortName,
38         const OsAccountType &type, OsAccountInfo &osAccountInfo, const CreateOsAccountOptions &options = {});
39 
40     ErrCode CreateOsAccount(
41         const std::string &name, int32_t typeValue, StringRawData& stringRawData) override;
42     ErrCode CreateOsAccount(const std::string &localName, const std::string &shortName, int32_t typeValue,
43         StringRawData& stringRawData) override;
44     ErrCode CreateOsAccount(const std::string &localName, const std::string &shortName,
45         int32_t typeValue, StringRawData& stringRawData, const CreateOsAccountOptions &options) override;
46     ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
47         const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &options = {});
48     ErrCode CreateOsAccountForDomain(int32_t typeValue, const DomainAccountInfo &domainInfo,
49         const sptr<IDomainAccountCallback> &callback) override;
50     ErrCode CreateOsAccountForDomain(int32_t typeValue, const DomainAccountInfo &domainInfo,
51         const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &options) override;
52 
53     ErrCode CreateOsAccountWithFullInfo(const OsAccountInfo& osAccountInfo) override;
54     ErrCode CreateOsAccountWithFullInfo(const OsAccountInfo& osAccountInfo,
55         const CreateOsAccountOptions &options) override;
56     ErrCode UpdateOsAccountWithFullInfo(const OsAccountInfo& osAccountInfo) override;
57 
58     ErrCode RemoveOsAccount(int32_t id) override;
59 
60     ErrCode IsOsAccountExists(int32_t id, bool &isOsAccountExists) override;
61     ErrCode IsOsAccountActived(int32_t id, bool &isOsAccountActived) override;
62 
63     ErrCode IsOsAccountConstraintEnable(
64         int32_t id, const std::string &constraint, bool &isConstraintEnable) override;
65     ErrCode CheckOsAccountConstraintEnabled(
66         int32_t id, const std::string &constraint, bool &isEnabled) override;
67     ErrCode IsOsAccountVerified(int32_t id, bool &isVerified) override;
68     ErrCode IsOsAccountDeactivating(int32_t id, bool &isDeactivating) override;
69 
70     ErrCode GetCreatedOsAccountsCount(unsigned int &osAccountsCount) override;
71     ErrCode GetOsAccountLocalIdFromProcess(int &id) override;
72     ErrCode IsMainOsAccount(bool &isMainOsAccount) override;
73     ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id) override;
74     ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber) override;
75     ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum) override;
76 
77     ErrCode GetOsAccountAllConstraints(int32_t id, std::vector<std::string> &constraints) override;
78     ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos);
79     ErrCode QueryAllCreatedOsAccounts(StringRawData& osAccountInfos) override;
80 
81     ErrCode QueryCurrentOsAccount(OsAccountInfo &osAccountInfo);
82     ErrCode QueryCurrentOsAccount(StringRawData& stringRawData) override;
83     ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo);
84     ErrCode QueryOsAccountById(int32_t id, StringRawData& stringRawData) override;
85 
86     ErrCode GetOsAccountTypeFromProcess(int32_t& typeValue) override;
87     ErrCode GetOsAccountType(int32_t id, int32_t& typeValue) override;
88     ErrCode GetOsAccountProfilePhoto(const int id, std::string &photo);
89     ErrCode GetOsAccountProfilePhoto(int32_t id, StringRawData& stringRawData) override;
90 
91     ErrCode IsMultiOsAccountEnable(bool &isMultiOsAccountEnable) override;
92     ErrCode SetOsAccountName(int32_t id, const std::string &name) override;
93 
94     ErrCode SetOsAccountConstraints(
95         int32_t id, const std::vector<std::string> &constraints, bool enable) override;
96     ErrCode SetOsAccountProfilePhoto(const int id, const std::string &photo);
97     ErrCode SetOsAccountProfilePhoto(int32_t id, const StringRawData& stringRawData) override;
98 
99     ErrCode ActivateOsAccount(int32_t id) override;
100     ErrCode DeactivateOsAccount(int32_t id) override;
101     ErrCode DeactivateAllOsAccounts() override;
102 
103     ErrCode StartOsAccount(int32_t id) override;
104 
105     ErrCode GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id) override;
106     ErrCode GetSerialNumberByOsAccountLocalId(int32_t id, int64_t &serialNumber) override;
107 
108     ErrCode SubscribeOsAccount(
109         const OsAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override;
110     ErrCode UnsubscribeOsAccount(const sptr<IRemoteObject> &eventListener) override;
111     ErrCode GetOsAccountSwitchMod(int32_t &switchMod) override;
112     ErrCode IsCurrentOsAccountVerified(bool &isVerified) override;
113 
114     ErrCode IsOsAccountCompleted(int32_t id, bool &isOsAccountCompleted) override;
115     ErrCode SetCurrentOsAccountIsVerified(bool isVerified) override;
116     ErrCode SetOsAccountIsVerified(int32_t id, bool isVerified) override;
117     ErrCode DumpState(int32_t id, std::vector<std::string> &state) override;
118     ErrCode DumpOsAccountInfo(std::vector<std::string> &state);
119 
120     ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID,
121         int &createdOsAccountNum) override;
122     ErrCode GetSerialNumberFromDatabase(const std::string& storeID,
123         int64_t &serialNumber) override;
124     ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id) override;
125     ErrCode GetOsAccountFromDatabase(const std::string& storeID,
126         const int id, OsAccountInfo &osAccountInfo);
127     ErrCode GetOsAccountFromDatabase(const std::string& storeID,
128         int32_t id, StringRawData& stringRawData) override;
129     ErrCode GetOsAccountListFromDatabase(const std::string& storeID,
130         std::vector<OsAccountInfo> &osAccountList);
131     ErrCode GetOsAccountListFromDatabase(const std::string& storeID,
132         StringRawData& osAccountInfos) override;
133     ErrCode QueryActiveOsAccountIds(std::vector<int32_t>& ids) override;
134 
135     ErrCode QueryOsAccountConstraintSourceTypes(int32_t id,
136         const std::string &constraint, std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos) override;
137     ErrCode SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints,
138         bool enable, int32_t enforcerId, bool isDeviceOwner) override;
139     ErrCode SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints,
140         bool enable, int32_t targetId, int32_t enforcerId, bool isDeviceOwner) override;
141     ErrCode SubscribeOsAccountConstraints(const OsAccountConstraintSubscribeInfo &subscribeInfo,
142         const sptr<IRemoteObject> &eventListener) override;
143     ErrCode UnsubscribeOsAccountConstraints(const OsAccountConstraintSubscribeInfo &subscribeInfo,
144         const sptr<IRemoteObject> &eventListener) override;
145 
146     ErrCode SetDefaultActivatedOsAccount(int32_t id) override;
147     ErrCode GetDefaultActivatedOsAccount(int32_t &id) override;
148     ErrCode GetOsAccountShortName(std::string &shortName) override;
149     ErrCode GetOsAccountName(std::string &name) override;
150     ErrCode GetOsAccountNameById(int32_t id, std::string &name) override;
151     ErrCode GetOsAccountShortNameById(int32_t id, std::string &shortName) override;
152 
153     ErrCode IsOsAccountForeground(int32_t localId, const uint64_t displayId, bool &isForeground) override;
154     ErrCode GetForegroundOsAccountLocalId(const uint64_t displayId, int32_t &localId) override;
155     ErrCode GetForegroundOsAccounts(std::vector<ForegroundOsAccount> &accounts) override;
156     ErrCode GetBackgroundOsAccountLocalIds(std::vector<int32_t> &localIds) override;
157     ErrCode SetOsAccountToBeRemoved(int32_t localId, bool toBeRemoved) override;
158     ErrCode GetOsAccountDomainInfo(int32_t localId, DomainAccountInfo &domainInfo) override;
159 #ifdef SUPPORT_LOCK_OS_ACCOUNT
160     ErrCode PublishOsAccountLockEvent(const int32_t localId, bool isLocking) override;
161     ErrCode LockOsAccount(const int32_t localId) override;
162 #endif
163     ErrCode BindDomainAccount(const int32_t localId, const DomainAccountInfo &domainInfo,
164         const sptr<IDomainAccountCallback> &callback) override;
165 #ifdef SUPPORT_DOMAIN_ACCOUNTS
166     ErrCode GetServerConfigInfo(OsAccountInfo &osAccountInfo);
167 #endif // SUPPORT_DOMAIN_ACCOUNTS
168     ErrCode CallbackEnter([[maybe_unused]] uint32_t code) override;
169     ErrCode CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override;
170 
171 private:
172     virtual ErrCode DumpStateByAccounts(
173         const std::vector<OsAccountInfo> &osAccountInfos, std::vector<std::string> &state);
174     bool PermissionCheck(const std::string& permissionName, const std::string& constraintName);
175     bool CheckCreateOsAccountWhiteList();
176     ErrCode ValidateShortName(const std::string &shortName);
177     void GetCurrentLocalId(int32_t &localId);
178     ErrCode GetOsAccountShortNameCommon(const int32_t id, std::string &shortName);
179     ErrCode ValidateAccountCreateParamAndPermission(const std::string &localName, const OsAccountType &type);
180     void ConstraintPublish(const std::vector<std::string> &oldConstraints,
181         const std::vector<std::string> &constraints, int32_t localId, bool enable);
182     ErrCode CheckLocalIdRestricted(int32_t localId);
183 
184 private:
185     IInnerOsAccountManager &innerManager_;
186     OsAccountConstraintManager &constraintManger_;
187     DISALLOW_COPY_AND_MOVE(OsAccountManagerService);
188 };
189 }  // namespace AccountSA
190 }  // namespace OHOS
191 
192 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_MANAGER_SERVICE_H
193