2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FShell_NotificationManagerImpl.cpp
20 * @brief This is the placeholder for _NotificationManagerImpl class.
23 #include <unique_ptr.h>
24 #include <appsvc/appsvc.h>
26 #include <notification/notification.h>
27 #include <appfw/app.h>
28 #include <appfw/app_manager.h>
29 #include <appfw/app_ui_notification.h>
32 #include <FBaseSysLog.h>
34 //#include <FAppTypes.h>
35 #include <FShellNotificationManager.h>
36 #include <FShellNotificationRequest.h>
38 //#include <FBaseInternalTypes.h>
39 #include <FBase_StringConverter.h>
40 #include "FApp_AppInfo.h"
43 #include "FAppPkg_PackageManagerImpl.h"
44 #include "FApp_AppArg.h"
45 #include "FShell_NotificationManagerImpl.h"
46 #include "FShell_NotificationManagerProxy.h"
47 #include "FAppPkgPackageAppInfo.h"
48 #include "FAppPkg_PackageAppInfoImpl.h"
50 using namespace Tizen::Base;
51 using namespace Tizen::App;
52 using namespace Tizen::App::Package;
53 using namespace Tizen::Io;
54 using namespace Tizen::Shell;
56 extern "C" int service_create_request(bundle *data, service_h *service);
57 extern "C" int service_to_bundle(service_h service, bundle** data);
63 ConvertNotificationResult(int error)
67 case NOTIFICATION_ERROR_NONE:
69 case NOTIFICATION_ERROR_INVALID_DATA:
71 case NOTIFICATION_ERROR_NO_MEMORY:
72 return E_OUT_OF_MEMORY;
73 case NOTIFICATION_ERROR_FROM_DB:
75 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
76 return E_OPERATION_FAILED;
77 case NOTIFICATION_ERROR_NOT_EXIST_ID:
78 return E_OPERATION_FAILED;
80 return E_OPERATION_FAILED;
85 IsPosted(ui_notification_h handle)
87 struct ui_notification_s
107 ui_notification_s* pStruct = reinterpret_cast<ui_notification_s*>(handle);
109 return pStruct->posted;
115 namespace Tizen { namespace Shell
118 _NotificationManagerImpl::_NotificationManagerImpl(void)
119 : __pNotificationManagerProxy(null)
120 , __notifyPrivitId(-1)
121 , __notifyPrivitIdForOngoing(-1)
125 _NotificationManagerImpl::~_NotificationManagerImpl(void)
130 _NotificationManagerImpl::Construct(void)
135 const _NotificationManagerImpl*
136 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
138 return notiMgr.__pNotificationManagerImpl;
141 _NotificationManagerImpl*
142 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
144 return notiMgr.__pNotificationManagerImpl;
148 _NotificationManagerImpl::GetBadgeNumber(void) const
150 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
151 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
153 int count = GetBadgeCount(pAppId.get());
154 SysTryReturn(NID_APP, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
155 GetErrorMessage(E_OPERATION_FAILED));
162 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
164 return NotifyMessage(NOTIFY_TYPE_SIMPLE, isOngoing, notiMessage);
168 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
170 return NotifyMessage(NOTIFY_TYPE_APP_ID, isOngoing, notiMessage, &appId);
171 // No more partner, no need to use IPC.
172 //return __pNotificationManagerProxy->NotifyMessage(appId, notiMessage, isOngoing);
177 _NotificationManagerImpl::Notify(int badgeNumber)
179 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
181 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
183 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
186 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
187 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
189 if (badgeNumber == 0)
191 RemoveBadge(pAppId.get());
196 SetBadgeCount(pAppId.get(), badgeNumber);
203 _NotificationManagerImpl::Notify(const String& messageText)
205 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
207 NotificationRequest request;
208 request.SetAlertText(messageText);
209 request.SetAppMessage(L"");
211 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
215 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber)
217 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
218 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
220 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
222 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
225 NotificationRequest request;
226 request.SetAlertText(messageText);
227 request.SetBadgeNumber(badgeNumber);
228 request.SetAppMessage(L"");
230 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
234 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
236 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
237 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
238 SysTryReturnResult(NID_APP, launchArguments != null && launchArguments.GetLength() > 0, E_INVALID_ARG,
239 "launchArguments is less than 0.");
241 SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
242 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
244 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
246 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
249 NotificationRequest request;
250 request.SetAlertText(messageText);
251 request.SetBadgeNumber(badgeNumber);
252 request.SetAppMessage(launchArguments);
254 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
258 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
260 bool b = _Aul::IsInstalled(appId);
261 SysTryReturn(NID_APP, b == true, -1, E_APP_NOT_INSTALLED, "[E_OBJ_NOT_FOUND] The application %ls is not installed",
263 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
264 int count = GetBadgeCount(pAppId.get());
266 SysTryReturn(NID_APP, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
267 GetErrorMessage(E_OPERATION_FAILED));
274 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText)
276 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
278 NotificationRequest request;
279 request.SetAlertText(messageText);
281 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
285 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
287 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
288 SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
289 SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
290 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
292 NotificationRequest request;
293 request.SetAlertText(messageText);
294 request.SetAppMessage(launchArguments);
296 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
300 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
302 return RemoveNotificationByAppId(appId, true);
303 // No more partner, no need to use IPC.
304 //return __pNotificationManagerProxy->RemoveNotification(appId, true);
309 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
311 return RemoveNotificationByAppId(appId, false);
313 // No more partner, no need to use IPC.
314 //return __pNotificationManagerProxy->RemoveNotification(appId,false);
318 _NotificationManagerImpl::NotifyTextMessage(const String& messageText) const
320 SysTryReturnResult(NID_APP, !messageText.IsEmpty(), E_INVALID_ARG, "MessageText is less than 0.");
322 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
323 int res = notification_status_message_post(pMsg.get());
325 result r = E_SUCCESS;
328 case NOTIFICATION_ERROR_NONE:
331 case NOTIFICATION_ERROR_INVALID_DATA:
334 case NOTIFICATION_ERROR_IO:
342 SysLog(NID_APP, "[%s] %ls posted.", GetErrorMessage(r), messageText.GetPointer());
347 _NotificationManagerImpl::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
348 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
350 result r = E_SUCCESS;
352 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, false, request, null, &operationId, pUriData, pDataType, pExtraData);
357 _NotificationManagerImpl::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
358 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
360 result r = E_SUCCESS;
362 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, true, request, null, &operationId, pUriData, pDataType, pExtraData);
368 _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing, const NotificationRequest& notifyRequest, const AppId* pAppId,
369 const Tizen::Base::String* pOperationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData)
371 result r = E_SUCCESS;
372 std::unique_ptr<char[]> pAppIdChar(null);
375 if ((notifyType == NOTIFY_TYPE_SIMPLE) || (notifyType == NOTIFY_TYPE_APP_CONTROL))
377 // // Below code not working for service appication context. So app_get_id API should be use for resolve this issue.
378 // char* pkgname = null;
379 // app_get_id(&pkgname); // AppId. (Not package Id)
380 // SysTryReturnResult(NID_APP, pkgname != NULL, E_OBJ_NOT_FOUND,"Cannot acquire package name for current application.");
381 // const String currentAppId(pkgname);
383 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
384 const String currentAppId = pApp->GetAppId();
385 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(currentAppId));
386 pAppIdChar = std::move(pAppIdTemp);
387 SysLog(NID_APP, "app_get_id: %ls", currentAppId.GetPointer());
390 if (notifyType == NOTIFY_TYPE_APP_ID)
392 bool isAppInstalled = _Aul::IsInstalled(*pAppId);
393 SysTryReturnResult(NID_APP, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", pAppId->GetPointer());
394 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(*pAppId));
395 pAppIdChar = std::move(pAppIdTemp);
399 SysTryReturnResult(NID_APP, false, E_INVALID_ARG, "Invalid argument is used.");
402 const int badgeNumber = notifyRequest.GetBadgeNumber();
403 const int badgeOffset = notifyRequest.GetBadgeOffset();
404 const String& contentText = notifyRequest.GetAlertText();
405 // Allow change the badge without other properties.
406 if (badgeNumber != -1 || badgeOffset != -1)
409 if (badgeOffset != 0)
411 int badgeNumber = GetBadgeCount(pAppIdChar.get());
412 if (badgeNumber <= 0)
414 SetBadgeCount(pAppIdChar.get(), badgeOffset);
418 SetBadgeCount(pAppIdChar.get(), badgeNumber + badgeOffset);
423 if (badgeNumber == 0)
425 RemoveBadge(pAppIdChar.get());
430 SetBadgeCount(pAppIdChar.get(), badgeNumber);
433 if (!(isOngoing || !contentText.IsEmpty()))
435 SysLog(NID_APP, "No valid for Notification, just for set a badgeNumber update.");
439 SysTryReturnResult(NID_APP, (isOngoing || !contentText.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. MessageText is Empty");
441 const String& titleText = notifyRequest.GetTitleText();
442 const String& launchArguments = notifyRequest.GetAppMessage();
443 const String& iconPath = notifyRequest.GetIconFilePath();
444 const String& soundPath = notifyRequest.GetSoundFilePath();
445 const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
446 int notiPrivateId = isOngoing ? __notifyPrivitIdForOngoing : __notifyPrivitId;
447 notification_h notiHandle = null;
448 bundle* pBundle = null;
449 bool needUpdate = false;
450 bundle* service_data = null;
452 service_h hSvc = null;
453 notification_ly_type_e layout= NOTIFICATION_LY_NOTI_EVENT_SINGLE;
455 // Notification creation
456 if (notiPrivateId != -1)
458 notiHandle = notification_load(pAppIdChar.get(), notiPrivateId);
459 SysTryLog(NID_APP, notiHandle != null, "Get notiHandle(%d) from notiPrivateId(%d).", notiHandle, notiPrivateId);
462 if (notiHandle == null)
464 SysLog(NID_APP, "Previous notification(%d) no more valid - create new notification", notiPrivateId);
465 notiPrivateId = -1; // reset
466 notiHandle = notification_create(notiType);
468 SysTryReturnResult(NID_APP, notiHandle != null , E_SYSTEM, "A system error has been occurred. Notification creation/load failed ");
470 // Content text(Alert text)
471 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(contentText));
474 std::unique_ptr<char[]> pTitleText(null);
475 if (!titleText.IsEmpty())
477 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(titleText));
478 pTitleText = std::move(pTitleTextTemp);
482 char* pAppName = null;
483 app_manager_get_app_name(pAppIdChar.get(), &pAppName);
486 String appName(pAppName);
487 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
488 pTitleText = std::move(pTitleTextTemp);
490 //SysLog(NID_APP, "Application Id is %ls.", appName.GetPointer());
494 SysTryLog(NID_APP, pTitleText, "Failed to get title from app_manager_get_app_name for default setting.");
498 std::unique_ptr<char[]> pIconPath(null);
499 if (!iconPath.IsEmpty())
501 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
502 pIconPath = std::move(pIconPathTemp);
506 std::unique_ptr<PackageAppInfo> pPackageAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(pAppIdChar.get()));
507 const String& appIconPath(_PackageAppInfoImpl::GetInstance(pPackageAppInfo.get())->GetAppNotificationIconPath());
509 if (!appIconPath.IsEmpty() && File::IsFileExist(appIconPath))
511 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(appIconPath));
512 pIconPath = std::move(pIconPathTemp);
516 char* pDefaultIconPath = null;
517 app_manager_get_app_icon_path(pAppIdChar.get(), &pDefaultIconPath);
518 if (pDefaultIconPath)
520 String iconPath(pDefaultIconPath);
521 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
522 pIconPath = std::move(pIconPathTemp);
523 free(pDefaultIconPath);
525 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
529 std::unique_ptr<char[]> pSoundPath(null);
530 if (!soundPath.IsEmpty())
532 std::unique_ptr<char[]> pSoundPathTemp(_StringConverter::CopyToCharArrayN(soundPath));
533 pSoundPath = std::move(pSoundPathTemp);
536 if (notifyType == NOTIFY_TYPE_APP_ID)
538 r = ConvertNotificationResult(notification_set_pkgname(notiHandle, pAppIdChar.get()));
539 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Package name failed.", GetErrorMessage(r));
542 if (pTitleText.get())
544 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
545 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
547 // Set - content text
550 r = notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
551 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
553 // Set - icon file path
554 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath.get()));
555 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
556 // Set - sound file path
557 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath.get()));
558 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set sound failed.", GetErrorMessage(r));
562 r = arg.Construct(launchArguments);
563 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
565 pBundle = arg.GetBundle();
567 service_create_request(pBundle, &hSvc);
568 SysTryCatch(NID_APP, hSvc != null, r = E_SYSTEM, r, "[%s] A system error has been occurred. service_create_request failed.", GetErrorMessage(E_SYSTEM));
570 if (notifyType == NOTIFY_TYPE_SIMPLE || notifyType == NOTIFY_TYPE_APP_ID)
572 service_set_app_id(hSvc, pAppIdChar.get());
575 if (notifyType == NOTIFY_TYPE_APP_CONTROL)
578 std::unique_ptr<char[]> pOperationIdChar(_StringConverter::CopyToCharArrayN(*pOperationId));
579 service_set_operation(hSvc, pOperationIdChar.get());
582 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
583 service_set_uri(hSvc, pUri.get());
587 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pDataType));
588 service_set_mime(hSvc, pMime.get());
592 std::unique_ptr<Tizen::Base::Collection::IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
595 while (pMapEnum->MoveNext() == E_SUCCESS)
597 String* pKey = static_cast<String* > (pMapEnum->GetKey());
598 String* pValue = static_cast<String* > (pMapEnum->GetValue());
601 std::unique_ptr<char[]> pKeyString(_StringConverter::CopyToCharArrayN(*pKey));
602 std::unique_ptr<char[]> pValueString(_StringConverter::CopyToCharArrayN(*pValue));
603 service_add_extra_data(hSvc, pKeyString.get(), pValueString.get());
607 SysLog(NID_APP, "pKey or pValue is ivalid.");
614 if (service_to_bundle(hSvc, &service_data) == SERVICE_ERROR_NONE)
616 notification_set_property(notiHandle, 0);
617 notification_set_execute_option(notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
621 SysLog(NID_APP, "service_to_bundle failed");
624 // insert for new notification / update for exist one.
625 if (notiPrivateId == -1)
627 r = ConvertNotificationResult(notification_insert(notiHandle, ¬iPrivateId));
628 SysLog(NID_APP, "Insert notification and get new notiPrivateId(%d)", notiPrivateId);
629 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
632 __notifyPrivitIdForOngoing = notiPrivateId;
636 __notifyPrivitId = notiPrivateId;
647 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
648 if (activityType == ONGOING_ACTIVITY_TYPE_TEXT)
650 layout = NOTIFICATION_LY_ONGOING_EVENT;
654 layout = NOTIFICATION_LY_ONGOING_PROGRESS;
659 // TODO: check and set from noti type.
661 notification_set_layout(notiHandle, layout);
666 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
667 int progress = notifyRequest.GetOngoingActivityProgress();
669 switch (activityType)
671 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
672 r = ConvertNotificationResult(notification_update_progress(notiHandle, notiPrivateId, progress/100.));
673 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
674 r = ConvertNotificationResult(notification_update_content(notiHandle, notiPrivateId, pMsg.get()));
675 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
678 case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
679 r = ConvertNotificationResult(notification_update_size(notiHandle, notiPrivateId, progress));
680 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
681 r = ConvertNotificationResult(notification_update_content(notiHandle, notiPrivateId, pMsg.get()));
682 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
685 case ONGOING_ACTIVITY_TYPE_TEXT:
686 r = ConvertNotificationResult(notification_update_content(notiHandle, notiPrivateId, pMsg.get()));
687 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
691 r = E_OPERATION_FAILED;
696 // notification_update call on Non ongoing or Text type ongoing only.
697 //if (needUpdate && !(isOngoing && (ONGOING_ACTIVITY_TYPE_TEXT != notifyRequest.GetOngoingActivityType())))
698 if (needUpdate && !isOngoing)
700 notification_update(notiHandle);
701 SysLog(NID_APP, "Notification update from notiPrivateId(%d)", notiPrivateId);
706 service_destroy(hSvc);
707 notification_free(notiHandle);
712 _NotificationManagerImpl::RemoveNotification(void)
714 return RemoveNotification(false);
715 // result r = E_SUCCESS;
716 // notification_error_e err = NOTIFICATION_ERROR_NONE;
718 // if (__notifyPrivitId != -1)
720 // notification_h notiHandle = notification_load(null, __notifyPrivitId);
723 // notification_delete(notiHandle);
725 // notification_free(notiHandle);
729 // err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
734 // case NOTIFICATION_ERROR_NONE:
738 // case NOTIFICATION_ERROR_INVALID_DATA:
739 // r = E_INVALID_ARG;
743 // r = E_OPERATION_FAILED;
751 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
753 return RemoveNotification(true);
754 // result r = E_SUCCESS;
755 // notification_error_e err = NOTIFICATION_ERROR_NONE;
757 // if (__notifyPrivitIdForOngoing != -1)
759 // notification_h notiHandle = notification_load(null, __notifyPrivitIdForOngoing);
762 // notification_delete(notiHandle);
764 // notification_free(notiHandle);
768 // err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
773 // case NOTIFICATION_ERROR_NONE:
777 // case NOTIFICATION_ERROR_INVALID_DATA:
778 // r = E_INVALID_ARG;
782 // r = E_OPERATION_FAILED;
790 _NotificationManagerImpl::RemoveNotification(bool onGoing)
792 result r = E_SUCCESS;
793 notification_error_e err = NOTIFICATION_ERROR_NONE;
794 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
795 const int notiPrivateId = onGoing ? __notifyPrivitIdForOngoing : __notifyPrivitId;
797 if (notiPrivateId != -1)
799 notification_h notiHandle = notification_load(null, notiPrivateId);
802 err = notification_delete(notiHandle);
803 SysLog(NID_APP, "Notification deleted.");
807 SysLog(NID_APP, "Notification already deleted.");
809 notification_free(notiHandle);
813 err = notification_delete_all_by_type(null, notiType);
814 SysLog(NID_APP, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
819 case NOTIFICATION_ERROR_NONE:
823 case NOTIFICATION_ERROR_INVALID_DATA:
836 _NotificationManagerImpl::RemoveNotificationByAppId(const Tizen::App::AppId& appId, bool onGoing)
838 result r = E_SUCCESS;
839 notification_error_e err = NOTIFICATION_ERROR_NONE;
840 bool isValidAppId = _Aul::IsInstalled(appId);
841 SysTryReturnResult(NID_APP, isValidAppId == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
843 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
844 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
845 const int notiPrivateId = onGoing ? __notifyPrivitIdForOngoing : __notifyPrivitId;
847 if (notiPrivateId != -1)
849 notification_h notiHandle = notification_load(pAppId.get(), notiPrivateId);
852 err = notification_delete(notiHandle);
853 SysLog(NID_APP, "Notification deleted.");
857 SysLog(NID_APP, "Notification already deleted.");
859 notification_free(notiHandle);
863 err = notification_delete_all_by_type(pAppId.get(), notiType);
864 SysLog(NID_APP, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
869 case NOTIFICATION_ERROR_NONE:
873 case NOTIFICATION_ERROR_INVALID_DATA:
886 _NotificationManagerImpl::RemoveBadge(const char* pkgName) const
888 bool badgeExist = false;
889 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
890 SysLog(NID_APP, "badge_is_existing: exitst= %d, error= %d.", badgeExist, badgeError); //#####
893 badgeError = badge_remove(pkgName);
894 SysLog(NID_APP, "badge_remove: error= %d.", badgeError); //#####
896 SysLog(NID_APP, "Badge removed.");
900 _NotificationManagerImpl::SetBadgeCount(const char* pkgName, int badgeCount) const
903 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
904 SysLog(NID_APP, "badge_is_existing: error= %d.", badgeError); //#####
907 badgeError = badge_create(pkgName, pkgName);
908 SysLog(NID_APP, "badge_create: error= %d.", badgeError); //#####
911 badge_set_count(pkgName, badgeCount);
912 SysLog(NID_APP, "badge_set_count: badgeNumber= %d.", badgeCount);
916 _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
918 unsigned int count = 0;
920 badge_error_e badgeError = badge_get_count(pkgName, &count);
921 if (badgeError == BADGE_ERROR_NONE)
923 SysLog(NID_APP, "badge_get_count: ret= %d.", count);
928 SysLog(NID_APP, "badge_get_count: error= %d.", badgeError);