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 "on_card_emulation_notify_cb_proxy.h"
17 
18 #include "nfc_service_ipc_interface_code.h"
19 #include "loghelper.h"
20 
21 namespace OHOS {
22 namespace NFC {
OnCardEmulationNotifyCbProxy(const sptr<IRemoteObject> & remote)23 OnCardEmulationNotifyCbProxy::OnCardEmulationNotifyCbProxy(const sptr<IRemoteObject> &remote)
24     : IRemoteProxy<IOnCardEmulationNotifyCb>(remote)
25 {}
26 
OnCardEmulationNotify(uint32_t eventType,std::string apduData)27 bool OnCardEmulationNotifyCbProxy::OnCardEmulationNotify(uint32_t eventType, std::string apduData)
28 {
29     MessageOption option = {MessageOption::TF_SYNC};
30     MessageParcel data;
31     MessageParcel reply;
32     if (!data.WriteInterfaceToken(GetDescriptor())) {
33         ErrorLog("OnCardEmulationNotifyCbProxy:WriteInterfaceToken token error");
34         return false;
35     }
36     data.WriteInt32(0);
37     data.WriteUint32(eventType);
38     data.WriteString(apduData);
39     int error = Remote()->SendRequest(
40         static_cast<uint32_t>(NfcServiceIpcInterfaceCode::COMMAND_ON_CARD_EMULATION_NOTIFY), data, reply, option);
41     if (error != ERR_NONE) {
42         ErrorLog("OnCardEmulationNotifyCbProxy::OnCardEmulationNotify, Set Attr %{public}d error: %{public}d",
43             NfcServiceIpcInterfaceCode::COMMAND_ON_CARD_EMULATION_NOTIFY, error);
44         return false;
45     }
46     return reply.ReadBool();
47 }
48 }  // namespace NFC
49 }  // namespace OHOS
50