2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FShell_NotificationManagerImpl.cpp
19 * @brief This is the implementation for _NotificationManagerImpl class.
22 #include <unique_ptr.h>
23 #include <notification/notification.h>
24 #include <appfw/app.h>
25 #include <appfw/app_manager.h>
27 #include <FBaseSysLog.h>
30 #include <FGrpColor.h>
31 #include <FShellNotificationManager.h>
32 #include <FShellNotificationRequest.h>
33 #include <FShellIBadgeEventListener.h>
34 #include <FBase_StringConverter.h>
36 #include <FApp_AppArg.h>
37 #include "FShell_NotificationManagerImpl.h"
38 #include "FShell_NotificationRequestImpl.h"
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::App;
43 using namespace Tizen::Io;
44 using namespace Tizen::Graphics;
46 extern "C" int service_create_request(bundle *data, service_h *service);
47 extern "C" int service_to_bundle(service_h service, bundle** data);
53 ConvertNotificationResult(int error)
57 case NOTIFICATION_ERROR_NONE:
59 case NOTIFICATION_ERROR_INVALID_DATA:
61 case NOTIFICATION_ERROR_NO_MEMORY:
62 return E_OUT_OF_MEMORY;
63 case NOTIFICATION_ERROR_FROM_DB:
65 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
67 case NOTIFICATION_ERROR_NOT_EXIST_ID:
68 return E_OPERATION_FAILED;
70 return E_OPERATION_FAILED;
75 ConvertAppManagerResult(int error)
79 case APP_MANAGER_ERROR_NONE:
81 case APP_MANAGER_ERROR_INVALID_PARAMETER:
83 case APP_MANAGER_ERROR_INVALID_PACKAGE:
85 case NOTIFICATION_ERROR_NO_MEMORY:
86 return E_OUT_OF_MEMORY;
87 case APP_MANAGER_ERROR_DB_FAILED:
88 return E_OPERATION_FAILED;
90 return E_OPERATION_FAILED;
97 namespace Tizen { namespace Shell
100 ///////////////////////////////////////////////////////////////////
102 ///////////////////////////////////////////////////////////////////
104 BadgeChangedCallback(unsigned int action, const char *pkgname, unsigned int count, void *data)
106 Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>* pBadgeEventListenerList = static_cast<Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>*>(data);
107 SysAssert(pBadgeEventListenerList);
109 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(pBadgeEventListenerList->GetEnumeratorN());
110 SysTryReturnVoidResult(NID_SHELL, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
112 IBadgeEventListener* pListener;
113 while (pEnum->MoveNext() == E_SUCCESS)
116 pEnum->GetCurrent(pListener);
119 SysLog(NID_SHELL, "pListener is null!");
123 pListener->OnBadgeUpdated(pkgname, count);
128 _BadgeManagerImpl::GetInstance(void)
130 static _BadgeManagerImpl* pTheInstance = null;
131 if (pTheInstance == null)
133 pTheInstance = new (std::nothrow) _BadgeManagerImpl;
134 SysTryReturn(NID_SHELL, pTheInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
136 pTheInstance->Construct();
142 _BadgeManagerImpl::Construct(void)
148 _BadgeManagerImpl::AddPrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
150 if( __primaryBadgeEventListenerList.GetCount() == 0)
152 int ret = badge_register_changed_cb(BadgeChangedCallback, &__primaryBadgeEventListenerList);
153 SysTryReturnResult(NID_SHELL, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_register_changed_cb, (%d)", ret);
156 return __primaryBadgeEventListenerList.Add(&primaryListener);
160 _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
162 __primaryBadgeEventListenerList.Remove(&primaryListener);
163 if( __primaryBadgeEventListenerList.GetCount() == 0)
165 int ret = badge_unregister_changed_cb(BadgeChangedCallback);
166 SysTryReturnResult(NID_SHELL, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
172 ///////////////////////////////////////////////////////////////////
173 // _NotificationManagerImpl
174 ///////////////////////////////////////////////////////////////////
175 _NotificationManagerImpl::_NotificationManagerImpl(void)
176 : __notifyPrivateId(-1)
177 , __notifyPrivateIdForOngoing(-1)
178 , __lastNotifyPrivateId(-1)
179 , __lightActivated(false)
183 _NotificationManagerImpl::~_NotificationManagerImpl(void)
185 bool isListeningBadgeEvent = (__badgeEventListenerList.GetCount() > 0)? true : false;
186 if(isListeningBadgeEvent == true)
188 _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
193 _NotificationManagerImpl::Construct(void)
198 const _NotificationManagerImpl*
199 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
201 return notiMgr.__pNotificationManagerImpl;
204 _NotificationManagerImpl*
205 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
207 return notiMgr.__pNotificationManagerImpl;
211 _NotificationManagerImpl::GetBadgeNumber(void) const
215 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
216 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
218 int count = GetBadgeCount(pAppId.get());
219 SysTryReturn(NID_SHELL, count != -1, count, E_OPERATION_FAILED, "[E_OPERATION_FAILED] The operation has failed. Badge may not exist.");
225 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
227 return NotifyMessage(NOTIFY_TYPE_SIMPLE, isOngoing, notiMessage);
231 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
233 return NotifyMessage(NOTIFY_TYPE_APP_ID, isOngoing, notiMessage, &appId);
238 _NotificationManagerImpl::Notify(int badgeNumber)
240 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
241 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
243 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
244 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
246 result r = E_SUCCESS;
248 if (badgeNumber == 0)
250 r = RemoveBadge(pAppId.get());
251 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to remove the badge.");
256 r = SetBadgeCount(pAppId.get(), badgeNumber);
257 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to set the badge.");
264 _NotificationManagerImpl::Notify(const String& messageText)
266 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
267 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
269 NotificationRequest request;
270 request.SetAlertText(messageText);
271 request.SetAppMessage(L"");
273 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
277 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber)
279 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
280 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
281 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
282 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
284 NotificationRequest request;
285 request.SetAlertText(messageText);
286 request.SetBadgeNumber(badgeNumber);
287 request.SetAppMessage(L"");
289 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
293 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
295 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
296 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
297 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
298 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
299 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() > 0 && launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
300 "launchArguments is less than 1 or greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
302 NotificationRequest request;
303 request.SetAlertText(messageText);
304 request.SetBadgeNumber(badgeNumber);
305 request.SetAppMessage(launchArguments);
307 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
311 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
315 bool b = _Aul::IsInstalled(appId);
316 SysTryReturn(NID_SHELL, b == true, -1, E_APP_NOT_INSTALLED, "[E_APP_NOT_INSTALLED] The application %ls is not installed",
318 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
319 int count = GetBadgeCount(pAppId.get());
321 SysTryReturn(NID_SHELL, count != -1, count, E_OPERATION_FAILED, "[E_OPERATION_FAILED] The operation has failed. Badge may not exist.");
327 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText)
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.");
332 NotificationRequest request;
333 request.SetAlertText(messageText);
335 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
339 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
341 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
342 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
343 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
344 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
345 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
347 NotificationRequest request;
348 request.SetAlertText(messageText);
349 request.SetAppMessage(launchArguments);
351 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
355 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
357 return RemoveNotificationByAppId(appId, true);
362 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
364 return RemoveNotificationByAppId(appId, false);
368 _NotificationManagerImpl::NotifyTextMessage(const String& messageText) const
370 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
371 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
373 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
374 int res = notification_status_message_post(pMsg.get());
376 result r = E_SUCCESS;
379 case NOTIFICATION_ERROR_NONE:
382 case NOTIFICATION_ERROR_INVALID_DATA:
385 case NOTIFICATION_ERROR_IO:
386 r = E_OPERATION_FAILED;
389 r = E_OPERATION_FAILED;
393 SysLog(NID_SHELL, "[%s] %ls posted.", GetErrorMessage(r), messageText.GetPointer());
398 _NotificationManagerImpl::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
399 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
401 result r = E_SUCCESS;
403 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, false, request, null, &operationId, pUriData, pDataType, pExtraData);
408 _NotificationManagerImpl::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
409 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
411 result r = E_SUCCESS;
413 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, true, request, null, &operationId, pUriData, pDataType, pExtraData);
420 // E_APP_NOT_INSTALLED - If AppId is invalid, it can occur.
421 // E_OPERATION_FAILED
425 _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing, const NotificationRequest& notifyRequest, const AppId* pAppId,
426 const Tizen::Base::String* pOperationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData)
428 result r = E_SUCCESS;
429 std::unique_ptr<char[]> pAppIdChar(null);
430 const _NotificationRequestImpl* pRequestImpl = _NotificationRequestImpl::GetInstance(notifyRequest);
431 SysTryReturnResult(NID_SHELL, pRequestImpl != null, E_INVALID_ARG, "Invalid argument is used.");
434 if ((notifyType == NOTIFY_TYPE_SIMPLE) || (notifyType == NOTIFY_TYPE_APP_CONTROL))
436 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
437 const String currentAppId = pApp->GetAppId();
438 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(currentAppId));
439 pAppIdChar = std::move(pAppIdTemp);
440 SysLog(NID_SHELL, "App ID is %ls.", currentAppId.GetPointer());
443 if (notifyType == NOTIFY_TYPE_APP_ID)
445 bool isAppInstalled = _Aul::IsInstalled(*pAppId);
446 SysTryReturnResult(NID_SHELL, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed.", pAppId->GetPointer());
447 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(*pAppId));
448 pAppIdChar = std::move(pAppIdTemp);
452 SysTryReturnResult(NID_SHELL, false, E_INVALID_ARG, "Invalid argument is used.");
454 __lastAppId = pAppIdChar.get();
456 const int badgeNumber = notifyRequest.GetBadgeNumber();
457 const int badgeOffset = notifyRequest.GetBadgeOffset();
458 const String& contentText = notifyRequest.GetAlertText();
459 // Allow change the badge without other properties.
460 if (badgeNumber != -1 || badgeOffset != 0)
463 if (badgeOffset != 0)
465 int badgeNumber = GetBadgeCount(pAppIdChar.get());
466 if (badgeNumber <= 0)
468 SetBadgeCount(pAppIdChar.get(), badgeOffset);
472 SetBadgeCount(pAppIdChar.get(), badgeNumber + badgeOffset);
477 if (badgeNumber == 0)
479 r = RemoveBadge(pAppIdChar.get());
480 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to remove the badge.");
485 r = SetBadgeCount(pAppIdChar.get(), badgeNumber);
486 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to set the badge.");
489 if (!(isOngoing || !contentText.IsEmpty()))
491 SysLog(NID_SHELL, "No valid for Notification, just for set a badgeNumber update.");
495 SysTryReturnResult(NID_SHELL, (isOngoing || !contentText.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. MessageText is Empty");
497 const String& titleText = notifyRequest.GetTitleText();
498 const String& launchArguments = notifyRequest.GetAppMessage();
499 const String& iconPath = notifyRequest.GetIconFilePath();
500 const String& soundPath = notifyRequest.GetSoundFilePath();
501 const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
502 int notiPrivateId = isOngoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
503 __lastNotifyPrivateId = notiPrivateId;
504 notification_h notiHandle = null;
505 bundle* pBundle = null;
506 bool needUpdate = false;
507 bundle* service_data = null;
509 service_h hSvc = null;
510 notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
512 // Notification creation
513 if (notiPrivateId != -1)
515 notiHandle = notification_load(pAppIdChar.get(), notiPrivateId);
516 SysTryLog(NID_SHELL, notiHandle != null, "Get notiHandle(%d) from notiPrivateId(%d).", notiHandle, notiPrivateId);
519 if (notiHandle == null)
521 SysLog(NID_SHELL, "Previous notification(%d) no more valid - create new notification", notiPrivateId);
522 notiPrivateId = -1; // reset
523 notiHandle = notification_create(notiType);
527 needUpdate = true; // No need to notification_insert.
529 SysTryReturnResult(NID_SHELL, notiHandle != null, E_OPERATION_FAILED, "Notification creation or loading failed.");
531 // Content text(Alert text)
532 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(contentText));
535 std::unique_ptr<char[]> pTitleText(null);
536 if (!titleText.IsEmpty())
538 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(titleText));
539 pTitleText = std::move(pTitleTextTemp);
543 char* pAppName = null;
544 r = ConvertAppManagerResult(app_manager_get_app_name(pAppIdChar.get(), &pAppName));
547 String appName(pAppName);
548 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
549 pTitleText = std::move(pTitleTextTemp);
551 SysSecureLog(NID_SHELL, "App name is %ls.", appName.GetPointer());
553 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Failed to get title from app_manager_get_app_name for default setting.", GetErrorMessage(r));
556 std::unique_ptr<char[]> pIconPath(null);
557 if (!iconPath.IsEmpty())
559 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
560 pIconPath = std::move(pIconPathTemp);
564 char* pDefaultIconPath = null;
565 r = ConvertAppManagerResult(app_manager_get_app_icon_path(pAppIdChar.get(), &pDefaultIconPath));
566 if (pDefaultIconPath)
568 String iconPath(pDefaultIconPath);
569 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
570 pIconPath = std::move(pIconPathTemp);
571 free(pDefaultIconPath);
573 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the icon path failed.", GetErrorMessage(r));
576 std::unique_ptr<char[]> pSoundPath(null);
577 if (!soundPath.IsEmpty())
579 std::unique_ptr<char[]> pSoundPathTemp(_StringConverter::CopyToCharArrayN(soundPath));
580 pSoundPath = std::move(pSoundPathTemp);
583 if (notifyType == NOTIFY_TYPE_APP_ID)
585 r = ConvertNotificationResult(notification_set_pkgname(notiHandle, pAppIdChar.get()));
586 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the package name failed.", GetErrorMessage(r));
589 if (pTitleText.get())
591 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
592 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the title text failed.", GetErrorMessage(r));
594 // Set - content text
597 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
598 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting content text failed.", GetErrorMessage(r));
600 // Set - icon file path
601 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath.get()));
602 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the icon path failed.", GetErrorMessage(r));
603 // Set - sound file path
604 if (pSoundPath.get())
606 if (isOngoing && needUpdate)
608 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
612 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath.get()));
619 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
623 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL));
626 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the sound failed.", GetErrorMessage(r));
628 // Set extended - text, thumbnail and background image
631 // Extended style set
632 String countText = notifyRequest.GetNotificationCountText();
633 NotificationStyle notiStyle= notifyRequest.GetNotificationStyle();
634 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
636 layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
639 if (notiStyle == NOTIFICATION_STYLE_NORMAL && !countText.IsEmpty())
641 layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
644 if (!countText.IsEmpty())
646 std::unique_ptr<char[]> text(_StringConverter::CopyToCharArrayN(countText));
647 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, text.get(),
648 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
651 String bgImageFilePath = notifyRequest.GetBackgroundImageFilePath();
652 if (!bgImageFilePath.IsEmpty() && File::IsFileExist(bgImageFilePath))
654 std::unique_ptr<char[]> pBgImageFilePath(_StringConverter::CopyToCharArrayN(bgImageFilePath));
655 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, pBgImageFilePath.get()));
656 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the background image path failed.", GetErrorMessage(r));
660 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
662 const IList* pThumbnailList = pRequestImpl->GetMessageThumbnailFilePathList();
665 const static notification_image_type_e thumbnailListEnum[] = {NOTIFICATION_IMAGE_TYPE_LIST_1, NOTIFICATION_IMAGE_TYPE_LIST_2,
666 NOTIFICATION_IMAGE_TYPE_LIST_3, NOTIFICATION_IMAGE_TYPE_LIST_4, NOTIFICATION_IMAGE_TYPE_LIST_5 };
667 int itemCount = pThumbnailList->GetCount();
668 const int maxCount = sizeof(thumbnailListEnum)/sizeof(thumbnailListEnum[0]);
669 if (itemCount > maxCount)
671 itemCount = maxCount;
673 for (int i = 0; i < itemCount; i++)
675 const String* pThumbnailPath = static_cast<const String*>(pThumbnailList->GetAt(i));
676 std::unique_ptr<char[]> filePath(_StringConverter::CopyToCharArrayN(*pThumbnailPath));
677 r = ConvertNotificationResult(notification_set_image(notiHandle, thumbnailListEnum[i], filePath.get()));
678 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the thumbnail path failed.", GetErrorMessage(r));
684 const IList* pMessageTextList = pRequestImpl->GetMessageTextList();
685 if (pMessageTextList && pMessageTextList->GetCount())
687 const String* pText1 = static_cast<const String*>(pMessageTextList->GetAt(0));
691 if (E_SUCCESS == pText1->IndexOf(L'\t', 0, matchIndex))
695 pText1->SubString(0, matchIndex+1, subText);
696 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
697 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
698 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
699 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 text failed.", GetErrorMessage(r));
701 if (E_SUCCESS == pText1->SubString(matchIndex+1, subText))
703 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
704 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, rightText.get(),
705 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
706 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 sub text failed.", GetErrorMessage(r));
711 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText1));
712 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
713 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
714 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 text failed.", GetErrorMessage(r));
717 const String* pText2 = static_cast<const String*>(pMessageTextList->GetAt(1));
721 // 2.1: Multiple layout has single line text for 2nd information text.
722 if ((layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE) && (E_SUCCESS == (pText2->IndexOf(L'\t', 0, matchIndex))))
726 pText2->SubString(0, matchIndex+1, subText);
727 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
728 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
729 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
730 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 text failed.", GetErrorMessage(r));
732 if (E_SUCCESS == pText2->SubString(matchIndex+1, subText))
734 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
735 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, rightText.get(),
736 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
737 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 sub text failed.", GetErrorMessage(r));
742 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText2));
743 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
744 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
745 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 text failed.", GetErrorMessage(r));
751 { // Reset text for update case. also must be checked the previous text with get_text
752 char* pRetStr = null;
753 notification_get_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, &pRetStr);
756 const static notification_text_type_e infoTextEnums[] = { NOTIFICATION_TEXT_TYPE_INFO_1, NOTIFICATION_TEXT_TYPE_INFO_SUB_1,
757 NOTIFICATION_TEXT_TYPE_INFO_2, NOTIFICATION_TEXT_TYPE_INFO_SUB_2 };
758 for (unsigned int i = 0; i < sizeof(infoTextEnums)/sizeof(infoTextEnums[0]); i++)
760 r = ConvertNotificationResult(notification_set_text(notiHandle, infoTextEnums[i], null, NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
761 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the initial text failed.", GetErrorMessage(r));
770 int lightColor32 = 0;
773 int retVal = SERVICE_ERROR_NONE;
774 int previousDisplaySet = NOTIFICATION_DISPLAY_APP_ALL;
775 int newDisplaySet = 0;
777 r = arg.Construct(launchArguments);
778 SysTryCatch(NID_SHELL, !IsFailed(r), r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] Failed to construct _AppArg.");
780 pBundle = arg.GetBundle();
782 service_create_request(pBundle, &hSvc);
783 SysTryCatch(NID_SHELL, hSvc != null, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_create_request failed.");
785 if (notifyType == NOTIFY_TYPE_SIMPLE || notifyType == NOTIFY_TYPE_APP_ID)
787 retVal = service_set_app_id(hSvc, pRequestImpl->IsAppBinding() ? pAppIdChar.get() : null);
788 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_set_app_id failed(%d).", retVal);
791 if (notifyType == NOTIFY_TYPE_APP_CONTROL)
793 std::unique_ptr<char[]> pOperationIdChar(_StringConverter::CopyToCharArrayN(*pOperationId));
794 retVal = service_set_operation(hSvc, pOperationIdChar.get());
795 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_set_operation failed(%d).", retVal);
799 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
800 retVal = service_set_uri(hSvc, pUri.get());
801 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_set_uri failed(%d).", retVal);
805 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pDataType));
806 retVal = service_set_mime(hSvc, pMime.get());
807 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_set_mime failed(%d).", retVal);
811 std::unique_ptr<Tizen::Base::Collection::IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
814 while (pMapEnum->MoveNext() == E_SUCCESS)
816 String* pKey = static_cast<String* > (pMapEnum->GetKey());
817 String* pValue = static_cast<String* > (pMapEnum->GetValue());
820 std::unique_ptr<char[]> pKeyString(_StringConverter::CopyToCharArrayN(*pKey));
821 std::unique_ptr<char[]> pValueString(_StringConverter::CopyToCharArrayN(*pValue));
822 retVal = service_add_extra_data(hSvc, pKeyString.get(), pValueString.get());
823 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_add_extra_data failed(%d).", retVal);
827 SysLog(NID_SHELL, "pKey or pValue is invalid.");
834 retVal = service_to_bundle(hSvc, &service_data);
835 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_to_bundle failed(%d).", retVal);
837 r = ConvertNotificationResult(notification_set_property(notiHandle, 0));
838 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification property failed.", GetErrorMessage(r));
840 r = ConvertNotificationResult(notification_set_execute_option(notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data));
841 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the execute option failed.", GetErrorMessage(r));
846 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
847 if (activityType == ONGOING_ACTIVITY_TYPE_TEXT)
849 layout = NOTIFICATION_LY_ONGOING_EVENT;
853 layout = NOTIFICATION_LY_ONGOING_PROGRESS;
856 r = ConvertNotificationResult(notification_set_layout(notiHandle, layout));
857 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification layout failed.", GetErrorMessage(r));
862 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
863 int progress = notifyRequest.GetOngoingActivityProgress();
865 switch (activityType)
867 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
870 r = ConvertNotificationResult(notification_set_size(notiHandle, 0)); // Reset for override BYTE type
871 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
873 r = ConvertNotificationResult(notification_set_progress(notiHandle, progress/100.));
874 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
877 case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
880 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset for override PERCENTAGE type
881 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
883 r = ConvertNotificationResult(notification_set_size(notiHandle, progress));
884 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
887 case ONGOING_ACTIVITY_TYPE_TEXT:
888 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset the progress
889 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
890 r = ConvertNotificationResult(notification_set_size(notiHandle, 0));
891 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
895 r = E_OPERATION_FAILED;
899 r = ConvertNotificationResult(notification_get_display_applist(notiHandle, &previousDisplaySet));
900 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
902 newDisplaySet = previousDisplaySet & ~NOTIFICATION_DISPLAY_APP_TICKER;
903 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, newDisplaySet));
904 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
908 lightColor = pRequestImpl->GetColor();
909 lightColor32 = lightColor.GetRGB32();
911 if (lightColor32 == 0 || (pRequestImpl->GetOnTime() == 0))
913 if (needUpdate && __lightActivated)
914 { // Not for first insertion
915 r = ConvertNotificationResult(notification_set_led(notiHandle, NOTIFICATION_LED_OP_OFF, 0x00000000));
916 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification led failed.", GetErrorMessage(r));
917 __lightActivated = false;
922 r = ConvertNotificationResult(notification_set_led(notiHandle, NOTIFICATION_LED_OP_ON_CUSTOM_COLOR, lightColor32));
923 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification led failed.", GetErrorMessage(r));
925 r = ConvertNotificationResult(notification_set_led_time_period(notiHandle, pRequestImpl->GetOnTime(), pRequestImpl->GetOffTime()));
926 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification led time period failed.", GetErrorMessage(r));
927 __lightActivated = true;
930 // insert for new notification
933 r = ConvertNotificationResult(notification_insert(notiHandle, ¬iPrivateId));
934 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting new notification failed.", GetErrorMessage(r));
936 SysLog(NID_SHELL, "Getting new notiPrivateId(%d)", notiPrivateId);
940 __notifyPrivateIdForOngoing = notiPrivateId;
944 __notifyPrivateId = notiPrivateId;
946 __lastNotifyPrivateId = notiPrivateId;
950 r = ConvertNotificationResult(notification_update(notiHandle));
951 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Updating the notification failed. notiPrivateId(%d)", GetErrorMessage(r), notiPrivateId);
956 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, previousDisplaySet));
957 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
961 service_destroy(hSvc);
962 notification_free(notiHandle);
967 _NotificationManagerImpl::RemoveNotification(void)
969 return RemoveNotification(false);
973 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
975 return RemoveNotification(true);
979 _NotificationManagerImpl::RemoveNotification(bool onGoing)
981 result r = E_SUCCESS;
982 notification_error_e err = NOTIFICATION_ERROR_NONE;
983 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
984 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
986 if (notiPrivateId != -1)
988 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(__lastAppId));
989 notification_h notiHandle = notification_load(pAppIdTemp.get(), notiPrivateId);
992 err = notification_delete(notiHandle);
993 SysLog(NID_SHELL, "Notification deleted.");
997 SysLog(NID_SHELL, "Notification already deleted.");
999 err = notification_free(notiHandle);
1003 err = notification_delete_all_by_type(null, notiType);
1004 SysLog(NID_SHELL, "All [%s] notifications deleted.", onGoing ? "Ongoing" : "Normal");
1007 SysTryReturnResult(NID_SHELL, err == NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Failed to RemoveNotification with reason (%d).", err);
1012 _NotificationManagerImpl::RemoveNotificationByAppId(const Tizen::App::AppId& appId, bool onGoing)
1014 result r = E_SUCCESS;
1015 notification_error_e err = NOTIFICATION_ERROR_NONE;
1016 bool isValidAppId = _Aul::IsInstalled(appId);
1017 SysTryReturnResult(NID_SHELL, isValidAppId == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
1019 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
1020 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
1021 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
1023 if (notiPrivateId != -1)
1025 notification_h notiHandle = notification_load(pAppId.get(), notiPrivateId);
1028 err = notification_delete(notiHandle);
1029 SysLog(NID_SHELL, "Notification deleted.");
1033 SysLog(NID_SHELL, "Notification already deleted.");
1035 err = notification_free(notiHandle);
1039 err = notification_delete_all_by_type(pAppId.get(), notiType);
1040 SysLog(NID_SHELL, "All [%s] notifications deleted.", onGoing ? "Ongoing" : "Normal");
1043 SysTryReturnResult(NID_SHELL, err == NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Failed to RemoveNotificationByAppId with reason (%d).", err);
1048 _NotificationManagerImpl::RemoveBadge(const char* pkgName) const
1050 bool badgeExist = false;
1051 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1052 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_is_existing failed(%d).", badgeError);
1056 badgeError = badge_remove(pkgName);
1057 SysTryReturnResult(NID_SHELL, badgeError == BADGE_ERROR_NONE, E_OPERATION_FAILED, "badge_remove failed(%d).", badgeError);
1060 SysLog(NID_SHELL, "Badge is removed.");
1065 _NotificationManagerImpl::SetBadgeCount(const char* pkgName, int badgeCount) const
1068 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1069 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_is_existing failed(%d).", badgeError);
1073 badgeError = badge_create(pkgName, pkgName);
1074 SysTryReturnResult(NID_SHELL, badgeError == BADGE_ERROR_NONE, E_OPERATION_FAILED, "badge_create failed(%d).", badgeError);
1077 badgeError = badge_set_count(pkgName, badgeCount);
1078 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_set_count failed(%d).", badgeError);
1080 SysLog(NID_SHELL, "Badge count is %d.", badgeCount);
1085 _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
1087 unsigned int count = 0;
1089 badge_error_e badgeError = badge_get_count(pkgName, &count);
1090 if (badgeError == BADGE_ERROR_NONE)
1092 SysLog(NID_SHELL, "badge_get_count(%d)", count);
1097 SysLog(NID_SHELL, "badge_get_count failed(%d).", badgeError);
1103 _NotificationManagerImpl::AddBadgeEventListener(IBadgeEventListener& listener)
1105 SysTryReturnResult(NID_SHELL, !__badgeEventListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
1106 SysLog(NID_SHELL, "AddBadgeEventListener (%x)", &listener);
1108 result r = _BadgeManagerImpl::GetInstance()->AddPrimaryBadgeEventListener(*this);
1109 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to AddPrimaryBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1111 return __badgeEventListenerList.Add(&listener);
1115 _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener)
1117 SysLog(NID_SHELL, "RemoveBadgeEventListener (%x)", &listener);
1119 result r = __badgeEventListenerList.Remove(&listener); // Remove() can return E_SUCCESS and E_OBJ_NOT_FOUND.
1120 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "Failed to RemoveBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1122 return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
1126 _NotificationManagerImpl::GetLastNotificationId(void) const
1128 return __lastNotifyPrivateId;
1131 const Tizen::Base::String&
1132 _NotificationManagerImpl::GetLastAppId(void) const
1138 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
1140 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(__badgeEventListenerList.GetEnumeratorN());
1141 SysTryReturnVoidResult(NID_SHELL, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
1143 IBadgeEventListener* pListener;
1144 while (pEnum->MoveNext() == E_SUCCESS)
1147 pEnum->GetCurrent(pListener);
1150 SysLog(NID_SHELL, "pListener is null!");
1153 pListener->OnBadgeUpdated(appId, badgeNumber);