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_stub.h"
17
18 #include "account_log_wrapper.h"
19 #include "ipc_skeleton.h"
20
21 namespace OHOS {
22 namespace AccountSA {
DomainAuthCallbackStub()23 DomainAuthCallbackStub::DomainAuthCallbackStub()
24 {}
25
~DomainAuthCallbackStub()26 DomainAuthCallbackStub::~DomainAuthCallbackStub()
27 {}
28
OnRemoteRequest(std::uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int32_t DomainAuthCallbackStub::OnRemoteRequest(
30 std::uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
31 {
32 ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d", code, IPCSkeleton::GetCallingUid());
33 if (data.ReadInterfaceToken() != GetDescriptor()) {
34 ACCOUNT_LOGE("check descriptor failed! code %{public}u.", code);
35 return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
36 }
37 switch (code) {
38 case IDomainAuthCallback::Message::DOMAIN_AUTH_ON_RESULT:
39 return ProcOnResult(data, reply);
40 default:
41 break;
42 }
43 ACCOUNT_LOGW("remote request unhandled: %{public}d", code);
44 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
45 }
46
ProcOnResult(MessageParcel & data,MessageParcel & reply)47 ErrCode DomainAuthCallbackStub::ProcOnResult(MessageParcel &data, MessageParcel &reply)
48 {
49 int32_t resultCode;
50 if (!data.ReadInt32(resultCode)) {
51 ACCOUNT_LOGE("failed to read result code");
52 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
53 }
54 DomainAuthResult result;
55 if (!data.ReadUInt8Vector(&result.token)) {
56 ACCOUNT_LOGE("failed to read token");
57 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
58 }
59 if (!data.ReadInt32(result.authStatusInfo.remainingTimes)) {
60 ACCOUNT_LOGE("failed to read remaining times");
61 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
62 }
63 if (!data.ReadInt32(result.authStatusInfo.freezingTime)) {
64 ACCOUNT_LOGE("failed to read freezing time");
65 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
66 }
67 OnResult(resultCode, result);
68 return ERR_NONE;
69 }
70 } // namespace AccountSA
71 } // namespace OHOS
72