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