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