• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "loghelper.h"
25 #include "nfc_service.h"
26 #include "system_ability.h"
27 #include "want.h"
28 
29 namespace OHOS {
30 namespace NFC {
31 using AppExecFwk::AbilityInfo;
32 using AppExecFwk::ExtensionAbilityInfo;
33 using OHOS::AppExecFwk::ElementName;
34 class AppDataParser {
35 public:
36     explicit AppDataParser();
37     ~AppDataParser();
38 
39     struct AidInfo {
40         std::string name; // the type, payment-aid, or other-aid
41         std::string value; // the aid value
42     };
43 
44     struct TagAppTechInfo {
45         ElementName element;
46         std::vector<std::string> tech; // technology, such as NfcA/NfcB/IsoDep.
47     };
48 
49     struct HceAppAidInfo {
50         ElementName element;
51         std::vector<AidInfo> customDataAid;
52     };
53 
54     std::vector<TagAppTechInfo> g_tagAppAndTechMap;
55     std::vector<HceAppAidInfo> g_hceAppAndAidMap;
56 
57     static AppDataParser& GetInstance();
58 
59     void HandleAppAddOrChangedEvent(std::shared_ptr<EventFwk::CommonEventData> data);
60     void HandleAppRemovedEvent(std::shared_ptr<EventFwk::CommonEventData> data);
61     void InitAppList();
62     std::vector<ElementName> GetDispatchTagAppsByTech(std::vector<int> discTechList);
63 private:
64     static sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy();
65     ElementName GetMatchedTagKeyElement(ElementName &element);
66     ElementName GetMatchedHceKeyElement(ElementName &element);
67     bool IsMatchedByBundleName(ElementName &src, ElementName &target);
68     bool InitAppListByAction(const std::string action);
69     void QueryAbilityInfos(const std::string action, std::vector<AbilityInfo> &abilityInfos,
70         std::vector<ExtensionAbilityInfo> &extensionInfos);
71     bool VerifyHapPermission(const std::string bundleName, const std::string action);
72     bool UpdateAppListInfo(ElementName &element, const std::string action);
73     void UpdateTagAppList(AbilityInfo &abilityInfo, ElementName &element);
74     void UpdateHceAppList(AbilityInfo &abilityInfo, ElementName &element);
75     void RemoveTagAppInfo(ElementName &element);
76     void RemoveHceAppInfo(ElementName &element);
77 };
78 }  // namespace NFC
79 }  // namespace OHOS
80 #endif  // COMMON_EVENT_HANDLER_H
81