• 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_set_data_proxy.h"
17 
18 #include "iam_logger.h"
19 
20 #define LOG_LABEL OHOS::UserIam::Common::LABEL_PIN_AUTH_SDK
21 
22 namespace OHOS {
23 namespace UserIam {
24 namespace PinAuth {
OnSetData(int32_t authSubType,std::vector<uint8_t> data)25 void InputerSetDataProxy::OnSetData(int32_t authSubType, std::vector<uint8_t> data)
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 
42     bool ret = SendRequest(InputerSetDataInterfaceCode::ON_SET_DATA, dataParcel, reply);
43     if (ret) {
44         int32_t result = reply.ReadInt32();
45         IAM_LOGI("result = %{public}d", result);
46     }
47 }
48 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)49 bool InputerSetDataProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
50 {
51     IAM_LOGI("code = %{public}u", code);
52     sptr<IRemoteObject> remote = Remote();
53     if (remote == nullptr) {
54         IAM_LOGE("failed to get remote");
55         return false;
56     }
57     MessageOption option(MessageOption::TF_SYNC);
58     int32_t result = remote->SendRequest(code, data, reply, option);
59     if (result != OHOS::NO_ERROR) {
60         IAM_LOGE("failed to send request, result = %{public}d", result);
61         return false;
62     }
63     return true;
64 }
65 } // namespace PinAuth
66 } // namespace UserIam
67 } // namespace OHOS