1bc2ed2b3Sopenharmony_ci/* 2bc2ed2b3Sopenharmony_ci* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3bc2ed2b3Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License"); 4bc2ed2b3Sopenharmony_ci* you may not use this file except in compliance with the License. 5bc2ed2b3Sopenharmony_ci* You may obtain a copy of the License at 6bc2ed2b3Sopenharmony_ci* 7bc2ed2b3Sopenharmony_ci* http://www.apache.org/licenses/LICENSE-2.0 8bc2ed2b3Sopenharmony_ci* 9bc2ed2b3Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software 10bc2ed2b3Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS, 11bc2ed2b3Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc2ed2b3Sopenharmony_ci* See the License for the specific language governing permissions and 13bc2ed2b3Sopenharmony_ci* limitations under the License. 14bc2ed2b3Sopenharmony_ci*/ 15bc2ed2b3Sopenharmony_ci#ifndef APP_DATA_PARSER_H 16bc2ed2b3Sopenharmony_ci#define APP_DATA_PARSER_H 17bc2ed2b3Sopenharmony_ci#include <vector> 18bc2ed2b3Sopenharmony_ci#include "ability_info.h" 19bc2ed2b3Sopenharmony_ci#include "bundle_mgr_interface.h" 20bc2ed2b3Sopenharmony_ci#include "bundle_mgr_proxy.h" 21bc2ed2b3Sopenharmony_ci#include "common_event_subscriber.h" 22bc2ed2b3Sopenharmony_ci#include "common_event_support.h" 23bc2ed2b3Sopenharmony_ci#include "element_name.h" 24bc2ed2b3Sopenharmony_ci#ifdef VENDOR_APPLICATIONS_ENABLED 25bc2ed2b3Sopenharmony_ci#include "ion_card_emulation_notify_cb.h" 26bc2ed2b3Sopenharmony_ci#include "iquery_app_info_callback.h" 27bc2ed2b3Sopenharmony_ci#endif 28bc2ed2b3Sopenharmony_ci#include "nfc_sdk_common.h" 29bc2ed2b3Sopenharmony_ci#include "want.h" 30bc2ed2b3Sopenharmony_ci 31bc2ed2b3Sopenharmony_cinamespace OHOS { 32bc2ed2b3Sopenharmony_cinamespace NFC { 33bc2ed2b3Sopenharmony_ciusing AppExecFwk::AbilityInfo; 34bc2ed2b3Sopenharmony_ciusing AppExecFwk::ExtensionAbilityInfo; 35bc2ed2b3Sopenharmony_ciusing OHOS::AppExecFwk::ElementName; 36bc2ed2b3Sopenharmony_ciclass BundleMgrDeathRecipient : public IRemoteObject::DeathRecipient { 37bc2ed2b3Sopenharmony_ci void OnRemoteDied([[maybe_unused]] const wptr<IRemoteObject> &remote) override; 38bc2ed2b3Sopenharmony_ci}; 39bc2ed2b3Sopenharmony_ciclass AppDataParser { 40bc2ed2b3Sopenharmony_cipublic: 41bc2ed2b3Sopenharmony_ci explicit AppDataParser(); 42bc2ed2b3Sopenharmony_ci ~AppDataParser(); 43bc2ed2b3Sopenharmony_ci 44bc2ed2b3Sopenharmony_ci struct AidInfo { 45bc2ed2b3Sopenharmony_ci std::string name; // the type, payment-aid, or other-aid 46bc2ed2b3Sopenharmony_ci std::string value; // the aid value 47bc2ed2b3Sopenharmony_ci }; 48bc2ed2b3Sopenharmony_ci 49bc2ed2b3Sopenharmony_ci struct TagAppTechInfo { 50bc2ed2b3Sopenharmony_ci ElementName element; 51bc2ed2b3Sopenharmony_ci std::vector<std::string> tech; 52bc2ed2b3Sopenharmony_ci }; 53bc2ed2b3Sopenharmony_ci 54bc2ed2b3Sopenharmony_ci struct HceAppAidInfo { 55bc2ed2b3Sopenharmony_ci ElementName element; 56bc2ed2b3Sopenharmony_ci int32_t labelId; 57bc2ed2b3Sopenharmony_ci int32_t iconId; 58bc2ed2b3Sopenharmony_ci std::vector<AidInfo> customDataAid; 59bc2ed2b3Sopenharmony_ci }; 60bc2ed2b3Sopenharmony_ci 61bc2ed2b3Sopenharmony_ci std::vector<TagAppTechInfo> g_tagAppAndTechMap; 62bc2ed2b3Sopenharmony_ci std::vector<HceAppAidInfo> g_hceAppAndAidMap; 63bc2ed2b3Sopenharmony_ci std::vector<HceAppAidInfo> g_offHostAppAndAidMap; 64bc2ed2b3Sopenharmony_ci 65bc2ed2b3Sopenharmony_ci static AppDataParser& GetInstance(); 66bc2ed2b3Sopenharmony_ci 67bc2ed2b3Sopenharmony_ci bool HandleAppAddOrChangedEvent(std::shared_ptr<EventFwk::CommonEventData> data); 68bc2ed2b3Sopenharmony_ci bool HandleAppRemovedEvent(std::shared_ptr<EventFwk::CommonEventData> data); 69bc2ed2b3Sopenharmony_ci void InitAppList(); 70bc2ed2b3Sopenharmony_ci std::vector<ElementName> GetDispatchTagAppsByTech(std::vector<int> discTechList); 71bc2ed2b3Sopenharmony_ci#ifdef VENDOR_APPLICATIONS_ENABLED 72bc2ed2b3Sopenharmony_ci std::vector<ElementName> GetVendorDispatchTagAppsByTech(std::vector<int>& discTechList); 73bc2ed2b3Sopenharmony_ci void RegQueryApplicationCb(sptr<IQueryAppInfoCallback> callback); 74bc2ed2b3Sopenharmony_ci void RegCardEmulationNotifyCb(sptr<IOnCardEmulationNotifyCb> callback); 75bc2ed2b3Sopenharmony_ci sptr<IOnCardEmulationNotifyCb> GetNotifyCardEmulationCallback() const; 76bc2ed2b3Sopenharmony_ci#endif 77bc2ed2b3Sopenharmony_ci void GetHceAppsByAid(const std::string &aid, std::vector<AppDataParser::HceAppAidInfo>& hceApps); 78bc2ed2b3Sopenharmony_ci bool IsBundleInstalled(const std::string &bundleName); 79bc2ed2b3Sopenharmony_ci void GetHceApps(std::vector<HceAppAidInfo> &hceApps); 80bc2ed2b3Sopenharmony_ci void GetPaymentAbilityInfos(std::vector<AbilityInfo> &paymentAbilityInfos); 81bc2ed2b3Sopenharmony_ci bool GetBundleInfo(AppExecFwk::BundleInfo &bundleInfo, const std::string &bundleName); 82bc2ed2b3Sopenharmony_ci bool IsSystemApp(uint32_t uid); 83bc2ed2b3Sopenharmony_ci bool IsHceApp(const ElementName &elementName); 84bc2ed2b3Sopenharmony_ci std::string GetBundleNameByUid(uint32_t uid); 85bc2ed2b3Sopenharmony_ciprivate: 86bc2ed2b3Sopenharmony_ci static sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy(); 87bc2ed2b3Sopenharmony_ci ElementName GetMatchedTagKeyElement(ElementName &element); 88bc2ed2b3Sopenharmony_ci ElementName GetMatchedHceKeyElement(ElementName &element); 89bc2ed2b3Sopenharmony_ci bool IsMatchedByBundleName(ElementName &src, ElementName &target); 90bc2ed2b3Sopenharmony_ci bool InitAppListByAction(const std::string action); 91bc2ed2b3Sopenharmony_ci void QueryAbilityInfos(const std::string action, std::vector<AbilityInfo> &abilityInfos, 92bc2ed2b3Sopenharmony_ci std::vector<ExtensionAbilityInfo> &extensionInfos); 93bc2ed2b3Sopenharmony_ci bool VerifyHapPermission(const std::string bundleName, const std::string action); 94bc2ed2b3Sopenharmony_ci bool UpdateAppListInfo(ElementName &element, const std::string action); 95bc2ed2b3Sopenharmony_ci void UpdateTagAppList(AbilityInfo &abilityInfo, ElementName &element); 96bc2ed2b3Sopenharmony_ci void UpdateHceAppList(AbilityInfo &abilityInfo, ElementName &element); 97bc2ed2b3Sopenharmony_ci void UpdateOffHostAppList(AbilityInfo &abilityInfo, ElementName &element); 98bc2ed2b3Sopenharmony_ci bool HaveMatchedOffHostKeyElement(ElementName &element); 99bc2ed2b3Sopenharmony_ci bool RemoveTagAppInfo(ElementName &element); 100bc2ed2b3Sopenharmony_ci bool RemoveHceAppInfo(ElementName &element); 101bc2ed2b3Sopenharmony_ci bool RemoveOffHostAppInfo(ElementName &element); 102bc2ed2b3Sopenharmony_ci bool IsPaymentApp(const AppDataParser::HceAppAidInfo &hceAppInfo); 103bc2ed2b3Sopenharmony_ci#ifdef VENDOR_APPLICATIONS_ENABLED 104bc2ed2b3Sopenharmony_ci void GetHceAppsFromVendor(std::vector<HceAppAidInfo> &hceApps); 105bc2ed2b3Sopenharmony_ci void GetPaymentAbilityInfosFromVendor(std::vector<AbilityInfo> &paymentAbilityInfos); 106bc2ed2b3Sopenharmony_ci bool IsHceAppFromVendor(const ElementName &elementName); 107bc2ed2b3Sopenharmony_ci sptr<IQueryAppInfoCallback> queryApplicationByVendor_ {}; 108bc2ed2b3Sopenharmony_ci sptr<IOnCardEmulationNotifyCb> onCardEmulationNotify_ {}; 109bc2ed2b3Sopenharmony_ci#endif 110bc2ed2b3Sopenharmony_ci bool appListInitDone_ = false; 111bc2ed2b3Sopenharmony_ci}; 112bc2ed2b3Sopenharmony_ci} // namespace NFC 113bc2ed2b3Sopenharmony_ci} // namespace OHOS 114bc2ed2b3Sopenharmony_ci#endif // NFC_EVENT_HANDLER_H 115