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