• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
16 #include "domain_account_proxy.h"
17 
18 #include "account_error_no.h"
19 #include "account_log_wrapper.h"
20 
21 namespace OHOS {
22 namespace AccountSA {
DomainAccountProxy(const sptr<IRemoteObject> & object)23 DomainAccountProxy::DomainAccountProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IDomainAccount>(object)
24 {}
25 
~DomainAccountProxy()26 DomainAccountProxy::~DomainAccountProxy()
27 {}
28 
SendRequest(DomainAccountInterfaceCode code,MessageParcel & data,MessageParcel & reply)29 ErrCode DomainAccountProxy::SendRequest(DomainAccountInterfaceCode code, MessageParcel &data, MessageParcel &reply)
30 {
31 #ifdef SUPPORT_DOMAIN_ACCOUNTS
32     sptr<IRemoteObject> remote = Remote();
33     if (remote == nullptr) {
34         ACCOUNT_LOGE("remote is nullptr, code = %{public}d", code);
35         return ERR_ACCOUNT_COMMON_NULL_PTR_ERROR;
36     }
37     MessageOption option(MessageOption::TF_SYNC);
38     ErrCode result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
39     if (result != ERR_OK) {
40         ACCOUNT_LOGE("failed to send domain account request, error code: %{public}d.", result);
41         return result;
42     }
43     if (!reply.ReadInt32(result)) {
44         ACCOUNT_LOGE("fail to read result");
45         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
46     }
47     return result;
48 #else
49     return ERR_DOMAIN_ACCOUNT_NOT_SUPPORT;
50 #endif // SUPPORT_DOMAIN_ACCOUNTS
51 }
52 
HasDomainAccount(const DomainAccountInfo & info,const sptr<IDomainAccountCallback> & callback)53 ErrCode DomainAccountProxy::HasDomainAccount(
54     const DomainAccountInfo &info, const sptr<IDomainAccountCallback> &callback)
55 {
56     MessageParcel data;
57     if (!data.WriteInterfaceToken(GetDescriptor())) {
58         ACCOUNT_LOGE("failed to write descriptor!");
59         return ERR_ACCOUNT_COMMON_WRITE_DESCRIPTOR_ERROR;
60     }
61     if (!data.WriteParcelable(&info)) {
62         ACCOUNT_LOGE("fail to write parcelable");
63         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
64     }
65     if ((callback == nullptr) || (!data.WriteRemoteObject(callback->AsObject()))) {
66         ACCOUNT_LOGE("fail to write callback");
67         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
68     }
69     MessageParcel reply;
70     return SendRequest(DomainAccountInterfaceCode::DOMAIN_HAS_DOMAIN_ACCOUNT, data, reply);
71 }
72 
RegisterPlugin(const sptr<IDomainAccountPlugin> & plugin)73 ErrCode DomainAccountProxy::RegisterPlugin(const sptr<IDomainAccountPlugin> &plugin)
74 {
75     MessageParcel data;
76     if (!data.WriteInterfaceToken(GetDescriptor())) {
77         ACCOUNT_LOGE("fail to write descriptor");
78         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
79     }
80     if ((plugin == nullptr) || (!data.WriteRemoteObject(plugin->AsObject()))) {
81         ACCOUNT_LOGE("fail to write plugin");
82         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
83     }
84     MessageParcel reply;
85     return SendRequest(DomainAccountInterfaceCode::REGISTER_PLUGIN, data, reply);
86 }
87 
UnregisterPlugin()88 ErrCode DomainAccountProxy::UnregisterPlugin()
89 {
90     MessageParcel data;
91     if (!data.WriteInterfaceToken(GetDescriptor())) {
92         ACCOUNT_LOGE("fail to write descriptor");
93         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
94     }
95     MessageParcel reply;
96     return SendRequest(DomainAccountInterfaceCode::UNREGISTER_PLUGIN, data, reply);
97 }
98 
GetAccountStatus(const DomainAccountInfo & info,DomainAccountStatus & status)99 ErrCode DomainAccountProxy::GetAccountStatus(const DomainAccountInfo &info, DomainAccountStatus &status)
100 {
101     MessageParcel data;
102     if (!data.WriteInterfaceToken(GetDescriptor())) {
103         ACCOUNT_LOGE("fail to write descriptor");
104         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
105     }
106     if (!data.WriteParcelable(&info)) {
107         ACCOUNT_LOGE("fail to write parcelable");
108         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
109     }
110 
111     MessageParcel reply;
112     ErrCode result = SendRequest(DomainAccountInterfaceCode::DOMAIN_ACCOUNT_STATUS_ENQUIRY, data, reply);
113     if (result != ERR_OK) {
114         ACCOUNT_LOGE("fail to read result");
115         return result;
116     }
117     int replyStatus;
118     if (!reply.ReadInt32(replyStatus)) {
119         ACCOUNT_LOGE("fail to read result");
120         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
121     }
122     status = static_cast<DomainAccountStatus>(replyStatus);
123     return ERR_OK;
124 }
125 
RegisterAccountStatusListener(const sptr<IDomainAccountCallback> & listener)126 ErrCode DomainAccountProxy::RegisterAccountStatusListener(const sptr<IDomainAccountCallback> &listener)
127 {
128     MessageParcel data;
129     if (!data.WriteInterfaceToken(GetDescriptor())) {
130         ACCOUNT_LOGE("failed to write descriptor!");
131         return ERR_ACCOUNT_COMMON_WRITE_DESCRIPTOR_ERROR;
132     }
133     if ((listener == nullptr) || (!data.WriteRemoteObject(listener->AsObject()))) {
134         ACCOUNT_LOGE("fail to write callback");
135         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
136     }
137     MessageParcel reply;
138     return SendRequest(DomainAccountInterfaceCode::DOMAIN_ACCOUNT_STATUS_LISTENER_REGISTER, data, reply);
139 }
140 
UnregisterAccountStatusListener(const sptr<IDomainAccountCallback> & listener)141 ErrCode DomainAccountProxy::UnregisterAccountStatusListener(const sptr<IDomainAccountCallback> &listener)
142 {
143     MessageParcel data;
144     if (!data.WriteInterfaceToken(GetDescriptor())) {
145         ACCOUNT_LOGE("failed to write descriptor!");
146         return ERR_ACCOUNT_COMMON_WRITE_DESCRIPTOR_ERROR;
147     }
148     if ((listener == nullptr) || (!data.WriteRemoteObject(listener->AsObject()))) {
149         ACCOUNT_LOGE("fail to write callback");
150         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
151     }
152 
153     MessageParcel reply;
154     return SendRequest(DomainAccountInterfaceCode::DOMAIN_ACCOUNT_STATUS_LISTENER_UNREGISTER, data, reply);
155 }
156 
Auth(const DomainAccountInfo & info,const std::vector<uint8_t> & password,const sptr<IDomainAccountCallback> & callback)157 ErrCode DomainAccountProxy::Auth(
158     const DomainAccountInfo &info, const std::vector<uint8_t> &password, const sptr<IDomainAccountCallback> &callback)
159 {
160     MessageParcel data;
161     if (!data.WriteInterfaceToken(GetDescriptor())) {
162         ACCOUNT_LOGE("fail to write descriptor");
163         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
164     }
165     if (!data.WriteString(info.accountName_)) {
166         ACCOUNT_LOGE("fail to write name");
167         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
168     }
169     if (!data.WriteString(info.domain_)) {
170         ACCOUNT_LOGE("fail to write domain");
171         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
172     }
173     if (!data.WriteUInt8Vector(password)) {
174         ACCOUNT_LOGE("fail to write password");
175         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
176     }
177     if (!data.WriteString(info.serverConfigId_)) {
178         ACCOUNT_LOGE("Fail to write serverConfigId");
179         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
180     }
181     if ((callback == nullptr) || (!data.WriteRemoteObject(callback->AsObject()))) {
182         ACCOUNT_LOGE("fail to write callback");
183         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
184     }
185     MessageParcel reply;
186     return SendRequest(DomainAccountInterfaceCode::DOMAIN_AUTH, data, reply);
187 }
188 
AuthUser(int32_t userId,const std::vector<uint8_t> & password,const sptr<IDomainAccountCallback> & callback)189 ErrCode DomainAccountProxy::AuthUser(
190     int32_t userId, const std::vector<uint8_t> &password, const sptr<IDomainAccountCallback> &callback)
191 {
192     MessageParcel data;
193     if (!data.WriteInterfaceToken(GetDescriptor())) {
194         ACCOUNT_LOGE("fail to write descriptor");
195         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
196     }
197     if (!data.WriteInt32(userId)) {
198         ACCOUNT_LOGE("fail to write userId for authUser");
199         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
200     }
201     if (!data.WriteUInt8Vector(password)) {
202         ACCOUNT_LOGE("fail to write password");
203         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
204     }
205     if ((callback == nullptr) || (!data.WriteRemoteObject(callback->AsObject()))) {
206         ACCOUNT_LOGE("fail to write callback");
207         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
208     }
209     MessageParcel reply;
210     return SendRequest(DomainAccountInterfaceCode::DOMAIN_AUTH_USER, data, reply);
211 }
212 
AuthWithPopup(int32_t userId,const sptr<IDomainAccountCallback> & callback)213 ErrCode DomainAccountProxy::AuthWithPopup(int32_t userId, const sptr<IDomainAccountCallback> &callback)
214 {
215     MessageParcel data;
216     if (!data.WriteInterfaceToken(GetDescriptor())) {
217         ACCOUNT_LOGE("fail to write descriptor");
218         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
219     }
220     if (!data.WriteInt32(userId)) {
221         ACCOUNT_LOGE("fail to write userId for authWithPopup");
222         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
223     }
224     if ((callback == nullptr) || (!data.WriteRemoteObject(callback->AsObject()))) {
225         ACCOUNT_LOGE("fail to write callback");
226         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
227     }
228     MessageParcel reply;
229     return SendRequest(DomainAccountInterfaceCode::DOMAIN_AUTH_WITH_POPUP, data, reply);
230 }
231 
UpdateAccountToken(const DomainAccountInfo & info,const std::vector<uint8_t> & token)232 ErrCode DomainAccountProxy::UpdateAccountToken(const DomainAccountInfo &info, const std::vector<uint8_t> &token)
233 {
234     MessageParcel data;
235     if (!data.WriteInterfaceToken(GetDescriptor())) {
236         ACCOUNT_LOGE("fail to write descriptor");
237         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
238     }
239     if (!data.WriteParcelable(&info)) {
240         ACCOUNT_LOGE("fail to write parcelable");
241         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
242     }
243     if (!data.WriteUInt8Vector(token)) {
244         ACCOUNT_LOGE("fail to write token");
245         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
246     }
247     MessageParcel reply;
248     return SendRequest(DomainAccountInterfaceCode::DOMAIN_UPDATE_ACCOUNT_TOKEN, data, reply);
249 }
250 
IsAuthenticationExpired(const DomainAccountInfo & info,bool & isExpired)251 ErrCode DomainAccountProxy::IsAuthenticationExpired(const DomainAccountInfo &info, bool &isExpired)
252 {
253     MessageParcel data;
254     if (!data.WriteInterfaceToken(GetDescriptor())) {
255         ACCOUNT_LOGE("Write descriptor failed.");
256         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
257     }
258     if (!data.WriteParcelable(&info)) {
259         ACCOUNT_LOGE("Write domainAccountInfo failed.");
260         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
261     }
262     MessageParcel reply;
263     ErrCode result = SendRequest(DomainAccountInterfaceCode::DOMAIN_IS_AUTHENTICATION_EXPIRED, data, reply);
264     if (result != ERR_OK) {
265         return result;
266     }
267 
268     if (!reply.ReadBool(isExpired)) {
269         ACCOUNT_LOGE("Read isExpired failed.");
270         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
271     }
272     return ERR_OK;
273 }
274 
SetAccountPolicy(const DomainAccountInfo & info,const std::string & policy)275 ErrCode DomainAccountProxy::SetAccountPolicy(const DomainAccountInfo &info, const std::string &policy)
276 {
277     MessageParcel data;
278     if (!data.WriteInterfaceToken(GetDescriptor())) {
279         ACCOUNT_LOGE("Write descriptor failed.");
280         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
281     }
282     if (!data.WriteParcelable(&info)) {
283         ACCOUNT_LOGE("Fail to write account.");
284         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
285     }
286     if (!data.WriteString(policy)) {
287         ACCOUNT_LOGE("Fail to write policy.");
288         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
289     }
290     MessageParcel reply;
291     return SendRequest(DomainAccountInterfaceCode::DOMAIN_SET_ACCOUNT_POLICY, data, reply);
292 }
293 
GetAccountPolicy(const DomainAccountInfo & info,std::string & policy)294 ErrCode DomainAccountProxy::GetAccountPolicy(const DomainAccountInfo &info, std::string &policy)
295 {
296     MessageParcel data;
297     if (!data.WriteInterfaceToken(GetDescriptor())) {
298         ACCOUNT_LOGE("Fail to write descriptor.");
299         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
300     }
301     if (!data.WriteParcelable(&info)) {
302         ACCOUNT_LOGE("Fail to write account.");
303         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
304     }
305 
306     MessageParcel reply;
307     ErrCode result = SendRequest(DomainAccountInterfaceCode::DOMAIN_GET_ACCOUNT_POLICY, data, reply);
308     if (result != ERR_OK) {
309         ACCOUNT_LOGE("Result is error=%{public}d.", result);
310         return result;
311     }
312     if (!reply.ReadString(policy)) {
313         ACCOUNT_LOGE("Read policy failed.");
314         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
315     }
316     return ERR_OK;
317 }
318 
GetAccessToken(const DomainAccountInfo & info,const AAFwk::WantParams & parameters,const sptr<IDomainAccountCallback> & callback)319 ErrCode DomainAccountProxy::GetAccessToken(
320     const DomainAccountInfo &info, const AAFwk::WantParams &parameters, const sptr<IDomainAccountCallback> &callback)
321 {
322     MessageParcel data;
323     if (!data.WriteInterfaceToken(GetDescriptor())) {
324         ACCOUNT_LOGE("fail to write descriptor");
325         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
326     }
327     if (!data.WriteParcelable(&info)) {
328         ACCOUNT_LOGE("fail to write info");
329         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
330     }
331     if (!data.WriteParcelable(&parameters)) {
332         ACCOUNT_LOGE("failed to write write parameters");
333         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
334     }
335     if ((callback == nullptr) || (!data.WriteRemoteObject(callback->AsObject()))) {
336         ACCOUNT_LOGE("fail to write callback");
337         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
338     }
339     MessageParcel reply;
340     return SendRequest(DomainAccountInterfaceCode::DOMAIN_GET_ACCESS_TOKEN, data, reply);
341 }
342 
GetDomainAccountInfo(const DomainAccountInfo & info,const sptr<IDomainAccountCallback> & callback)343 ErrCode DomainAccountProxy::GetDomainAccountInfo(
344     const DomainAccountInfo &info, const sptr<IDomainAccountCallback> &callback)
345 {
346     MessageParcel data;
347     if (!data.WriteInterfaceToken(GetDescriptor())) {
348         ACCOUNT_LOGE("fail to write descriptor");
349         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
350     }
351     if (!data.WriteParcelable(&info)) {
352         ACCOUNT_LOGE("fail to write accountInfo");
353         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
354     }
355     if ((callback == nullptr) || (!data.WriteRemoteObject(callback->AsObject()))) {
356         ACCOUNT_LOGE("fail to write callback");
357         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
358     }
359     MessageParcel reply;
360     return SendRequest(DomainAccountInterfaceCode::DOMAIN_GET_ACCOUNT_INFO, data, reply);
361 }
362 
AddServerConfig(const std::string & parameters,DomainServerConfig & config)363 ErrCode DomainAccountProxy::AddServerConfig(const std::string &parameters, DomainServerConfig &config)
364 {
365     MessageParcel data;
366     if (!data.WriteInterfaceToken(GetDescriptor())) {
367         ACCOUNT_LOGE("Fail to write descriptor.");
368         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
369     }
370     if (!data.WriteString(parameters)) {
371         ACCOUNT_LOGE("Fail to write config.");
372         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
373     }
374 
375     MessageParcel reply;
376     ErrCode result = SendRequest(DomainAccountInterfaceCode::ADD_SERVER_CONFIG, data, reply);
377     if (result != ERR_OK) {
378         ACCOUNT_LOGE("Result is error=%{public}d.", result);
379         return result;
380     }
381     std::unique_ptr<DomainServerConfig> serverConfig(reply.ReadParcelable<DomainServerConfig>());
382     if (serverConfig == nullptr) {
383         ACCOUNT_LOGE("ReadParcelable domainServerConfig fail");
384         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
385     }
386     config = *serverConfig;
387     return ERR_OK;
388 }
389 
RemoveServerConfig(const std::string & configId)390 ErrCode DomainAccountProxy::RemoveServerConfig(const std::string &configId)
391 {
392     MessageParcel data;
393     if (!data.WriteInterfaceToken(GetDescriptor())) {
394         ACCOUNT_LOGE("Fail to write descriptor.");
395         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
396     }
397     if (!data.WriteString(configId)) {
398         ACCOUNT_LOGE("Fail to write config.");
399         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
400     }
401 
402     MessageParcel reply;
403     ErrCode result = SendRequest(DomainAccountInterfaceCode::REMOVE_SERVER_CONFIG, data, reply);
404     if (result != ERR_OK) {
405         ACCOUNT_LOGE("Result is error=%{public}d.", result);
406     }
407     return result;
408 }
409 
UpdateServerConfig(const std::string & configId,const std::string & parameters,DomainServerConfig & config)410 ErrCode DomainAccountProxy::UpdateServerConfig(const std::string &configId, const std::string &parameters,
411     DomainServerConfig &config)
412 {
413     MessageParcel data;
414     if (!data.WriteInterfaceToken(GetDescriptor())) {
415         ACCOUNT_LOGE("Fail to write descriptor.");
416         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
417     }
418     if (!data.WriteString(configId)) {
419         ACCOUNT_LOGE("Fail to write config.");
420         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
421     }
422     if (!data.WriteString(parameters)) {
423         ACCOUNT_LOGE("Fail to write parameters.");
424         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
425     }
426 
427     MessageParcel reply;
428     ErrCode result = SendRequest(DomainAccountInterfaceCode::UPDATE_SERVER_CONFIG, data, reply);
429     if (result != ERR_OK) {
430         ACCOUNT_LOGE("Result is error=%{public}d.", result);
431         return result;
432     }
433     std::unique_ptr<DomainServerConfig> serverConfig(reply.ReadParcelable<DomainServerConfig>());
434     if (serverConfig == nullptr) {
435         ACCOUNT_LOGE("ReadParcelable domainServerConfig fail");
436         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
437     }
438     config = *serverConfig;
439     return ERR_OK;
440 }
441 
GetServerConfig(const std::string & configId,DomainServerConfig & config)442 ErrCode DomainAccountProxy::GetServerConfig(const std::string &configId, DomainServerConfig &config)
443 {
444     MessageParcel data;
445     if (!data.WriteInterfaceToken(GetDescriptor())) {
446         ACCOUNT_LOGE("Fail to write descriptor.");
447         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
448     }
449     if (!data.WriteString(configId)) {
450         ACCOUNT_LOGE("Fail to write configId.");
451         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
452     }
453 
454     MessageParcel reply;
455     ErrCode result = SendRequest(DomainAccountInterfaceCode::GET_SERVER_CONFIG, data, reply);
456     if (result != ERR_OK) {
457         ACCOUNT_LOGE("Result is error=%{public}d.", result);
458         return result;
459     }
460     std::unique_ptr<DomainServerConfig> serverConfig(reply.ReadParcelable<DomainServerConfig>());
461     if (serverConfig == nullptr) {
462         ACCOUNT_LOGE("ReadParcelable domainServerConfig fail");
463         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
464     }
465     config = *serverConfig;
466     return ERR_OK;
467 }
468 
GetAllServerConfigs(std::vector<DomainServerConfig> & configs)469 ErrCode DomainAccountProxy::GetAllServerConfigs(std::vector<DomainServerConfig> &configs)
470 {
471     MessageParcel data;
472     if (!data.WriteInterfaceToken(GetDescriptor())) {
473         ACCOUNT_LOGE("Fail to write descriptor.");
474         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
475     }
476 
477     MessageParcel reply;
478     ErrCode result = SendRequest(DomainAccountInterfaceCode::GET_ALL_SERVER_CONFIGS, data, reply);
479     if (result != ERR_OK) {
480         ACCOUNT_LOGE("Result is error=%{public}d.", result);
481         return result;
482     }
483     uint32_t configCount;
484     if (!reply.ReadUint32(configCount)) {
485         ACCOUNT_LOGE("ReadParcelable configCount fail");
486         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
487     }
488 
489     configs.reserve(configCount);
490     for (uint32_t i = 0; i < configCount; ++i) {
491         std::unique_ptr<DomainServerConfig> serverConfig(reply.ReadParcelable<DomainServerConfig>());
492         if (serverConfig == nullptr) {
493             ACCOUNT_LOGE("ReadParcelable domainServerConfig fail");
494             return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
495         }
496         configs.push_back(*serverConfig);
497     }
498     return ERR_OK;
499 }
500 
GetAccountServerConfig(const DomainAccountInfo & info,DomainServerConfig & config)501 ErrCode DomainAccountProxy::GetAccountServerConfig(const DomainAccountInfo &info, DomainServerConfig &config)
502 {
503     MessageParcel data;
504     if (!data.WriteInterfaceToken(GetDescriptor())) {
505         ACCOUNT_LOGE("Fail to write descriptor.");
506         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
507     }
508     if (!data.WriteParcelable(&info)) {
509         ACCOUNT_LOGE("Fail to write info.");
510         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
511     }
512 
513     MessageParcel reply;
514     ErrCode result = SendRequest(DomainAccountInterfaceCode::GET_ACCOUNT_SERVER_CONFIG, data, reply);
515     if (result != ERR_OK) {
516         ACCOUNT_LOGE("Result is error=%{public}d.", result);
517         return result;
518     }
519     std::unique_ptr<DomainServerConfig> serverConfig(reply.ReadParcelable<DomainServerConfig>());
520     if (serverConfig == nullptr) {
521         ACCOUNT_LOGE("ReadParcelable domainServerConfig fail");
522         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
523     }
524     config = *serverConfig;
525     return ERR_OK;
526 }
527 
UpdateAccountInfo(const DomainAccountInfo & oldAccountInfo,const DomainAccountInfo & newAccountInfo)528 ErrCode DomainAccountProxy::UpdateAccountInfo(
529     const DomainAccountInfo &oldAccountInfo, const DomainAccountInfo &newAccountInfo)
530 {
531     MessageParcel data;
532     if (!data.WriteInterfaceToken(GetDescriptor())) {
533         ACCOUNT_LOGE("Fail to write descriptor");
534         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
535     }
536     if (!data.WriteParcelable(&oldAccountInfo)) {
537         ACCOUNT_LOGE("Fail to write oldAccountInfo");
538         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
539     }
540     if (!data.WriteParcelable(&newAccountInfo)) {
541         ACCOUNT_LOGE("Fail to write newAccountInfo");
542         return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
543     }
544     MessageParcel reply;
545     return SendRequest(DomainAccountInterfaceCode::DOMAIN_UPDATE_ACCOUNT_INFO, data, reply);
546 }
547 } // namespace AccountSA
548 } // namespace OHOS