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