1 /* 2 * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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 APP_DATA_PARSER_H 16 #define APP_DATA_PARSER_H 17 #include <vector> 18 #include "ability_info.h" 19 #include "bundle_mgr_interface.h" 20 #include "bundle_mgr_proxy.h" 21 #include "common_event_subscriber.h" 22 #include "common_event_support.h" 23 #include "element_name.h" 24 #ifdef VENDOR_APPLICATIONS_ENABLED 25 #include "ion_card_emulation_notify_cb.h" 26 #include "iquery_app_info_callback.h" 27 #endif 28 #include "nfc_sdk_common.h" 29 #include "want.h" 30 31 namespace OHOS { 32 namespace NFC { 33 using AppExecFwk::AbilityInfo; 34 using AppExecFwk::ExtensionAbilityInfo; 35 using OHOS::AppExecFwk::ElementName; 36 class BundleMgrDeathRecipient : public IRemoteObject::DeathRecipient { 37 void OnRemoteDied([[maybe_unused]] const wptr<IRemoteObject> &remote) override; 38 }; 39 class AppDataParser { 40 public: 41 explicit AppDataParser(); 42 ~AppDataParser(); 43 44 struct AidInfo { 45 std::string name; // the type, payment-aid, or other-aid 46 std::string value; // the aid value 47 }; 48 49 struct TagAppTechInfo { 50 ElementName element; 51 std::vector<std::string> tech; 52 }; 53 54 struct HceAppAidInfo { 55 ElementName element; 56 uint32_t labelId; 57 uint32_t iconId; 58 int32_t appIndex; 59 std::vector<AidInfo> customDataAid; 60 }; 61 62 std::vector<TagAppTechInfo> g_tagAppAndTechMap; 63 std::vector<HceAppAidInfo> g_hceAppAndAidMap; 64 std::vector<HceAppAidInfo> g_offHostAppAndAidMap; 65 66 static AppDataParser& GetInstance(); 67 68 bool HandleAppAddOrChangedEvent(std::shared_ptr<EventFwk::CommonEventData> data); 69 bool HandleAppRemovedEvent(std::shared_ptr<EventFwk::CommonEventData> data); 70 void InitAppList(); 71 std::vector<ElementName> GetDispatchTagAppsByTech(std::vector<int> discTechList); 72 #ifdef VENDOR_APPLICATIONS_ENABLED 73 std::vector<ElementName> GetVendorDispatchTagAppsByTech(std::vector<int>& discTechList); 74 void RegQueryApplicationCb(sptr<IQueryAppInfoCallback> callback); 75 void RegCardEmulationNotifyCb(sptr<IOnCardEmulationNotifyCb> callback); 76 sptr<IOnCardEmulationNotifyCb> GetNotifyCardEmulationCallback() const; 77 #endif 78 void GetHceAppsByAid(const std::string &aid, std::vector<AppDataParser::HceAppAidInfo>& hceApps); 79 bool IsBundleInstalled(const std::string &bundleName); 80 void GetHceApps(std::vector<HceAppAidInfo> &hceApps); 81 void GetPaymentAbilityInfos(std::vector<AbilityInfo> &paymentAbilityInfos); 82 bool GetBundleInfo(AppExecFwk::BundleInfo &bundleInfo, const std::string &bundleName); 83 bool IsSystemApp(uint32_t uid); 84 bool IsHceApp(const ElementName &elementName); 85 std::string GetBundleNameByUid(uint32_t uid); 86 private: 87 static sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy(); 88 ElementName GetMatchedTagKeyElement(ElementName &element); 89 ElementName GetMatchedHceKeyElement(ElementName &element, int32_t appIndex); 90 bool IsMatchedByBundleName(ElementName &src, ElementName &target); 91 bool InitAppListByAction(const std::string action); 92 void QueryAbilityInfos(const std::string action, std::vector<AbilityInfo> &abilityInfos, 93 std::vector<ExtensionAbilityInfo> &extensionInfos); 94 bool VerifyHapPermission(const std::string bundleName, const std::string action); 95 bool UpdateAppListInfo(ElementName &element, const std::string action, int32_t appIndex = 0); 96 void UpdateTagAppList(AbilityInfo &abilityInfo, ElementName &element); 97 void UpdateHceAppList(AbilityInfo &abilityInfo, ElementName &element, int32_t appIndex = 0); 98 void UpdateOffHostAppList(AbilityInfo &abilityInfo, ElementName &element); 99 bool HaveMatchedOffHostKeyElement(ElementName &element); 100 bool RemoveTagAppInfo(ElementName &element); 101 bool RemoveHceAppInfo(ElementName &element, int32_t appIndex); 102 bool RemoveOffHostAppInfo(ElementName &element); 103 bool IsPaymentApp(const AppDataParser::HceAppAidInfo &hceAppInfo); 104 #ifdef VENDOR_APPLICATIONS_ENABLED 105 void GetHceAppsFromVendor(std::vector<HceAppAidInfo> &hceApps); 106 void GetPaymentAbilityInfosFromVendor(std::vector<AbilityInfo> &paymentAbilityInfos); 107 bool IsHceAppFromVendor(const ElementName &elementName); 108 sptr<IQueryAppInfoCallback> queryApplicationByVendor_ {}; 109 sptr<IOnCardEmulationNotifyCb> onCardEmulationNotify_ {}; 110 #endif 111 bool appListInitDone_ = false; 112 }; 113 } // namespace NFC 114 } // namespace OHOS 115 #endif // NFC_EVENT_HANDLER_H 116