updated the osp-shell to osp-shell and osp-shell-core
[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
31 #include <FBaseSysLog.h>
32 #include <FAppTypes.h>
33 #include <FShellNotificationManager.h>
34 #include <FShellNotificationRequest.h>
35
36 #include <FBaseInternalTypes.h>
37 #include <FBase_StringConverter.h>
38 #include "FApp_AppInfo.h"
39 #include "FApp_PackageManagerImpl.h"
40 #include "FApp_Aul.h"
41 #include "FApp_AppArg.h"
42 #include "FShell_NotificationManagerImpl.h"
43 #include "FShell_NotificationManagerProxy.h"
44
45 using namespace Tizen::Base;
46 using namespace Tizen::App;
47 using namespace Tizen::Shell;
48
49 extern "C" int service_create_request(bundle *data, service_h *service);
50
51 namespace
52 {
53
54 result
55 ConvertNotificationResult(int error)
56 {
57         switch (error)
58         {
59         case UI_NOTIFICATION_ERROR_NONE:
60                 return E_SUCCESS;
61         case UI_NOTIFICATION_ERROR_INVALID_PARAMETER:
62                 return E_INVALID_ARG;
63         case UI_NOTIFICATION_ERROR_OUT_OF_MEMORY:
64                 return E_OUT_OF_MEMORY;
65         case UI_NOTIFICATION_ERROR_DB_FAILED:
66                 return E_DATABASE;
67         case UI_NOTIFICATION_ERROR_NO_SUCH_FILE:
68                 return E_OPERATION_FAILED;
69         case UI_NOTIFICATION_ERROR_INVALID_STATE:
70                 return E_OPERATION_FAILED;
71         default:
72                 return E_OPERATION_FAILED;
73         }
74 }
75
76 static int
77 GetMessageLength()
78 {
79         static int length = (_AppInfo::GetApiVersion() < _API_VERSION_2_1) ? 127 : MAX_NOTIFICATION_MESSAGE_LENGTH;
80
81         return length;
82 }
83
84 ui_notification_progress_type_e
85 ConvertToNotificationProgressType(int progressType)
86 {
87         switch (progressType)
88         {
89         case ONGOING_ACTIVITY_TYPE_TEXT:
90                 return UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
91         case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
92                 return UI_NOTIFICATION_PROGRESS_TYPE_SIZE;
93         case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
94                 return UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
95         default:
96                 return UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
97         }
98 }
99
100 bool
101 IsPosted(ui_notification_h handle)
102 {
103         struct ui_notification_s
104         {
105                 void* raw_handle;
106                 bool ongoing;
107                 bool posted;
108                 bool removed;
109                 char *icon;
110                 struct tm *time;
111                 char *title;
112                 char *content;
113                 service_h service;
114                 char *sound;
115                 bool vibration;
116         };
117
118         if (handle == NULL)
119         {
120                 return false;
121         }
122
123         ui_notification_s* pStruct = reinterpret_cast<ui_notification_s*>(handle);
124
125         return pStruct->posted;
126 }
127
128 }
129
130 namespace Tizen { namespace Shell
131 {
132
133 _NotificationManagerImpl::_NotificationManagerImpl(void)
134 : __pNotificationManager(null)
135 {
136 }
137
138 _NotificationManagerImpl::~_NotificationManagerImpl(void)
139 {
140 }
141
142 result
143 _NotificationManagerImpl::Construct(void)
144 {
145         result r = E_SUCCESS;
146
147         __pNotificationManager = new (std::nothrow) _NotificationManagerProxy;
148         SysTryReturnResult(NID_APP, __pNotificationManager != null, E_OUT_OF_MEMORY, "__pNotificationManagerProxy creation failed.");
149
150         r = __pNotificationManager->Construct();
151         SysTryCatch(NID_APP, !IsFailed(r), , r, "__pNotificationManager->Construct() failed [%s].", GetErrorMessage(r));
152
153         return E_SUCCESS;
154
155 CATCH:
156         delete __pNotificationManager;
157         __pNotificationManager = null;
158
159         return r;
160 }
161
162 const _NotificationManagerImpl*
163 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
164 {
165         return notiMgr.__pNotificationManagerImpl;
166 }
167
168 _NotificationManagerImpl*
169 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
170 {
171         return notiMgr.__pNotificationManagerImpl;
172 }
173
174 int
175 _NotificationManagerImpl::GetBadgeNumber(void) const
176 {
177         int count = -1;
178         notification_get_badge(NULL, NOTIFICATION_GROUP_ID_NONE, &count);
179         return count;
180 }
181
182 result
183 _NotificationManagerImpl::OngoingImpl(const String& messageText, const String& launchArguments) const
184 {
185         return NotifyImpl(messageText, -1, launchArguments, true);
186 }
187
188 result
189 _NotificationManagerImpl::OngoingImpl(const AppId& appId, const String& messageText, const String& launchArguments) const
190 {
191
192         return NotifyImpl(appId, messageText, -1, launchArguments, true);
193 }
194
195 result
196 _NotificationManagerImpl::NotifyImpl(const String& messageText, int badgeNumber,
197                                                                          const String& launchArguments,
198                                                                          bool isOngoing) const
199 {
200         result r = E_SUCCESS;
201         int retcode = 0;
202         char* pMsg = null;
203         ui_notification_h core = NULL;
204         char* pkgname = NULL;
205
206         if (!messageText.IsEmpty())
207         {
208                 SysTryReturnResult(NID_APP,
209                                           messageText.GetLength() <= GetMessageLength(), E_INVALID_ARG,
210                                           "MessageText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
211
212                 retcode = ui_notification_create(isOngoing, &core);
213                 SysTryReturnResult(NID_APP, retcode == UI_NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Notification creation error : 0x%x.", retcode);
214
215                 pMsg = _StringConverter::CopyToCharArrayN(messageText);
216
217                 int ret = ui_notification_set_content(core, pMsg);
218                 SysTryLog(NID_APP, ret == UI_NOTIFICATION_ERROR_NONE, "Setting notification content failure : %d.", ret);
219
220                 bundle* pKb = NULL;
221                 service_h svc = NULL;
222                 _AppArg arg;
223
224                 app_get_package(&pkgname);
225                 SysTryCatch(NID_APP, pkgname != NULL, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Cannot acquire package name for current application.");
226
227                 r = arg.Construct(launchArguments);
228                 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
229
230                 pKb = arg.GetBundle();
231                 service_create_request(pKb, &svc);
232                 service_set_package(svc, pkgname);
233                 ui_notification_set_service(core, svc);
234
235                 SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), pkgname);
236
237                 r = ConvertNotificationResult(ui_notification_post(core));
238
239                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
240         }
241
242         if (badgeNumber >= 0)
243         {
244                 notification_set_badge(NULL, NOTIFICATION_GROUP_ID_NONE, badgeNumber);
245                 SysLog(NID_APP, "Badge number is set to %d.", badgeNumber);
246         }
247
248 CATCH:
249         delete[] pMsg;
250         if (pkgname)
251         {
252                 free(pkgname);
253         }
254
255         if (core)
256         {
257                 ui_notification_destroy(core);
258         }
259
260         return r;
261 }
262
263 result
264 _NotificationManagerImpl::NotifyImpl(const AppId& appId, const String& messageText, int badgeNumber,
265                                                                          const String& launchArguments,
266                                                                          bool isOngoing) const
267 {
268         result r = E_SUCCESS;
269         int retcode = 0;
270         char* pMsg = null;
271         char* pIcon = NULL;
272         char* pName = NULL;
273         ui_notification_h core = NULL;
274         char buffer[256];
275
276         memset(buffer, 0, 256);
277
278         bool b = _Aul::IsInstalled(appId);
279
280         SysTryReturnResult(NID_APP, b == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
281
282         if (!isOngoing || !messageText.IsEmpty())
283         {
284                 SysTryReturnResult(NID_APP,
285                                           messageText.GetLength() <= GetMessageLength(), E_INVALID_ARG,
286                                           "MessageText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
287
288                 retcode = ui_notification_create(isOngoing, &core);
289                 SysTryReturnResult(NID_APP, retcode == UI_NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Notification creation error : 0x%x.", retcode);
290
291                 pMsg = _StringConverter::CopyToCharArrayN(messageText);
292
293                 int ret = ui_notification_set_content(core, pMsg);
294                 SysTryLog(NID_APP, ret == UI_NOTIFICATION_ERROR_NONE, "Setting notification content failure : %d.", ret);
295
296                 bundle* pKb = NULL;
297                 service_h svc = NULL;
298                 _AppArg arg;
299
300                 snprintf(buffer, 256, "%ls", appId.GetPointer());
301
302                 app_manager_get_app_icon_path(buffer, &pIcon);
303                 ui_notification_set_icon(core, pIcon);
304
305                 app_manager_get_app_name(buffer, &pName);
306                 ui_notification_set_title(core, pName);
307
308                 r = arg.Construct(launchArguments);
309                 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
310
311                 pKb = arg.GetBundle();
312                 service_create_request(pKb, &svc);
313                 service_set_app_id(svc, buffer);
314                 ui_notification_set_service(core, svc);
315
316                 SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), buffer);
317
318                 r = ConvertNotificationResult(ui_notification_post(core));
319
320                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
321         }
322
323         if (badgeNumber >= 0)
324         {
325                 notification_set_badge(buffer, NOTIFICATION_GROUP_ID_NONE, badgeNumber);
326                 SysLog(NID_APP, "Badge number is set to %d.", badgeNumber);
327         }
328
329 CATCH:
330         delete[] pMsg;
331
332         if (core)
333         {
334                 ui_notification_destroy(core);
335         }
336
337         if (pIcon)
338         {
339                 free(pIcon);
340         }
341
342         if (pName)
343         {
344                 free(pName);
345         }
346
347         return r;
348 }
349
350
351 result
352 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
353 {
354         result r = E_SUCCESS;
355         int retcode = 0;
356         int progress = -1;
357         ui_notification_h core = NULL;
358         char* pkgname = NULL;
359         char* pTitleText = NULL;
360         char* pIconPath = NULL;
361         char* pSoundPath = NULL;
362
363         const String& messageText = notiMessage.GetAlertText();
364         const String& launchArguments = notiMessage.GetAppMessage();
365         const String& titleText = notiMessage.GetTitleText();
366         const String& iconPath = notiMessage.GetIconFilePath();
367         const String& soundPath = notiMessage.GetSoundFilePath();
368         const int badgeNumber = notiMessage.GetBadgeNumber();
369         const int badgeOffset = notiMessage.GetBadgeOffset();
370
371         if (isOngoing || !messageText.IsEmpty())
372         {
373                 SysTryReturnResult(NID_APP,
374                                           messageText.GetLength() <= GetMessageLength(), E_INVALID_ARG,
375                                           "MessageText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
376
377                 retcode = ui_notification_create(isOngoing, &core);
378                 SysTryReturnResult(NID_APP, retcode == UI_NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Notification creation error : 0x%x.", retcode);
379
380                 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
381
382                 if (pMsg)
383                 {
384                         int ret = ui_notification_set_content(core, pMsg.get());
385                         SysTryLog(NID_APP, ret == UI_NOTIFICATION_ERROR_NONE, "Setting notification content failure : %d.", ret);
386                 }
387
388                 if (!titleText.IsEmpty())
389                 {
390                         pTitleText = _StringConverter::CopyToCharArrayN(titleText);
391                         ui_notification_set_title(core, pTitleText);
392                 }
393
394                 if (!iconPath.IsEmpty())
395                 {
396                         pIconPath = _StringConverter::CopyToCharArrayN(iconPath);
397                         ui_notification_set_icon(core, pIconPath);
398                 }
399
400                 if (!soundPath.IsEmpty())
401                 {
402                         pSoundPath = _StringConverter::CopyToCharArrayN(soundPath);
403                         ui_notification_set_sound(core, pSoundPath);
404                 }
405
406                 bundle* pKb = NULL;
407                 service_h svc = NULL;
408                 _AppArg arg;
409
410                 app_get_id(&pkgname);
411                 SysTryCatch(NID_APP, pkgname != NULL, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Cannot acquire package name for current application.");
412
413                 r = arg.Construct(launchArguments);
414                 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
415
416                 pKb = arg.GetBundle();
417                 service_create_request(pKb, &svc);
418                 service_set_app_id(svc, pkgname);
419
420                 ui_notification_set_service(core, svc);
421                 SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), pkgname);
422
423                 if (isOngoing)
424                 {
425                         OngoingActivityType activityType = notiMessage.GetOngoingActivityType();
426                         progress = notiMessage.GetOngoingActivityProgress();
427                         switch (activityType)
428                         {
429                         case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
430                                 if (!IsPosted(core))
431                                 {
432                                         ui_notification_post(core);
433                                 }
434                                 r = ConvertNotificationResult(ui_notification_update_progress(core, ConvertToNotificationProgressType(activityType), progress/100.));
435                                 break;
436                         case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
437                                 if (!IsPosted(core))
438                                 {
439                                         ui_notification_post(core);
440                                 }
441                                 r = ConvertNotificationResult(ui_notification_update_progress(core, ConvertToNotificationProgressType(activityType), progress));
442                                 break;
443                         case ONGOING_ACTIVITY_TYPE_TEXT:
444                                 r = ConvertNotificationResult(ui_notification_post(core));
445                                 break;
446                         default:
447                                 r = E_OPERATION_FAILED;
448                                 // ui_notification_set_content() is done already
449                                 break;
450                         }
451                 }
452                 else
453                 {
454                         r = ConvertNotificationResult(ui_notification_post(core));
455                         SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
456                 }
457         }
458         else
459         {
460                 SysTryReturnResult(NID_APP, 0, E_INVALID_ARG, "MessageText is Empty");
461         }
462
463         if (badgeNumber >= 0)
464         {
465                 notification_set_badge(NULL, NOTIFICATION_GROUP_ID_NONE, badgeNumber);
466                 SysLog(NID_APP, "Badge number is set to %d.", badgeNumber);
467         }
468
469         if (badgeOffset != 0)
470         {
471                 // badge offset is exclusive to badge number
472
473                 int count = 0;
474                 notification_error_e noti_err = notification_get_badge(NULL, NOTIFICATION_GROUP_ID_NONE, &count);
475                 if (noti_err == NOTIFICATION_ERROR_NONE)
476                 {
477                         count += badgeOffset;
478                         if (count > 0)
479                         {
480                                 notification_set_badge(NULL, NOTIFICATION_GROUP_ID_NONE, count);
481                                 SysLog(NID_APP, "Badge number is set to %d.", count);
482                         }
483                 }
484         }
485
486 CATCH:
487         delete[] pIconPath;
488         delete[] pTitleText;
489         delete[] pSoundPath;
490         if (pkgname)
491         {
492                 free(pkgname);
493         }
494         if (core)
495         {
496                 ui_notification_destroy(core);
497         }
498
499         return r;
500 }
501
502 result
503 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
504 {
505         return __pNotificationManager->NotifyMessage(appId, notiMessage, isOngoing);
506 }
507
508
509 result
510 _NotificationManagerImpl::Notify(int badgeNumber) const
511 {
512         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
513
514         if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
515         {
516                 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
517         }
518
519         String messageText = String(L"");
520         String appMessage = String(L"");
521
522         return NotifyImpl(messageText, badgeNumber, appMessage, false);
523 }
524
525 result
526 _NotificationManagerImpl::Notify(const String& messageText) const
527 {
528         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
529
530         String appMessage = String(L"");
531
532         return NotifyImpl(messageText, -1, appMessage, false);
533 }
534
535 result
536 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber) const
537 {
538         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
539         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
540
541         if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
542         {
543                 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
544         }
545
546         String appMessage = String(L"");
547
548         return NotifyImpl(messageText, badgeNumber, appMessage, false);
549 }
550
551 result
552 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments) const
553 {
554         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
555         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
556         SysTryReturnResult(NID_APP,
557                                           launchArguments != null && launchArguments.GetLength() > 0, E_INVALID_ARG,
558                                           "launchArguments is less than 0.");
559
560         SysTryReturnResult(NID_APP,
561                                           launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
562                                           "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
563
564         if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
565         {
566                 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
567         }
568
569         return NotifyImpl(messageText, badgeNumber, launchArguments, false);
570 }
571
572 int
573 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
574 {
575         bool b = _Aul::IsInstalled(appId);
576
577         SysTryReturn(NID_APP, b == true, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The application %ls is not installed",
578                                 appId.GetPointer());
579
580         char buffer[256];
581         int count = -1;
582
583         memset(buffer, 0, 256);
584
585         snprintf(buffer, 256, "%ls", appId.GetPointer());
586
587         notification_get_badge(buffer, NOTIFICATION_GROUP_ID_NONE, &count);
588
589         return count;
590 }
591
592
593 result
594 _NotificationManagerImpl::NotifyByAppId(const AppId& appId, int badgeNumber) const
595 {
596         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
597
598         String messageText = String(L"");
599         String appMessage = String(L"");
600         return NotifyImpl(appId, messageText, badgeNumber, appMessage);
601 }
602
603 result
604 _NotificationManagerImpl::NotifyByAppId(const AppId& appId, const String& messageText) const
605 {
606         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
607
608         return NotifyImpl(appId, messageText, -1, String(L""));
609 }
610
611 result
612 _NotificationManagerImpl::NotifyByAppId(const AppId& appId, const String& messageText, int badgeNumber) const
613 {
614         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
615         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
616
617         return NotifyImpl(appId, messageText, badgeNumber, String(L""));
618 }
619
620 result
621 _NotificationManagerImpl::NotifyByAppId(const AppId& appId, const String& messageText, const String& launchArguments) const
622 {
623         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
624         SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
625         SysTryReturnResult(NID_APP,
626                                           launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
627                                           "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
628
629         return NotifyImpl(appId, messageText, -1, launchArguments);
630 }
631
632 result
633 _NotificationManagerImpl::NotifyByAppId(const AppId& appId, const String& messageText, int badgeNumber,
634                                                                                  const String& launchArguments) const
635 {
636         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
637         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
638         SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
639         SysTryReturnResult(NID_APP,
640                                           launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
641                                           "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
642
643         return NotifyImpl(appId, messageText, badgeNumber, launchArguments);
644 }
645
646 result
647 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText) const
648 {
649         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
650
651         return OngoingImpl(messageText, String(L""));
652 }
653
654 result
655 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments) const
656 {
657         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
658         SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
659         SysTryReturnResult(NID_APP,
660                                           launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
661                                           "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
662
663         return OngoingImpl(messageText, launchArguments);
664 }
665
666 result
667 _NotificationManagerImpl::NotifyOngoingActivityByAppId(const AppId& appId, const String& messageText) const
668 {
669         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
670
671         return OngoingImpl(appId, messageText, String(L""));
672 }
673
674 result
675 _NotificationManagerImpl::NotifyOngoingActivityByAppId(const AppId& appId, const String& messageText,
676                                                                                                                 const String& launchArguments) const
677 {
678         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
679         SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
680         SysTryReturnResult(NID_APP,
681                                           launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
682                                           "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
683
684         return OngoingImpl(appId, messageText, launchArguments);
685 }
686
687 result
688 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
689 {
690         result r = E_SUCCESS;
691
692         notification_error_e err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
693         switch (err)
694         {
695         case NOTIFICATION_ERROR_NONE:
696                 r = E_SUCCESS;
697                 break;
698
699         case NOTIFICATION_ERROR_INVALID_DATA:
700                 r = E_INVALID_ARG;
701                 break;
702
703         default:
704                 r = E_OPERATION_FAILED;
705                 break;
706         }
707
708         return r;
709 }
710
711 result
712 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
713 {
714         return __pNotificationManager->RemoveNotification(appId, true);
715 }
716
717 result
718 _NotificationManagerImpl::RemoveNotification(void)
719 {
720         result r = E_SUCCESS;
721
722         notification_error_e err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
723         switch (err)
724         {
725         case NOTIFICATION_ERROR_NONE:
726                 r = E_SUCCESS;
727                 break;
728
729         case NOTIFICATION_ERROR_INVALID_DATA:
730                 r = E_INVALID_ARG;
731                 break;
732
733         default:
734                 r = E_OPERATION_FAILED;
735                 break;
736         }
737
738         return r;
739 }
740
741 result
742 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
743 {
744         return __pNotificationManager->RemoveNotification(appId,false);
745 }
746
747 };
748 };    // Tizen::Shell