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