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 = 100;
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 NFC_NTF_CONTROL_FLAG = 0;
62 const int NFC_SLOT_CONTROL_FLAG = 0b101111; // no vibration
63 const int NTF_COUNT_CONSTANT = 1000000; // final notification id = 1000000 * count + NfcNotificationId
64 const int NFC_MAX_NTF_COUNT = 100;
65 
66 constexpr const char* NFC_ICON_PATH = "system/etc/nfc/nfc_icon.png";
67 constexpr const char* NFC_RES_DEFAULT_JSON_FILEPATH = "system/etc/nfc/string_zh.json";
68 constexpr const char* NFC_RES_EN_JSON_FILEPATH = "system/etc/nfc/string_en.json";
69 
70 constexpr const char* KEY_STRING = "string";
71 constexpr const char* KEY_NAME = "name";
72 constexpr const char* KEY_VALUE = "value";
73 
74 constexpr const char* KEY_TAG_DEFAULT_NTF_TITLE     = "DefaultTitle";
75 constexpr const char* KEY_TAG_DEFAULT_NTF_TEXT      = "DefaultText";
76 constexpr const char* KEY_TRANSPORT_CARD_NTF_TITLE  = "TransportCardTitle";
77 constexpr const char* KEY_TRANSPORT_CARD_NTF_TEXT   = "TransportCardText";
78 constexpr const char* KEY_NFC_WIFI_NTF_TITLE        = "NfcWifiNtfTitle";
79 constexpr const char* KEY_NFC_WIFI_NTF_TEXT         = "NfcWifiNtfText";
80 constexpr const char* KEY_ACTION_BUTTON_NAME        = "ActionButtonName";
81 constexpr const char* KEY_NFC_WIFI_BUTTON_NAME      = "NfcWifiButtonName";
82 constexpr const char* KEY_NFC_BT_NTF_TITLE          = "NfcBtNtfTitle";
83 constexpr const char* KEY_NFC_BT_NTF_TEXT           = "NfcBtNtfText";
84 constexpr const char* KEY_NFC_BT_BUTTON_NAME        = "NfcBtButtonName";
85 constexpr const char* NFC_OPEN_LINK_BUTTON_NAME     = "NfcOpenLinkButtonName";
86 constexpr const char* NFC_OPEN_LINK_TEXT_HEAD       = "NfcOpenLinkTextHead";
87 constexpr const char* KEY_HCE_AID_CONFLICTED_TITLE  = "NfcHceAidConflictedTitle";
88 constexpr const char* KEY_HCE_AID_CONFLICTED_TEXT   = "NfcHceAidConflictedText";
89 constexpr const char* KEY_NO_HAP_TITLE              = "NoHapSupportedNtfTitle";
90 constexpr const char* KEY_NO_HAP_TEXT               = "NoHapSupportedNtfText";
91 constexpr const char* KEY_NO_HAP_BUTTON_NAME        = "NoHapSupportedNtfButtonName";
92 
93 class NfcNotification {
94 public:
95     static NfcNotification& GetInstance(void);
96 
97     void PublishNfcNotification(int notificationId, const std::string &name, int balance);
98     void RegNotificationCallback(NfcNtfCallback callback);
99 
100 private:
101     NfcNotification();
102     ~NfcNotification();
103     NfcNotification(const NfcNotification&) = delete;
104     NfcNotification& operator=(const NfcNotification&) = delete;
105 
106     void GetPixelMap(const std::string &path);
107 
108     std::mutex mutex_ {};
109     std::shared_ptr<Media::PixelMap> nfcIconPixelMap_ {};
110     std::vector<int> tagNtfCountVec_ {};
111 };
112 }  // namespace TAG
113 }  // namespace NFC
114 }  // namespace OHOS
115 #endif  // NFC_NOTIFICATION_H
116