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