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