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 "external_deps_proxy.h"
16 
17 namespace OHOS {
18 namespace NFC {
HandleAppAddOrChangedEvent(std::shared_ptr<EventFwk::CommonEventData> data)19 bool ExternalDepsProxy::HandleAppAddOrChangedEvent(std::shared_ptr<EventFwk::CommonEventData> data)
20 {
21     return AppDataParser::GetInstance().HandleAppAddOrChangedEvent(data);
22 }
23 
HandleAppRemovedEvent(std::shared_ptr<EventFwk::CommonEventData> data)24 bool ExternalDepsProxy::HandleAppRemovedEvent(std::shared_ptr<EventFwk::CommonEventData> data)
25 {
26     return AppDataParser::GetInstance().HandleAppRemovedEvent(data);
27 }
28 
InitAppList()29 void ExternalDepsProxy::InitAppList()
30 {
31     AppDataParser::GetInstance().InitAppList();
32 }
33 
GetDispatchTagAppsByTech(std::vector<int> discTechList)34 std::vector<ElementName> ExternalDepsProxy::GetDispatchTagAppsByTech(std::vector<int> discTechList)
35 {
36     return AppDataParser::GetInstance().GetDispatchTagAppsByTech(discTechList);
37 }
38 
39 #ifdef VENDOR_APPLICATIONS_ENABLED
GetVendorDispatchTagAppsByTech(std::vector<int> discTechList)40 std::vector<ElementName> ExternalDepsProxy::GetVendorDispatchTagAppsByTech(std::vector<int> discTechList)
41 {
42     return AppDataParser::GetInstance().GetVendorDispatchTagAppsByTech(discTechList);
43 }
44 
RegQueryApplicationCb(sptr<IQueryAppInfoCallback> callback)45 void ExternalDepsProxy::RegQueryApplicationCb(sptr<IQueryAppInfoCallback> callback)
46 {
47     AppDataParser::GetInstance().RegQueryApplicationCb(callback);
48 }
49 
RegCardEmulationNotifyCb(sptr<IOnCardEmulationNotifyCb> callback)50 void ExternalDepsProxy::RegCardEmulationNotifyCb(sptr<IOnCardEmulationNotifyCb> callback)
51 {
52     AppDataParser::GetInstance().RegCardEmulationNotifyCb(callback);
53 }
54 
GetNotifyCardEmulationCallback()55 sptr<IOnCardEmulationNotifyCb> ExternalDepsProxy::GetNotifyCardEmulationCallback()
56 {
57     return AppDataParser::GetInstance().GetNotifyCardEmulationCallback();
58 }
59 #endif
60 
NfcDataGetValue(Uri & uri,const std::string & column,int32_t & value)61 KITS::ErrorCode ExternalDepsProxy::NfcDataGetValue(Uri &uri, const std::string &column, int32_t &value)
62 {
63     return NfcDataShareImpl::GetInstance()->GetValue(uri, column, value);
64 }
65 
NfcDataSetValue(Uri & uri,const std::string & column,int & value)66 KITS::ErrorCode ExternalDepsProxy::NfcDataSetValue(Uri &uri, const std::string &column, int &value)
67 {
68     return NfcDataShareImpl::GetInstance()->SetValue(uri, column, value);
69 }
70 
NfcDataSetString(const std::string & key,const std::string & value)71 void ExternalDepsProxy::NfcDataSetString(const std::string& key, const std::string& value)
72 {
73     NfcPreferences::GetInstance().SetString(key, value);
74 }
75 
NfcDataGetString(const std::string & key)76 std::string ExternalDepsProxy::NfcDataGetString(const std::string& key)
77 {
78     return NfcPreferences::GetInstance().GetString(key);
79 }
80 
NfcDataSetInt(const std::string & key,const int value)81 void ExternalDepsProxy::NfcDataSetInt(const std::string& key, const int value)
82 {
83     NfcPreferences::GetInstance().SetInt(key, value);
84 }
85 
NfcDataGetInt(const std::string & key)86 int ExternalDepsProxy::NfcDataGetInt(const std::string& key)
87 {
88     return NfcPreferences::GetInstance().GetInt(key);
89 }
90 
NfcDataClear()91 void ExternalDepsProxy::NfcDataClear()
92 {
93     NfcPreferences::GetInstance().Clear();
94 }
95 
NfcDataDelete(const std::string & key)96 void ExternalDepsProxy::NfcDataDelete(const std::string& key)
97 {
98     NfcPreferences::GetInstance().Delete(key);
99 }
100 
UpdateNfcState(int newState)101 void ExternalDepsProxy::UpdateNfcState(int newState)
102 {
103     NfcParamUtil::UpdateNfcStateToParam(newState);
104 }
105 
GetNfcStateFromParam()106 int ExternalDepsProxy::GetNfcStateFromParam()
107 {
108     return NfcParamUtil::GetNfcStateFromParam();
109 }
110 
PublishNfcStateChanged(int newState)111 void ExternalDepsProxy::PublishNfcStateChanged(int newState)
112 {
113     NfcEventPublisher::PublishNfcStateChanged(newState);
114 }
115 
PublishNfcFieldStateChanged(bool isFieldOn)116 void ExternalDepsProxy::PublishNfcFieldStateChanged(bool isFieldOn)
117 {
118     NfcEventPublisher::PublishNfcFieldStateChanged(isFieldOn);
119 }
120 
WriteNfcFailedHiSysEvent(MainErrorCode mainErrorCode,SubErrorCode subErrorCode)121 void ExternalDepsProxy::WriteNfcFailedHiSysEvent(MainErrorCode mainErrorCode, SubErrorCode subErrorCode)
122 {
123     NfcFailedParams nfcFailedParams;
124     ExternalDepsProxy::GetInstance().BuildFailedParams(nfcFailedParams, mainErrorCode, subErrorCode);
125     ExternalDepsProxy::GetInstance().WriteNfcFailedHiSysEvent(&nfcFailedParams);
126 }
127 
WriteNfcFailedHiSysEvent(const NfcFailedParams * failedParams)128 void ExternalDepsProxy::WriteNfcFailedHiSysEvent(const NfcFailedParams* failedParams)
129 {
130     NfcHisysEvent::WriteNfcFailedHiSysEvent(failedParams);
131 }
132 
WriteOpenAndCloseHiSysEvent(int openRequestCnt,int openFailCnt,int closeRequestCnt,int closeFailCnt)133 void ExternalDepsProxy::WriteOpenAndCloseHiSysEvent(int openRequestCnt, int openFailCnt,
134                                                     int closeRequestCnt, int closeFailCnt)
135 {
136     NfcHisysEvent::WriteOpenAndCloseHiSysEvent(openRequestCnt, openFailCnt,
137         closeRequestCnt, closeFailCnt);
138 }
139 
WriteHceSwipeResultHiSysEvent(const std::string & appPackageName,int hceSwipeCnt)140 void ExternalDepsProxy::WriteHceSwipeResultHiSysEvent(const std::string &appPackageName, int hceSwipeCnt)
141 {
142     NfcHisysEvent::WriteHceSwipeResultHiSysEvent(appPackageName, hceSwipeCnt);
143 }
144 
WriteDefaultPaymentAppChangeHiSysEvent(const std::string & oldAppPackageName,const std::string & newAppPackageName)145 void ExternalDepsProxy::WriteDefaultPaymentAppChangeHiSysEvent(const std::string &oldAppPackageName,
146                                                                const std::string &newAppPackageName)
147 {
148     NfcHisysEvent::WriteDefaultPaymentAppChangeHiSysEvent(oldAppPackageName, newAppPackageName);
149 }
150 
WriteForegroundAppChangeHiSysEvent(const std::string & appPackageName)151 void ExternalDepsProxy::WriteForegroundAppChangeHiSysEvent(const std::string &appPackageName)
152 {
153     NfcHisysEvent::WriteForegroundAppChangeHiSysEvent(appPackageName);
154 }
155 
WriteTagFoundHiSysEvent(const std::vector<int> & techList)156 void ExternalDepsProxy::WriteTagFoundHiSysEvent(const std::vector<int>& techList)
157 {
158     NfcHisysEvent::WriteTagFoundHiSysEvent(techList);
159 }
160 
WritePassiveListenHiSysEvent(int requestCnt,int failCnt)161 void ExternalDepsProxy::WritePassiveListenHiSysEvent(int requestCnt, int failCnt)
162 {
163     NfcHisysEvent::WritePassiveListenHiSysEvent(requestCnt, failCnt);
164 }
165 
WriteFirmwareUpdateHiSysEvent(int requestCnt,int failCnt)166 void ExternalDepsProxy::WriteFirmwareUpdateHiSysEvent(int requestCnt, int failCnt)
167 {
168     NfcHisysEvent::WriteFirmwareUpdateHiSysEvent(requestCnt, failCnt);
169 }
170 
BuildFailedParams(NfcFailedParams & nfcFailedParams,MainErrorCode mainErrorCode,SubErrorCode subErrorCode)171 void ExternalDepsProxy::BuildFailedParams(NfcFailedParams &nfcFailedParams,
172                                           MainErrorCode mainErrorCode,
173                                           SubErrorCode subErrorCode)
174 {
175     NfcHisysEvent::BuildFailedParams(nfcFailedParams, mainErrorCode, subErrorCode);
176 }
177 
WriteDefaultRouteChangeHiSysEvent(int oldRoute,int newRoute)178 void ExternalDepsProxy::WriteDefaultRouteChangeHiSysEvent(int oldRoute, int newRoute)
179 {
180     NfcHisysEvent::WriteDefaultRouteChangeHiSysEvent(oldRoute, newRoute);
181 }
182 
WriteAppBehaviorHiSysEvent(SubErrorCode behaviorCode,const std::string & appName)183 void ExternalDepsProxy::WriteAppBehaviorHiSysEvent(SubErrorCode behaviorCode, const std::string &appName)
184 {
185     NfcHisysEvent::WriteAppBehaviorHiSysEvent(behaviorCode, appName);
186 }
187 
IsGranted(std::string permission)188 bool ExternalDepsProxy::IsGranted(std::string permission)
189 {
190     return NfcPermissionChecker::IsGranted(permission);
191 }
192 
DispatchTagAbility(std::shared_ptr<KITS::TagInfo> tagInfo,OHOS::sptr<IRemoteObject> tagServiceIface)193 void ExternalDepsProxy::DispatchTagAbility(std::shared_ptr<KITS::TagInfo> tagInfo,
194                                            OHOS::sptr<IRemoteObject> tagServiceIface)
195 {
196     TAG::TagAbilityDispatcher::DispatchTagAbility(tagInfo, tagServiceIface);
197 }
198 
DispatchAppGallery(OHOS::sptr<IRemoteObject> tagServiceIface,std::string appGalleryBundleName)199 void ExternalDepsProxy::DispatchAppGallery(OHOS::sptr<IRemoteObject> tagServiceIface, std::string appGalleryBundleName)
200 {
201     TAG::TagAbilityDispatcher::DispatchAppGallery(tagServiceIface, appGalleryBundleName);
202 }
203 
StartVibratorOnce()204 void ExternalDepsProxy::StartVibratorOnce()
205 {
206     TAG::TagAbilityDispatcher::StartVibratorOnce();
207 }
208 
GetPaymentAbilityInfos(std::vector<AbilityInfo> & paymentAbilityInfos)209 void ExternalDepsProxy::GetPaymentAbilityInfos(std::vector<AbilityInfo>& paymentAbilityInfos)
210 {
211     AppDataParser::GetInstance().GetPaymentAbilityInfos(paymentAbilityInfos);
212 }
213 
GetHceAppsByAid(const std::string & aid,std::vector<AppDataParser::HceAppAidInfo> & hceApps)214 void ExternalDepsProxy::GetHceAppsByAid(const std::string& aid, std::vector<AppDataParser::HceAppAidInfo>& hceApps)
215 {
216     AppDataParser::GetInstance().GetHceAppsByAid(aid, hceApps);
217 }
218 
GetHceApps(std::vector<AppDataParser::HceAppAidInfo> & hceApps)219 void ExternalDepsProxy::GetHceApps(std::vector<AppDataParser::HceAppAidInfo>& hceApps)
220 {
221     AppDataParser::GetInstance().GetHceApps(hceApps);
222 }
IsSystemApp(uint32_t uid)223 bool ExternalDepsProxy::IsSystemApp(uint32_t uid)
224 {
225     return AppDataParser::GetInstance().IsSystemApp(uid);
226 }
227 
IsHceApp(const ElementName & elementName)228 bool ExternalDepsProxy::IsHceApp(const ElementName& elementName)
229 {
230     return AppDataParser::GetInstance().IsHceApp(elementName);
231 }
232 
IsBundleInstalled(const std::string & bundleName)233 bool ExternalDepsProxy::IsBundleInstalled(const std::string& bundleName)
234 {
235     return AppDataParser::GetInstance().IsBundleInstalled(bundleName);
236 }
237 
GetBundleInfo(AppExecFwk::BundleInfo & bundleInfo,const std::string & bundleName)238 bool ExternalDepsProxy::GetBundleInfo(AppExecFwk::BundleInfo& bundleInfo, const std::string& bundleName)
239 {
240     return AppDataParser::GetInstance().GetBundleInfo(bundleInfo, bundleName);
241 }
242 
SetWantExtraParam(std::shared_ptr<KITS::TagInfo> & tagInfo,AAFwk::Want & want)243 void ExternalDepsProxy::SetWantExtraParam(std::shared_ptr<KITS::TagInfo> &tagInfo, AAFwk::Want &want)
244 {
245     TAG::TagAbilityDispatcher::SetWantExtraParam(tagInfo, want);
246 }
247 
GetBundleNameByUid(uint32_t uid)248 std::string ExternalDepsProxy::GetBundleNameByUid(uint32_t uid)
249 {
250     std::string bundleName = AppDataParser::GetInstance().GetBundleNameByUid(uid);
251     if (bundleName == "") {
252         // system abilities have no bundle name, should return UID.
253         bundleName = std::to_string(uid);
254     }
255     return bundleName;
256 }
257 
PublishNfcNotification(int notificationId,const std::string & name,int balance)258 void ExternalDepsProxy::PublishNfcNotification(int notificationId, const std::string &name, int balance)
259 {
260     TAG::NfcNotificationPublisher::GetInstance().PublishNfcNotification(notificationId, name, balance);
261 }
262 
RegNotificationCallback(std::weak_ptr<NfcService> nfcService)263 void ExternalDepsProxy::RegNotificationCallback(std::weak_ptr<NfcService> nfcService)
264 {
265     TAG::NfcNotificationPublisher::GetInstance().RegNotificationCallback(nfcService);
266 }
267 } // namespace NFC
268 } // OHOS