1 /*
2 * Copyright (c) 2022 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_get_data_proxy.h"
17
18 #include "iam_logger.h"
19
20 #define LOG_LABEL UserIam::Common::LABEL_PIN_AUTH_SA
21
22 namespace OHOS {
23 namespace UserIam {
24 namespace PinAuth {
OnGetData(int32_t authSubType,const std::vector<uint8_t> & salt,const sptr<InputerSetData> & inputerSetData)25 void InputerGetDataProxy::OnGetData(int32_t authSubType, const std::vector<uint8_t> &salt,
26 const sptr<InputerSetData> &inputerSetData)
27 {
28 IAM_LOGI("start");
29 if (inputerSetData == nullptr) {
30 IAM_LOGE("inputerSetData is nullptr");
31 return;
32 }
33
34 MessageParcel data;
35 MessageParcel reply;
36
37 if (!data.WriteInterfaceToken(InputerGetDataProxy::GetDescriptor())) {
38 IAM_LOGE("write descriptor fail");
39 return;
40 }
41 if (!data.WriteInt32(authSubType)) {
42 IAM_LOGE("write authSubType fail");
43 return;
44 }
45
46 if (!data.WriteUInt8Vector(salt)) {
47 IAM_LOGE("write salt fail");
48 return;
49 }
50
51 if (!data.WriteRemoteObject(inputerSetData->AsObject())) {
52 IAM_LOGE("write inputerData fail");
53 return;
54 }
55 bool ret = SendRequest(InputerGetData::ON_GET_DATA, data, reply);
56 if (ret) {
57 int32_t result = reply.ReadInt32();
58 IAM_LOGI("result = %{public}d", result);
59 }
60 }
61
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)62 bool InputerGetDataProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
63 {
64 IAM_LOGI("code = %{public}u", code);
65 sptr<IRemoteObject> remote = Remote();
66 if (remote == nullptr) {
67 IAM_LOGE("failed to get remote");
68 return false;
69 }
70 MessageOption option(MessageOption::TF_SYNC);
71 int32_t result = remote->SendRequest(code, data, reply, option);
72 if (result != OHOS::NO_ERROR) {
73 IAM_LOGE("failed to send request, result = %{public}d", result);
74 return false;
75 }
76 return true;
77 }
78 } // namespace PinAuth
79 } // namespace UserIam
80 } // namespace OHOS
81