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_auth_callback_proxy.h"
17
18 #include "account_error_no.h"
19 #include "account_log_wrapper.h"
20
21 namespace OHOS {
22 namespace AccountSA {
DomainAuthCallbackProxy(const sptr<IRemoteObject> & object)23 DomainAuthCallbackProxy::DomainAuthCallbackProxy(const sptr<IRemoteObject> &object)
24 : IRemoteProxy<IDomainAuthCallback>(object)
25 {}
26
~DomainAuthCallbackProxy()27 DomainAuthCallbackProxy::~DomainAuthCallbackProxy()
28 {}
29
SendRequest(IDomainAuthCallback::Message code,MessageParcel & data)30 ErrCode DomainAuthCallbackProxy::SendRequest(IDomainAuthCallback::Message code, MessageParcel &data)
31 {
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 MessageParcel reply;
38 MessageOption option(MessageOption::TF_SYNC);
39 return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
40 }
41
OnResult(int32_t resultCode,const DomainAuthResult & result)42 void DomainAuthCallbackProxy::OnResult(int32_t resultCode, const DomainAuthResult &result)
43 {
44 MessageParcel data;
45 if (!data.WriteInterfaceToken(GetDescriptor())) {
46 ACCOUNT_LOGE("fail to write descriptor");
47 return;
48 }
49 if (!data.WriteInt32(resultCode)) {
50 ACCOUNT_LOGE("fail to write result code");
51 return;
52 }
53 if (!data.WriteUInt8Vector(result.token)) {
54 ACCOUNT_LOGE("fail to write token");
55 return;
56 }
57 if (!data.WriteInt32(result.authStatusInfo.remainingTimes)) {
58 ACCOUNT_LOGE("fail to write remaining times");
59 return;
60 }
61 if (!data.WriteInt32(result.authStatusInfo.freezingTime)) {
62 ACCOUNT_LOGE("fail to write freezing time");
63 return;
64 }
65 ErrCode errCode = SendRequest(IDomainAuthCallback::Message::DOMAIN_AUTH_ON_RESULT, data);
66 if (errCode != ERR_OK) {
67 ACCOUNT_LOGE("fail to send request, error code: %{public}d", errCode);
68 }
69 }
70 } // namespace AccountSA
71 } // namespace OHOS
72