Merge "updated appid installation issue with _Aul::IsInstalled(appid) API"
[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 "FAppPkg_PackageManagerImpl.h"
41 #include "FApp_AppArg.h"
42 #include "FShell_NotificationManagerImpl.h"
43 #include "FShell_NotificationManagerProxy.h"
44
45 using namespace Tizen::Base;
46 using namespace Tizen::App;
47 using namespace Tizen::App::Package;
48 using namespace Tizen::Shell;
49
50 extern "C" int service_create_request(bundle *data, service_h *service);
51 extern "C" int service_to_bundle(service_h service, bundle** data);
52
53 namespace
54 {
55
56 result
57 ConvertNotificationResult(int error)
58 {
59         switch (error)
60         {
61         case NOTIFICATION_ERROR_NONE:
62                 return E_SUCCESS;
63         case NOTIFICATION_ERROR_INVALID_DATA:
64                 return E_INVALID_ARG;
65         case NOTIFICATION_ERROR_NO_MEMORY:
66                 return E_OUT_OF_MEMORY;
67         case NOTIFICATION_ERROR_FROM_DB:
68                 return E_DATABASE;
69         case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
70                 return E_OPERATION_FAILED;
71         case NOTIFICATION_ERROR_NOT_EXIST_ID:
72                 return E_OPERATION_FAILED;
73         default:
74                 return E_OPERATION_FAILED;
75         }
76 }
77
78 bool
79 IsPosted(ui_notification_h handle)
80 {
81         struct ui_notification_s
82         {
83                 void* raw_handle;
84                 bool ongoing;
85                 bool posted;
86                 bool removed;
87                 char *icon;
88                 struct tm *time;
89                 char *title;
90                 char *content;
91                 service_h service;
92                 char *sound;
93                 bool vibration;
94         };
95
96         if (handle == NULL)
97         {
98                 return false;
99         }
100
101         ui_notification_s* pStruct = reinterpret_cast<ui_notification_s*>(handle);
102
103         return pStruct->posted;
104 }
105
106 }
107
108 namespace Tizen { namespace Shell
109 {
110
111 _NotificationManagerImpl::_NotificationManagerImpl(void)
112 : __pNotificationManager(null)
113 {
114 }
115
116 _NotificationManagerImpl::~_NotificationManagerImpl(void)
117 {
118 }
119
120 result
121 _NotificationManagerImpl::Construct(void)
122 {
123         result r = E_SUCCESS;
124
125         __pNotificationManager = new (std::nothrow) _NotificationManagerProxy;
126         SysTryReturnResult(NID_APP, __pNotificationManager != null, E_OUT_OF_MEMORY, "__pNotificationManagerProxy creation failed.");
127
128         r = __pNotificationManager->Construct();
129         SysTryCatch(NID_APP, !IsFailed(r), , r, "__pNotificationManager->Construct() failed [%s].", GetErrorMessage(r));
130
131         return E_SUCCESS;
132
133 CATCH:
134         delete __pNotificationManager;
135         __pNotificationManager = null;
136
137         return r;
138 }
139
140 const _NotificationManagerImpl*
141 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
142 {
143         return notiMgr.__pNotificationManagerImpl;
144 }
145
146 _NotificationManagerImpl*
147 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
148 {
149         return notiMgr.__pNotificationManagerImpl;
150 }
151
152 int
153 _NotificationManagerImpl::GetBadgeNumber(void) const
154 {
155         int count = -1;
156         notification_get_badge(NULL, NOTIFICATION_GROUP_ID_NONE, &count);
157         return count;
158 }
159
160 result
161 _NotificationManagerImpl::OngoingImpl(const String& messageText, const String& launchArguments) const
162 {
163         return NotifyImpl(messageText, -1, launchArguments, true);
164 }
165
166 result
167 _NotificationManagerImpl::OngoingImpl(const AppId& appId, const String& messageText, const String& launchArguments) const
168 {
169
170         return NotifyImpl(appId, messageText, -1, launchArguments, true);
171 }
172
173 result
174 _NotificationManagerImpl::NotifyImpl(const String& messageText, int badgeNumber,
175                                                                          const String& launchArguments,
176                                                                          bool isOngoing) const
177 {
178         result r = E_SUCCESS;
179         char* pMsg = null;
180         notification_h core = NULL;
181         char* pkgname = NULL;
182         bundle* pKb = NULL;
183         bundle* service_data = NULL;
184         service_h svc = NULL;
185         _AppArg arg;
186
187         if (!messageText.IsEmpty())
188         {
189                 SysTryReturnResult(NID_APP,
190                                           messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
191                                           "MessageText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
192
193                 if (isOngoing)
194                 {
195                         core = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
196                         SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
197                 }
198                 else
199                 {
200                         core = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
201                         SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
202                 }
203
204                 pMsg = _StringConverter::CopyToCharArrayN(messageText);
205                 notification_set_text(core, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
206
207                 app_get_package(&pkgname);
208                 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.");
209
210                 r = arg.Construct(launchArguments);
211                 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
212
213                 pKb = arg.GetBundle();
214                 service_create_request(pKb, &svc);
215                 service_set_package(svc, pkgname);
216
217                 if (service_to_bundle(svc, &service_data) == SERVICE_ERROR_NONE)
218                 {
219                         notification_set_property(core, 0);
220                         notification_set_execute_option(core, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
221                         SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), pkgname);
222                 }
223
224                 r = ConvertNotificationResult(notification_insert(core, NULL));
225                 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
226         }
227
228         if (badgeNumber >= 0)
229         {
230                 notification_set_badge(NULL, NOTIFICATION_GROUP_ID_NONE, badgeNumber);
231                 SysLog(NID_APP, "Badge number is set to %d.", badgeNumber);
232         }
233
234 CATCH:
235         delete[] pMsg;
236         if (pkgname)
237         {
238                 free(pkgname);
239         }
240
241         if (core)
242         {
243                 notification_free(core);
244         }
245         service_destroy(svc);
246         return r;
247 }
248
249 result
250 _NotificationManagerImpl::NotifyImpl(const AppId& appId, const String& messageText, int badgeNumber,
251                                                                          const String& launchArguments,
252                                                                          bool isOngoing) const
253 {
254         result r = E_SUCCESS;
255         char* pMsg = null;
256         char* pIcon = NULL;
257         char* pName = NULL;
258         notification_h core = NULL;
259         char buffer[256];
260         bundle* pKb = NULL;
261         bundle* service_data = NULL;
262         service_h svc = NULL;
263         _AppArg arg;
264
265         memset(buffer, 0, 256);
266
267         bool b = _Aul::IsInstalled(appId);
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 = _Aul::IsInstalled(appId);
584         SysTryReturn(NID_APP, b == true, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The application %ls is not installed",
585                                 appId.GetPointer());
586
587         char buffer[256];
588         int count = -1;
589
590         memset(buffer, 0, 256);
591
592         snprintf(buffer, 256, "%ls", appId.GetPointer());
593
594         notification_get_badge(buffer, NOTIFICATION_GROUP_ID_NONE, &count);
595
596         return count;
597 }
598
599
600 result
601 _NotificationManagerImpl::NotifyByAppId(const AppId& appId, int badgeNumber) const
602 {
603         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
604
605         String messageText = String(L"");
606         String appMessage = String(L"");
607         return NotifyImpl(appId, messageText, badgeNumber, appMessage);
608 }
609
610 result
611 _NotificationManagerImpl::NotifyByAppId(const AppId& appId, const String& messageText) const
612 {
613         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
614
615         return NotifyImpl(appId, messageText, -1, String(L""));
616 }
617
618 result
619 _NotificationManagerImpl::NotifyByAppId(const AppId& appId, const String& messageText, int badgeNumber) const
620 {
621         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
622         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
623
624         return NotifyImpl(appId, messageText, badgeNumber, String(L""));
625 }
626
627 result
628 _NotificationManagerImpl::NotifyByAppId(const AppId& appId, const String& messageText, const String& launchArguments) const
629 {
630         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
631         SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
632         SysTryReturnResult(NID_APP,
633                                           launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
634                                           "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
635
636         return NotifyImpl(appId, messageText, -1, launchArguments);
637 }
638
639 result
640 _NotificationManagerImpl::NotifyByAppId(const AppId& appId, const String& messageText, int badgeNumber,
641                                                                                  const String& launchArguments) const
642 {
643         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
644         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
645         SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
646         SysTryReturnResult(NID_APP,
647                                           launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
648                                           "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
649
650         return NotifyImpl(appId, messageText, badgeNumber, launchArguments);
651 }
652
653 result
654 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText) const
655 {
656         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
657
658         return OngoingImpl(messageText, String(L""));
659 }
660
661 result
662 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments) const
663 {
664         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
665         SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
666         SysTryReturnResult(NID_APP,
667                                           launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
668                                           "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
669
670         return OngoingImpl(messageText, launchArguments);
671 }
672
673 result
674 _NotificationManagerImpl::NotifyOngoingActivityByAppId(const AppId& appId, const String& messageText) const
675 {
676         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
677
678         return OngoingImpl(appId, messageText, String(L""));
679 }
680
681 result
682 _NotificationManagerImpl::NotifyOngoingActivityByAppId(const AppId& appId, const String& messageText,
683                                                                                                                 const String& launchArguments) const
684 {
685         SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
686         SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
687         SysTryReturnResult(NID_APP,
688                                           launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
689                                           "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
690
691         return OngoingImpl(appId, messageText, launchArguments);
692 }
693
694 result
695 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
696 {
697         result r = E_SUCCESS;
698
699         notification_error_e err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
700         switch (err)
701         {
702         case NOTIFICATION_ERROR_NONE:
703                 r = E_SUCCESS;
704                 break;
705
706         case NOTIFICATION_ERROR_INVALID_DATA:
707                 r = E_INVALID_ARG;
708                 break;
709
710         default:
711                 r = E_OPERATION_FAILED;
712                 break;
713         }
714
715         return r;
716 }
717
718 result
719 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
720 {
721         return __pNotificationManager->RemoveNotification(appId, true);
722 }
723
724 result
725 _NotificationManagerImpl::RemoveNotification(void)
726 {
727         result r = E_SUCCESS;
728
729         notification_error_e err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
730         switch (err)
731         {
732         case NOTIFICATION_ERROR_NONE:
733                 r = E_SUCCESS;
734                 break;
735
736         case NOTIFICATION_ERROR_INVALID_DATA:
737                 r = E_INVALID_ARG;
738                 break;
739
740         default:
741                 r = E_OPERATION_FAILED;
742                 break;
743         }
744
745         return r;
746 }
747
748 result
749 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
750 {
751         return __pNotificationManager->RemoveNotification(appId,false);
752 }
753
754 };
755 };    // Tizen::Shell