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 "inputer_set_data_proxy.h"
17
18 #include "iam_logger.h"
19
20 #define LOG_TAG "PIN_AUTH_SDK"
21
22 namespace OHOS {
23 namespace UserIam {
24 namespace PinAuth {
OnSetData(int32_t authSubType,std::vector<uint8_t> data,uint32_t pinLength,int32_t errorCode)25 void InputerSetDataProxy::OnSetData(int32_t authSubType, std::vector<uint8_t> data,
26 uint32_t pinLength, int32_t errorCode)
27 {
28 IAM_LOGI("start");
29 MessageParcel dataParcel;
30 MessageParcel reply;
31
32 if (!dataParcel.WriteInterfaceToken(InputerSetDataProxy::GetDescriptor())) {
33 IAM_LOGE("write descriptor fail");
34 }
35
36 if (!dataParcel.WriteInt32(authSubType)) {
37 IAM_LOGE("write authSubType fail");
38 }
39 if (!dataParcel.WriteUInt8Vector(data)) {
40 IAM_LOGE("write data fail");
41 }
42 if (!dataParcel.WriteUint32(pinLength)) {
43 IAM_LOGE("write pinLength fail");
44 }
45 if (!dataParcel.WriteInt32(errorCode)) {
46 IAM_LOGE("write errorCode fail");
47 }
48
49 bool ret = SendRequest(InputerSetDataInterfaceCode::ON_SET_DATA, dataParcel, reply);
50 if (ret) {
51 int32_t result = reply.ReadInt32();
52 IAM_LOGI("result = %{public}d", result);
53 }
54 }
55
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)56 bool InputerSetDataProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
57 {
58 IAM_LOGI("code = %{public}u", code);
59 sptr<IRemoteObject> remote = Remote();
60 if (remote == nullptr) {
61 IAM_LOGE("failed to get remote");
62 return false;
63 }
64 MessageOption option(MessageOption::TF_SYNC);
65 int32_t result = remote->SendRequest(code, data, reply, option);
66 if (result != OHOS::NO_ERROR) {
67 IAM_LOGE("failed to send request, result = %{public}d", result);
68 return false;
69 }
70 return true;
71 }
72 } // namespace PinAuth
73 } // namespace UserIam
74 } // namespace OHOS