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 int32_t labelId; 57 int32_t iconId; 58 std::vector<AidInfo> customDataAid; 59 }; 60 61 std::vector<TagAppTechInfo> g_tagAppAndTechMap; 62 std::vector<HceAppAidInfo> g_hceAppAndAidMap; 63 std::vector<HceAppAidInfo> g_offHostAppAndAidMap; 64 65 static AppDataParser& GetInstance(); 66 67 bool HandleAppAddOrChangedEvent(std::shared_ptr<EventFwk::CommonEventData> data); 68 bool HandleAppRemovedEvent(std::shared_ptr<EventFwk::CommonEventData> data); 69 void InitAppList(); 70 std::vector<ElementName> GetDispatchTagAppsByTech(std::vector<int> discTechList); 71 #ifdef VENDOR_APPLICATIONS_ENABLED 72 std::vector<ElementName> GetVendorDispatchTagAppsByTech(std::vector<int>& discTechList); 73 void RegQueryApplicationCb(sptr<IQueryAppInfoCallback> callback); 74 void RegCardEmulationNotifyCb(sptr<IOnCardEmulationNotifyCb> callback); 75 sptr<IOnCardEmulationNotifyCb> GetNotifyCardEmulationCallback() const; 76 #endif 77 void GetHceAppsByAid(const std::string &aid, std::vector<AppDataParser::HceAppAidInfo>& hceApps); 78 bool IsBundleInstalled(const std::string &bundleName); 79 void GetHceApps(std::vector<HceAppAidInfo> &hceApps); 80 void GetPaymentAbilityInfos(std::vector<AbilityInfo> &paymentAbilityInfos); 81 bool GetBundleInfo(AppExecFwk::BundleInfo &bundleInfo, const std::string &bundleName); 82 bool IsSystemApp(uint32_t uid); 83 bool IsHceApp(const ElementName &elementName); 84 private: 85 static sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy(); 86 ElementName GetMatchedTagKeyElement(ElementName &element); 87 ElementName GetMatchedHceKeyElement(ElementName &element); 88 bool IsMatchedByBundleName(ElementName &src, ElementName &target); 89 bool InitAppListByAction(const std::string action); 90 void QueryAbilityInfos(const std::string action, std::vector<AbilityInfo> &abilityInfos, 91 std::vector<ExtensionAbilityInfo> &extensionInfos); 92 bool VerifyHapPermission(const std::string bundleName, const std::string action); 93 bool UpdateAppListInfo(ElementName &element, const std::string action); 94 void UpdateTagAppList(AbilityInfo &abilityInfo, ElementName &element); 95 void UpdateHceAppList(AbilityInfo &abilityInfo, ElementName &element); 96 void UpdateOffHostAppList(AbilityInfo &abilityInfo, ElementName &element); 97 bool HaveMatchedOffHostKeyElement(ElementName &element); 98 bool RemoveTagAppInfo(ElementName &element); 99 bool RemoveHceAppInfo(ElementName &element); 100 bool RemoveOffHostAppInfo(ElementName &element); 101 bool IsPaymentApp(const AppDataParser::HceAppAidInfo &hceAppInfo); 102 #ifdef VENDOR_APPLICATIONS_ENABLED 103 void GetHceAppsFromVendor(std::vector<HceAppAidInfo> &hceApps); 104 void GetPaymentAbilityInfosFromVendor(std::vector<AbilityInfo> &paymentAbilityInfos); 105 bool IsHceAppFromVendor(const ElementName &elementName); 106 sptr<IQueryAppInfoCallback> queryApplicationByVendor_ {}; 107 sptr<IOnCardEmulationNotifyCb> onCardEmulationNotify_ {}; 108 #endif 109 bool appListInitDone_ = false; 110 }; 111 } // namespace NFC 112 } // namespace OHOS 113 #endif // NFC_EVENT_HANDLER_H 114