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