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