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 #include "nfc_notification.h"
17
18 #include <map>
19
20 #include "cJSON.h"
21 #include "file_ex.h"
22 #include "locale_config.h"
23 #include "locale_info.h"
24 #include "loghelper.h"
25 #include "nfc_sdk_common.h"
26 #include "securec.h"
27 #include "want_agent_helper.h"
28 #include "want_agent_info.h"
29
30 #ifdef DEBUG
31 #undef DEBUG
32 #endif
33 #include "notification_helper.h"
34
35 namespace OHOS {
36 namespace NFC {
37 namespace TAG {
38 static std::string g_sysLanguage = "";
39 static std::string g_sysRegion = "";
40 static std::map<std::string, std::string> g_resourceMap;
41 static std::mutex g_callbackMutex {};
42 static NfcNtfCallback g_ntfCallback = nullptr;
43
44 class NfcNotificationSubscriber : public Notification::NotificationSubscriber {
OnConnected()45 void OnConnected() {}
OnDisconnected()46 void OnDisconnected() {}
OnUpdate(const std::shared_ptr<Notification::NotificationSortingMap> & sortingMap)47 void OnUpdate(const std::shared_ptr<Notification::NotificationSortingMap> &sortingMap) {}
OnDoNotDisturbDateChange(const std::shared_ptr<Notification::NotificationDoNotDisturbDate> & date)48 void OnDoNotDisturbDateChange(const std::shared_ptr<Notification::NotificationDoNotDisturbDate> &date) {}
OnEnabledNotificationChanged(const std::shared_ptr<Notification::EnabledNotificationCallbackData> & callbackData)49 void OnEnabledNotificationChanged(
50 const std::shared_ptr<Notification::EnabledNotificationCallbackData> &callbackData) {}
OnDied()51 void OnDied() {}
OnCanceled(const std::shared_ptr<OHOS::Notification::Notification> & request,const std::shared_ptr<Notification::NotificationSortingMap> & sortingMap,int deleteReason)52 void OnCanceled(const std::shared_ptr<OHOS::Notification::Notification> &request,
53 const std::shared_ptr<Notification::NotificationSortingMap> &sortingMap, int deleteReason)
54 {
55 int creatorUid = request->GetUid();
56 int notificationId = request->GetId();
57 InfoLog("Oncanceled, creatorUid = %{public}d, notificationId = %{public}d, deleteReason = %{public}d",
58 creatorUid, notificationId, deleteReason);
59
60 std::lock_guard<std::mutex> lock(g_callbackMutex);
61 if (deleteReason == Notification::NotificationConstant::CLICK_REASON_DELETE && g_ntfCallback) {
62 g_ntfCallback(notificationId % OHOS::NFC::TAG::NTF_COUNT_CONSTANT);
63 }
64 }
OnConsumed(const std::shared_ptr<OHOS::Notification::Notification> & notification,const std::shared_ptr<Notification::NotificationSortingMap> & sortingMap)65 void OnConsumed(const std::shared_ptr<OHOS::Notification::Notification> ¬ification,
66 const std::shared_ptr<Notification::NotificationSortingMap> &sortingMap) {}
OnBadgeChanged(const std::shared_ptr<Notification::BadgeNumberCallbackData> & badgeData)67 void OnBadgeChanged(const std::shared_ptr<Notification::BadgeNumberCallbackData> &badgeData) {}
OnBadgeEnabledChanged(const sptr<Notification::EnabledNotificationCallbackData> & callbackData)68 void OnBadgeEnabledChanged(const sptr<Notification::EnabledNotificationCallbackData> &callbackData) {}
OnBatchCanceled(const std::vector<std::shared_ptr<OHOS::Notification::Notification>> & requestList,const std::shared_ptr<Notification::NotificationSortingMap> & sortingMap,int32_t deleteReason)69 void OnBatchCanceled(const std::vector<std::shared_ptr<OHOS::Notification::Notification>> &requestList,
70 const std::shared_ptr<Notification::NotificationSortingMap> &sortingMap, int32_t deleteReason) {}
71 };
72
73 static std::shared_ptr<NfcNotificationSubscriber> g_notificationSubscriber
74 = std::make_shared<NfcNotificationSubscriber>();
75
UpdateResourceMap(const std::string & resourcePath)76 static void UpdateResourceMap(const std::string &resourcePath)
77 {
78 InfoLog("Reading resource string from json config.");
79
80 std::string content;
81 LoadStringFromFile(resourcePath, content);
82 cJSON *json = cJSON_Parse(content.c_str());
83 if (json == nullptr) {
84 ErrorLog("json nullptr.");
85 return;
86 }
87
88 cJSON *resJson = cJSON_GetObjectItemCaseSensitive(json, KEY_STRING);
89 if (resJson == nullptr || cJSON_GetArraySize(resJson) > MAX_RES_VEC_LEN) {
90 ErrorLog("fail to parse res json");
91 cJSON_Delete(json);
92 return;
93 }
94
95 g_resourceMap.clear();
96 cJSON *resJsonEach = nullptr;
97 cJSON_ArrayForEach(resJsonEach, resJson) {
98 cJSON *key = cJSON_GetObjectItemCaseSensitive(resJsonEach, KEY_NAME);
99 if (key == nullptr || !cJSON_IsString(key)) {
100 ErrorLog("json param not string");
101 cJSON_Delete(json);
102 return;
103 }
104
105 cJSON *value = cJSON_GetObjectItemCaseSensitive(resJsonEach, KEY_VALUE);
106 if (value == nullptr || !cJSON_IsString(value)) {
107 ErrorLog("json param not string");
108 cJSON_Delete(json);
109 return;
110 }
111
112 g_resourceMap.insert(std::pair<std::string, std::string>(key->valuestring, value->valuestring));
113 }
114 cJSON_Delete(json);
115 }
116
GetLanguageFilePath(const std::string & sysLanguage,const std::string & sysRegion)117 static std::string GetLanguageFilePath(const std::string &sysLanguage, const std::string &sysRegion)
118 {
119 InfoLog("Reading language file path from json config.");
120 std::string content;
121 std::string filePath = NFC_DEFAULT_LANGUAGE_FILE_PATH;
122 LoadStringFromFile(NFC_LANGUAGE_MAP_PATH, content);
123 cJSON *json = cJSON_Parse(content.c_str());
124 if (json == nullptr) {
125 ErrorLog("json nullptr.");
126 return filePath;
127 }
128
129 cJSON *resJson = cJSON_GetObjectItemCaseSensitive(json, KEY_LANGUAGE_MAP);
130 if (resJson == nullptr || !cJSON_IsArray(resJson)) {
131 ErrorLog("fail to parse KEY_LANGUAGE_MAP");
132 cJSON_Delete(json);
133 return filePath;
134 }
135
136 if (sysLanguage == NFC_ZHHANT_LANGUAGE_FILE_PATH && sysRegion == NFC_ZHTW_REGION) {
137 cJSON_Delete(json);
138 InfoLog("file path is zh-TW");
139 return NFC_ZHTW_LANGUAGE_FILE_PATH;
140 }
141
142 cJSON *resJsonEach = nullptr;
143 cJSON_ArrayForEach(resJsonEach, resJson) {
144 cJSON *key = cJSON_GetObjectItemCaseSensitive(resJsonEach, KEY_SYSTEM_LANGUAGE);
145 if (key == nullptr || !cJSON_IsString(key)) {
146 ErrorLog("json param KEY_SYSTEM_LANGUAGE not string");
147 continue;
148 }
149 if (key->valuestring != sysLanguage) {
150 continue;
151 }
152
153 cJSON *value = cJSON_GetObjectItemCaseSensitive(resJsonEach, KEY_FILE_PATH);
154 if (value == nullptr || !cJSON_IsString(value)) {
155 ErrorLog("json param KEY_FILE_PATH not string");
156 cJSON_Delete(json);
157 return filePath;
158 }
159
160 filePath = value->valuestring;
161 break;
162 }
163 cJSON_Delete(json);
164 InfoLog("file path %{public}s", filePath.c_str());
165 return filePath;
166 }
167
UpdateResourceMapByLanguage()168 static void UpdateResourceMapByLanguage()
169 {
170 std::string curSysLanguage = Global::I18n::LocaleConfig::GetSystemLanguage();
171 std::string curSysRegion = Global::I18n::LocaleConfig::GetSystemRegion();
172 if (g_sysLanguage == curSysLanguage && curSysRegion == g_sysRegion) {
173 DebugLog("same language environment[%{public}s], region[%{public}s] ,no need to update resource map.",
174 curSysLanguage.c_str(), curSysRegion.c_str());
175 return;
176 }
177
178 InfoLog("current system language[%{public}s], region[%{public}s] changes, should update resource map",
179 curSysLanguage.c_str(), curSysRegion.c_str());
180 g_sysLanguage = curSysLanguage;
181 g_sysRegion = curSysRegion;
182
183 std::string filePath = NFC_LANGUAGE_FILEPATH_PREFIX +
184 GetLanguageFilePath(g_sysLanguage, g_sysRegion) +
185 NFC_LANGUAGE_FILEPATH_SUFFIX;
186 UpdateResourceMap(filePath);
187 }
188
GetTrafficCardNotificationText(const std::string & cardName,int balance)189 static std::string GetTrafficCardNotificationText(const std::string &cardName, int balance)
190 {
191 char buf[MAX_BUFF_LEN] = {0};
192 int ret = sprintf_s(buf, MAX_BUFF_LEN, g_resourceMap[KEY_TRANSPORT_CARD_NTF_TEXT].c_str(),
193 g_resourceMap[cardName].c_str(), static_cast<float>(balance) / NFC_UNIT_CHANGE_CONSTANT);
194 if (ret <= 0) {
195 ErrorLog("sprintf_s failed, ret[%{public}d]", ret);
196 return "";
197 }
198
199 return std::string(buf);
200 }
201
202 #ifdef NDEF_WIFI_ENABLED
GetWifiNotificationText(const std::string & ssid)203 static std::string GetWifiNotificationText(const std::string &ssid)
204 {
205 char buf[MAX_BUFF_LEN] = {0};
206 int ret = sprintf_s(buf, MAX_BUFF_LEN, g_resourceMap[KEY_NFC_WIFI_NTF_TEXT].c_str(), ssid.c_str());
207 if (ret <= 0) {
208 ErrorLog("sprintf_s failed, ret[%{public}d]", ret);
209 return "";
210 }
211
212 return std::string(buf);
213 }
214 #endif
215
216 #ifdef NDEF_BT_ENABLED
GetBtNotificationText(const std::string & name)217 static std::string GetBtNotificationText(const std::string &name)
218 {
219 char buf[MAX_BUFF_LEN] = {0};
220 int ret = sprintf_s(buf, MAX_BUFF_LEN, g_resourceMap[KEY_NFC_BT_NTF_TEXT].c_str(), name.c_str());
221 if (ret <= 0) {
222 ErrorLog("sprintf_s failed, ret[%{public}d]", ret);
223 return "";
224 }
225
226 return std::string(buf);
227 }
228 #endif
229
SetTitleAndTextForOtherNotificationId(int notificationId,std::shared_ptr<Notification::NotificationNormalContent> nfcContent,const std::string & name,int balance)230 static bool SetTitleAndTextForOtherNotificationId(int notificationId,
231 std::shared_ptr<Notification::NotificationNormalContent> nfcContent, const std::string &name, int balance)
232 {
233 switch (notificationId) {
234 case NFC_TAG_DEFAULT_NTF_ID:
235 if (g_resourceMap.find(KEY_TAG_DEFAULT_NTF_TITLE) != g_resourceMap.end() &&
236 g_resourceMap.find(KEY_TAG_DEFAULT_NTF_TEXT) != g_resourceMap.end()) {
237 nfcContent->SetTitle(g_resourceMap[KEY_TAG_DEFAULT_NTF_TITLE]);
238 nfcContent->SetText(g_resourceMap[KEY_TAG_DEFAULT_NTF_TEXT]);
239 }
240 break;
241 case NFC_BROWSER_NOTIFICATION_ID:
242 if (g_resourceMap.find(KEY_TAG_DEFAULT_NTF_TITLE) != g_resourceMap.end() &&
243 g_resourceMap.find(NFC_OPEN_LINK_TEXT_HEAD) != g_resourceMap.end()) {
244 nfcContent->SetTitle(g_resourceMap[KEY_TAG_DEFAULT_NTF_TITLE]);
245 nfcContent->SetText(g_resourceMap[NFC_OPEN_LINK_TEXT_HEAD] + name);
246 }
247 break;
248 case NFC_HCE_AID_CONFLICTED_ID:
249 if (g_resourceMap.find(KEY_HCE_AID_CONFLICTED_TITLE) != g_resourceMap.end() &&
250 g_resourceMap.find(KEY_HCE_AID_CONFLICTED_TEXT) != g_resourceMap.end()) {
251 nfcContent->SetTitle(g_resourceMap[KEY_HCE_AID_CONFLICTED_TITLE]);
252 nfcContent->SetText(g_resourceMap[KEY_HCE_AID_CONFLICTED_TEXT]);
253 }
254 break;
255 case NFC_NO_HAP_SUPPORTED_NOTIFICATION_ID:
256 if (g_resourceMap.find(KEY_NO_HAP_TITLE) != g_resourceMap.end() &&
257 g_resourceMap.find(KEY_NO_HAP_TEXT) != g_resourceMap.end()) {
258 nfcContent->SetTitle(g_resourceMap[KEY_NO_HAP_TITLE]);
259 nfcContent->SetText(g_resourceMap[KEY_NO_HAP_TEXT]);
260 }
261 break;
262 default:
263 WarnLog("unknown notification ID");
264 return false;
265 }
266 return true;
267 }
268
SetTitleAndText(int notificationId,std::shared_ptr<Notification::NotificationNormalContent> nfcContent,const std::string & name,int balance)269 static bool SetTitleAndText(int notificationId,
270 std::shared_ptr<Notification::NotificationNormalContent> nfcContent, const std::string &name, int balance)
271 {
272 if (nfcContent == nullptr) {
273 ErrorLog("notification normal content nullptr");
274 return false;
275 }
276 UpdateResourceMapByLanguage();
277
278 switch (notificationId) {
279 case NFC_TRANSPORT_CARD_NOTIFICATION_ID:
280 if (g_resourceMap.find(KEY_TRANSPORT_CARD_NTF_TITLE) != g_resourceMap.end() &&
281 g_resourceMap.find(KEY_TRANSPORT_CARD_NTF_TEXT) != g_resourceMap.end() &&
282 g_resourceMap.find(name) != g_resourceMap.end()) {
283 nfcContent->SetTitle(g_resourceMap[KEY_TRANSPORT_CARD_NTF_TITLE]);
284 nfcContent->SetText(GetTrafficCardNotificationText(name, balance));
285 }
286 break;
287 case NFC_WIFI_NOTIFICATION_ID:
288 #ifdef NDEF_WIFI_ENABLED
289 if (g_resourceMap.find(KEY_NFC_WIFI_NTF_TITLE) != g_resourceMap.end() &&
290 g_resourceMap.find(KEY_NFC_WIFI_NTF_TEXT) != g_resourceMap.end()) {
291 nfcContent->SetTitle(g_resourceMap[KEY_NFC_WIFI_NTF_TITLE]);
292 nfcContent->SetText(GetWifiNotificationText(name));
293 }
294 break;
295 #else
296 ErrorLog("nfc wifi notification not supported");
297 return false;
298 #endif
299 case NFC_BT_NOTIFICATION_ID:
300 #ifdef NDEF_BT_ENABLED
301 if (g_resourceMap.find(KEY_NFC_BT_NTF_TITLE) != g_resourceMap.end() &&
302 g_resourceMap.find(KEY_NFC_BT_NTF_TEXT) != g_resourceMap.end()) {
303 nfcContent->SetTitle(g_resourceMap[KEY_NFC_BT_NTF_TITLE]);
304 nfcContent->SetText(GetBtNotificationText(name));
305 }
306 break;
307 #else
308 ErrorLog("nfc bt notification not supported");
309 return false;
310 #endif
311 default:
312 return SetTitleAndTextForOtherNotificationId(notificationId, nfcContent, name, balance);
313 }
314 return true;
315 }
316
GetButtonName(int notificationId)317 static std::string GetButtonName(int notificationId)
318 {
319 switch (notificationId) {
320 case NFC_BT_NOTIFICATION_ID:
321 if (g_resourceMap.find(KEY_NFC_BT_BUTTON_NAME) != g_resourceMap.end()) {
322 return g_resourceMap[KEY_NFC_BT_BUTTON_NAME];
323 }
324 return "";
325 case NFC_WIFI_NOTIFICATION_ID:
326 if (g_resourceMap.find(KEY_NFC_WIFI_BUTTON_NAME) != g_resourceMap.end()) {
327 return g_resourceMap[KEY_NFC_WIFI_BUTTON_NAME];
328 }
329 return "";
330 case NFC_BROWSER_NOTIFICATION_ID:
331 if (g_resourceMap.find(NFC_OPEN_LINK_BUTTON_NAME) != g_resourceMap.end()) {
332 return g_resourceMap[NFC_OPEN_LINK_BUTTON_NAME];
333 }
334 return "";
335 case NFC_NO_HAP_SUPPORTED_NOTIFICATION_ID:
336 if (g_resourceMap.find(KEY_NO_HAP_BUTTON_NAME) != g_resourceMap.end()) {
337 return g_resourceMap[KEY_NO_HAP_BUTTON_NAME];
338 }
339 return "";
340 default:
341 if (g_resourceMap.find(KEY_ACTION_BUTTON_NAME) != g_resourceMap.end()) {
342 return g_resourceMap[KEY_ACTION_BUTTON_NAME];
343 }
344 return "";
345 }
346 }
347
SetActionButton(const std::string & buttonName,Notification::NotificationRequest & request)348 static void SetActionButton(const std::string& buttonName, Notification::NotificationRequest& request)
349 {
350 auto want = std::make_shared<AAFwk::Want>();
351 std::vector<std::shared_ptr<AAFwk::Want>> wants;
352 wants.push_back(want);
353 std::vector<AbilityRuntime::WantAgent::WantAgentConstant::Flags> flags;
354 flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG);
355 AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo(
356 0, AbilityRuntime::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE,
357 flags, wants, nullptr
358 );
359 auto wantAgentDeal = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo);
360 std::shared_ptr<Notification::NotificationActionButton> actionButtonDeal =
361 Notification::NotificationActionButton::Create(nullptr, buttonName, wantAgentDeal);
362 if (actionButtonDeal == nullptr) {
363 ErrorLog("get notification actionButton nullptr");
364 return;
365 }
366 request.AddActionButton(actionButtonDeal);
367 }
368
GetAutoDeleteTime()369 static int64_t GetAutoDeleteTime()
370 {
371 auto now = std::chrono::system_clock::now();
372 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
373 return duration.count() + NTF_AUTO_DELETE_TIME;
374 }
375
SetBasicOption(Notification::NotificationRequest & request)376 static void SetBasicOption(Notification::NotificationRequest &request)
377 {
378 request.SetCreatorUid(NFC_SERVICE_UID);
379 request.SetAutoDeletedTime(GetAutoDeleteTime());
380 request.SetTapDismissed(true);
381 request.SetSlotType(OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
382 request.SetNotificationControlFlags(NFC_NTF_CONTROL_FLAG);
383 }
384
GetPixelMap(const std::string & path)385 void NfcNotification::GetPixelMap(const std::string &path)
386 {
387 if (nfcIconPixelMap_ != nullptr) {
388 InfoLog("nfc icon pixel map already exists.");
389 return;
390 }
391
392 if (!std::filesystem::exists(path)) {
393 ErrorLog("nfc icon file path not exists.");
394 nfcIconPixelMap_ = nullptr;
395 return;
396 }
397 uint32_t errorCode = 0;
398 Media::SourceOptions opts;
399 opts.formatHint = "image/png";
400 std::unique_ptr<Media::ImageSource> imageSource = Media::ImageSource::CreateImageSource(path, opts, errorCode);
401 if (imageSource == nullptr) {
402 ErrorLog("imageSource nullptr");
403 nfcIconPixelMap_ = nullptr;
404 return;
405 }
406 Media::DecodeOptions decodeOpts;
407 std::unique_ptr<Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
408 nfcIconPixelMap_ = std::move(pixelMap);
409 }
410
GetInstance()411 NfcNotification& NfcNotification::GetInstance()
412 {
413 static NfcNotification instance;
414 return instance;
415 }
416
NfcNotification()417 NfcNotification::NfcNotification()
418 {
419 InfoLog("NfcNotification constructor enter.");
420 std::lock_guard<std::mutex> lock(mutex_);
421 // only need to subscribe notification once
422 int result = Notification::NotificationHelper::SubscribeNotification(*g_notificationSubscriber);
423 if (result != ERR_OK) {
424 ErrorLog("fail to subscribe notification");
425 }
426 UpdateResourceMapByLanguage();
427 // initialize the vector with the length of (NFC_NTF_END - NFC_TAG_DEFAULT_NTF_ID)
428 tagNtfCountVec_.resize(NFC_NTF_END - NFC_TAG_DEFAULT_NTF_ID);
429 }
430
~NfcNotification()431 NfcNotification::~NfcNotification()
432 {
433 InfoLog("NfcNotification destructor enter.");
434 // no operation to unsubscribe notification
435 }
436
PublishNfcNotification(int notificationId,const std::string & name,int balance)437 void NfcNotification::PublishNfcNotification(int notificationId, const std::string &name, int balance)
438 {
439 if (notificationId >= NFC_NTF_END || notificationId < NFC_TAG_DEFAULT_NTF_ID) {
440 ErrorLog("invalid notification id.");
441 return;
442 }
443 std::shared_ptr<Notification::NotificationNormalContent> nfcContent =
444 std::make_shared<Notification::NotificationNormalContent>();
445 if (nfcContent == nullptr) {
446 ErrorLog("get notification normal content nullptr");
447 return;
448 }
449 std::lock_guard<std::mutex> lock(mutex_);
450 Notification::NotificationBundleOption bundle(KITS::NFC_MANAGER_SYS_ABILITY_NAME, NFC_SERVICE_UID);
451 int lastNtfId = (tagNtfCountVec_[notificationId - NFC_TAG_DEFAULT_NTF_ID]++) * NTF_COUNT_CONSTANT + notificationId;
452 if (tagNtfCountVec_[notificationId - NFC_TAG_DEFAULT_NTF_ID] >= NFC_MAX_NTF_COUNT) {
453 tagNtfCountVec_[notificationId - NFC_TAG_DEFAULT_NTF_ID] = 0;
454 }
455 int currentNtfId = (tagNtfCountVec_[notificationId - NFC_TAG_DEFAULT_NTF_ID]) * NTF_COUNT_CONSTANT + notificationId;
456 int ret = Notification::NotificationHelper::CancelAsBundle(bundle, lastNtfId);
457 // ret value 67108880 represents the notification does not exist
458 InfoLog("Cancel ntf result[%{public}d], last id[%{public}d], current id[%{public}d]", ret, lastNtfId, currentNtfId);
459
460 if (!SetTitleAndText(notificationId, nfcContent, name, balance)) {
461 ErrorLog("error setting title and text");
462 return;
463 }
464
465 std::shared_ptr<Notification::NotificationContent> content =
466 std::make_shared<Notification::NotificationContent>(nfcContent);
467 if (content == nullptr) {
468 ErrorLog("get notification content nullptr");
469 return;
470 }
471
472 Notification::NotificationRequest request;
473 SetBasicOption(request);
474 request.SetNotificationId(currentNtfId);
475 request.SetContent(content);
476
477 GetPixelMap(NFC_ICON_PATH);
478 if (nfcIconPixelMap_ != nullptr) {
479 request.SetLittleIcon(nfcIconPixelMap_);
480 request.SetBadgeIconStyle(Notification::NotificationRequest::BadgeStyle::LITTLE);
481 }
482
483 std::string buttonName = GetButtonName(notificationId);
484 if (!buttonName.empty()) {
485 SetActionButton(buttonName, request);
486 }
487
488 ret = Notification::NotificationHelper::PublishNotification(request);
489 InfoLog("NFC service publish notification result = %{public}d", ret);
490 }
491
RegNotificationCallback(NfcNtfCallback callback)492 void NfcNotification::RegNotificationCallback(NfcNtfCallback callback)
493 {
494 std::lock_guard<std::mutex> lock(g_callbackMutex);
495 g_ntfCallback = callback;
496 }
497 } // namespace TAG
498 } // namespace NFC
499 } // namespace OHOS
500
RegNotificationCallback(NfcNtfCallback callback)501 void RegNotificationCallback(NfcNtfCallback callback)
502 {
503 OHOS::NFC::TAG::NfcNotification::GetInstance().RegNotificationCallback(callback);
504 }
505
PublishNfcNotification(int notificationId,const std::string & name,int balance)506 void PublishNfcNotification(int notificationId, const std::string &name, int balance)
507 {
508 InfoLog("Publishing nfc tag notification, id [%{public}d]", notificationId);
509 OHOS::NFC::TAG::NfcNotification::GetInstance().PublishNfcNotification(notificationId, name, balance);
510 }