• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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> & algoParameter,const sptr<InputerSetData> & inputerSetData,uint32_t algoVersion,bool isEnroll)25 void InputerGetDataProxy::OnGetData(int32_t authSubType, const std::vector<uint8_t> &algoParameter,
26     const sptr<InputerSetData> &inputerSetData, uint32_t algoVersion, bool isEnroll)
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(algoParameter)) {
47         IAM_LOGE("write algoParameter fail");
48         return;
49     }
50 
51     if (!data.WriteRemoteObject(inputerSetData->AsObject())) {
52         IAM_LOGE("write inputerData fail");
53         return;
54     }
55     if (!data.WriteUint32(algoVersion)) {
56         IAM_LOGE("write algoVersion fail");
57         return;
58     }
59     if (!data.WriteBool(isEnroll)) {
60         IAM_LOGE("write isEnroll fail");
61         return;
62     }
63     bool ret = SendRequest(InputerGetDataInterfaceCode::ON_GET_DATA, data, reply);
64     if (ret) {
65         int32_t result = reply.ReadInt32();
66         IAM_LOGI("result = %{public}d", result);
67     }
68 }
69 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)70 bool InputerGetDataProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
71 {
72     IAM_LOGI("code = %{public}u", code);
73     sptr<IRemoteObject> remote = Remote();
74     if (remote == nullptr) {
75         IAM_LOGE("failed to get remote");
76         return false;
77     }
78     MessageOption option(MessageOption::TF_SYNC);
79     int32_t result = remote->SendRequest(code, data, reply, option);
80     if (result != OHOS::NO_ERROR) {
81         IAM_LOGE("failed to send request, result = %{public}d", result);
82         return false;
83     }
84     return true;
85 }
86 } // namespace PinAuth
87 } // namespace UserIam
88 } // namespace OHOS
89