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 implementation for _NotificationManagerImpl class.
23 #include <unique_ptr.h>
24 #include <notification/notification.h>
25 #include <appfw/app.h>
26 #include <appfw/app_manager.h>
28 #include <FBaseSysLog.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;
45 extern "C" int service_create_request(bundle *data, service_h *service);
46 extern "C" int service_to_bundle(service_h service, bundle** data);
52 ConvertNotificationResult(int error)
56 case NOTIFICATION_ERROR_NONE:
58 case NOTIFICATION_ERROR_INVALID_DATA:
60 case NOTIFICATION_ERROR_NO_MEMORY:
61 return E_OUT_OF_MEMORY;
62 case NOTIFICATION_ERROR_FROM_DB:
64 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
66 case NOTIFICATION_ERROR_NOT_EXIST_ID:
67 return E_OPERATION_FAILED;
69 return E_OPERATION_FAILED;
74 ConvertAppManagerResult(int error)
78 case APP_MANAGER_ERROR_NONE:
80 case APP_MANAGER_ERROR_INVALID_PARAMETER:
82 case APP_MANAGER_ERROR_INVALID_PACKAGE:
84 case NOTIFICATION_ERROR_NO_MEMORY:
85 return E_OUT_OF_MEMORY;
86 case APP_MANAGER_ERROR_DB_FAILED:
87 return E_OPERATION_FAILED;
89 return E_OPERATION_FAILED;
96 namespace Tizen { namespace Shell
99 ///////////////////////////////////////////////////////////////////
101 ///////////////////////////////////////////////////////////////////
103 BadgeChangedCallback(unsigned int action, const char *pkgname, unsigned int count, void *data)
105 Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>* pBadgeEventListenerList = static_cast<Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>*>(data);
106 SysAssert(pBadgeEventListenerList);
108 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(pBadgeEventListenerList->GetEnumeratorN());
109 SysTryReturnVoidResult(NID_SHELL, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
111 IBadgeEventListener* pListener;
112 while (pEnum->MoveNext() == E_SUCCESS)
115 pEnum->GetCurrent(pListener);
118 SysLog(NID_SHELL, "pListener is null!");
122 pListener->OnBadgeUpdated(pkgname, count);
127 _BadgeManagerImpl::GetInstance(void)
129 static _BadgeManagerImpl* pTheInstance = null;
130 if (pTheInstance == null)
132 pTheInstance = new (std::nothrow) _BadgeManagerImpl;
133 SysTryReturn(NID_SHELL, pTheInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
135 pTheInstance->Construct();
141 _BadgeManagerImpl::Construct(void)
147 _BadgeManagerImpl::AddPrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
149 if( __primaryBadgeEventListenerList.GetCount() == 0)
151 int ret = badge_register_changed_cb(BadgeChangedCallback, &__primaryBadgeEventListenerList);
152 SysTryReturnResult(NID_SHELL, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_register_changed_cb, (%d)", ret);
155 return __primaryBadgeEventListenerList.Add(&primaryListener);
159 _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
161 __primaryBadgeEventListenerList.Remove(&primaryListener);
162 if( __primaryBadgeEventListenerList.GetCount() == 0)
164 int ret = badge_unregister_changed_cb(BadgeChangedCallback);
165 SysTryReturnResult(NID_SHELL, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
171 ///////////////////////////////////////////////////////////////////
172 // _NotificationManagerImpl
173 ///////////////////////////////////////////////////////////////////
174 _NotificationManagerImpl::_NotificationManagerImpl(void)
175 : __notifyPrivateId(-1)
176 , __notifyPrivateIdForOngoing(-1)
180 _NotificationManagerImpl::~_NotificationManagerImpl(void)
182 bool isListeningBadgeEvent = (__badgeEventListenerList.GetCount() > 0)? true : false;
183 if(isListeningBadgeEvent == true)
185 _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
190 _NotificationManagerImpl::Construct(void)
195 const _NotificationManagerImpl*
196 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
198 return notiMgr.__pNotificationManagerImpl;
201 _NotificationManagerImpl*
202 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
204 return notiMgr.__pNotificationManagerImpl;
208 _NotificationManagerImpl::GetBadgeNumber(void) const
212 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
213 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
215 int count = GetBadgeCount(pAppId.get());
216 SysTryReturn(NID_SHELL, count != -1, count, E_OPERATION_FAILED, "[E_OPERATION_FAILED] The operation has failed. Badge may not exist.");
222 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
224 return NotifyMessage(NOTIFY_TYPE_SIMPLE, isOngoing, notiMessage);
228 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
230 return NotifyMessage(NOTIFY_TYPE_APP_ID, isOngoing, notiMessage, &appId);
235 _NotificationManagerImpl::Notify(int badgeNumber)
237 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
238 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
240 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
241 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
243 result r = E_SUCCESS;
245 if (badgeNumber == 0)
247 r = RemoveBadge(pAppId.get());
248 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to remove the badge.");
253 r = SetBadgeCount(pAppId.get(), badgeNumber);
254 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to set the badge.");
261 _NotificationManagerImpl::Notify(const String& messageText)
263 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
264 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
266 NotificationRequest request;
267 request.SetAlertText(messageText);
268 request.SetAppMessage(L"");
270 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
274 _NotificationManagerImpl::Notify(const String& messageText, 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.");
278 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
279 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
281 NotificationRequest request;
282 request.SetAlertText(messageText);
283 request.SetBadgeNumber(badgeNumber);
284 request.SetAppMessage(L"");
286 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
290 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
292 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
293 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
294 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
295 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
296 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() > 0 && launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
297 "launchArguments is less than 1 or greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
299 NotificationRequest request;
300 request.SetAlertText(messageText);
301 request.SetBadgeNumber(badgeNumber);
302 request.SetAppMessage(launchArguments);
304 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
308 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
312 bool b = _Aul::IsInstalled(appId);
313 SysTryReturn(NID_SHELL, b == true, -1, E_APP_NOT_INSTALLED, "[E_APP_NOT_INSTALLED] The application %ls is not installed",
315 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
316 int count = GetBadgeCount(pAppId.get());
318 SysTryReturn(NID_SHELL, count != -1, count, E_OPERATION_FAILED, "[E_OPERATION_FAILED] The operation has failed. Badge may not exist.");
324 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText)
326 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
327 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
329 NotificationRequest request;
330 request.SetAlertText(messageText);
332 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
336 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
338 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
339 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
340 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
341 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
342 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
344 NotificationRequest request;
345 request.SetAlertText(messageText);
346 request.SetAppMessage(launchArguments);
348 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
352 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
354 return RemoveNotificationByAppId(appId, true);
359 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
361 return RemoveNotificationByAppId(appId, false);
365 _NotificationManagerImpl::NotifyTextMessage(const String& messageText) const
367 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
368 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
370 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
371 int res = notification_status_message_post(pMsg.get());
373 result r = E_SUCCESS;
376 case NOTIFICATION_ERROR_NONE:
379 case NOTIFICATION_ERROR_INVALID_DATA:
382 case NOTIFICATION_ERROR_IO:
383 r = E_OPERATION_FAILED;
386 r = E_OPERATION_FAILED;
390 SysLog(NID_SHELL, "[%s] %ls posted.", GetErrorMessage(r), messageText.GetPointer());
395 _NotificationManagerImpl::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
396 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
398 result r = E_SUCCESS;
400 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, false, request, null, &operationId, pUriData, pDataType, pExtraData);
405 _NotificationManagerImpl::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
406 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
408 result r = E_SUCCESS;
410 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, true, request, null, &operationId, pUriData, pDataType, pExtraData);
417 // E_APP_NOT_INSTALLED - If AppId is invalid, it can occur.
418 // E_OPERATION_FAILED
422 _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing, const NotificationRequest& notifyRequest, const AppId* pAppId,
423 const Tizen::Base::String* pOperationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData)
425 result r = E_SUCCESS;
426 std::unique_ptr<char[]> pAppIdChar(null);
427 const _NotificationRequestImpl* pRequestImpl = _NotificationRequestImpl::GetInstance(notifyRequest);
428 SysTryReturnResult(NID_SHELL, pRequestImpl != null, E_INVALID_ARG, "Invalid argument is used.");
431 if ((notifyType == NOTIFY_TYPE_SIMPLE) || (notifyType == NOTIFY_TYPE_APP_CONTROL))
433 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
434 const String currentAppId = pApp->GetAppId();
435 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(currentAppId));
436 pAppIdChar = std::move(pAppIdTemp);
437 SysLog(NID_SHELL, "App ID is %ls.", currentAppId.GetPointer());
440 if (notifyType == NOTIFY_TYPE_APP_ID)
442 bool isAppInstalled = _Aul::IsInstalled(*pAppId);
443 SysTryReturnResult(NID_SHELL, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed.", pAppId->GetPointer());
444 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(*pAppId));
445 pAppIdChar = std::move(pAppIdTemp);
449 SysTryReturnResult(NID_SHELL, false, E_INVALID_ARG, "Invalid argument is used.");
452 const int badgeNumber = notifyRequest.GetBadgeNumber();
453 const int badgeOffset = notifyRequest.GetBadgeOffset();
454 const String& contentText = notifyRequest.GetAlertText();
455 // Allow change the badge without other properties.
456 if (badgeNumber != -1 || badgeOffset != 0)
459 if (badgeOffset != 0)
461 int badgeNumber = GetBadgeCount(pAppIdChar.get());
462 if (badgeNumber <= 0)
464 SetBadgeCount(pAppIdChar.get(), badgeOffset);
468 SetBadgeCount(pAppIdChar.get(), badgeNumber + badgeOffset);
473 if (badgeNumber == 0)
475 r = RemoveBadge(pAppIdChar.get());
476 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to remove the badge.");
481 r = SetBadgeCount(pAppIdChar.get(), badgeNumber);
482 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to set the badge.");
485 if (!(isOngoing || !contentText.IsEmpty()))
487 SysLog(NID_SHELL, "No valid for Notification, just for set a badgeNumber update.");
491 SysTryReturnResult(NID_SHELL, (isOngoing || !contentText.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. MessageText is Empty");
493 const String& titleText = notifyRequest.GetTitleText();
494 const String& launchArguments = notifyRequest.GetAppMessage();
495 const String& iconPath = notifyRequest.GetIconFilePath();
496 const String& soundPath = notifyRequest.GetSoundFilePath();
497 const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
498 int notiPrivateId = isOngoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
499 notification_h notiHandle = null;
500 bundle* pBundle = null;
501 bool needUpdate = false;
502 bundle* service_data = null;
504 service_h hSvc = null;
505 notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
507 // Notification creation
508 if (notiPrivateId != -1)
510 notiHandle = notification_load(pAppIdChar.get(), notiPrivateId);
511 SysTryLog(NID_SHELL, notiHandle != null, "Get notiHandle(%d) from notiPrivateId(%d).", notiHandle, notiPrivateId);
514 if (notiHandle == null)
516 SysLog(NID_SHELL, "Previous notification(%d) no more valid - create new notification", notiPrivateId);
517 notiPrivateId = -1; // reset
518 notiHandle = notification_create(notiType);
522 needUpdate = true; // No need to notification_insert.
524 SysTryReturnResult(NID_SHELL, notiHandle != null, E_OPERATION_FAILED, "Notification creation or loading failed.");
526 // Content text(Alert text)
527 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(contentText));
530 std::unique_ptr<char[]> pTitleText(null);
531 if (!titleText.IsEmpty())
533 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(titleText));
534 pTitleText = std::move(pTitleTextTemp);
538 char* pAppName = null;
539 r = ConvertAppManagerResult(app_manager_get_app_name(pAppIdChar.get(), &pAppName));
542 String appName(pAppName);
543 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
544 pTitleText = std::move(pTitleTextTemp);
546 SysSecureLog(NID_SHELL, "App name is %ls.", appName.GetPointer());
548 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Failed to get title from app_manager_get_app_name for default setting.", GetErrorMessage(r));
551 std::unique_ptr<char[]> pIconPath(null);
552 if (!iconPath.IsEmpty())
554 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
555 pIconPath = std::move(pIconPathTemp);
559 char* pDefaultIconPath = null;
560 r = ConvertAppManagerResult(app_manager_get_app_icon_path(pAppIdChar.get(), &pDefaultIconPath));
561 if (pDefaultIconPath)
563 String iconPath(pDefaultIconPath);
564 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
565 pIconPath = std::move(pIconPathTemp);
566 free(pDefaultIconPath);
568 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the icon path failed.", GetErrorMessage(r));
571 std::unique_ptr<char[]> pSoundPath(null);
572 if (!soundPath.IsEmpty())
574 std::unique_ptr<char[]> pSoundPathTemp(_StringConverter::CopyToCharArrayN(soundPath));
575 pSoundPath = std::move(pSoundPathTemp);
578 if (notifyType == NOTIFY_TYPE_APP_ID)
580 r = ConvertNotificationResult(notification_set_pkgname(notiHandle, pAppIdChar.get()));
581 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the package name failed.", GetErrorMessage(r));
584 if (pTitleText.get())
586 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
587 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the title text failed.", GetErrorMessage(r));
589 // Set - content text
592 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
593 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting content text failed.", GetErrorMessage(r));
595 // Set - icon file path
596 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath.get()));
597 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the icon path failed.", GetErrorMessage(r));
598 // Set - sound file path
599 if (pSoundPath.get())
601 if (isOngoing && needUpdate)
603 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
607 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath.get()));
614 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
618 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL));
621 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the sound failed.", GetErrorMessage(r));
623 // Set extended - text, thumbnail and background image
626 // Extended style set
627 String countText = notifyRequest.GetNotificationCountText();
628 NotificationStyle notiStyle= notifyRequest.GetNotificationStyle();
629 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
631 layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
634 if (notiStyle == NOTIFICATION_STYLE_NORMAL && !countText.IsEmpty())
636 layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
639 if (!countText.IsEmpty())
641 std::unique_ptr<char[]> text(_StringConverter::CopyToCharArrayN(countText));
642 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, text.get(),
643 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
646 String bgImageFilePath = notifyRequest.GetBackgroundImageFilePath();
647 if (!bgImageFilePath.IsEmpty() && File::IsFileExist(bgImageFilePath))
649 std::unique_ptr<char[]> pBgImageFilePath(_StringConverter::CopyToCharArrayN(bgImageFilePath));
650 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, pBgImageFilePath.get()));
651 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the background image path failed.", GetErrorMessage(r));
655 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
657 const IList* pThumbnailList = pRequestImpl->GetMessageThumbnailFilePathList();
660 const static notification_image_type_e thumbnailListEnum[] = {NOTIFICATION_IMAGE_TYPE_LIST_1, NOTIFICATION_IMAGE_TYPE_LIST_2,
661 NOTIFICATION_IMAGE_TYPE_LIST_3, NOTIFICATION_IMAGE_TYPE_LIST_4, NOTIFICATION_IMAGE_TYPE_LIST_5 };
662 int itemCount = pThumbnailList->GetCount();
663 const int maxCount = sizeof(thumbnailListEnum)/sizeof(thumbnailListEnum[0]);
664 if (itemCount > maxCount)
666 itemCount = maxCount;
668 for (int i = 0; i < itemCount; i++)
670 const String* pThumbnailPath = static_cast<const String*>(pThumbnailList->GetAt(i));
671 std::unique_ptr<char[]> filePath(_StringConverter::CopyToCharArrayN(*pThumbnailPath));
672 r = ConvertNotificationResult(notification_set_image(notiHandle, thumbnailListEnum[i], filePath.get()));
673 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the thumbnail path failed.", GetErrorMessage(r));
679 const IList* pMessageTextList = pRequestImpl->GetMessageTextList();
680 if (pMessageTextList && pMessageTextList->GetCount())
682 const String* pText1 = static_cast<const String*>(pMessageTextList->GetAt(0));
686 if (E_SUCCESS == pText1->IndexOf(L'\t', 0, matchIndex))
690 pText1->SubString(0, matchIndex+1, subText);
691 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
692 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
693 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
694 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 text failed.", GetErrorMessage(r));
696 if (E_SUCCESS == pText1->SubString(matchIndex+1, subText))
698 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
699 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, rightText.get(),
700 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
701 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 sub text failed.", GetErrorMessage(r));
706 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText1));
707 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
708 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
709 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 text failed.", GetErrorMessage(r));
712 const String* pText2 = static_cast<const String*>(pMessageTextList->GetAt(1));
716 // 2.1: Multiple layout has single line text for 2nd information text.
717 if ((layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE) && (E_SUCCESS == (pText2->IndexOf(L'\t', 0, matchIndex))))
721 pText2->SubString(0, matchIndex+1, subText);
722 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
723 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
724 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
725 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 text failed.", GetErrorMessage(r));
727 if (E_SUCCESS == pText2->SubString(matchIndex+1, subText))
729 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
730 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, rightText.get(),
731 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
732 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 sub text failed.", GetErrorMessage(r));
737 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText2));
738 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
739 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
740 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 text failed.", GetErrorMessage(r));
746 { // Reset text for update case. also must be checked the previous text with get_text
747 char* pRetStr = null;
748 notification_get_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, &pRetStr);
751 const static notification_text_type_e infoTextEnums[] = { NOTIFICATION_TEXT_TYPE_INFO_1, NOTIFICATION_TEXT_TYPE_INFO_SUB_1,
752 NOTIFICATION_TEXT_TYPE_INFO_2, NOTIFICATION_TEXT_TYPE_INFO_SUB_2 };
753 for (unsigned int i = 0; i < sizeof(infoTextEnums)/sizeof(infoTextEnums[0]); i++)
755 r = ConvertNotificationResult(notification_set_text(notiHandle, infoTextEnums[i], null, NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
756 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the initial text failed.", GetErrorMessage(r));
764 int retVal = SERVICE_ERROR_NONE;
765 int previousDisplaySet = NOTIFICATION_DISPLAY_APP_ALL;
766 int newDisplaySet = 0;
768 r = arg.Construct(launchArguments);
769 SysTryCatch(NID_SHELL, !IsFailed(r), r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] Failed to construct _AppArg.");
771 pBundle = arg.GetBundle();
773 service_create_request(pBundle, &hSvc);
774 SysTryCatch(NID_SHELL, hSvc != null, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_create_request failed.");
776 if (notifyType == NOTIFY_TYPE_SIMPLE || notifyType == NOTIFY_TYPE_APP_ID)
778 retVal = service_set_app_id(hSvc, pRequestImpl->IsAppBinding() ? pAppIdChar.get() : null);
779 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_set_app_id failed(%d).", retVal);
782 if (notifyType == NOTIFY_TYPE_APP_CONTROL)
784 std::unique_ptr<char[]> pOperationIdChar(_StringConverter::CopyToCharArrayN(*pOperationId));
785 retVal = service_set_operation(hSvc, pOperationIdChar.get());
786 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_set_operation failed(%d).", retVal);
790 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
791 retVal = service_set_uri(hSvc, pUri.get());
792 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_set_uri failed(%d).", retVal);
796 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pDataType));
797 retVal = service_set_mime(hSvc, pMime.get());
798 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_set_mime failed(%d).", retVal);
802 std::unique_ptr<Tizen::Base::Collection::IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
805 while (pMapEnum->MoveNext() == E_SUCCESS)
807 String* pKey = static_cast<String* > (pMapEnum->GetKey());
808 String* pValue = static_cast<String* > (pMapEnum->GetValue());
811 std::unique_ptr<char[]> pKeyString(_StringConverter::CopyToCharArrayN(*pKey));
812 std::unique_ptr<char[]> pValueString(_StringConverter::CopyToCharArrayN(*pValue));
813 retVal = service_add_extra_data(hSvc, pKeyString.get(), pValueString.get());
814 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_add_extra_data failed(%d).", retVal);
818 SysLog(NID_SHELL, "pKey or pValue is invalid.");
825 retVal = service_to_bundle(hSvc, &service_data);
826 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_to_bundle failed(%d).", retVal);
828 r = ConvertNotificationResult(notification_set_property(notiHandle, 0));
829 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification property failed.", GetErrorMessage(r));
831 r = ConvertNotificationResult(notification_set_execute_option(notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data));
832 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the execute option failed.", GetErrorMessage(r));
837 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
838 if (activityType == ONGOING_ACTIVITY_TYPE_TEXT)
840 layout = NOTIFICATION_LY_ONGOING_EVENT;
844 layout = NOTIFICATION_LY_ONGOING_PROGRESS;
847 r = ConvertNotificationResult(notification_set_layout(notiHandle, layout));
848 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification layout failed.", GetErrorMessage(r));
853 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
854 int progress = notifyRequest.GetOngoingActivityProgress();
856 switch (activityType)
858 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
861 r = ConvertNotificationResult(notification_set_size(notiHandle, 0)); // Reset for override BYTE type
862 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
864 r = ConvertNotificationResult(notification_set_progress(notiHandle, progress/100.));
865 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
868 case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
871 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset for override PERCENTAGE type
872 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
874 r = ConvertNotificationResult(notification_set_size(notiHandle, progress));
875 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
878 case ONGOING_ACTIVITY_TYPE_TEXT:
879 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset the progress
880 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
881 r = ConvertNotificationResult(notification_set_size(notiHandle, 0));
882 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
886 r = E_OPERATION_FAILED;
890 r = ConvertNotificationResult(notification_get_display_applist(notiHandle, &previousDisplaySet));
891 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
893 newDisplaySet = previousDisplaySet & ~NOTIFICATION_DISPLAY_APP_TICKER;
894 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, newDisplaySet));
895 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
898 // insert for new notification
901 r = ConvertNotificationResult(notification_insert(notiHandle, ¬iPrivateId));
902 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting new notification failed.", GetErrorMessage(r));
904 SysLog(NID_SHELL, "Getting new notiPrivateId(%d)", notiPrivateId);
908 __notifyPrivateIdForOngoing = notiPrivateId;
912 __notifyPrivateId = notiPrivateId;
917 r = ConvertNotificationResult(notification_update(notiHandle));
918 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Updating the notification failed. notiPrivateId(%d)", GetErrorMessage(r), notiPrivateId);
923 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, previousDisplaySet));
924 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
928 service_destroy(hSvc);
929 notification_free(notiHandle);
934 _NotificationManagerImpl::RemoveNotification(void)
936 return RemoveNotification(false);
940 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
942 return RemoveNotification(true);
946 _NotificationManagerImpl::RemoveNotification(bool onGoing)
948 result r = E_SUCCESS;
949 notification_error_e err = NOTIFICATION_ERROR_NONE;
950 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
951 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
953 if (notiPrivateId != -1)
955 notification_h notiHandle = notification_load(null, notiPrivateId);
958 err = notification_delete(notiHandle);
959 SysLog(NID_SHELL, "Notification deleted.");
963 SysLog(NID_SHELL, "Notification already deleted.");
965 err = notification_free(notiHandle);
969 err = notification_delete_all_by_type(null, notiType);
970 SysLog(NID_SHELL, "All [%s] notifications deleted.", onGoing ? "Ongoing" : "Normal");
973 SysTryReturnResult(NID_SHELL, err == NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Failed to RemoveNotification with reason (%d).", err);
978 _NotificationManagerImpl::RemoveNotificationByAppId(const Tizen::App::AppId& appId, bool onGoing)
980 result r = E_SUCCESS;
981 notification_error_e err = NOTIFICATION_ERROR_NONE;
982 bool isValidAppId = _Aul::IsInstalled(appId);
983 SysTryReturnResult(NID_SHELL, isValidAppId == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
985 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
986 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
987 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
989 if (notiPrivateId != -1)
991 notification_h notiHandle = notification_load(pAppId.get(), notiPrivateId);
994 err = notification_delete(notiHandle);
995 SysLog(NID_SHELL, "Notification deleted.");
999 SysLog(NID_SHELL, "Notification already deleted.");
1001 err = notification_free(notiHandle);
1005 err = notification_delete_all_by_type(pAppId.get(), notiType);
1006 SysLog(NID_SHELL, "All [%s] notifications deleted.", onGoing ? "Ongoing" : "Normal");
1009 SysTryReturnResult(NID_SHELL, err == NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Failed to RemoveNotificationByAppId with reason (%d).", err);
1014 _NotificationManagerImpl::RemoveBadge(const char* pkgName) const
1016 bool badgeExist = false;
1017 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1018 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_is_existing failed(%d).", badgeError);
1022 badgeError = badge_remove(pkgName);
1023 SysTryReturnResult(NID_SHELL, badgeError == BADGE_ERROR_NONE, E_OPERATION_FAILED, "badge_remove failed(%d).", badgeError);
1026 SysLog(NID_SHELL, "Badge is removed.");
1031 _NotificationManagerImpl::SetBadgeCount(const char* pkgName, int badgeCount) const
1034 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1035 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_is_existing failed(%d).", badgeError);
1039 badgeError = badge_create(pkgName, pkgName);
1040 SysTryReturnResult(NID_SHELL, badgeError == BADGE_ERROR_NONE, E_OPERATION_FAILED, "badge_create failed(%d).", badgeError);
1043 badgeError = badge_set_count(pkgName, badgeCount);
1044 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_set_count failed(%d).", badgeError);
1046 SysLog(NID_SHELL, "Badge count is %d.", badgeCount);
1051 _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
1053 unsigned int count = 0;
1055 badge_error_e badgeError = badge_get_count(pkgName, &count);
1056 if (badgeError == BADGE_ERROR_NONE)
1058 SysLog(NID_SHELL, "badge_get_count(%d)", count);
1063 SysLog(NID_SHELL, "badge_get_count failed(%d).", badgeError);
1069 _NotificationManagerImpl::AddBadgeEventListener(IBadgeEventListener& listener)
1071 SysTryReturnResult(NID_SHELL, !__badgeEventListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
1072 SysLog(NID_SHELL, "AddBadgeEventListener (%x)", &listener);
1074 result r = _BadgeManagerImpl::GetInstance()->AddPrimaryBadgeEventListener(*this);
1075 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to AddPrimaryBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1077 return __badgeEventListenerList.Add(&listener);
1081 _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener)
1083 SysLog(NID_SHELL, "RemoveBadgeEventListener (%x)", &listener);
1085 result r = __badgeEventListenerList.Remove(&listener); // Remove() can return E_SUCCESS and E_OBJ_NOT_FOUND.
1086 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "Failed to RemoveBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1088 return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
1092 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
1094 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(__badgeEventListenerList.GetEnumeratorN());
1095 SysTryReturnVoidResult(NID_SHELL, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
1097 IBadgeEventListener* pListener;
1098 while (pEnum->MoveNext() == E_SUCCESS)
1101 pEnum->GetCurrent(pListener);
1104 SysLog(NID_SHELL, "pListener is null!");
1107 pListener->OnBadgeUpdated(appId, badgeNumber);