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 #ifndef EXTERNAL_DEPS_PROXY_H 16 #define EXTERNAL_DEPS_PROXY_H 17 #include <vector> 18 19 #include "app_data_parser.h" 20 #include "common_event_manager.h" 21 #include "nfc_sdk_common.h" 22 #include "nfc_data_share_impl.h" 23 #include "nfc_preferences.h" 24 #include "nfc_event_publisher.h" 25 #include "nfc_hisysevent.h" 26 #include "nfc_param_util.h" 27 #include "nfc_permission_checker.h" 28 #include "nfc_notification_publisher.h" 29 #include "tag_ability_dispatcher.h" 30 #include "taginfo.h" 31 #include "ability_info.h" 32 #include "want.h" 33 34 namespace OHOS { 35 namespace NFC { 36 using OHOS::AppExecFwk::ElementName; 37 using AppExecFwk::AbilityInfo; 38 class ExternalDepsProxy { 39 public: GetInstance()40 static ExternalDepsProxy &GetInstance() 41 { 42 static ExternalDepsProxy instance; 43 return instance; 44 } 45 46 bool HandleAppAddOrChangedEvent(std::shared_ptr<EventFwk::CommonEventData> data); 47 bool HandleAppRemovedEvent(std::shared_ptr<EventFwk::CommonEventData> data); 48 void InitAppList(); 49 std::vector<ElementName> GetDispatchTagAppsByTech(std::vector<int> discTechList); 50 #ifdef VENDOR_APPLICATIONS_ENABLED 51 std::vector<ElementName> GetVendorDispatchTagAppsByTech(std::vector<int> discTechList); 52 void RegQueryApplicationCb(sptr<IQueryAppInfoCallback> callback); 53 void RegCardEmulationNotifyCb(sptr<IOnCardEmulationNotifyCb> callback); 54 sptr<IOnCardEmulationNotifyCb> GetNotifyCardEmulationCallback(); 55 #endif 56 57 KITS::ErrorCode NfcDataGetValue(Uri &uri, const std::string &column, int32_t &value); 58 KITS::ErrorCode NfcDataSetValue(Uri &uri, const std::string &column, int &value); 59 60 void NfcDataSetString(const std::string& key, const std::string& value); 61 std::string NfcDataGetString(const std::string& key); 62 void NfcDataSetInt(const std::string& key, const int value); 63 int NfcDataGetInt(const std::string& key); 64 void NfcDataClear(); 65 void NfcDataDelete(const std::string& key); 66 void UpdateNfcState(int newState); 67 int GetNfcStateFromParam(); 68 69 void PublishNfcStateChanged(int newState); 70 void PublishNfcFieldStateChanged(bool isFieldOn); 71 72 void WriteNfcFailedHiSysEvent(MainErrorCode mainErrorCode, SubErrorCode subErrorCode); 73 void WriteNfcFailedHiSysEvent(const NfcFailedParams* failedParams); 74 void WriteOpenAndCloseHiSysEvent(int openRequestCnt, int openFailCnt, 75 int closeRequestCnt, int closeFailCnt); 76 void WriteHceSwipeResultHiSysEvent(const std::string &appPackageName, int hceSwipeCnt); 77 void WriteDefaultPaymentAppChangeHiSysEvent(const std::string &oldAppPackageName, 78 const std::string &newAppPackageName); 79 void WriteForegroundAppChangeHiSysEvent(const std::string &appPackageName); 80 void WriteTagFoundHiSysEvent(const std::vector<int> &techList); 81 void WritePassiveListenHiSysEvent(int requestCnt, int failCnt); 82 void WriteFirmwareUpdateHiSysEvent(int requestCnt, int failCnt); 83 void BuildFailedParams(NfcFailedParams &nfcFailedParams, MainErrorCode mainErrorCode, SubErrorCode subErrorCode); 84 void WriteDefaultRouteChangeHiSysEvent(int oldRoute, int newRoute); 85 void WriteAppBehaviorHiSysEvent(SubErrorCode behaviorCode, const std::string &appName); 86 87 bool IsGranted(std::string permission); 88 89 void DispatchTagAbility(std::shared_ptr<KITS::TagInfo> tagInfo, OHOS::sptr<IRemoteObject> tagServiceIface); 90 void DispatchAppGallery(OHOS::sptr<IRemoteObject> tagServiceIface, std::string appGalleryBundleName); 91 void StartVibratorOnce(); 92 void GetPaymentAbilityInfos(std::vector<AbilityInfo> &paymentAbilityInfos); 93 void GetHceAppsByAid(const std::string &aid, std::vector<AppDataParser::HceAppAidInfo>& hceApps); 94 void GetHceApps(std::vector<AppDataParser::HceAppAidInfo> &hceApps); 95 bool IsSystemApp(uint32_t uid); 96 bool IsHceApp(const ElementName &elementName); 97 bool IsBundleInstalled(const std::string &bundleName); 98 bool GetBundleInfo(AppExecFwk::BundleInfo &bundleInfo, const std::string &bundleName); 99 void SetWantExtraParam(std::shared_ptr<KITS::TagInfo> &tagInfo, AAFwk::Want &want); 100 std::string GetBundleNameByUid(uint32_t uid); 101 102 void PublishNfcNotification(int notificationId, const std::string &name, int balance); 103 void RegNotificationCallback(std::weak_ptr<NfcService> nfcService); 104 }; 105 } // NFC 106 } // OHOS 107 #endif // EXTERNAL_DEPS_PROXY_H