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 #include "os_account_manager.h"
16 #include "account_info.h"
17 #include "account_log_wrapper.h"
18 #include "os_account.h"
19
20 namespace OHOS {
21 namespace AccountSA {
CreateOsAccount(const std::string & name,const OsAccountType & type,OsAccountInfo & osAccountInfo)22 ErrCode OsAccountManager::CreateOsAccount(
23 const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo)
24 {
25 return OsAccount::GetInstance().CreateOsAccount(name, type, osAccountInfo);
26 }
27
CreateOsAccountForDomain(const OsAccountType & type,const DomainAccountInfo & domainInfo,OsAccountInfo & osAccountInfo)28 ErrCode OsAccountManager::CreateOsAccountForDomain(
29 const OsAccountType &type, const DomainAccountInfo &domainInfo, OsAccountInfo &osAccountInfo)
30 {
31 return OsAccount::GetInstance().CreateOsAccountForDomain(
32 type, domainInfo, osAccountInfo);
33 }
34
RemoveOsAccount(const int id)35 ErrCode OsAccountManager::RemoveOsAccount(const int id)
36 {
37 return OsAccount::GetInstance().RemoveOsAccount(id);
38 }
39
IsOsAccountExists(const int id,bool & isOsAccountExists)40 ErrCode OsAccountManager::IsOsAccountExists(const int id, bool &isOsAccountExists)
41 {
42 return OsAccount::GetInstance().IsOsAccountExists(id, isOsAccountExists);
43 }
44
IsOsAccountActived(const int id,bool & isOsAccountActived)45 ErrCode OsAccountManager::IsOsAccountActived(const int id, bool &isOsAccountActived)
46 {
47 return OsAccount::GetInstance().IsOsAccountActived(id, isOsAccountActived);
48 }
49
IsOsAccountConstraintEnable(const int id,const std::string & constraint,bool & isConstraintEnable)50 ErrCode OsAccountManager::IsOsAccountConstraintEnable(
51 const int id, const std::string &constraint, bool &isConstraintEnable)
52 {
53 return OsAccount::GetInstance().IsOsAccountConstraintEnable(id, constraint, isConstraintEnable);
54 }
55
CheckOsAccountConstraintEnabled(const int id,const std::string & constraint,bool & isEnabled)56 ErrCode OsAccountManager::CheckOsAccountConstraintEnabled(
57 const int id, const std::string &constraint, bool &isEnabled)
58 {
59 return OsAccount::GetInstance().
60 CheckOsAccountConstraintEnabled(id, constraint, isEnabled);
61 }
62
IsOsAccountVerified(const int id,bool & isTestOsAccount)63 ErrCode OsAccountManager::IsOsAccountVerified(const int id, bool &isTestOsAccount)
64 {
65 return OsAccount::GetInstance().IsOsAccountVerified(id, isTestOsAccount);
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_OSACCOUNT_SERVICE_MANAGER_BAD_UID_ERROR;
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 if (uid < 0) {
96 ACCOUNT_LOGE("invalid uid %{public}d.", uid);
97 return ERR_OSACCOUNT_SERVICE_MANAGER_BAD_UID_ERROR;
98 }
99 bundleId = uid % UID_TRANSFORM_DIVISOR;
100 return ERR_OK;
101 }
102
GetOsAccountLocalIdFromDomain(const DomainAccountInfo & domainInfo,int & id)103 ErrCode OsAccountManager::GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id)
104 {
105 return OsAccount::GetInstance().GetOsAccountLocalIdFromDomain(domainInfo, id);
106 }
107
QueryMaxOsAccountNumber(int & maxOsAccountNumber)108 ErrCode OsAccountManager::QueryMaxOsAccountNumber(int &maxOsAccountNumber)
109 {
110 return OsAccount::GetInstance().QueryMaxOsAccountNumber(maxOsAccountNumber);
111 }
112
GetOsAccountAllConstraints(const int id,std::vector<std::string> & constraints)113 ErrCode OsAccountManager::GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints)
114 {
115 return OsAccount::GetInstance().GetOsAccountAllConstraints(id, constraints);
116 }
117
QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> & osAccountInfos)118 ErrCode OsAccountManager::QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos)
119 {
120 return OsAccount::GetInstance().QueryAllCreatedOsAccounts(osAccountInfos);
121 }
122
QueryCurrentOsAccount(OsAccountInfo & osAccountInfo)123 ErrCode OsAccountManager::QueryCurrentOsAccount(OsAccountInfo &osAccountInfo)
124 {
125 return OsAccount::GetInstance().QueryCurrentOsAccount(osAccountInfo);
126 }
127
QueryOsAccountById(const int id,OsAccountInfo & osAccountInfo)128 ErrCode OsAccountManager::QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo)
129 {
130 return OsAccount::GetInstance().QueryOsAccountById(id, osAccountInfo);
131 }
132
GetOsAccountTypeFromProcess(OsAccountType & type)133 ErrCode OsAccountManager::GetOsAccountTypeFromProcess(OsAccountType &type)
134 {
135 return OsAccount::GetInstance().GetOsAccountTypeFromProcess(type);
136 }
137
GetOsAccountProfilePhoto(const int id,std::string & photo)138 ErrCode OsAccountManager::GetOsAccountProfilePhoto(const int id, std::string &photo)
139 {
140 return OsAccount::GetInstance().GetOsAccountProfilePhoto(id, photo);
141 }
142
IsMultiOsAccountEnable(bool & isMultiOsAccountEnable)143 ErrCode OsAccountManager::IsMultiOsAccountEnable(bool &isMultiOsAccountEnable)
144 {
145 return OsAccount::GetInstance().IsMultiOsAccountEnable(isMultiOsAccountEnable);
146 }
147
SetOsAccountName(const int id,const std::string & localName)148 ErrCode OsAccountManager::SetOsAccountName(const int id, const std::string &localName)
149 {
150 return OsAccount::GetInstance().SetOsAccountName(id, localName);
151 }
152
SetOsAccountConstraints(const int id,const std::vector<std::string> & constraints,const bool enable)153 ErrCode OsAccountManager::SetOsAccountConstraints(
154 const int id, const std::vector<std::string> &constraints, const bool enable)
155 {
156 return OsAccount::GetInstance().SetOsAccountConstraints(id, constraints, enable);
157 }
158
SetOsAccountProfilePhoto(const int id,const std::string & photo)159 ErrCode OsAccountManager::SetOsAccountProfilePhoto(const int id, const std::string &photo)
160 {
161 return OsAccount::GetInstance().SetOsAccountProfilePhoto(id, photo);
162 }
163
GetDistributedVirtualDeviceId(std::string & deviceId)164 ErrCode OsAccountManager::GetDistributedVirtualDeviceId(std::string &deviceId)
165 {
166 return OsAccount::GetInstance().GetDistributedVirtualDeviceId(deviceId);
167 }
168
ActivateOsAccount(const int id)169 ErrCode OsAccountManager::ActivateOsAccount(const int id)
170 {
171 return OsAccount::GetInstance().ActivateOsAccount(id);
172 }
173
StartOsAccount(const int id)174 ErrCode OsAccountManager::StartOsAccount(const int id)
175 {
176 return OsAccount::GetInstance().StartOsAccount(id);
177 }
178
StopOsAccount(const int id)179 ErrCode OsAccountManager::StopOsAccount(const int id)
180 {
181 return OsAccount::GetInstance().StopOsAccount(id);
182 }
183
GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber,int & id)184 ErrCode OsAccountManager::GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id)
185 {
186 return OsAccount::GetInstance().GetOsAccountLocalIdBySerialNumber(serialNumber, id);
187 }
188
GetSerialNumberByOsAccountLocalId(const int & id,int64_t & serialNumber)189 ErrCode OsAccountManager::GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber)
190 {
191 return OsAccount::GetInstance().GetSerialNumberByOsAccountLocalId(id, serialNumber);
192 }
193
SubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> & subscriber)194 ErrCode OsAccountManager::SubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber)
195 {
196 return OsAccount::GetInstance().SubscribeOsAccount(subscriber);
197 }
198
UnsubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> & subscriber)199 ErrCode OsAccountManager::UnsubscribeOsAccount(const std::shared_ptr<OsAccountSubscriber> &subscriber)
200 {
201 return OsAccount::GetInstance().UnsubscribeOsAccount(subscriber);
202 }
GetOsAccountSwitchMod()203 OS_ACCOUNT_SWITCH_MOD OsAccountManager::GetOsAccountSwitchMod()
204 {
205 return OsAccount::GetInstance().GetOsAccountSwitchMod();
206 }
207
IsCurrentOsAccountVerified(bool & isVerified)208 ErrCode OsAccountManager::IsCurrentOsAccountVerified(bool &isVerified)
209 {
210 return OsAccount::GetInstance().IsCurrentOsAccountVerified(isVerified);
211 }
212
IsOsAccountCompleted(const int id,bool & isOsAccountCompleted)213 ErrCode OsAccountManager::IsOsAccountCompleted(const int id, bool &isOsAccountCompleted)
214 {
215 return OsAccount::GetInstance().IsOsAccountCompleted(id, isOsAccountCompleted);
216 }
217
SetCurrentOsAccountIsVerified(const bool isVerified)218 ErrCode OsAccountManager::SetCurrentOsAccountIsVerified(const bool isVerified)
219 {
220 return OsAccount::GetInstance().SetCurrentOsAccountIsVerified(isVerified);
221 }
222
SetOsAccountIsVerified(const int id,const bool isVerified)223 ErrCode OsAccountManager::SetOsAccountIsVerified(const int id, const bool isVerified)
224 {
225 return OsAccount::GetInstance().SetOsAccountIsVerified(id, isVerified);
226 }
227
GetCreatedOsAccountNumFromDatabase(const std::string & storeID,int & createdOsAccountNum)228 ErrCode OsAccountManager::GetCreatedOsAccountNumFromDatabase(const std::string& storeID, int &createdOsAccountNum)
229 {
230 return OsAccount::GetInstance().GetCreatedOsAccountNumFromDatabase(
231 storeID, createdOsAccountNum);
232 }
233
GetSerialNumberFromDatabase(const std::string & storeID,int64_t & serialNumber)234 ErrCode OsAccountManager::GetSerialNumberFromDatabase(const std::string& storeID, int64_t &serialNumber)
235 {
236 return OsAccount::GetInstance().GetSerialNumberFromDatabase(storeID, serialNumber);
237 }
238
GetMaxAllowCreateIdFromDatabase(const std::string & storeID,int & id)239 ErrCode OsAccountManager::GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id)
240 {
241 return OsAccount::GetInstance().GetMaxAllowCreateIdFromDatabase(storeID, id);
242 }
243
GetOsAccountFromDatabase(const std::string & storeID,const int id,OsAccountInfo & osAccountInfo)244 ErrCode OsAccountManager::GetOsAccountFromDatabase(const std::string& storeID,
245 const int id,
246 OsAccountInfo &osAccountInfo)
247 {
248 return OsAccount::GetInstance().GetOsAccountFromDatabase(storeID, id, osAccountInfo);
249 }
250
GetOsAccountListFromDatabase(const std::string & storeID,std::vector<OsAccountInfo> & osAccountList)251 ErrCode OsAccountManager::GetOsAccountListFromDatabase(const std::string& storeID,
252 std::vector<OsAccountInfo> &osAccountList)
253 {
254 return OsAccount::GetInstance().GetOsAccountListFromDatabase(storeID, osAccountList);
255 }
256
QueryActiveOsAccountIds(std::vector<int32_t> & ids)257 ErrCode OsAccountManager::QueryActiveOsAccountIds(std::vector<int32_t>& ids)
258 {
259 return OsAccount::GetInstance().QueryActiveOsAccountIds(ids);
260 }
261
QueryOsAccountConstraintSourceTypes(const int32_t id,const std::string constraint,std::vector<ConstraintSourceTypeInfo> & constraintSourceTypeInfos)262 ErrCode OsAccountManager::QueryOsAccountConstraintSourceTypes(const int32_t id, const std::string constraint,
263 std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos)
264 {
265 return OsAccount::GetInstance().
266 QueryOsAccountConstraintSourceTypes(id, constraint, constraintSourceTypeInfos);
267 }
268
SetGlobalOsAccountConstraints(const std::vector<std::string> & constraints,const bool enable,const int32_t enforcerId,const bool isDeviceOwner)269 ErrCode OsAccountManager::SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints,
270 const bool enable, const int32_t enforcerId, const bool isDeviceOwner)
271 {
272 return OsAccount::GetInstance().
273 SetGlobalOsAccountConstraints(constraints, enable, enforcerId, isDeviceOwner);
274 }
275
SetSpecificOsAccountConstraints(const std::vector<std::string> & constraints,const bool enable,const int32_t targetId,const int32_t enforcerId,const bool isDeviceOwner)276 ErrCode OsAccountManager::SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints,
277 const bool enable, const int32_t targetId, const int32_t enforcerId, const bool isDeviceOwner)
278 {
279 return OsAccount::GetInstance().
280 SetSpecificOsAccountConstraints(constraints, enable, targetId, enforcerId, isDeviceOwner);
281 }
282 } // namespace AccountSA
283 } // namespace OHOS
284