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 #include "nci_ce_proxy.h"
16 #include "nci_native_selector.h"
17
18 namespace OHOS {
19 namespace NFC {
20 namespace NCI {
NciCeProxy()21 NciCeProxy::NciCeProxy()
22 {
23 nciCeInterface_ = NciNativeSelector::GetInstance().GetNciCeInterface();
24 }
25
26 /**
27 * @brief Set the listener to receive the card emulation notifications.
28 * @param listener The listener to receive the card emulation notifications.
29 */
SetCeHostListener(std::weak_ptr<ICeHostListener> listener)30 void NciCeProxy::SetCeHostListener(std::weak_ptr<ICeHostListener> listener)
31 {
32 if (nciCeInterface_ && !listener.expired()) {
33 return nciCeInterface_->SetCeHostListener(listener);
34 }
35 }
36
37 /**
38 * @brief compute the routing parameters based on the default payment app and
39 * all installed app.
40 * @return True if success, otherwise false.
41 */
ComputeRoutingParams(int defaultPaymentType)42 bool NciCeProxy::ComputeRoutingParams(int defaultPaymentType)
43 {
44 if (nciCeInterface_) {
45 return nciCeInterface_->ComputeRoutingParams(defaultPaymentType);
46 }
47 return true;
48 }
49
50 /**
51 * @brief Commit the routing parameters to nfc controller.
52 * @return True if success, otherwise false.
53 */
CommitRouting()54 bool NciCeProxy::CommitRouting()
55 {
56 if (nciCeInterface_) {
57 return nciCeInterface_->CommitRouting();
58 }
59 return true;
60 }
61
62 /**
63 * @brief send raw frame data
64 * @param hexCmdData the data to send
65 * @return True if success, otherwise false.
66 */
SendRawFrame(std::string & hexCmdData)67 bool NciCeProxy::SendRawFrame(std::string &hexCmdData)
68 {
69 if (nciCeInterface_) {
70 return nciCeInterface_->SendRawFrame(hexCmdData);
71 }
72 return false;
73 }
74
AddAidRouting(const std::string & aidStr,int route,int aidInfo,int power)75 bool NciCeProxy::AddAidRouting(const std::string &aidStr, int route, int aidInfo,
76 int power)
77 {
78 if (nciCeInterface_) {
79 return nciCeInterface_->AddAidRouting(aidStr, route, aidInfo, power);
80 }
81 return false;
82 }
83
ClearAidTable()84 bool NciCeProxy::ClearAidTable()
85 {
86 if (nciCeInterface_) {
87 return nciCeInterface_->ClearAidTable();
88 }
89 return false;
90 }
GetSimVendorBundleName()91 std::string NciCeProxy::GetSimVendorBundleName()
92 {
93 if (nciCeInterface_) {
94 return nciCeInterface_->GetSimVendorBundleName();
95 }
96 return "";
97 }
98
NotifyDefaultPaymentType(int paymentType)99 void NciCeProxy::NotifyDefaultPaymentType(int paymentType)
100 {
101 if (nciCeInterface_) {
102 nciCeInterface_->NotifyDefaultPaymentType(paymentType);
103 }
104 }
105 } // namespace NCI
106 } // namespace NFC
107 } // namespace OHOS