1 /*
2  * Copyright (C) 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 "hce_cmd_callback_proxy.h"
17 
18 #include "nfc_service_ipc_interface_code.h"
19 #include "loghelper.h"
20 
21 namespace OHOS {
22 namespace NFC {
23 namespace HCE {
HceCmdCallbackProxy(const sptr<IRemoteObject> & remote)24 HceCmdCallbackProxy::HceCmdCallbackProxy(const sptr<IRemoteObject> &remote)
25     : IRemoteProxy<KITS::IHceCmdCallback>(remote)
26 {
27 }
28 
OnCeApduData(const std::vector<uint8_t> & apduData)29 void HceCmdCallbackProxy::OnCeApduData(const std::vector<uint8_t> &apduData)
30 {
31     DebugLog("HceCmdCallbackProxy::OnNotify");
32     MessageOption option = {MessageOption::TF_ASYNC};
33     MessageParcel data;
34     MessageParcel reply;
35     if (!data.WriteInterfaceToken(GetDescriptor())) {
36         DebugLog("Write interface token error: %{public}s", __func__);
37         return;
38     }
39     data.WriteInt32(0);
40     data.WriteUInt8Vector(apduData);
41 
42     int error = Remote()->SendRequest(
43         static_cast<uint32_t>(
44             NfcServiceIpcInterfaceCode::COMMAND_ON_CE_APDU_DATA),
45         data, reply, option);
46     if (error != ERR_NONE) {
47         InfoLog("Set Attr %{public}d failed,error code is %{public}d",
48                 NfcServiceIpcInterfaceCode::COMMAND_ON_CE_APDU_DATA, error);
49         return;
50     }
51     int exception = reply.ReadInt32();
52     if (exception) {
53         DebugLog("notify COMMAND_ON_CE_APDU_DATA failed!");
54     }
55     return;
56 }
57 
58 } // namespace HCE
59 } // namespace NFC
60 } // namespace OHOS
61