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 #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
CreateOsAccountForDomain(const OsAccountType & type,const DomainAccountInfo & domainInfo,const std::shared_ptr<DomainAccountCallback> & callback)30 ErrCode OsAccountManager::CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
31 const std::shared_ptr<DomainAccountCallback> &callback)
32 {
33 return OsAccount::GetInstance().CreateOsAccountForDomain(type, domainInfo, callback);
34 }
35
RemoveOsAccount(const int id)36 ErrCode OsAccountManager::RemoveOsAccount(const int id)
37 {
38 return OsAccount::GetInstance().RemoveOsAccount(id);
39 }
40
IsOsAccountExists(const int id,bool & isOsAccountExists)41 ErrCode OsAccountManager::IsOsAccountExists(const int id, bool &isOsAccountExists)
42 {
43 return OsAccount::GetInstance().IsOsAccountExists(id, isOsAccountExists);
44 }
45
IsOsAccountActived(const int id,bool & isOsAccountActived)46 ErrCode OsAccountManager::IsOsAccountActived(const int id, bool &isOsAccountActived)
47 {
48 return OsAccount::GetInstance().IsOsAccountActived(id, isOsAccountActived);
49 }
50
IsOsAccountConstraintEnable(const int id,const std::string & constraint,bool & isConstraintEnable)51 ErrCode OsAccountManager::IsOsAccountConstraintEnable(
52 const int id, const std::string &constraint, bool &isConstraintEnable)
53 {
54 return OsAccount::GetInstance().IsOsAccountConstraintEnable(id, constraint, isConstraintEnable);
55 }
56
CheckOsAccountConstraintEnabled(const int id,const std::string & constraint,bool & isEnabled)57 ErrCode OsAccountManager::CheckOsAccountConstraintEnabled(
58 const int id, const std::string &constraint, bool &isEnabled)
59 {
60 return OsAccount::GetInstance().CheckOsAccountConstraintEnabled(id, constraint, isEnabled);
61 }
62
IsOsAccountVerified(const int id,bool & isVerified)63 ErrCode OsAccountManager::IsOsAccountVerified(const int id, bool &isVerified)
64 {
65 return OsAccount::GetInstance().IsOsAccountVerified(id, isVerified);
66 }
67
GetCreatedOsAccountsCount(unsigned int & osAccountsCount)68 ErrCode OsAccountManager::GetCreatedOsAccountsCount(unsigned int &osAccountsCount)
69 {
70 return OsAccount::GetInstance().GetCreatedOsAccountsCount(osAccountsCount);
71 }
72
GetOsAccountLocalIdFromProcess(int & id)73 ErrCode OsAccountManager::GetOsAccountLocalIdFromProcess(int &id)
74 {
75 return OsAccount::GetInstance().GetOsAccountLocalIdFromProcess(id);
76 }
77
IsMainOsAccount(bool & isMainOsAccount)78 ErrCode OsAccountManager::IsMainOsAccount(bool &isMainOsAccount)
79 {
80 return OsAccount::GetInstance().IsMainOsAccount(isMainOsAccount);
81 }
82
GetOsAccountLocalIdFromUid(const int uid,int & id)83 ErrCode OsAccountManager::GetOsAccountLocalIdFromUid(const int uid, int &id)
84 {
85 if (uid < 0) {
86 ACCOUNT_LOGE("invalid uid %{public}d.", uid);
87 return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
88 }
89 id = uid / UID_TRANSFORM_DIVISOR;
90 return ERR_OK;
91 }
92
GetBundleIdFromUid(const int uid,int & bundleId)93 ErrCode OsAccountManager::GetBundleIdFromUid(const int uid, int &bundleId)
94 {
95 ErrCode result = AccountPermissionManager::CheckSystemApp(false);
96 if (result != ERR_OK) {
97 ACCOUNT_LOGE("is not system application, result = %{public}u.", result);
98 return result;
99 }
100 if (uid < 0) {
101 ACCOUNT_LOGE("invalid uid %{public}d.", uid);
102 return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
103 }
104 bundleId = uid % UID_TRANSFORM_DIVISOR;
105 return ERR_OK;
106 }
107
GetOsAccountLocalIdFromDomain(const DomainAccountInfo & domainInfo,int & id)108 ErrCode OsAccountManager::GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id)
109 {
110 return OsAccount::GetInstance().GetOsAccountLocalIdFromDomain(domainInfo, id);
111 }
112
QueryMaxOsAccountNumber(int & maxOsAccountNumber)113 ErrCode OsAccountManager::QueryMaxOsAccountNumber(int &maxOsAccountNumber)
114 {
115 return OsAccount::GetInstance().QueryMaxOsAccountNumber(maxOsAccountNumber);
116 }
117
GetOsAccountAllConstraints(const int id,std::vector<std::string> & constraints)118 ErrCode OsAccountManager::GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints)
119 {
120 return OsAccount::GetInstance().GetOsAccountAllConstraints(id, constraints);
121 }
122
QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> & osAccountInfos)123 ErrCode OsAccountManager::QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos)
124 {
125 return OsAccount::GetInstance().QueryAllCreatedOsAccounts(osAccountInfos);
126 }
127
QueryCurrentOsAccount(OsAccountInfo & osAccountInfo)128 ErrCode OsAccountManager::QueryCurrentOsAccount(OsAccountInfo &osAccountInfo)
129 {
130 return OsAccount::GetInstance().QueryCurrentOsAccount(osAccountInfo);
131 }
132
QueryOsAccountById(const int id,OsAccountInfo & osAccountInfo)133 ErrCode OsAccountManager::QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo)
134 {
135 return OsAccount::GetInstance().QueryOsAccountById(id, osAccountInfo);
136 }
137
GetOsAccountTypeFromProcess(OsAccountType & type)138 ErrCode OsAccountManager::GetOsAccountTypeFromProcess(OsAccountType &type)
139 {
140 return OsAccount::GetInstance().GetOsAccountTypeFromProcess(type);
141 }
142
GetOsAccountProfilePhoto(const int id,std::string & photo)143 ErrCode OsAccountManager::GetOsAccountProfilePhoto(const int id, std::string &photo)
144 {
145 return OsAccount::GetInstance().GetOsAccountProfilePhoto(id, photo);
146 }
147
IsMultiOsAccountEnable(bool & isMultiOsAccountEnable)148 ErrCode OsAccountManager::IsMultiOsAccountEnable(bool &isMultiOsAccountEnable)
149 {
150 return OsAccount::GetInstance().IsMultiOsAccountEnable(isMultiOsAccountEnable);
151 }
152
SetOsAccountName(const int id,const std::string & localName)153 ErrCode OsAccountManager::SetOsAccountName(const int id, const std::string &localName)
154 {
155 return OsAccount::GetInstance().SetOsAccountName(id, localName);
156 }
157
SetOsAccountConstraints(const int id,const std::vector<std::string> & constraints,const bool enable)158 ErrCode OsAccountManager::SetOsAccountConstraints(
159 const int id, const std::vector<std::string> &constraints, const bool enable)
160 {
161 return OsAccount::GetInstance().SetOsAccountConstraints(id, constraints, enable);
162 }
163
SetOsAccountProfilePhoto(const int id,const std::string & photo)164 ErrCode OsAccountManager::SetOsAccountProfilePhoto(const int id, const std::string &photo)
165 {
166 return OsAccount::GetInstance().SetOsAccountProfilePhoto(id, photo);
167 }
168
GetDistributedVirtualDeviceId(std::string & deviceId)169 ErrCode OsAccountManager::GetDistributedVirtualDeviceId(std::string &deviceId)
170 {
171 return OsAccount::GetInstance().GetDistributedVirtualDeviceId(deviceId);
172 }
173
ActivateOsAccount(const int id)174 ErrCode OsAccountManager::ActivateOsAccount(const int id)
175 {
176 return OsAccount::GetInstance().ActivateOsAccount(id);
177 }
178
StartOsAccount(const int id)179 ErrCode OsAccountManager::StartOsAccount(const int id)
180 {
181 return OsAccount::GetInstance().StartOsAccount(id);
182 }
183
StopOsAccount(const int id)184 ErrCode OsAccountManager::StopOsAccount(const int id)
185 {
186 return OsAccount::GetInstance().StopOsAccount(id);
187 }
188
GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber,int & id)189 ErrCode OsAccountManager::GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id)
190 {
191 return OsAccount::GetInstance().GetOsAccountLocalIdBySerialNumber(serialNumber, id);
192 }
193
GetSerialNumberByOsAccountLocalId(const int & id,int64_t & serialNumber)194 ErrCode OsAccountManager::GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber)
195 {
196 return OsAccount::GetInstance().GetSerialNumberByOsAccountLocalId(id, serialNumber);
197 }
198
SubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> & subscriber)199 ErrCode OsAccountManager::SubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber)
200 {
201 return OsAccount::GetInstance().SubscribeOsAccount(subscriber);
202 }
203
UnsubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> & subscriber)204 ErrCode OsAccountManager::UnsubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber)
205 {
206 return OsAccount::GetInstance().UnsubscribeOsAccount(subscriber);
207 }
GetOsAccountSwitchMod()208 OS_ACCOUNT_SWITCH_MOD OsAccountManager::GetOsAccountSwitchMod()
209 {
210 return OsAccount::GetInstance().GetOsAccountSwitchMod();
211 }
212
IsCurrentOsAccountVerified(bool & isVerified)213 ErrCode OsAccountManager::IsCurrentOsAccountVerified(bool &isVerified)
214 {
215 return OsAccount::GetInstance().IsCurrentOsAccountVerified(isVerified);
216 }
217
IsOsAccountCompleted(const int id,bool & isOsAccountCompleted)218 ErrCode OsAccountManager::IsOsAccountCompleted(const int id, bool &isOsAccountCompleted)
219 {
220 return OsAccount::GetInstance().IsOsAccountCompleted(id, isOsAccountCompleted);
221 }
222
SetCurrentOsAccountIsVerified(const bool isVerified)223 ErrCode OsAccountManager::SetCurrentOsAccountIsVerified(const bool isVerified)
224 {
225 return OsAccount::GetInstance().SetCurrentOsAccountIsVerified(isVerified);
226 }
227
SetOsAccountIsVerified(const int id,const bool isVerified)228 ErrCode OsAccountManager::SetOsAccountIsVerified(const int id, const bool isVerified)
229 {
230 return OsAccount::GetInstance().SetOsAccountIsVerified(id, isVerified);
231 }
232
GetCreatedOsAccountNumFromDatabase(const std::string & storeID,int & createdOsAccountNum)233 ErrCode OsAccountManager::GetCreatedOsAccountNumFromDatabase(const std::string& storeID, int &createdOsAccountNum)
234 {
235 return OsAccount::GetInstance().GetCreatedOsAccountNumFromDatabase(
236 storeID, createdOsAccountNum);
237 }
238
GetSerialNumberFromDatabase(const std::string & storeID,int64_t & serialNumber)239 ErrCode OsAccountManager::GetSerialNumberFromDatabase(const std::string& storeID, int64_t &serialNumber)
240 {
241 return OsAccount::GetInstance().GetSerialNumberFromDatabase(storeID, serialNumber);
242 }
243
GetMaxAllowCreateIdFromDatabase(const std::string & storeID,int & id)244 ErrCode OsAccountManager::GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id)
245 {
246 return OsAccount::GetInstance().GetMaxAllowCreateIdFromDatabase(storeID, id);
247 }
248
GetOsAccountFromDatabase(const std::string & storeID,const int id,OsAccountInfo & osAccountInfo)249 ErrCode OsAccountManager::GetOsAccountFromDatabase(const std::string& storeID,
250 const int id,
251 OsAccountInfo &osAccountInfo)
252 {
253 return OsAccount::GetInstance().GetOsAccountFromDatabase(storeID, id, osAccountInfo);
254 }
255
GetOsAccountListFromDatabase(const std::string & storeID,std::vector<OsAccountInfo> & osAccountList)256 ErrCode OsAccountManager::GetOsAccountListFromDatabase(const std::string& storeID,
257 std::vector<OsAccountInfo> &osAccountList)
258 {
259 return OsAccount::GetInstance().GetOsAccountListFromDatabase(storeID, osAccountList);
260 }
261
QueryActiveOsAccountIds(std::vector<int32_t> & ids)262 ErrCode OsAccountManager::QueryActiveOsAccountIds(std::vector<int32_t>& ids)
263 {
264 return OsAccount::GetInstance().QueryActiveOsAccountIds(ids);
265 }
266
QueryOsAccountConstraintSourceTypes(const int32_t id,const std::string constraint,std::vector<ConstraintSourceTypeInfo> & constraintSourceTypeInfos)267 ErrCode OsAccountManager::QueryOsAccountConstraintSourceTypes(const int32_t id, const std::string constraint,
268 std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos)
269 {
270 return OsAccount::GetInstance().
271 QueryOsAccountConstraintSourceTypes(id, constraint, constraintSourceTypeInfos);
272 }
273
SetGlobalOsAccountConstraints(const std::vector<std::string> & constraints,const bool enable,const int32_t enforcerId,const bool isDeviceOwner)274 ErrCode OsAccountManager::SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints,
275 const bool enable, const int32_t enforcerId, const bool isDeviceOwner)
276 {
277 return OsAccount::GetInstance().
278 SetGlobalOsAccountConstraints(constraints, enable, enforcerId, isDeviceOwner);
279 }
280
SetSpecificOsAccountConstraints(const std::vector<std::string> & constraints,const bool enable,const int32_t targetId,const int32_t enforcerId,const bool isDeviceOwner)281 ErrCode OsAccountManager::SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints,
282 const bool enable, const int32_t targetId, const int32_t enforcerId, const bool isDeviceOwner)
283 {
284 return OsAccount::GetInstance().
285 SetSpecificOsAccountConstraints(constraints, enable, targetId, enforcerId, isDeviceOwner);
286 }
287
SetDefaultActivatedOsAccount(const int32_t id)288 ErrCode OsAccountManager::SetDefaultActivatedOsAccount(const int32_t id)
289 {
290 return OsAccount::GetInstance().SetDefaultActivatedOsAccount(id);
291 }
292
GetDefaultActivatedOsAccount(int32_t & id)293 ErrCode OsAccountManager::GetDefaultActivatedOsAccount(int32_t &id)
294 {
295 return OsAccount::GetInstance().GetDefaultActivatedOsAccount(id);
296 }
297 } // namespace AccountSA
298 } // namespace OHOS
299