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 #include "os_account_manager.h"
16 #include "account_info.h"
17 #include "account_log_wrapper.h"
18 #include "account_permission_manager.h"
19 #include "os_account.h"
20
21 namespace OHOS {
22 namespace AccountSA {
23
CreateOsAccount(const std::string & name,const OsAccountType & type,OsAccountInfo & osAccountInfo)24 ErrCode OsAccountManager::CreateOsAccount(
25 const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo)
26 {
27 return OsAccount::GetInstance().CreateOsAccount(name, type, osAccountInfo);
28 }
29
CreateOsAccount(const std::string & localName,const std::string & shortName,const OsAccountType & type,OsAccountInfo & osAccountInfo)30 ErrCode OsAccountManager::CreateOsAccount(
31 const std::string &localName, const std::string &shortName, const OsAccountType &type, OsAccountInfo &osAccountInfo)
32 {
33 return OsAccount::GetInstance().CreateOsAccount(localName, shortName, type, osAccountInfo);
34 }
35
CreateOsAccount(const std::string & localName,const std::string & shortName,const OsAccountType & type,const CreateOsAccountOptions & options,OsAccountInfo & osAccountInfo)36 ErrCode OsAccountManager::CreateOsAccount(const std::string& localName, const std::string& shortName,
37 const OsAccountType& type, const CreateOsAccountOptions& options, OsAccountInfo& osAccountInfo)
38 {
39 return OsAccount::GetInstance().CreateOsAccount(localName, shortName, type, osAccountInfo, options);
40 }
41
CreateOsAccountWithFullInfo(OsAccountInfo & osAccountInfo,const CreateOsAccountOptions & options)42 ErrCode OsAccountManager::CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo,
43 const CreateOsAccountOptions& options)
44 {
45 return OsAccount::GetInstance().CreateOsAccountWithFullInfo(osAccountInfo, options);
46 }
47
UpdateOsAccountWithFullInfo(OsAccountInfo & osAccountInfo)48 ErrCode OsAccountManager::UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo)
49 {
50 return OsAccount::GetInstance().UpdateOsAccountWithFullInfo(osAccountInfo);
51 }
52
CreateOsAccountForDomain(const OsAccountType & type,const DomainAccountInfo & domainInfo,const std::shared_ptr<DomainAccountCallback> & callback,const CreateOsAccountForDomainOptions & options)53 ErrCode OsAccountManager::CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
54 const std::shared_ptr<DomainAccountCallback> &callback, const CreateOsAccountForDomainOptions &options)
55 {
56 return OsAccount::GetInstance().CreateOsAccountForDomain(type, domainInfo, callback, options);
57 }
58
RemoveOsAccount(const int id)59 ErrCode OsAccountManager::RemoveOsAccount(const int id)
60 {
61 return OsAccount::GetInstance().RemoveOsAccount(id);
62 }
63
IsOsAccountExists(const int id,bool & isOsAccountExists)64 ErrCode OsAccountManager::IsOsAccountExists(const int id, bool &isOsAccountExists)
65 {
66 return OsAccount::GetInstance().IsOsAccountExists(id, isOsAccountExists);
67 }
68
IsOsAccountActived(const int id,bool & isOsAccountActived)69 ErrCode OsAccountManager::IsOsAccountActived(const int id, bool &isOsAccountActived)
70 {
71 return OsAccount::GetInstance().IsOsAccountActived(id, isOsAccountActived);
72 }
73
IsOsAccountConstraintEnable(const int id,const std::string & constraint,bool & isConstraintEnable)74 ErrCode OsAccountManager::IsOsAccountConstraintEnable(
75 const int id, const std::string &constraint, bool &isConstraintEnable)
76 {
77 return OsAccount::GetInstance().IsOsAccountConstraintEnable(id, constraint, isConstraintEnable);
78 }
79
CheckOsAccountConstraintEnabled(const int id,const std::string & constraint,bool & isEnabled)80 ErrCode OsAccountManager::CheckOsAccountConstraintEnabled(
81 const int id, const std::string &constraint, bool &isEnabled)
82 {
83 return OsAccount::GetInstance().CheckOsAccountConstraintEnabled(id, constraint, isEnabled);
84 }
85
IsOsAccountVerified(const int id,bool & isVerified)86 ErrCode OsAccountManager::IsOsAccountVerified(const int id, bool &isVerified)
87 {
88 return OsAccount::GetInstance().IsOsAccountVerified(id, isVerified);
89 }
90
IsOsAccountDeactivating(const int id,bool & isDeactivating)91 ErrCode OsAccountManager::IsOsAccountDeactivating(const int id, bool &isDeactivating)
92 {
93 return OsAccount::GetInstance().IsOsAccountDeactivating(id, isDeactivating);
94 }
95
GetCreatedOsAccountsCount(unsigned int & osAccountsCount)96 ErrCode OsAccountManager::GetCreatedOsAccountsCount(unsigned int &osAccountsCount)
97 {
98 return OsAccount::GetInstance().GetCreatedOsAccountsCount(osAccountsCount);
99 }
100
GetOsAccountLocalIdFromProcess(int & id)101 ErrCode OsAccountManager::GetOsAccountLocalIdFromProcess(int &id)
102 {
103 return OsAccount::GetInstance().GetOsAccountLocalIdFromProcess(id);
104 }
105
IsMainOsAccount(bool & isMainOsAccount)106 ErrCode OsAccountManager::IsMainOsAccount(bool &isMainOsAccount)
107 {
108 return OsAccount::GetInstance().IsMainOsAccount(isMainOsAccount);
109 }
110
GetOsAccountLocalIdFromUid(const int uid,int & id)111 ErrCode OsAccountManager::GetOsAccountLocalIdFromUid(const int uid, int &id)
112 {
113 if (uid < 0) {
114 ACCOUNT_LOGE("invalid uid %{public}d.", uid);
115 return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
116 }
117 id = uid / UID_TRANSFORM_DIVISOR;
118 return ERR_OK;
119 }
120
GetBundleIdFromUid(const int uid,int & bundleId)121 ErrCode OsAccountManager::GetBundleIdFromUid(const int uid, int &bundleId)
122 {
123 ErrCode result = AccountPermissionManager::CheckSystemApp(false);
124 if (result != ERR_OK) {
125 ACCOUNT_LOGE("is not system application, result = %{public}u.", result);
126 return result;
127 }
128 if (uid < 0) {
129 ACCOUNT_LOGE("invalid uid %{public}d.", uid);
130 return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
131 }
132 bundleId = uid % UID_TRANSFORM_DIVISOR;
133 return ERR_OK;
134 }
135
GetOsAccountLocalIdFromDomain(const DomainAccountInfo & domainInfo,int & id)136 ErrCode OsAccountManager::GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id)
137 {
138 return OsAccount::GetInstance().GetOsAccountLocalIdFromDomain(domainInfo, id);
139 }
140
QueryMaxOsAccountNumber(uint32_t & maxOsAccountNumber)141 ErrCode OsAccountManager::QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber)
142 {
143 return OsAccount::GetInstance().QueryMaxOsAccountNumber(maxOsAccountNumber);
144 }
145
QueryMaxLoggedInOsAccountNumber(uint32_t & maxNum)146 ErrCode OsAccountManager::QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum)
147 {
148 return OsAccount::GetInstance().QueryMaxLoggedInOsAccountNumber(maxNum);
149 }
150
GetOsAccountAllConstraints(const int id,std::vector<std::string> & constraints)151 ErrCode OsAccountManager::GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints)
152 {
153 return OsAccount::GetInstance().GetOsAccountAllConstraints(id, constraints);
154 }
155
QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> & osAccountInfos)156 ErrCode OsAccountManager::QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos)
157 {
158 return OsAccount::GetInstance().QueryAllCreatedOsAccounts(osAccountInfos);
159 }
160
QueryCurrentOsAccount(OsAccountInfo & osAccountInfo)161 ErrCode OsAccountManager::QueryCurrentOsAccount(OsAccountInfo &osAccountInfo)
162 {
163 return OsAccount::GetInstance().QueryCurrentOsAccount(osAccountInfo);
164 }
165
QueryOsAccountById(const int id,OsAccountInfo & osAccountInfo)166 ErrCode OsAccountManager::QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo)
167 {
168 return OsAccount::GetInstance().QueryOsAccountById(id, osAccountInfo);
169 }
170
GetOsAccountTypeFromProcess(OsAccountType & type)171 ErrCode OsAccountManager::GetOsAccountTypeFromProcess(OsAccountType &type)
172 {
173 return OsAccount::GetInstance().GetOsAccountTypeFromProcess(type);
174 }
175
GetOsAccountType(const int id,OsAccountType & type)176 ErrCode OsAccountManager::GetOsAccountType(const int id, OsAccountType& type)
177 {
178 return OsAccount::GetInstance().GetOsAccountType(id, type);
179 }
180
GetOsAccountProfilePhoto(const int id,std::string & photo)181 ErrCode OsAccountManager::GetOsAccountProfilePhoto(const int id, std::string &photo)
182 {
183 return OsAccount::GetInstance().GetOsAccountProfilePhoto(id, photo);
184 }
185
IsMultiOsAccountEnable(bool & isMultiOsAccountEnable)186 ErrCode OsAccountManager::IsMultiOsAccountEnable(bool &isMultiOsAccountEnable)
187 {
188 return OsAccount::GetInstance().IsMultiOsAccountEnable(isMultiOsAccountEnable);
189 }
190
SetOsAccountName(const int id,const std::string & localName)191 ErrCode OsAccountManager::SetOsAccountName(const int id, const std::string &localName)
192 {
193 return OsAccount::GetInstance().SetOsAccountName(id, localName);
194 }
195
SetOsAccountConstraints(const int id,const std::vector<std::string> & constraints,const bool enable)196 ErrCode OsAccountManager::SetOsAccountConstraints(
197 const int id, const std::vector<std::string> &constraints, const bool enable)
198 {
199 return OsAccount::GetInstance().SetOsAccountConstraints(id, constraints, enable);
200 }
201
SetOsAccountProfilePhoto(const int id,const std::string & photo)202 ErrCode OsAccountManager::SetOsAccountProfilePhoto(const int id, const std::string &photo)
203 {
204 return OsAccount::GetInstance().SetOsAccountProfilePhoto(id, photo);
205 }
206
GetDistributedVirtualDeviceId(std::string & deviceId)207 ErrCode OsAccountManager::GetDistributedVirtualDeviceId(std::string &deviceId)
208 {
209 return OsAccount::GetInstance().GetDistributedVirtualDeviceId(deviceId);
210 }
211
ActivateOsAccount(const int id)212 ErrCode OsAccountManager::ActivateOsAccount(const int id)
213 {
214 return OsAccount::GetInstance().ActivateOsAccount(id);
215 }
216
DeactivateOsAccount(const int id)217 ErrCode OsAccountManager::DeactivateOsAccount(const int id)
218 {
219 return OsAccount::GetInstance().DeactivateOsAccount(id);
220 }
221
DeactivateAllOsAccounts()222 ErrCode OsAccountManager::DeactivateAllOsAccounts()
223 {
224 return OsAccount::GetInstance().DeactivateAllOsAccounts();
225 }
226
StartOsAccount(const int id)227 ErrCode OsAccountManager::StartOsAccount(const int id)
228 {
229 return OsAccount::GetInstance().StartOsAccount(id);
230 }
231
GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber,int & id)232 ErrCode OsAccountManager::GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id)
233 {
234 return OsAccount::GetInstance().GetOsAccountLocalIdBySerialNumber(serialNumber, id);
235 }
236
GetSerialNumberByOsAccountLocalId(const int & id,int64_t & serialNumber)237 ErrCode OsAccountManager::GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber)
238 {
239 return OsAccount::GetInstance().GetSerialNumberByOsAccountLocalId(id, serialNumber);
240 }
241
SubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> & subscriber)242 ErrCode OsAccountManager::SubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber)
243 {
244 return OsAccount::GetInstance().SubscribeOsAccount(subscriber);
245 }
246
UnsubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> & subscriber)247 ErrCode OsAccountManager::UnsubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber)
248 {
249 return OsAccount::GetInstance().UnsubscribeOsAccount(subscriber);
250 }
GetOsAccountSwitchMod()251 OS_ACCOUNT_SWITCH_MOD OsAccountManager::GetOsAccountSwitchMod()
252 {
253 return OsAccount::GetInstance().GetOsAccountSwitchMod();
254 }
255
IsCurrentOsAccountVerified(bool & isVerified)256 ErrCode OsAccountManager::IsCurrentOsAccountVerified(bool &isVerified)
257 {
258 return OsAccount::GetInstance().IsCurrentOsAccountVerified(isVerified);
259 }
260
IsOsAccountCompleted(const int id,bool & isOsAccountCompleted)261 ErrCode OsAccountManager::IsOsAccountCompleted(const int id, bool &isOsAccountCompleted)
262 {
263 return OsAccount::GetInstance().IsOsAccountCompleted(id, isOsAccountCompleted);
264 }
265
SetCurrentOsAccountIsVerified(const bool isVerified)266 ErrCode OsAccountManager::SetCurrentOsAccountIsVerified(const bool isVerified)
267 {
268 return OsAccount::GetInstance().SetCurrentOsAccountIsVerified(isVerified);
269 }
270
SetOsAccountIsVerified(const int id,const bool isVerified)271 ErrCode OsAccountManager::SetOsAccountIsVerified(const int id, const bool isVerified)
272 {
273 return OsAccount::GetInstance().SetOsAccountIsVerified(id, isVerified);
274 }
275
GetCreatedOsAccountNumFromDatabase(const std::string & storeID,int & createdOsAccountNum)276 ErrCode OsAccountManager::GetCreatedOsAccountNumFromDatabase(const std::string& storeID, int &createdOsAccountNum)
277 {
278 return OsAccount::GetInstance().GetCreatedOsAccountNumFromDatabase(
279 storeID, createdOsAccountNum);
280 }
281
GetSerialNumberFromDatabase(const std::string & storeID,int64_t & serialNumber)282 ErrCode OsAccountManager::GetSerialNumberFromDatabase(const std::string& storeID, int64_t &serialNumber)
283 {
284 return OsAccount::GetInstance().GetSerialNumberFromDatabase(storeID, serialNumber);
285 }
286
GetMaxAllowCreateIdFromDatabase(const std::string & storeID,int & id)287 ErrCode OsAccountManager::GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id)
288 {
289 return OsAccount::GetInstance().GetMaxAllowCreateIdFromDatabase(storeID, id);
290 }
291
GetOsAccountFromDatabase(const std::string & storeID,const int id,OsAccountInfo & osAccountInfo)292 ErrCode OsAccountManager::GetOsAccountFromDatabase(const std::string& storeID,
293 const int id,
294 OsAccountInfo &osAccountInfo)
295 {
296 return OsAccount::GetInstance().GetOsAccountFromDatabase(storeID, id, osAccountInfo);
297 }
298
GetOsAccountListFromDatabase(const std::string & storeID,std::vector<OsAccountInfo> & osAccountList)299 ErrCode OsAccountManager::GetOsAccountListFromDatabase(const std::string& storeID,
300 std::vector<OsAccountInfo> &osAccountList)
301 {
302 return OsAccount::GetInstance().GetOsAccountListFromDatabase(storeID, osAccountList);
303 }
304
QueryActiveOsAccountIds(std::vector<int32_t> & ids)305 ErrCode OsAccountManager::QueryActiveOsAccountIds(std::vector<int32_t>& ids)
306 {
307 return OsAccount::GetInstance().QueryActiveOsAccountIds(ids);
308 }
309
QueryOsAccountConstraintSourceTypes(const int32_t id,const std::string constraint,std::vector<ConstraintSourceTypeInfo> & constraintSourceTypeInfos)310 ErrCode OsAccountManager::QueryOsAccountConstraintSourceTypes(const int32_t id, const std::string constraint,
311 std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos)
312 {
313 return OsAccount::GetInstance().
314 QueryOsAccountConstraintSourceTypes(id, constraint, constraintSourceTypeInfos);
315 }
316
SetGlobalOsAccountConstraints(const std::vector<std::string> & constraints,const bool enable,const int32_t enforcerId,const bool isDeviceOwner)317 ErrCode OsAccountManager::SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints,
318 const bool enable, const int32_t enforcerId, const bool isDeviceOwner)
319 {
320 return OsAccount::GetInstance().
321 SetGlobalOsAccountConstraints(constraints, enable, enforcerId, isDeviceOwner);
322 }
323
SetSpecificOsAccountConstraints(const std::vector<std::string> & constraints,const bool enable,const int32_t targetId,const int32_t enforcerId,const bool isDeviceOwner)324 ErrCode OsAccountManager::SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints,
325 const bool enable, const int32_t targetId, const int32_t enforcerId, const bool isDeviceOwner)
326 {
327 return OsAccount::GetInstance().
328 SetSpecificOsAccountConstraints(constraints, enable, targetId, enforcerId, isDeviceOwner);
329 }
330
SetDefaultActivatedOsAccount(const int32_t id)331 ErrCode OsAccountManager::SetDefaultActivatedOsAccount(const int32_t id)
332 {
333 return OsAccount::GetInstance().SetDefaultActivatedOsAccount(id);
334 }
335
GetDefaultActivatedOsAccount(int32_t & id)336 ErrCode OsAccountManager::GetDefaultActivatedOsAccount(int32_t &id)
337 {
338 return OsAccount::GetInstance().GetDefaultActivatedOsAccount(id);
339 }
340
GetOsAccountShortName(std::string & shortName)341 ErrCode OsAccountManager::GetOsAccountShortName(std::string &shortName)
342 {
343 return OsAccount::GetInstance().GetOsAccountShortName(shortName);
344 }
345
GetOsAccountShortName(const int32_t id,std::string & shortName)346 ErrCode OsAccountManager::GetOsAccountShortName(const int32_t id, std::string &shortName)
347 {
348 return OsAccount::GetInstance().GetOsAccountShortNameById(id, shortName);
349 }
350
GetOsAccountName(std::string & name)351 ErrCode OsAccountManager::GetOsAccountName(std::string &name)
352 {
353 return OsAccount::GetInstance().GetOsAccountName(name);
354 }
355
IsOsAccountForeground(bool & isForeground)356 ErrCode OsAccountManager::IsOsAccountForeground(bool &isForeground)
357 {
358 return OsAccount::GetInstance().IsOsAccountForeground(isForeground);
359 }
360
IsOsAccountForeground(const int32_t localId,bool & isForeground)361 ErrCode OsAccountManager::IsOsAccountForeground(const int32_t localId, bool &isForeground)
362 {
363 return OsAccount::GetInstance().IsOsAccountForeground(localId, isForeground);
364 }
365
IsOsAccountForeground(const int32_t localId,const uint64_t displayId,bool & isForeground)366 ErrCode OsAccountManager::IsOsAccountForeground(const int32_t localId, const uint64_t displayId, bool &isForeground)
367 {
368 return OsAccount::GetInstance().IsOsAccountForeground(localId, displayId, isForeground);
369 }
370
GetForegroundOsAccountLocalId(int32_t & localId)371 ErrCode OsAccountManager::GetForegroundOsAccountLocalId(int32_t &localId)
372 {
373 return OsAccount::GetInstance().GetForegroundOsAccountLocalId(localId);
374 }
375
GetForegroundOsAccountLocalId(const uint64_t displayId,int32_t & localId)376 ErrCode OsAccountManager::GetForegroundOsAccountLocalId(const uint64_t displayId, int32_t &localId)
377 {
378 return OsAccount::GetInstance().GetForegroundOsAccountLocalId(displayId, localId);
379 }
380
GetForegroundOsAccounts(std::vector<ForegroundOsAccount> & accounts)381 ErrCode OsAccountManager::GetForegroundOsAccounts(std::vector<ForegroundOsAccount> &accounts)
382 {
383 return OsAccount::GetInstance().GetForegroundOsAccounts(accounts);
384 }
385
GetBackgroundOsAccountLocalIds(std::vector<int32_t> & localIds)386 ErrCode OsAccountManager::GetBackgroundOsAccountLocalIds(std::vector<int32_t> &localIds)
387 {
388 return OsAccount::GetInstance().GetBackgroundOsAccountLocalIds(localIds);
389 }
390
SetOsAccountToBeRemoved(int32_t localId,bool toBeRemoved)391 ErrCode OsAccountManager::SetOsAccountToBeRemoved(int32_t localId, bool toBeRemoved)
392 {
393 return OsAccount::GetInstance().SetOsAccountToBeRemoved(localId, toBeRemoved);
394 }
395 } // namespace AccountSA
396 } // namespace OHOS
397