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 <FShellNotificationManager.h>
35 #include <FShellNotificationRequest.h>
36 #include <FShellIBadgeEventListener.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 "FAppPkgPackageAppInfo.h"
46 #include "FAppPkg_PackageAppInfoImpl.h"
47 #include "FShell_NotificationManagerImpl.h"
48 #include "FShell_NotificationRequestImpl.h"
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::App;
53 using namespace Tizen::App::Package;
54 using namespace Tizen::Io;
55 using namespace Tizen::Shell;
57 extern "C" int service_create_request(bundle *data, service_h *service);
58 extern "C" int service_to_bundle(service_h service, bundle** data);
64 ConvertNotificationResult(int error)
68 case NOTIFICATION_ERROR_NONE:
70 case NOTIFICATION_ERROR_INVALID_DATA:
72 case NOTIFICATION_ERROR_NO_MEMORY:
73 return E_OUT_OF_MEMORY;
74 case NOTIFICATION_ERROR_FROM_DB:
76 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
78 case NOTIFICATION_ERROR_NOT_EXIST_ID:
79 return E_OPERATION_FAILED;
81 return E_OPERATION_FAILED;
86 ConvertAppManagerResult(int error)
90 case APP_MANAGER_ERROR_NONE:
92 case APP_MANAGER_ERROR_INVALID_PARAMETER:
94 case APP_MANAGER_ERROR_INVALID_PACKAGE:
96 case NOTIFICATION_ERROR_NO_MEMORY:
97 return E_OUT_OF_MEMORY;
98 case APP_MANAGER_ERROR_DB_FAILED:
99 return E_OPERATION_FAILED;
101 return E_OPERATION_FAILED;
106 IsPosted(ui_notification_h handle)
108 struct ui_notification_s
128 ui_notification_s* pStruct = reinterpret_cast<ui_notification_s*>(handle);
130 return pStruct->posted;
136 namespace Tizen { namespace Shell
139 ///////////////////////////////////////////////////////////////////
141 ///////////////////////////////////////////////////////////////////
143 BadgeChangedCallback(unsigned int action, const char *pkgname, unsigned int count, void *data)
145 Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>* pBadgeEventListenerList = static_cast<Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>*>(data);
146 SysAssert(pBadgeEventListenerList);
148 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(pBadgeEventListenerList->GetEnumeratorN());
149 SysTryReturnVoidResult(NID_SHELL, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
151 IBadgeEventListener* pListener;
152 while (pEnum->MoveNext() == E_SUCCESS)
155 pEnum->GetCurrent(pListener);
158 SysLog(NID_SHELL, "pListener is null!");
162 pListener->OnBadgeUpdated(pkgname, count);
167 _BadgeManagerImpl::GetInstance(void)
169 static _BadgeManagerImpl* pTheInstance = null;
170 if( pTheInstance == null)
172 pTheInstance = new (std::nothrow) _BadgeManagerImpl;
173 pTheInstance->Construct();
179 _BadgeManagerImpl::Construct(void)
185 _BadgeManagerImpl::AddPrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
187 if( __primaryBadgeEventListenerList.GetCount() == 0)
189 int ret = badge_register_changed_cb(BadgeChangedCallback, &__primaryBadgeEventListenerList);
190 SysTryReturnResult(NID_SHELL, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
193 return __primaryBadgeEventListenerList.Add(&primaryListener);
197 _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
199 __primaryBadgeEventListenerList.Remove(&primaryListener);
200 if( __primaryBadgeEventListenerList.GetCount() == 0)
202 int ret = badge_unregister_changed_cb(BadgeChangedCallback);
203 SysTryReturnResult(NID_SHELL, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
209 ///////////////////////////////////////////////////////////////////
210 // _NotificationManagerImpl
211 ///////////////////////////////////////////////////////////////////
212 _NotificationManagerImpl::_NotificationManagerImpl(void)
213 : __notifyPrivateId(-1)
214 , __notifyPrivateIdForOngoing(-1)
218 _NotificationManagerImpl::~_NotificationManagerImpl(void)
220 bool isListeningBadgeEvent = (__badgeEventListenerList.GetCount() > 0)? true : false;
221 if(isListeningBadgeEvent == true)
223 _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
228 _NotificationManagerImpl::Construct(void)
233 const _NotificationManagerImpl*
234 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
236 return notiMgr.__pNotificationManagerImpl;
239 _NotificationManagerImpl*
240 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
242 return notiMgr.__pNotificationManagerImpl;
246 _NotificationManagerImpl::GetBadgeNumber(void) const
250 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
251 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
253 int count = GetBadgeCount(pAppId.get());
254 SysTryReturn(NID_SHELL, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
255 GetErrorMessage(E_OPERATION_FAILED));
261 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
263 return NotifyMessage(NOTIFY_TYPE_SIMPLE, isOngoing, notiMessage);
267 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
269 return NotifyMessage(NOTIFY_TYPE_APP_ID, isOngoing, notiMessage, &appId);
274 _NotificationManagerImpl::Notify(int badgeNumber)
276 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
277 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
279 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
280 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
282 if (badgeNumber == 0)
284 RemoveBadge(pAppId.get());
289 SetBadgeCount(pAppId.get(), badgeNumber);
296 _NotificationManagerImpl::Notify(const String& messageText)
298 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
299 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
301 NotificationRequest request;
302 request.SetAlertText(messageText);
303 request.SetAppMessage(L"");
305 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
309 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber)
311 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
312 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
313 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
314 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
316 NotificationRequest request;
317 request.SetAlertText(messageText);
318 request.SetBadgeNumber(badgeNumber);
319 request.SetAppMessage(L"");
321 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
325 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
327 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
328 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
329 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
330 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
331 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() > 0 && launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
332 "launchArguments is less than 1 or greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
334 NotificationRequest request;
335 request.SetAlertText(messageText);
336 request.SetBadgeNumber(badgeNumber);
337 request.SetAppMessage(launchArguments);
339 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
343 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
347 bool b = _Aul::IsInstalled(appId);
348 SysTryReturn(NID_SHELL, b == true, -1, E_APP_NOT_INSTALLED, "[E_OBJ_NOT_FOUND] The application %ls is not installed",
350 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
351 int count = GetBadgeCount(pAppId.get());
353 SysTryReturn(NID_SHELL, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
354 GetErrorMessage(E_OPERATION_FAILED));
360 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText)
362 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
363 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
365 NotificationRequest request;
366 request.SetAlertText(messageText);
368 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
372 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
374 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
375 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
376 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
377 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
378 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
380 NotificationRequest request;
381 request.SetAlertText(messageText);
382 request.SetAppMessage(launchArguments);
384 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
388 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
390 return RemoveNotificationByAppId(appId, true);
395 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
397 return RemoveNotificationByAppId(appId, false);
401 _NotificationManagerImpl::NotifyTextMessage(const String& messageText) const
403 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
404 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
406 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
407 int res = notification_status_message_post(pMsg.get());
409 result r = E_SUCCESS;
412 case NOTIFICATION_ERROR_NONE:
415 case NOTIFICATION_ERROR_INVALID_DATA:
418 case NOTIFICATION_ERROR_IO:
419 r = E_OPERATION_FAILED;
422 r = E_OPERATION_FAILED;
426 SysLog(NID_SHELL, "[%s] %ls posted.", GetErrorMessage(r), messageText.GetPointer());
431 _NotificationManagerImpl::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
432 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
434 result r = E_SUCCESS;
436 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, false, request, null, &operationId, pUriData, pDataType, pExtraData);
441 _NotificationManagerImpl::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
442 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
444 result r = E_SUCCESS;
446 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, true, request, null, &operationId, pUriData, pDataType, pExtraData);
452 _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing, const NotificationRequest& notifyRequest, const AppId* pAppId,
453 const Tizen::Base::String* pOperationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData)
455 result r = E_SUCCESS;
456 std::unique_ptr<char[]> pAppIdChar(null);
457 const _NotificationRequestImpl* pRequestImpl = _NotificationRequestImpl::GetInstance(notifyRequest);
458 SysTryReturnResult(NID_SHELL, pRequestImpl != null, E_INVALID_ARG, "Invalid argument is used.");
461 if ((notifyType == NOTIFY_TYPE_SIMPLE) || (notifyType == NOTIFY_TYPE_APP_CONTROL))
463 // char* pkgname = null;
464 // app_get_id(&pkgname); // AppId. (Not package Id)
465 // SysTryReturnResult(NID_SHELL, pkgname != NULL, E_OBJ_NOT_FOUND,"Cannot acquire package name for current application.");
466 // const String currentAppId(pkgname);
468 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
469 const String currentAppId = pApp->GetAppId();
470 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(currentAppId));
471 pAppIdChar = std::move(pAppIdTemp);
472 SysLog(NID_SHELL, "app_get_id: %ls", currentAppId.GetPointer());
475 if (notifyType == NOTIFY_TYPE_APP_ID)
477 bool isAppInstalled = _Aul::IsInstalled(*pAppId);
478 SysTryReturnResult(NID_SHELL, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", pAppId->GetPointer());
479 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(*pAppId));
480 pAppIdChar = std::move(pAppIdTemp);
484 SysTryReturnResult(NID_SHELL, false, E_INVALID_ARG, "Invalid argument is used.");
487 const int badgeNumber = notifyRequest.GetBadgeNumber();
488 const int badgeOffset = notifyRequest.GetBadgeOffset();
489 const String& contentText = notifyRequest.GetAlertText();
490 // Allow change the badge without other properties.
491 if (badgeNumber != -1 || badgeOffset != -1)
494 if (badgeOffset != 0)
496 int badgeNumber = GetBadgeCount(pAppIdChar.get());
497 if (badgeNumber <= 0)
499 SetBadgeCount(pAppIdChar.get(), badgeOffset);
503 SetBadgeCount(pAppIdChar.get(), badgeNumber + badgeOffset);
508 if (badgeNumber == 0)
510 RemoveBadge(pAppIdChar.get());
515 SetBadgeCount(pAppIdChar.get(), badgeNumber);
518 if (!(isOngoing || !contentText.IsEmpty()))
520 SysLog(NID_SHELL, "No valid for Notification, just for set a badgeNumber update.");
524 SysTryReturnResult(NID_SHELL, (isOngoing || !contentText.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. MessageText is Empty");
526 const String& titleText = notifyRequest.GetTitleText();
527 const String& launchArguments = notifyRequest.GetAppMessage();
528 const String& iconPath = notifyRequest.GetIconFilePath();
529 const String& soundPath = notifyRequest.GetSoundFilePath();
530 const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
531 int notiPrivateId = isOngoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
532 notification_h notiHandle = null;
533 bundle* pBundle = null;
534 bool needUpdate = false;
535 bundle* service_data = null;
537 service_h hSvc = null;
538 notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
540 // Notification creation
541 if (notiPrivateId != -1)
543 notiHandle = notification_load(pAppIdChar.get(), notiPrivateId);
544 SysTryLog(NID_SHELL, notiHandle != null, "Get notiHandle(%d) from notiPrivateId(%d).", notiHandle, notiPrivateId);
547 if (notiHandle == null)
549 SysLog(NID_SHELL, "Previous notification(%d) no more valid - create new notification", notiPrivateId);
550 notiPrivateId = -1; // reset
551 notiHandle = notification_create(notiType);
555 needUpdate = true; // No need to notification_insert.
557 SysTryReturnResult(NID_SHELL, notiHandle != null , E_SYSTEM, "A system error has been occurred. Notification creation/load failed ");
559 // Content text(Alert text)
560 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(contentText));
563 std::unique_ptr<char[]> pTitleText(null);
564 if (!titleText.IsEmpty())
566 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(titleText));
567 pTitleText = std::move(pTitleTextTemp);
571 char* pAppName = null;
572 r = ConvertAppManagerResult(app_manager_get_app_name(pAppIdChar.get(), &pAppName));
575 String appName(pAppName);
576 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
577 pTitleText = std::move(pTitleTextTemp);
579 //SysLog(NID_SHELL, "Application Id is %ls.", appName.GetPointer());
581 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Failed to get title from app_manager_get_app_name for default setting.", GetErrorMessage(r));
584 std::unique_ptr<char[]> pIconPath(null);
585 if (!iconPath.IsEmpty())
587 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
588 pIconPath = std::move(pIconPathTemp);
592 char* pDefaultIconPath = null;
593 r = ConvertAppManagerResult(app_manager_get_app_icon_path(pAppIdChar.get(), &pDefaultIconPath));
594 if (pDefaultIconPath)
596 String iconPath(pDefaultIconPath);
597 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
598 pIconPath = std::move(pIconPathTemp);
599 free(pDefaultIconPath);
601 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
604 std::unique_ptr<char[]> pSoundPath(null);
605 if (!soundPath.IsEmpty())
607 std::unique_ptr<char[]> pSoundPathTemp(_StringConverter::CopyToCharArrayN(soundPath));
608 pSoundPath = std::move(pSoundPathTemp);
611 if (notifyType == NOTIFY_TYPE_APP_ID)
613 r = ConvertNotificationResult(notification_set_pkgname(notiHandle, pAppIdChar.get()));
614 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set Package name failed.", GetErrorMessage(r));
617 if (pTitleText.get())
619 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
620 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
622 // Set - content text
625 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
626 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
628 // Set - icon file path
629 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath.get()));
630 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
631 // Set - sound file path
632 if (pSoundPath.get())
634 if (isOngoing && needUpdate)
636 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
640 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath.get()));
645 if (isOngoing && needUpdate)
647 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
651 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL));
654 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set sound failed.", GetErrorMessage(r));
656 // Set extended - text, thumbnail and background image
659 // Extended style set
660 String countText = notifyRequest.GetNotificationCountText();
661 NotificationStyle notiStyle= notifyRequest.GetNotificationStyle();
662 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
664 layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
667 if (notiStyle == NOTIFICATION_STYLE_NORMAL && !countText.IsEmpty())
669 layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
672 if (!countText.IsEmpty())
674 std::unique_ptr<char[]> text(_StringConverter::CopyToCharArrayN(countText));
675 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, text.get(),
676 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
679 String bgImageFilePath = notifyRequest.GetBackgroundImageFilePath();
680 if (!bgImageFilePath.IsEmpty() && File::IsFileExist(bgImageFilePath))
682 std::unique_ptr<char[]> pBgImageFilePath(_StringConverter::CopyToCharArrayN(bgImageFilePath));
683 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, pBgImageFilePath.get()));
684 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set Background image path failed.", GetErrorMessage(r));
688 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
690 const IList* pThumbnailList = pRequestImpl->GetMessageThumbnailFilePathList();
693 const static notification_image_type_e thumbnailListEnum[] = {NOTIFICATION_IMAGE_TYPE_LIST_1, NOTIFICATION_IMAGE_TYPE_LIST_2,
694 NOTIFICATION_IMAGE_TYPE_LIST_3, NOTIFICATION_IMAGE_TYPE_LIST_4, NOTIFICATION_IMAGE_TYPE_LIST_5 };
695 int itemCount = pThumbnailList->GetCount();
696 const int maxCount = sizeof(thumbnailListEnum)/sizeof(thumbnailListEnum[0]);
697 if (itemCount > maxCount)
699 itemCount = maxCount;
701 for (int i = 0; i < itemCount; i++)
703 const String* pThumbnailPath = static_cast<const String*>(pThumbnailList->GetAt(i));
704 // TODO: check pThumbnailPath
705 std::unique_ptr<char[]> filePath(_StringConverter::CopyToCharArrayN(*pThumbnailPath));
706 r = ConvertNotificationResult(notification_set_image(notiHandle, thumbnailListEnum[i], filePath.get()));
707 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set thumnail path failed.", GetErrorMessage(r));
713 // TODO: Check the valid
714 const IList* pMessageTextList = pRequestImpl->GetMessageTextList();
715 if (pMessageTextList && pMessageTextList->GetCount())
717 const String* pText1 = static_cast<const String*>(pMessageTextList->GetAt(0));
721 if (E_SUCCESS == pText1->IndexOf(L'\t', 0, matchIndex))
725 pText1->SubString(0, matchIndex+1, subText);
726 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
727 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
728 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
729 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
731 if (E_SUCCESS == pText1->SubString(matchIndex+1, subText))
733 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
734 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, rightText.get(),
735 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
736 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set Info1 Sub Text failed.", GetErrorMessage(r));
741 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText1));
742 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
743 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
744 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
747 const String* pText2 = static_cast<const String*>(pMessageTextList->GetAt(1));
751 // 2.1: Multiple layout has single line text for 2nd information text.
752 if ((layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE && E_SUCCESS) == (pText2->IndexOf(L'\t', 0, matchIndex)))
756 pText2->SubString(0, matchIndex+1, subText);
757 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
758 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
759 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
760 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
762 if (E_SUCCESS == pText2->SubString(matchIndex+1, subText))
764 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
765 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, rightText.get(),
766 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
767 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set Info1 Sub Text failed.", GetErrorMessage(r));
772 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText2));
773 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
774 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
775 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
781 { // Reset text for update case. also must be check the previous text with get_text
782 char* pRetStr = null;
783 notification_get_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, &pRetStr);
786 const static notification_text_type_e infoTextEnums[] = { NOTIFICATION_TEXT_TYPE_INFO_1, NOTIFICATION_TEXT_TYPE_INFO_SUB_1,
787 NOTIFICATION_TEXT_TYPE_INFO_2, NOTIFICATION_TEXT_TYPE_INFO_SUB_2 };
788 for (unsigned int i = 0; i < sizeof(infoTextEnums)/sizeof(infoTextEnums[0]); i++)
790 notification_set_text(notiHandle, infoTextEnums[i], null, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
798 r = arg.Construct(launchArguments);
799 SysTryCatch(NID_SHELL, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
801 pBundle = arg.GetBundle();
803 service_create_request(pBundle, &hSvc);
804 SysTryCatch(NID_SHELL, hSvc != null, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] A system error has been occurred. service_create_request failed.");
806 if (notifyType == NOTIFY_TYPE_SIMPLE || notifyType == NOTIFY_TYPE_APP_ID)
808 service_set_app_id(hSvc, pRequestImpl->IsAppBinding() ? pAppIdChar.get() : null);
811 if (notifyType == NOTIFY_TYPE_APP_CONTROL)
813 std::unique_ptr<char[]> pOperationIdChar(_StringConverter::CopyToCharArrayN(*pOperationId));
814 int retVal = service_set_operation(hSvc, pOperationIdChar.get());
815 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] A system error has been occurred. service_create_request failed.");
819 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
820 service_set_uri(hSvc, pUri.get());
824 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pDataType));
825 service_set_mime(hSvc, pMime.get());
829 std::unique_ptr<Tizen::Base::Collection::IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
832 while (pMapEnum->MoveNext() == E_SUCCESS)
834 String* pKey = static_cast<String* > (pMapEnum->GetKey());
835 String* pValue = static_cast<String* > (pMapEnum->GetValue());
838 std::unique_ptr<char[]> pKeyString(_StringConverter::CopyToCharArrayN(*pKey));
839 std::unique_ptr<char[]> pValueString(_StringConverter::CopyToCharArrayN(*pValue));
840 service_add_extra_data(hSvc, pKeyString.get(), pValueString.get());
844 SysLog(NID_SHELL, "pKey or pValue is ivalid.");
851 if (service_to_bundle(hSvc, &service_data) == SERVICE_ERROR_NONE)
853 r = ConvertNotificationResult(notification_set_property(notiHandle, 0));
854 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_set_property failed.", GetErrorMessage(r));
855 r = ConvertNotificationResult(notification_set_execute_option(notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
856 NULL, NULL, service_data));
857 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Nnotification_set_execute_option failed.", GetErrorMessage(r));
858 SysLog(NID_SHELL, "notification_set_execute_option");
862 SysLog(NID_SHELL, "service_to_bundle failed");
868 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
869 if (activityType == ONGOING_ACTIVITY_TYPE_TEXT)
871 layout = NOTIFICATION_LY_ONGOING_EVENT;
875 layout = NOTIFICATION_LY_ONGOING_PROGRESS;
878 notification_set_layout(notiHandle, layout);
883 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
884 int progress = notifyRequest.GetOngoingActivityProgress();
886 switch (activityType)
888 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
891 r = ConvertNotificationResult(notification_set_size(notiHandle, 0)); // Reset for override BYTE type
892 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_set_size failure.", GetErrorMessage(r));
894 r = ConvertNotificationResult(notification_set_progress(notiHandle, progress/100.));
895 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_set_progress failure.", GetErrorMessage(r));
898 case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
901 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset for override PERCENTAGE type
902 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_set_progress failure.", GetErrorMessage(r));
904 r = ConvertNotificationResult(notification_set_size(notiHandle, progress));
905 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_set_size failure.", GetErrorMessage(r));
908 case ONGOING_ACTIVITY_TYPE_TEXT:
909 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset the progress
910 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_set_size failure.", GetErrorMessage(r));
911 r = ConvertNotificationResult(notification_set_size(notiHandle, 0));
912 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_set_size failure.", GetErrorMessage(r));
916 r = E_OPERATION_FAILED;
921 // insert for new notification
924 r = ConvertNotificationResult(notification_insert(notiHandle, ¬iPrivateId));
925 SysLog(NID_SHELL, "Insert notification and get new notiPrivateId(%d)", notiPrivateId);
926 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
929 __notifyPrivateIdForOngoing = notiPrivateId;
933 __notifyPrivateId = notiPrivateId;
938 int previousDisplaySet = NOTIFICATION_DISPLAY_APP_ALL;
941 r = ConvertNotificationResult(notification_get_display_applist(notiHandle, &previousDisplaySet));
942 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_set_display_applist failure.", GetErrorMessage(r));
943 int newDisplaySet = previousDisplaySet & ~NOTIFICATION_DISPLAY_APP_TICKER;
944 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, newDisplaySet));
945 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_set_display_applist failure.", GetErrorMessage(r));
948 r = ConvertNotificationResult(notification_update(notiHandle));
949 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_update failure. notiPrivateId(%d)", GetErrorMessage(r), notiPrivateId);
953 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, previousDisplaySet));
954 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] notification_set_display_applist failure.", GetErrorMessage(r));
960 service_destroy(hSvc);
961 notification_free(notiHandle);
966 _NotificationManagerImpl::RemoveNotification(void)
968 return RemoveNotification(false);
972 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
974 return RemoveNotification(true);
978 _NotificationManagerImpl::RemoveNotification(bool onGoing)
980 result r = E_SUCCESS;
981 notification_error_e err = NOTIFICATION_ERROR_NONE;
982 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
983 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
985 if (notiPrivateId != -1)
987 notification_h notiHandle = notification_load(null, notiPrivateId);
990 err = notification_delete(notiHandle);
991 SysLog(NID_SHELL, "Notification deleted.");
995 SysLog(NID_SHELL, "Notification already deleted.");
997 notification_free(notiHandle);
1001 err = notification_delete_all_by_type(null, notiType);
1002 SysLog(NID_SHELL, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
1005 SysTryReturnResult(NID_SHELL, err == NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Failed to RemoveNotification with reason (%d).", err);
1010 _NotificationManagerImpl::RemoveNotificationByAppId(const Tizen::App::AppId& appId, bool onGoing)
1012 result r = E_SUCCESS;
1013 notification_error_e err = NOTIFICATION_ERROR_NONE;
1014 bool isValidAppId = _Aul::IsInstalled(appId);
1015 SysTryReturnResult(NID_SHELL, isValidAppId == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
1017 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
1018 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
1019 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
1021 if (notiPrivateId != -1)
1023 notification_h notiHandle = notification_load(pAppId.get(), notiPrivateId);
1026 err = notification_delete(notiHandle);
1027 SysLog(NID_SHELL, "Notification deleted.");
1031 SysLog(NID_SHELL, "Notification already deleted.");
1033 notification_free(notiHandle);
1037 err = notification_delete_all_by_type(pAppId.get(), notiType);
1038 SysLog(NID_SHELL, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
1041 SysTryReturnResult(NID_SHELL, err == NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Failed to RemoveNotificationByAppId with reason (%d).", err);
1046 _NotificationManagerImpl::RemoveBadge(const char* pkgName) const
1048 bool badgeExist = false;
1049 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1050 SysLog(NID_SHELL, "badge_is_existing: exitst= %d, error= %d.", badgeExist, badgeError); //#####
1053 badgeError = badge_remove(pkgName);
1054 SysLog(NID_SHELL, "badge_remove: error= %d.", badgeError); //#####
1056 SysLog(NID_SHELL, "Badge removed.");
1060 _NotificationManagerImpl::SetBadgeCount(const char* pkgName, int badgeCount) const
1063 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1064 SysLog(NID_SHELL, "badge_is_existing: error= %d.", badgeError); //#####
1067 badgeError = badge_create(pkgName, pkgName);
1068 SysLog(NID_SHELL, "badge_create: error= %d.", badgeError); //#####
1071 badge_set_count(pkgName, badgeCount);
1072 SysLog(NID_SHELL, "badge_set_count: badgeNumber= %d.", badgeCount);
1076 _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
1078 unsigned int count = 0;
1080 badge_error_e badgeError = badge_get_count(pkgName, &count);
1081 if (badgeError == BADGE_ERROR_NONE)
1083 SysLog(NID_SHELL, "badge_get_count: ret= %d.", count);
1088 SysLog(NID_SHELL, "badge_get_count: error= %d.", badgeError);
1094 _NotificationManagerImpl::AddBadgeEventListener(IBadgeEventListener& listener)
1096 SysTryReturnResult(NID_SHELL, !__badgeEventListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
1097 SysLog(NID_SHELL, "AddBadgeEventListener (%x)", &listener);
1099 result r = _BadgeManagerImpl::GetInstance()->AddPrimaryBadgeEventListener(*this);
1100 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to AddPrimaryBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1102 return __badgeEventListenerList.Add(&listener);
1106 _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener)
1108 SysLog(NID_SHELL, "RemoveBadgeEventListener (%x)", &listener);
1109 result r = __badgeEventListenerList.Remove(&listener);
1110 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "Failed to RemoveBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1112 return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
1116 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
1118 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(__badgeEventListenerList.GetEnumeratorN());
1119 SysTryReturnVoidResult(NID_SHELL, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
1121 IBadgeEventListener* pListener;
1122 while (pEnum->MoveNext() == E_SUCCESS)
1125 pEnum->GetCurrent(pListener);
1128 SysLog(NID_SHELL, "pListener is null!");
1131 pListener->OnBadgeUpdated(appId, badgeNumber);