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