• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 
16 #ifndef NFC_NOTIFICATION_H
17 #define NFC_NOTIFICATION_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "image_source.h"
23 #include "pixel_map.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29 #endif /* __cplusplus */
30 
31 typedef void (*NfcNtfCallback)(int notificationId);
32 void RegNotificationCallback(NfcNtfCallback callback);
33 void PublishNfcNotification(int notificationId, const std::string &name, int balance);
34 
35 #ifdef __cplusplus
36 #if __cplusplus
37 }
38 #endif /* __cplusplus */
39 #endif /* __cplusplus */
40 
41 namespace OHOS {
42 namespace NFC {
43 namespace TAG {
44 enum NfcNotificationId : int {
45     NFC_TAG_DEFAULT_NTF_ID = 114000,
46     NFC_BT_NOTIFICATION_ID = 114001,
47     NFC_WIFI_NOTIFICATION_ID = 114002,
48     NFC_TRANSPORT_CARD_NOTIFICATION_ID = 114003,
49     NFC_BROWSER_NOTIFICATION_ID = 114004,
50     NFC_HCE_AID_CONFLICTED_ID = 114005,
51     NFC_NO_HAP_SUPPORTED_NOTIFICATION_ID = 114006,
52 
53     // add NTF ID type before NFC_NTF_END
54     NFC_NTF_END,
55 };
56 
57 const int MAX_BUFF_LEN = 500;
58 const int NFC_UNIT_CHANGE_CONSTANT = 100;
59 const int NTF_AUTO_DELETE_TIME = 10000;
60 const int MAX_RES_VEC_LEN = 100;
61 const int NTF_COUNT_CONSTANT = 1000000; // final notification id = 1000000 * count + NfcNotificationId
62 const int NFC_MAX_NTF_COUNT = 100;
63 const int NFC_SERVICE_UID = 1027;
64 
65 // use this flag to control notification banners
66 // 1 << 9 represents turning on the banner switch for System Ability.
67 // 0b010000 represents no vibration
68 const int NFC_NTF_CONTROL_FLAG = 1 << 9 | 0b010000; // no vibration
69 
70 constexpr const char* NFC_ICON_PATH = "system/etc/nfc/resources/base/media/nfc_icon.png";
71 constexpr const char* NFC_LANGUAGE_MAP_PATH = "system/etc/nfc/resources/base/profile/nfc_language_map.json";
72 constexpr const char* NFC_DEFAULT_LANGUAGE_FILE_PATH = "zh_CN";
73 constexpr const char* NFC_LANGUAGE_FILEPATH_PREFIX = "system/etc/nfc/resources/";
74 constexpr const char* NFC_LANGUAGE_FILEPATH_SUFFIX = "/element/string.json";
75 constexpr const char* NFC_ZHTW_LANGUAGE_FILE_PATH = "zh_TW";
76 constexpr const char* NFC_ZHHANT_LANGUAGE_FILE_PATH = "zh-Hant";  // The language type is Traditional Chinese
77 constexpr const char* NFC_ZHTW_REGION = "TW";
78 
79 constexpr const char* KEY_LANGUAGE_MAP = "nfc_language_map";
80 constexpr const char* KEY_SYSTEM_LANGUAGE = "system_language";
81 constexpr const char* KEY_FILE_PATH = "file_path";
82 
83 constexpr const char* KEY_STRING = "string";
84 constexpr const char* KEY_NAME = "name";
85 constexpr const char* KEY_VALUE = "value";
86 
87 constexpr const char* KEY_TAG_DEFAULT_NTF_TITLE     = "DefaultTitle";
88 constexpr const char* KEY_TAG_DEFAULT_NTF_TEXT      = "DefaultText";
89 constexpr const char* KEY_TRANSPORT_CARD_NTF_TITLE  = "TransportCardTitle";
90 constexpr const char* KEY_TRANSPORT_CARD_NTF_TEXT   = "TransportCardText";
91 constexpr const char* KEY_NFC_WIFI_NTF_TITLE        = "NfcWifiNtfTitle";
92 constexpr const char* KEY_NFC_WIFI_NTF_TEXT         = "NfcWifiNtfText";
93 constexpr const char* KEY_ACTION_BUTTON_NAME        = "ActionButtonName";
94 constexpr const char* KEY_NFC_WIFI_BUTTON_NAME      = "NfcWifiButtonName";
95 constexpr const char* KEY_NFC_BT_NTF_TITLE          = "NfcBtNtfTitle";
96 constexpr const char* KEY_NFC_BT_NTF_TEXT           = "NfcBtNtfText";
97 constexpr const char* KEY_NFC_BT_BUTTON_NAME        = "NfcBtButtonName";
98 constexpr const char* NFC_OPEN_LINK_BUTTON_NAME     = "NfcOpenLinkButtonName";
99 constexpr const char* NFC_OPEN_LINK_TEXT_HEAD       = "NfcOpenLinkTextHead";
100 constexpr const char* KEY_HCE_AID_CONFLICTED_TITLE  = "NfcHceAidConflictedTitle";
101 constexpr const char* KEY_HCE_AID_CONFLICTED_TEXT   = "NfcHceAidConflictedText";
102 constexpr const char* KEY_NO_HAP_TITLE              = "NoHapSupportedNtfTitle";
103 constexpr const char* KEY_NO_HAP_TEXT               = "NoHapSupportedNtfText";
104 constexpr const char* KEY_NO_HAP_BUTTON_NAME        = "NoHapSupportedNtfButtonName";
105 
106 class NfcNotification {
107 public:
108     static NfcNotification& GetInstance(void);
109 
110     void PublishNfcNotification(int notificationId, const std::string &name, int balance);
111     void RegNotificationCallback(NfcNtfCallback callback);
112 
113 private:
114     NfcNotification();
115     ~NfcNotification();
116     NfcNotification(const NfcNotification&) = delete;
117     NfcNotification& operator=(const NfcNotification&) = delete;
118 
119     void GetPixelMap(const std::string &path);
120 
121     std::mutex mutex_ {};
122     std::shared_ptr<Media::PixelMap> nfcIconPixelMap_ {};
123     std::vector<int> tagNtfCountVec_ {};
124 };
125 }  // namespace TAG
126 }  // namespace NFC
127 }  // namespace OHOS
128 #endif  // NFC_NOTIFICATION_H
129