• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "i_inputer_data_proxy.h"
17 #include "iremote_inputer.h"
18 #include "iremote_proxy.h"
19 #include "pinauth_log_wrapper.h"
20 
21 namespace OHOS {
22 namespace UserIAM {
23 namespace PinAuth {
OnSetData(int32_t authSubType,std::vector<uint8_t> data)24 void IInputerDataProxy::OnSetData(int32_t authSubType, std::vector<uint8_t> data)
25 {
26     PINAUTH_HILOGI(MODULE_FRAMEWORKS, "IInputerDataProxy::OnSetData start");
27     MessageParcel dataParcel;
28     MessageParcel reply;
29 
30     if (!dataParcel.WriteInterfaceToken(IInputerDataProxy::GetDescriptor())) {
31         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "write descriptor failed");
32     }
33 
34     if (!dataParcel.WriteInt64(authSubType)) {
35         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "fail to write parcellable for WriteInt64");
36     }
37     if (!dataParcel.WriteUInt8Vector(data)) {
38         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "fail to write parcellable for WriteUInt8Vector");
39     }
40 
41     bool ret = SendRequest(static_cast<uint32_t>(IRemoteInputerData::ON_SET_DATA), dataParcel, reply);
42     if (ret) {
43         int32_t result = reply.ReadInt32();
44         PINAUTH_HILOGI(MODULE_FRAMEWORKS, "result = %{public}d", result);
45     }
46 }
47 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)48 bool IInputerDataProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
49 {
50     PINAUTH_HILOGI(MODULE_FRAMEWORKS, "IInputerDataProxy::SendRequest start");
51     sptr<IRemoteObject> remote = Remote();
52     if (remote == nullptr) {
53         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "failed to get remote");
54         return false;
55     }
56     MessageOption option(MessageOption::TF_SYNC);
57     int32_t result = remote->SendRequest(code, data, reply, option);
58     if (result != OHOS::NO_ERROR) {
59         PINAUTH_HILOGE(MODULE_FRAMEWORKS, "failed to SendRequest.result = %{public}d", result);
60         return false;
61     }
62     return true;
63 }
64 } // namespace PinAuth
65 } // namespace UserIAM
66 } // namespace OHOS
67