add IBadgeEventListener and setters to NotificaionManager and apply forward declarati...
[platform/framework/native/shell.git] / src / core / FShell_NotificationManagerImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FShell_NotificationManagerImpl.cpp
20  * @brief               This is the placeholder for _NotificationManagerImpl class.
21  */
22
23 #include <unique_ptr.h>
24 #include <appsvc/appsvc.h>
25 #include <bundle.h>
26 #include <notification/notification.h>
27 #include <appfw/app.h>
28 #include <appfw/app_manager.h>
29 #include <appfw/app_ui_notification.h>
30 #include <badge.h>
31
32 #include <FBaseSysLog.h>
33 #include <FApp.h>
34
35 #include <FShellNotificationManager.h>
36 #include <FShellNotificationRequest.h>
37 #include <FShellIBadgeEventListener.h>
38
39 //#include <FBaseInternalTypes.h>
40 #include <FBase_StringConverter.h>
41 #include "FApp_AppInfo.h"
42 #include "FApp_Aul.h"
43 #include "FIoFile.h"
44 #include "FAppPkg_PackageManagerImpl.h"
45 #include "FApp_AppArg.h"
46 #include "FAppPkgPackageAppInfo.h"
47 #include "FAppPkg_PackageAppInfoImpl.h"
48 #include "FShell_NotificationManagerImpl.h"
49 #include "FShell_NotificationRequestImpl.h"
50
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::App;
54 using namespace Tizen::App::Package;
55 using namespace Tizen::Io;
56 using namespace Tizen::Shell;
57
58 extern "C" int service_create_request(bundle *data, service_h *service);
59 extern "C" int service_to_bundle(service_h service, bundle** data);
60
61 namespace
62 {
63
64 result
65 ConvertNotificationResult(int error)
66 {
67         switch (error)
68         {
69         case NOTIFICATION_ERROR_NONE:
70                 return E_SUCCESS;
71         case NOTIFICATION_ERROR_INVALID_DATA:
72                 return E_INVALID_ARG;
73         case NOTIFICATION_ERROR_NO_MEMORY:
74                 return E_OUT_OF_MEMORY;
75         case NOTIFICATION_ERROR_FROM_DB:
76                 return E_DATABASE;
77         case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
78                 return E_OPERATION_FAILED;
79         case NOTIFICATION_ERROR_NOT_EXIST_ID:
80                 return E_OPERATION_FAILED;
81         default:
82                 return E_OPERATION_FAILED;
83         }
84 }
85
86 bool
87 IsPosted(ui_notification_h handle)
88 {
89         struct ui_notification_s
90         {
91                 void* raw_handle;
92                 bool ongoing;
93                 bool posted;
94                 bool removed;
95                 char *icon;
96                 struct tm *time;
97                 char *title;
98                 char *content;
99                 service_h service;
100                 char *sound;
101                 bool vibration;
102         };
103
104         if (handle == NULL)
105         {
106                 return false;
107         }
108
109         ui_notification_s* pStruct = reinterpret_cast<ui_notification_s*>(handle);
110
111         return pStruct->posted;
112 }
113
114 } // namespace
115
116
117 namespace Tizen { namespace Shell
118 {
119
120 ///////////////////////////////////////////////////////////////////
121 // _BadgeManagerImpl
122 ///////////////////////////////////////////////////////////////////
123 void
124 BadgeChangedCallback(unsigned int action, const char *pkgname, unsigned int count, void *data)
125 {
126         Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>* pBadgeEventListenerList = static_cast<Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>*>(data);
127         SysAssert(pBadgeEventListenerList);
128
129         std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(pBadgeEventListenerList->GetEnumeratorN());
130         SysTryReturnVoidResult(NID_APP, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
131
132         IBadgeEventListener* pListener;
133         while (pEnum->MoveNext() == E_SUCCESS)
134         {
135                 pListener = null;
136                 pEnum->GetCurrent(pListener);
137                 if( !pListener)
138                 {
139                         SysLog(NID_APP, "pListener is null!");
140                         continue;
141                 }
142
143                 pListener->OnBadgeUpdated(pkgname, count);
144         }
145 }
146
147 _BadgeManagerImpl*
148 _BadgeManagerImpl::GetInstance(void)
149 {
150         static _BadgeManagerImpl* pTheInstance = null;
151         if( pTheInstance == null)
152         {
153                 pTheInstance = new (std::nothrow) _BadgeManagerImpl;
154                 pTheInstance->Construct();
155         }
156         return pTheInstance;
157 }
158
159 result
160 _BadgeManagerImpl::Construct(void)
161 {
162         return E_SUCCESS;
163 }
164
165 result
166 _BadgeManagerImpl::AddPrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
167 {
168         if( __primaryBadgeEventListenerList.GetCount() == 0)
169         {
170                 int ret = badge_register_changed_cb(BadgeChangedCallback, &__primaryBadgeEventListenerList);
171                 SysTryReturnResult(NID_APP, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
172         }
173
174         return __primaryBadgeEventListenerList.Add(&primaryListener);
175 }
176
177 result
178 _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
179 {
180         __primaryBadgeEventListenerList.Remove(&primaryListener);
181         if( __primaryBadgeEventListenerList.GetCount() == 0)
182         {
183                 int ret = badge_unregister_changed_cb(BadgeChangedCallback);
184                 SysTryReturnResult(NID_APP, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
185         }
186         return E_SUCCESS;
187 }
188
189
190 ///////////////////////////////////////////////////////////////////
191 // _NotificationManagerImpl
192 ///////////////////////////////////////////////////////////////////
193 _NotificationManagerImpl::_NotificationManagerImpl(void)
194         : __notifyPrivitId(-1)
195         , __notifyPrivitIdForOngoing(-1)
196 {
197 }
198
199 _NotificationManagerImpl::~_NotificationManagerImpl(void)
200 {
201         bool isListeningBadgeEvent = (__badgeEventListenerList.GetCount() > 0)? true : false;
202         if( isListeningBadgeEvent == true )
203         {
204                 _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
205         }
206 }
207
208 result
209 _NotificationManagerImpl::Construct(void)
210 {
211         return E_SUCCESS;
212 }
213
214 const _NotificationManagerImpl*
215 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
216 {
217         return notiMgr.__pNotificationManagerImpl;
218 }
219
220 _NotificationManagerImpl*
221 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
222 {
223         return notiMgr.__pNotificationManagerImpl;
224 }
225
226 int
227 _NotificationManagerImpl::GetBadgeNumber(void) const
228 {
229         Tizen::App::App* pApp = Tizen::App::App::GetInstance();
230         std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
231
232         int count = GetBadgeCount(pAppId.get());
233         SysTryReturn(NID_APP, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
234                                  GetErrorMessage(E_OPERATION_FAILED));
235
236         ClearLastResult();
237         return count;
238 }
239
240 result
241 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
242 {
243         return NotifyMessage(NOTIFY_TYPE_SIMPLE, isOngoing, notiMessage);
244 }
245
246 result
247 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
248 {
249         return NotifyMessage(NOTIFY_TYPE_APP_ID, isOngoing, notiMessage, &appId);
250 }
251
252
253 result
254 _NotificationManagerImpl::Notify(int badgeNumber)
255 {
256         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
257
258         if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
259         {
260                 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
261         }
262
263         Tizen::App::App* pApp = Tizen::App::App::GetInstance();
264         std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
265
266         if (badgeNumber == 0)
267         {
268                 RemoveBadge(pAppId.get());
269         }
270         else
271         if (badgeNumber > 0)
272         {
273                 SetBadgeCount(pAppId.get(), badgeNumber);
274         }
275
276         return E_SUCCESS;
277 }
278
279 result
280 _NotificationManagerImpl::Notify(const String& messageText)
281 {
282         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
283
284         NotificationRequest request;
285         request.SetAlertText(messageText);
286         request.SetAppMessage(L"");
287
288         return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
289 }
290
291 result
292 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber)
293 {
294         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
295         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
296
297         if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
298         {
299                 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
300         }
301
302         NotificationRequest request;
303         request.SetAlertText(messageText);
304         request.SetBadgeNumber(badgeNumber);
305         request.SetAppMessage(L"");
306
307         return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
308 }
309
310 result
311 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
312 {
313         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
314         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
315         SysTryReturnResult(NID_APP, launchArguments != null && launchArguments.GetLength() > 0, E_INVALID_ARG,
316                                            "launchArguments is less than 0.");
317
318         SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
319                                            "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
320
321         if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
322         {
323                 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
324         }
325
326         NotificationRequest request;
327         request.SetAlertText(messageText);
328         request.SetBadgeNumber(badgeNumber);
329         request.SetAppMessage(launchArguments);
330
331         return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
332 }
333
334 int
335 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
336 {
337         bool b = _Aul::IsInstalled(appId);
338         SysTryReturn(NID_APP, b == true, -1, E_APP_NOT_INSTALLED, "[E_OBJ_NOT_FOUND] The application %ls is not installed",
339                                  appId.GetPointer());
340         std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
341         int count = GetBadgeCount(pAppId.get());
342
343         SysTryReturn(NID_APP, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
344                                  GetErrorMessage(E_OPERATION_FAILED));
345         ClearLastResult();
346
347         return count;
348 }
349
350 result
351 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText)
352 {
353         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
354
355         NotificationRequest request;
356         request.SetAlertText(messageText);
357
358         return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
359 }
360
361 result
362 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
363 {
364         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
365         SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
366         SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
367                                            "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
368
369         NotificationRequest request;
370         request.SetAlertText(messageText);
371         request.SetAppMessage(launchArguments);
372
373         return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
374 }
375
376 result
377 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
378 {
379         return RemoveNotificationByAppId(appId, true);
380 }
381
382
383 result
384 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
385 {
386         return RemoveNotificationByAppId(appId, false);
387 }
388
389 result
390 _NotificationManagerImpl::NotifyTextMessage(const String& messageText) const
391 {
392         SysTryReturnResult(NID_APP, !messageText.IsEmpty(), E_INVALID_ARG, "MessageText is less than 0.");
393
394         std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
395         int res = notification_status_message_post(pMsg.get());
396
397         result r = E_SUCCESS;
398         switch (res)
399         {
400         case NOTIFICATION_ERROR_NONE:
401                 // success
402                 break;
403         case NOTIFICATION_ERROR_INVALID_DATA:
404                 r = E_INVALID_ARG;
405                 break;
406         case NOTIFICATION_ERROR_IO:
407                 r = E_SYSTEM;
408                 break;
409         default:
410                 r = E_SYSTEM;
411                 break;
412         }
413
414         SysLog(NID_APP, "[%s] %ls posted.", GetErrorMessage(r), messageText.GetPointer());
415         return r;
416 }
417
418 result
419 _NotificationManagerImpl::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
420                                                                                          const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
421 {
422         result r = E_SUCCESS;
423
424         r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, false, request, null, &operationId, pUriData, pDataType, pExtraData);
425         return r;
426 }
427
428 result
429 _NotificationManagerImpl::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
430                                                                                                                         const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
431 {
432         result r = E_SUCCESS;
433
434         r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, true, request, null, &operationId, pUriData, pDataType, pExtraData);
435         return r;
436 }
437
438
439 result
440 _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing, const NotificationRequest& notifyRequest, const AppId* pAppId,
441                                                                                 const Tizen::Base::String* pOperationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData)
442 {
443         result r = E_SUCCESS;
444         std::unique_ptr<char[]> pAppIdChar(null);
445         const _NotificationRequestImpl* pRequestImpl = _NotificationRequestImpl::GetInstance(notifyRequest);
446         SysTryReturnResult(NID_APP, pRequestImpl != null, E_INVALID_ARG, "Invalid argument is used.");
447
448         // Set pAppIdChar
449         if ((notifyType == NOTIFY_TYPE_SIMPLE) || (notifyType == NOTIFY_TYPE_APP_CONTROL))
450         {
451 //              char* pkgname = null;
452 //              app_get_id(&pkgname);   // AppId. (Not package Id)
453 //              SysTryReturnResult(NID_APP, pkgname != NULL, E_OBJ_NOT_FOUND,"Cannot acquire package name for current application.");
454 //              const String currentAppId(pkgname);
455 //              free(pkgname);
456                 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
457                 const String currentAppId = pApp->GetAppId();
458                 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(currentAppId));
459                 pAppIdChar = std::move(pAppIdTemp);
460                 SysLog(NID_APP, "app_get_id: %ls", currentAppId.GetPointer());
461         }
462         else
463         if (notifyType == NOTIFY_TYPE_APP_ID)
464         {
465                 bool isAppInstalled = _Aul::IsInstalled(*pAppId);
466                 SysTryReturnResult(NID_APP, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", pAppId->GetPointer());
467                 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(*pAppId));
468                 pAppIdChar = std::move(pAppIdTemp);
469         }
470         else
471         {
472                 SysTryReturnResult(NID_APP, false, E_INVALID_ARG, "Invalid argument is used.");
473         }
474
475         const int badgeNumber = notifyRequest.GetBadgeNumber();
476         const int badgeOffset = notifyRequest.GetBadgeOffset();
477         const String& contentText = notifyRequest.GetAlertText();
478         // Allow change the badge without other properties.
479         if (badgeNumber != -1 || badgeOffset != -1)
480         {
481                 // Set - Badge
482                 if (badgeOffset != 0)
483                 {
484                         int badgeNumber = GetBadgeCount(pAppIdChar.get());
485                         if (badgeNumber <= 0)
486                         {
487                                 SetBadgeCount(pAppIdChar.get(), badgeOffset);
488                         }
489                         else
490                         {
491                                 SetBadgeCount(pAppIdChar.get(), badgeNumber + badgeOffset);
492                         }
493                 }
494                 else
495                 {
496                         if (badgeNumber == 0)
497                         {
498                                 RemoveBadge(pAppIdChar.get());
499                         }
500                         else
501                         if (badgeNumber > 0)
502                         {
503                                 SetBadgeCount(pAppIdChar.get(), badgeNumber);
504                         }
505                 }
506                 if (!(isOngoing || !contentText.IsEmpty()))
507                 {
508                         SysLog(NID_APP, "No valid for Notification, just for set a badgeNumber update.");
509                         return E_SUCCESS;
510                 }
511         }
512         SysTryReturnResult(NID_APP, (isOngoing || !contentText.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. MessageText is Empty");
513
514         const String& titleText = notifyRequest.GetTitleText();
515         const String& launchArguments = notifyRequest.GetAppMessage();
516         const String& iconPath = notifyRequest.GetIconFilePath();
517         const String& soundPath = notifyRequest.GetSoundFilePath();
518         const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
519         int notiPrivateId = isOngoing ? __notifyPrivitIdForOngoing : __notifyPrivitId;
520         notification_h notiHandle = null;
521         bundle* pBundle = null;
522         bool needUpdate = false;
523         bundle* service_data = null;
524         _AppArg arg;
525         service_h hSvc = null;
526         notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
527
528         // Notification creation
529         if (notiPrivateId != -1)
530         {
531                 notiHandle = notification_load(pAppIdChar.get(), notiPrivateId);
532                 SysTryLog(NID_APP, notiHandle != null, "Get notiHandle(%d) from notiPrivateId(%d).", notiHandle, notiPrivateId);
533         }
534
535         if (notiHandle == null)
536         {
537                 SysLog(NID_APP, "Previous notification(%d) no more valid - create new notification", notiPrivateId);
538                 notiPrivateId = -1;             // reset
539                 notiHandle = notification_create(notiType);
540         }
541         else
542         {
543                 needUpdate = true;              // No need to notification_insert.
544         }
545         SysTryReturnResult(NID_APP, notiHandle != null , E_SYSTEM, "A system error has been occurred. Notification creation/load failed ");
546
547         // Content text(Alert text)
548         std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(contentText));
549
550         // Title text
551         std::unique_ptr<char[]> pTitleText(null);
552         if (!titleText.IsEmpty())
553         {
554                 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(titleText));
555                 pTitleText = std::move(pTitleTextTemp);
556         }
557         else
558         {
559                 char* pAppName = null;
560                 app_manager_get_app_name(pAppIdChar.get(), &pAppName);
561                 if (pAppName)
562                 {
563                         String appName(pAppName);
564                         std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
565                         pTitleText = std::move(pTitleTextTemp);
566                         free(pAppName);
567                         //SysLog(NID_APP, "Application Id is %ls.", appName.GetPointer());
568                 }
569                 else
570                 {
571                         SysTryLog(NID_APP, pTitleText, "Failed to get title from app_manager_get_app_name for default setting.");
572                 }
573         }
574         // Icon file path
575         std::unique_ptr<char[]> pIconPath(null);
576         if (!iconPath.IsEmpty())
577         {
578                 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
579                 pIconPath = std::move(pIconPathTemp);
580         }
581         else
582         {
583                 std::unique_ptr<PackageAppInfo> pPackageAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(pAppIdChar.get()));
584                 const String& appIconPath(_PackageAppInfoImpl::GetInstance(pPackageAppInfo.get())->GetAppNotificationIconPath());
585
586                 if (!appIconPath.IsEmpty() && File::IsFileExist(appIconPath))
587                 {
588                         std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(appIconPath));
589                         pIconPath = std::move(pIconPathTemp);
590                 }
591                 else
592                 {
593                         char* pDefaultIconPath = null;
594                         app_manager_get_app_icon_path(pAppIdChar.get(), &pDefaultIconPath);
595                         if (pDefaultIconPath)
596                         {
597                                 String iconPath(pDefaultIconPath);
598                                 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
599                                 pIconPath = std::move(pIconPathTemp);
600                                 free(pDefaultIconPath);
601                         }
602                         SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path  failed.", GetErrorMessage(r));
603                 }
604         }
605         // Sound file path
606         std::unique_ptr<char[]> pSoundPath(null);
607         if (!soundPath.IsEmpty())
608         {
609                 std::unique_ptr<char[]> pSoundPathTemp(_StringConverter::CopyToCharArrayN(soundPath));
610                 pSoundPath = std::move(pSoundPathTemp);
611         }
612         // Set - AppId
613         if (notifyType == NOTIFY_TYPE_APP_ID)
614         {
615                 r = ConvertNotificationResult(notification_set_pkgname(notiHandle, pAppIdChar.get()));
616                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Package name failed.", GetErrorMessage(r));
617         }
618         // Set - title text
619         if (pTitleText.get())
620         {
621                 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
622                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
623         }
624         // Set - content text
625         if (pMsg.get())
626         {
627                 r = notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
628                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
629         }
630         // Set - icon file path
631         r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath.get()));
632         SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path  failed.", GetErrorMessage(r));
633         // Set - sound file path
634         r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath.get()));
635         SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set sound  failed.", GetErrorMessage(r));
636
637         // Set extended - text, thumbnail and background image
638         if (!isOngoing)
639         {
640                 // Extended style set
641                 String countText = notifyRequest.GetNotificationCountText();
642                 NotificationStyle notiStyle= notifyRequest.GetNotificationStyle();
643                 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
644                 {
645                         layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
646                 }
647                 else
648                 if (notiStyle == NOTIFICATION_STYLE_NORMAL && !countText.IsEmpty())
649                 {
650                         layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
651                 }
652
653                 if (!countText.IsEmpty())
654                 {
655                         std::unique_ptr<char[]> text(_StringConverter::CopyToCharArrayN(countText));
656                         r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, text.get(),
657                                                                                                                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
658                 }
659
660                 String bgImageFilePath = notifyRequest.GetBackgroundImageFilePath();
661                 if (!bgImageFilePath.IsEmpty() && File::IsFileExist(bgImageFilePath))
662                 {
663                         std::unique_ptr<char[]> pBgImageFilePath(_StringConverter::CopyToCharArrayN(bgImageFilePath));
664                         r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, pBgImageFilePath.get()));
665                         SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Background image path failed.", GetErrorMessage(r));
666                 }
667
668
669                 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
670                 {
671                         const IList* pThumbnailList = pRequestImpl->GetMessageThumbnailFilePathList();
672                         if (pThumbnailList)
673                         {
674                                 const static notification_image_type_e thumbnailListEnum[] = {NOTIFICATION_IMAGE_TYPE_LIST_1, NOTIFICATION_IMAGE_TYPE_LIST_2,
675                                                 NOTIFICATION_IMAGE_TYPE_LIST_3, NOTIFICATION_IMAGE_TYPE_LIST_4, NOTIFICATION_IMAGE_TYPE_LIST_5 };
676                                 int itemCount = pThumbnailList->GetCount();
677                                 const int maxCount = sizeof(thumbnailListEnum)/sizeof(thumbnailListEnum[0]);
678                                 if (itemCount > maxCount)
679                                 {
680                                         itemCount = maxCount;
681                                 }
682                                 for (int i = 0; i < itemCount; i++)
683                                 {
684                                         const String* pThumbnailPath = static_cast<const String*>(pThumbnailList->GetAt(i));
685                                         // TODO: check pThumbnailPath
686                                         std::unique_ptr<char[]> filePath(_StringConverter::CopyToCharArrayN(*pThumbnailPath));
687                                         r = ConvertNotificationResult(notification_set_image(notiHandle, thumbnailListEnum[i], filePath.get()));
688                                         SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set thumnail path  failed.", GetErrorMessage(r));
689                                 }
690                         }
691                 }
692                 else
693                 {
694                         // TODO: Check the valid
695                         const IList* pMessageTextList = pRequestImpl->GetMessageTextList();
696                         if (pMessageTextList && pMessageTextList->GetCount())
697                         {
698                                 const String* pText1 = static_cast<const String*>(pMessageTextList->GetAt(0));
699                                 if (pText1)
700                                 {
701                                         int matchIndex;
702                                         if (E_SUCCESS == pText1->IndexOf(L'\t', 0, matchIndex))
703                                         {
704                                                 // Make two token
705                                                 String subText;
706                                                 pText1->SubString(0, matchIndex+1, subText);
707                                                 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
708                                                 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
709                                                                                                                                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
710                                                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
711                                                 subText.Clear();
712                                                 if (E_SUCCESS == pText1->SubString(matchIndex+1, subText))
713                                                 {
714                                                         std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
715                                                         r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, rightText.get(),
716                                                                                                                                                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
717                                                         SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Sub Text failed.", GetErrorMessage(r));
718                                                 }
719                                         }
720                                         else
721                                         {
722                                                 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText1));
723                                                 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
724                                                                                                                                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
725                                                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
726                                         }
727                                 }
728                                 const String* pText2 = static_cast<const String*>(pMessageTextList->GetAt(1));
729                                 if (pText2)
730                                 {
731                                         int matchIndex;
732                                         // 2.1: Multiple layout has single line text for 2nd information text.
733                                         if ((layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE && E_SUCCESS) == (pText2->IndexOf(L'\t', 0, matchIndex)))
734                                         {
735                                                 // Make two token
736                                                 String subText;
737                                                 pText2->SubString(0, matchIndex+1, subText);
738                                                 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
739                                                 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
740                                                                                                                                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
741                                                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
742                                                 subText.Clear();
743                                                 if (E_SUCCESS == pText2->SubString(matchIndex+1, subText))
744                                                 {
745                                                         std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
746                                                         r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, rightText.get(),
747                                                                                                                                                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
748                                                         SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Sub Text failed.", GetErrorMessage(r));
749                                                 }
750                                         }
751                                         else
752                                         {
753                                                 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText2));
754                                                 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
755                                                                                                                                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
756                                                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
757                                         }
758                                 }
759                         }
760                         else
761                         if (needUpdate)
762                         {       // Reset text for update case. also must be check the previous text with get_text
763                                 char* pRetStr = null;
764                                 notification_get_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, &pRetStr);
765                                 if (pRetStr)
766                                 {
767                                         const static notification_text_type_e infoTextEnums[] = { NOTIFICATION_TEXT_TYPE_INFO_1, NOTIFICATION_TEXT_TYPE_INFO_SUB_1,
768                                                                                                                                                          NOTIFICATION_TEXT_TYPE_INFO_2, NOTIFICATION_TEXT_TYPE_INFO_SUB_2 };
769                                         for (unsigned int i = 0; i < sizeof(infoTextEnums)/sizeof(infoTextEnums[0]); i++)
770                                         {
771                                                 notification_set_text(notiHandle, infoTextEnums[i], null, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
772                                         }
773                                 }
774                         }
775                 }
776         }
777
778         // Set - service
779         r = arg.Construct(launchArguments);
780         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
781
782         pBundle = arg.GetBundle();
783
784         service_create_request(pBundle, &hSvc);
785         SysTryCatch(NID_APP, hSvc != null, r = E_SYSTEM, r, "[%s] A system error has been occurred. service_create_request failed.", GetErrorMessage(E_SYSTEM));
786
787         if (notifyType == NOTIFY_TYPE_SIMPLE || notifyType == NOTIFY_TYPE_APP_ID)
788         {
789                 service_set_app_id(hSvc, pRequestImpl->IsAppBinding() ? pAppIdChar.get() : null);
790         }
791         else
792         if (notifyType == NOTIFY_TYPE_APP_CONTROL)
793         {
794
795                 std::unique_ptr<char[]> pOperationIdChar(_StringConverter::CopyToCharArrayN(*pOperationId));
796                 service_set_operation(hSvc, pOperationIdChar.get());
797                 if (pUriData)
798                 {
799                         std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
800                         service_set_uri(hSvc, pUri.get());
801                 }
802                 if (pDataType)
803                 {
804                         std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pDataType));
805                         service_set_mime(hSvc, pMime.get());
806                 }
807                 if (pExtraData)
808                 {
809                         std::unique_ptr<Tizen::Base::Collection::IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
810                         if (pMapEnum)
811                         {
812                                 while (pMapEnum->MoveNext() == E_SUCCESS)
813                                 {
814                                         String* pKey = static_cast<String* > (pMapEnum->GetKey());
815                                         String* pValue = static_cast<String* > (pMapEnum->GetValue());
816                                         if (pKey && pValue)
817                                         {
818                                                 std::unique_ptr<char[]> pKeyString(_StringConverter::CopyToCharArrayN(*pKey));
819                                                 std::unique_ptr<char[]> pValueString(_StringConverter::CopyToCharArrayN(*pValue));
820                                                 service_add_extra_data(hSvc, pKeyString.get(), pValueString.get());
821                                         }
822                                         else
823                                         {
824                                                 SysLog(NID_APP, "pKey or pValue is ivalid.");
825                                         }
826                                 }
827                         }
828                 }
829         }
830
831         if (service_to_bundle(hSvc, &service_data) == SERVICE_ERROR_NONE)
832         {
833                 notification_set_property(notiHandle, 0);
834                 notification_set_execute_option(notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
835         }
836         else
837         {
838                 SysLog(NID_APP, "service_to_bundle failed");
839         }
840
841         // Set layout
842         if (isOngoing)
843         {
844                 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
845                 if (activityType == ONGOING_ACTIVITY_TYPE_TEXT)
846                 {
847                         layout = NOTIFICATION_LY_ONGOING_EVENT;
848                 }
849                 else
850                 {
851                         layout = NOTIFICATION_LY_ONGOING_PROGRESS;
852                 }
853         }
854         notification_set_layout(notiHandle, layout);
855
856         // For ongoing
857         if (isOngoing)
858         {
859                 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
860                 int progress = notifyRequest.GetOngoingActivityProgress();
861
862                 switch (activityType)
863                 {
864                 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
865                         if (needUpdate)
866                         {
867                                 r = ConvertNotificationResult(notification_update_progress(notiHandle, notiPrivateId, progress/100.));
868                         }
869                         else
870                         {
871                                 r = ConvertNotificationResult(notification_set_progress(notiHandle, progress/100.));
872                         }
873                         SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
874                         break;
875
876                 case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
877                         if (needUpdate)
878                         {
879                                 r = ConvertNotificationResult(notification_update_size(notiHandle, notiPrivateId, progress));
880                         }
881                         else
882                         {
883                                 r = ConvertNotificationResult(notification_set_size(notiHandle, progress));
884                         }
885                         SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
886                         break;
887
888                 case ONGOING_ACTIVITY_TYPE_TEXT:
889                         // Do nothing
890                         break;
891
892                 default:
893                         r = E_OPERATION_FAILED;
894                         break;
895                 }
896                 if (needUpdate)
897                 {
898                         r = ConvertNotificationResult(notification_update_content(notiHandle, notiPrivateId, pMsg.get()));
899                 }
900                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
901         }
902
903         // insert for new notification
904         if (!needUpdate)
905         {       // new
906                 r = ConvertNotificationResult(notification_insert(notiHandle, &notiPrivateId));
907                 SysLog(NID_APP, "Insert notification and get new notiPrivateId(%d)", notiPrivateId);
908                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
909                 if (isOngoing)
910                 {
911                         __notifyPrivitIdForOngoing  = notiPrivateId;
912                 }
913                 else
914                 {
915                         __notifyPrivitId = notiPrivateId;
916                 }
917         }
918
919         // notification_update just for non ongoing and text type ongoing only.
920         if (needUpdate && !isOngoing)
921         {
922                 notification_update(notiHandle);
923                 SysLog(NID_APP, "Notification update from notiPrivateId(%d)", notiPrivateId);
924         }
925
926
927 CATCH:
928         service_destroy(hSvc);
929         notification_free(notiHandle);
930         return r;
931 }
932
933 result
934 _NotificationManagerImpl::RemoveNotification(void)
935 {
936         return RemoveNotification(false);
937 }
938
939 result
940 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
941 {
942         return RemoveNotification(true);
943 }
944
945 result
946 _NotificationManagerImpl::RemoveNotification(bool onGoing)
947 {
948         result r = E_SUCCESS;
949         notification_error_e err = NOTIFICATION_ERROR_NONE;
950         const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
951         const int notiPrivateId = onGoing ? __notifyPrivitIdForOngoing : __notifyPrivitId;
952
953         if (notiPrivateId != -1)
954         {
955                 notification_h notiHandle = notification_load(null, notiPrivateId);
956                 if (notiHandle)
957                 {
958                         err = notification_delete(notiHandle);
959                         SysLog(NID_APP, "Notification deleted.");
960                 }
961                 else
962                 {
963                         SysLog(NID_APP, "Notification already deleted.");
964                 }
965                 notification_free(notiHandle);
966         }
967         else
968         {
969                 err = notification_delete_all_by_type(null, notiType);
970                 SysLog(NID_APP, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
971         }
972
973         switch (err)
974         {
975         case NOTIFICATION_ERROR_NONE:
976                 r = E_SUCCESS;
977                 break;
978
979         case NOTIFICATION_ERROR_INVALID_DATA:
980                 r = E_INVALID_ARG;
981                 break;
982
983         default:
984                 r = E_SYSTEM;
985                 break;
986         }
987
988         return r;
989 }
990
991 result
992 _NotificationManagerImpl::RemoveNotificationByAppId(const Tizen::App::AppId& appId, bool onGoing)
993 {
994         result r = E_SUCCESS;
995         notification_error_e err = NOTIFICATION_ERROR_NONE;
996         bool isValidAppId = _Aul::IsInstalled(appId);
997         SysTryReturnResult(NID_APP, isValidAppId == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
998
999         std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
1000         const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
1001         const int notiPrivateId = onGoing ? __notifyPrivitIdForOngoing : __notifyPrivitId;
1002
1003         if (notiPrivateId != -1)
1004         {
1005                 notification_h notiHandle = notification_load(pAppId.get(), notiPrivateId);
1006                 if (notiHandle)
1007                 {
1008                         err = notification_delete(notiHandle);
1009                         SysLog(NID_APP, "Notification deleted.");
1010                 }
1011                 else
1012                 {
1013                         SysLog(NID_APP, "Notification already deleted.");
1014                 }
1015                 notification_free(notiHandle);
1016         }
1017         else
1018         {
1019                 err = notification_delete_all_by_type(pAppId.get(), notiType);
1020                 SysLog(NID_APP, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
1021         }
1022
1023         switch (err)
1024         {
1025         case NOTIFICATION_ERROR_NONE:
1026                 r = E_SUCCESS;
1027                 break;
1028
1029         case NOTIFICATION_ERROR_INVALID_DATA:
1030                 r = E_INVALID_ARG;
1031                 break;
1032
1033         default:
1034                 r = E_SYSTEM;
1035                 break;
1036         }
1037
1038         return r;
1039 }
1040
1041 void
1042 _NotificationManagerImpl::RemoveBadge(const char* pkgName) const
1043 {
1044         bool badgeExist = false;
1045         badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1046         SysLog(NID_APP, "badge_is_existing: exitst= %d, error= %d.", badgeExist, badgeError);   //#####
1047         if (badgeExist)
1048         {
1049                 badgeError = badge_remove(pkgName);
1050                 SysLog(NID_APP, "badge_remove: error= %d.", badgeError);        //#####
1051         }
1052         SysLog(NID_APP, "Badge removed.");
1053 }
1054
1055 void
1056 _NotificationManagerImpl::SetBadgeCount(const char* pkgName, int badgeCount) const
1057 {
1058         bool badgeExist;
1059         badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1060         SysLog(NID_APP, "badge_is_existing: error= %d.", badgeError);   //#####
1061         if (!badgeExist)
1062         {
1063                 badgeError = badge_create(pkgName, pkgName);
1064                 SysLog(NID_APP, "badge_create: error= %d.", badgeError);        //#####
1065         }
1066
1067         badge_set_count(pkgName, badgeCount);
1068         SysLog(NID_APP, "badge_set_count: badgeNumber= %d.", badgeCount);
1069 }
1070
1071 int
1072 _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
1073 {
1074         unsigned int count = 0;
1075
1076         badge_error_e badgeError = badge_get_count(pkgName, &count);
1077         if (badgeError == BADGE_ERROR_NONE)
1078         {
1079                 SysLog(NID_APP, "badge_get_count: ret= %d.", count);
1080                 return count;
1081         }
1082         else
1083         {
1084                 SysLog(NID_APP, "badge_get_count: error= %d.", badgeError);
1085                 return -1;
1086         }
1087 }
1088
1089 result
1090 _NotificationManagerImpl::AddBadgeEventListener(IBadgeEventListener& listener)
1091 {
1092         SysTryReturnResult(NID_APP, !__badgeEventListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
1093         SysLog(NID_APP, "(%x)", &listener);
1094
1095         result r = _BadgeManagerImpl::GetInstance()->AddPrimaryBadgeEventListener(*this);
1096         SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "Failed to AddPrimaryBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1097
1098         return __badgeEventListenerList.Add(&listener);
1099 }
1100
1101 result
1102 _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener)
1103 {
1104         SysLog(NID_APP, "(%x)", &listener);
1105         result r = __badgeEventListenerList.Remove(&listener);
1106         SysTryReturn(NID_APP, !IsFailed(r), r, r, "Failed to RemoveBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1107
1108         return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
1109 }
1110
1111 void
1112 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
1113 {
1114         std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(__badgeEventListenerList.GetEnumeratorN());
1115         SysTryReturnVoidResult(NID_APP, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
1116
1117         IBadgeEventListener* pListener;
1118         while (pEnum->MoveNext() == E_SUCCESS)
1119         {
1120                 pListener = null;
1121                 pEnum->GetCurrent(pListener);
1122                 if( !pListener)
1123                 {
1124                         SysLog(NID_APP, "pListener is null!");
1125                         continue;
1126                 }
1127                 pListener->OnBadgeUpdated(appId, badgeNumber);
1128         }
1129 }
1130
1131 } }    // Tizen::Shell