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 <FShellNotificationManager.h>
31 #include <FShellNotificationRequest.h>
32 #include <FShellIBadgeEventListener.h>
33 #include <FBase_StringConverter.h>
35 #include <FApp_AppArg.h>
36 #include "FShell_NotificationManagerImpl.h"
37 #include "FShell_NotificationRequestImpl.h"
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Collection;
41 using namespace Tizen::App;
42 using namespace Tizen::Io;
44 extern "C" int service_create_request(bundle *data, service_h *service);
45 extern "C" int service_to_bundle(service_h service, bundle** data);
51 ConvertNotificationResult(int error)
55 case NOTIFICATION_ERROR_NONE:
57 case NOTIFICATION_ERROR_INVALID_DATA:
59 case NOTIFICATION_ERROR_NO_MEMORY:
60 return E_OUT_OF_MEMORY;
61 case NOTIFICATION_ERROR_FROM_DB:
63 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
65 case NOTIFICATION_ERROR_NOT_EXIST_ID:
66 return E_OPERATION_FAILED;
68 return E_OPERATION_FAILED;
73 ConvertAppManagerResult(int error)
77 case APP_MANAGER_ERROR_NONE:
79 case APP_MANAGER_ERROR_INVALID_PARAMETER:
81 case APP_MANAGER_ERROR_INVALID_PACKAGE:
83 case NOTIFICATION_ERROR_NO_MEMORY:
84 return E_OUT_OF_MEMORY;
85 case APP_MANAGER_ERROR_DB_FAILED:
86 return E_OPERATION_FAILED;
88 return E_OPERATION_FAILED;
95 namespace Tizen { namespace Shell
98 ///////////////////////////////////////////////////////////////////
100 ///////////////////////////////////////////////////////////////////
102 BadgeChangedCallback(unsigned int action, const char *pkgname, unsigned int count, void *data)
104 Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>* pBadgeEventListenerList = static_cast<Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>*>(data);
105 SysAssert(pBadgeEventListenerList);
107 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(pBadgeEventListenerList->GetEnumeratorN());
108 SysTryReturnVoidResult(NID_SHELL, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
110 IBadgeEventListener* pListener;
111 while (pEnum->MoveNext() == E_SUCCESS)
114 pEnum->GetCurrent(pListener);
117 SysLog(NID_SHELL, "pListener is null!");
121 pListener->OnBadgeUpdated(pkgname, count);
126 _BadgeManagerImpl::GetInstance(void)
128 static _BadgeManagerImpl* pTheInstance = null;
129 if (pTheInstance == null)
131 pTheInstance = new (std::nothrow) _BadgeManagerImpl;
132 SysTryReturn(NID_SHELL, pTheInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
134 pTheInstance->Construct();
140 _BadgeManagerImpl::Construct(void)
146 _BadgeManagerImpl::AddPrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
148 if( __primaryBadgeEventListenerList.GetCount() == 0)
150 int ret = badge_register_changed_cb(BadgeChangedCallback, &__primaryBadgeEventListenerList);
151 SysTryReturnResult(NID_SHELL, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_register_changed_cb, (%d)", ret);
154 return __primaryBadgeEventListenerList.Add(&primaryListener);
158 _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
160 __primaryBadgeEventListenerList.Remove(&primaryListener);
161 if( __primaryBadgeEventListenerList.GetCount() == 0)
163 int ret = badge_unregister_changed_cb(BadgeChangedCallback);
164 SysTryReturnResult(NID_SHELL, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
170 ///////////////////////////////////////////////////////////////////
171 // _NotificationManagerImpl
172 ///////////////////////////////////////////////////////////////////
173 _NotificationManagerImpl::_NotificationManagerImpl(void)
174 : __notifyPrivateId(-1)
175 , __notifyPrivateIdForOngoing(-1)
179 _NotificationManagerImpl::~_NotificationManagerImpl(void)
181 bool isListeningBadgeEvent = (__badgeEventListenerList.GetCount() > 0)? true : false;
182 if(isListeningBadgeEvent == true)
184 _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
189 _NotificationManagerImpl::Construct(void)
194 const _NotificationManagerImpl*
195 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
197 return notiMgr.__pNotificationManagerImpl;
200 _NotificationManagerImpl*
201 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
203 return notiMgr.__pNotificationManagerImpl;
207 _NotificationManagerImpl::GetBadgeNumber(void) const
211 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
212 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
214 int count = GetBadgeCount(pAppId.get());
215 SysTryReturn(NID_SHELL, count != -1, count, E_OPERATION_FAILED, "[E_OPERATION_FAILED] The operation has failed. Badge may not exist.");
221 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
223 return NotifyMessage(NOTIFY_TYPE_SIMPLE, isOngoing, notiMessage);
227 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
229 return NotifyMessage(NOTIFY_TYPE_APP_ID, isOngoing, notiMessage, &appId);
234 _NotificationManagerImpl::Notify(int badgeNumber)
236 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
237 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
239 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
240 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
242 result r = E_SUCCESS;
244 if (badgeNumber == 0)
246 r = RemoveBadge(pAppId.get());
247 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to remove the badge.");
252 r = SetBadgeCount(pAppId.get(), badgeNumber);
253 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to set the badge.");
260 _NotificationManagerImpl::Notify(const String& messageText)
262 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
263 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
265 NotificationRequest request;
266 request.SetAlertText(messageText);
267 request.SetAppMessage(L"");
269 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
273 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber)
275 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
276 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
277 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
278 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
280 NotificationRequest request;
281 request.SetAlertText(messageText);
282 request.SetBadgeNumber(badgeNumber);
283 request.SetAppMessage(L"");
285 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
289 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
291 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
292 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
293 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
294 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
295 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() > 0 && launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
296 "launchArguments is less than 1 or greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
298 NotificationRequest request;
299 request.SetAlertText(messageText);
300 request.SetBadgeNumber(badgeNumber);
301 request.SetAppMessage(launchArguments);
303 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
307 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
311 bool b = _Aul::IsInstalled(appId);
312 SysTryReturn(NID_SHELL, b == true, -1, E_APP_NOT_INSTALLED, "[E_APP_NOT_INSTALLED] The application %ls is not installed",
314 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
315 int count = GetBadgeCount(pAppId.get());
317 SysTryReturn(NID_SHELL, count != -1, count, E_OPERATION_FAILED, "[E_OPERATION_FAILED] The operation has failed. Badge may not exist.");
323 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText)
325 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
326 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
328 NotificationRequest request;
329 request.SetAlertText(messageText);
331 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
335 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
337 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
338 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
339 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
340 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
341 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
343 NotificationRequest request;
344 request.SetAlertText(messageText);
345 request.SetAppMessage(launchArguments);
347 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
351 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
353 return RemoveNotificationByAppId(appId, true);
358 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
360 return RemoveNotificationByAppId(appId, false);
364 _NotificationManagerImpl::NotifyTextMessage(const String& messageText) const
366 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
367 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
369 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
370 int res = notification_status_message_post(pMsg.get());
372 result r = E_SUCCESS;
375 case NOTIFICATION_ERROR_NONE:
378 case NOTIFICATION_ERROR_INVALID_DATA:
381 case NOTIFICATION_ERROR_IO:
382 r = E_OPERATION_FAILED;
385 r = E_OPERATION_FAILED;
389 SysLog(NID_SHELL, "[%s] %ls posted.", GetErrorMessage(r), messageText.GetPointer());
394 _NotificationManagerImpl::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
395 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
397 result r = E_SUCCESS;
399 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, false, request, null, &operationId, pUriData, pDataType, pExtraData);
404 _NotificationManagerImpl::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
405 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
407 result r = E_SUCCESS;
409 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, true, request, null, &operationId, pUriData, pDataType, pExtraData);
416 // E_APP_NOT_INSTALLED - If AppId is invalid, it can occur.
417 // E_OPERATION_FAILED
421 _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing, const NotificationRequest& notifyRequest, const AppId* pAppId,
422 const Tizen::Base::String* pOperationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData)
424 result r = E_SUCCESS;
425 std::unique_ptr<char[]> pAppIdChar(null);
426 const _NotificationRequestImpl* pRequestImpl = _NotificationRequestImpl::GetInstance(notifyRequest);
427 SysTryReturnResult(NID_SHELL, pRequestImpl != null, E_INVALID_ARG, "Invalid argument is used.");
430 if ((notifyType == NOTIFY_TYPE_SIMPLE) || (notifyType == NOTIFY_TYPE_APP_CONTROL))
432 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
433 const String currentAppId = pApp->GetAppId();
434 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(currentAppId));
435 pAppIdChar = std::move(pAppIdTemp);
436 SysLog(NID_SHELL, "App ID is %ls.", currentAppId.GetPointer());
439 if (notifyType == NOTIFY_TYPE_APP_ID)
441 bool isAppInstalled = _Aul::IsInstalled(*pAppId);
442 SysTryReturnResult(NID_SHELL, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed.", pAppId->GetPointer());
443 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(*pAppId));
444 pAppIdChar = std::move(pAppIdTemp);
448 SysTryReturnResult(NID_SHELL, false, E_INVALID_ARG, "Invalid argument is used.");
451 const int badgeNumber = notifyRequest.GetBadgeNumber();
452 const int badgeOffset = notifyRequest.GetBadgeOffset();
453 const String& contentText = notifyRequest.GetAlertText();
454 // Allow change the badge without other properties.
455 if (badgeNumber != -1 || badgeOffset != 0)
458 if (badgeOffset != 0)
460 int badgeNumber = GetBadgeCount(pAppIdChar.get());
461 if (badgeNumber <= 0)
463 SetBadgeCount(pAppIdChar.get(), badgeOffset);
467 SetBadgeCount(pAppIdChar.get(), badgeNumber + badgeOffset);
472 if (badgeNumber == 0)
474 r = RemoveBadge(pAppIdChar.get());
475 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to remove the badge.");
480 r = SetBadgeCount(pAppIdChar.get(), badgeNumber);
481 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to set the badge.");
484 if (!(isOngoing || !contentText.IsEmpty()))
486 SysLog(NID_SHELL, "No valid for Notification, just for set a badgeNumber update.");
490 SysTryReturnResult(NID_SHELL, (isOngoing || !contentText.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. MessageText is Empty");
492 const String& titleText = notifyRequest.GetTitleText();
493 const String& launchArguments = notifyRequest.GetAppMessage();
494 const String& iconPath = notifyRequest.GetIconFilePath();
495 const String& soundPath = notifyRequest.GetSoundFilePath();
496 const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
497 int notiPrivateId = isOngoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
498 notification_h notiHandle = null;
499 bundle* pBundle = null;
500 bool needUpdate = false;
501 bundle* service_data = null;
503 service_h hSvc = null;
504 notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
506 // Notification creation
507 if (notiPrivateId != -1)
509 notiHandle = notification_load(pAppIdChar.get(), notiPrivateId);
510 SysTryLog(NID_SHELL, notiHandle != null, "Get notiHandle(%d) from notiPrivateId(%d).", notiHandle, notiPrivateId);
513 if (notiHandle == null)
515 SysLog(NID_SHELL, "Previous notification(%d) no more valid - create new notification", notiPrivateId);
516 notiPrivateId = -1; // reset
517 notiHandle = notification_create(notiType);
521 needUpdate = true; // No need to notification_insert.
523 SysTryReturnResult(NID_SHELL, notiHandle != null, E_OPERATION_FAILED, "Notification creation or loading failed.");
525 // Content text(Alert text)
526 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(contentText));
529 std::unique_ptr<char[]> pTitleText(null);
530 if (!titleText.IsEmpty())
532 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(titleText));
533 pTitleText = std::move(pTitleTextTemp);
537 char* pAppName = null;
538 r = ConvertAppManagerResult(app_manager_get_app_name(pAppIdChar.get(), &pAppName));
541 String appName(pAppName);
542 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
543 pTitleText = std::move(pTitleTextTemp);
545 SysSecureLog(NID_SHELL, "App name is %ls.", appName.GetPointer());
547 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Failed to get title from app_manager_get_app_name for default setting.", GetErrorMessage(r));
550 std::unique_ptr<char[]> pIconPath(null);
551 if (!iconPath.IsEmpty())
553 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
554 pIconPath = std::move(pIconPathTemp);
558 char* pDefaultIconPath = null;
559 r = ConvertAppManagerResult(app_manager_get_app_icon_path(pAppIdChar.get(), &pDefaultIconPath));
560 if (pDefaultIconPath)
562 String iconPath(pDefaultIconPath);
563 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
564 pIconPath = std::move(pIconPathTemp);
565 free(pDefaultIconPath);
567 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the icon path failed.", GetErrorMessage(r));
570 std::unique_ptr<char[]> pSoundPath(null);
571 if (!soundPath.IsEmpty())
573 std::unique_ptr<char[]> pSoundPathTemp(_StringConverter::CopyToCharArrayN(soundPath));
574 pSoundPath = std::move(pSoundPathTemp);
577 if (notifyType == NOTIFY_TYPE_APP_ID)
579 r = ConvertNotificationResult(notification_set_pkgname(notiHandle, pAppIdChar.get()));
580 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the package name failed.", GetErrorMessage(r));
583 if (pTitleText.get())
585 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
586 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the title text failed.", GetErrorMessage(r));
588 // Set - content text
591 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
592 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting content text failed.", GetErrorMessage(r));
594 // Set - icon file path
595 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath.get()));
596 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the icon path failed.", GetErrorMessage(r));
597 // Set - sound file path
598 if (pSoundPath.get())
600 if (isOngoing && needUpdate)
602 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
606 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath.get()));
613 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
617 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL));
620 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the sound failed.", GetErrorMessage(r));
622 // Set extended - text, thumbnail and background image
625 // Extended style set
626 String countText = notifyRequest.GetNotificationCountText();
627 NotificationStyle notiStyle= notifyRequest.GetNotificationStyle();
628 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
630 layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
633 if (notiStyle == NOTIFICATION_STYLE_NORMAL && !countText.IsEmpty())
635 layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
638 if (!countText.IsEmpty())
640 std::unique_ptr<char[]> text(_StringConverter::CopyToCharArrayN(countText));
641 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, text.get(),
642 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
645 String bgImageFilePath = notifyRequest.GetBackgroundImageFilePath();
646 if (!bgImageFilePath.IsEmpty() && File::IsFileExist(bgImageFilePath))
648 std::unique_ptr<char[]> pBgImageFilePath(_StringConverter::CopyToCharArrayN(bgImageFilePath));
649 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, pBgImageFilePath.get()));
650 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the background image path failed.", GetErrorMessage(r));
654 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
656 const IList* pThumbnailList = pRequestImpl->GetMessageThumbnailFilePathList();
659 const static notification_image_type_e thumbnailListEnum[] = {NOTIFICATION_IMAGE_TYPE_LIST_1, NOTIFICATION_IMAGE_TYPE_LIST_2,
660 NOTIFICATION_IMAGE_TYPE_LIST_3, NOTIFICATION_IMAGE_TYPE_LIST_4, NOTIFICATION_IMAGE_TYPE_LIST_5 };
661 int itemCount = pThumbnailList->GetCount();
662 const int maxCount = sizeof(thumbnailListEnum)/sizeof(thumbnailListEnum[0]);
663 if (itemCount > maxCount)
665 itemCount = maxCount;
667 for (int i = 0; i < itemCount; i++)
669 const String* pThumbnailPath = static_cast<const String*>(pThumbnailList->GetAt(i));
670 std::unique_ptr<char[]> filePath(_StringConverter::CopyToCharArrayN(*pThumbnailPath));
671 r = ConvertNotificationResult(notification_set_image(notiHandle, thumbnailListEnum[i], filePath.get()));
672 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the thumbnail path failed.", GetErrorMessage(r));
678 const IList* pMessageTextList = pRequestImpl->GetMessageTextList();
679 if (pMessageTextList && pMessageTextList->GetCount())
681 const String* pText1 = static_cast<const String*>(pMessageTextList->GetAt(0));
685 if (E_SUCCESS == pText1->IndexOf(L'\t', 0, matchIndex))
689 pText1->SubString(0, matchIndex+1, subText);
690 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
691 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
692 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
693 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 text failed.", GetErrorMessage(r));
695 if (E_SUCCESS == pText1->SubString(matchIndex+1, subText))
697 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
698 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, rightText.get(),
699 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
700 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 sub text failed.", GetErrorMessage(r));
705 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText1));
706 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
707 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
708 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 text failed.", GetErrorMessage(r));
711 const String* pText2 = static_cast<const String*>(pMessageTextList->GetAt(1));
715 // 2.1: Multiple layout has single line text for 2nd information text.
716 if ((layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE) && (E_SUCCESS == (pText2->IndexOf(L'\t', 0, matchIndex))))
720 pText2->SubString(0, matchIndex+1, subText);
721 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
722 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
723 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
724 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 text failed.", GetErrorMessage(r));
726 if (E_SUCCESS == pText2->SubString(matchIndex+1, subText))
728 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
729 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, rightText.get(),
730 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
731 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 sub text failed.", GetErrorMessage(r));
736 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText2));
737 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
738 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
739 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 text failed.", GetErrorMessage(r));
745 { // Reset text for update case. also must be checked the previous text with get_text
746 char* pRetStr = null;
747 notification_get_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, &pRetStr);
750 const static notification_text_type_e infoTextEnums[] = { NOTIFICATION_TEXT_TYPE_INFO_1, NOTIFICATION_TEXT_TYPE_INFO_SUB_1,
751 NOTIFICATION_TEXT_TYPE_INFO_2, NOTIFICATION_TEXT_TYPE_INFO_SUB_2 };
752 for (unsigned int i = 0; i < sizeof(infoTextEnums)/sizeof(infoTextEnums[0]); i++)
754 r = ConvertNotificationResult(notification_set_text(notiHandle, infoTextEnums[i], null, NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
755 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the initial text failed.", GetErrorMessage(r));
763 int retVal = SERVICE_ERROR_NONE;
764 int previousDisplaySet = NOTIFICATION_DISPLAY_APP_ALL;
765 int newDisplaySet = 0;
767 r = arg.Construct(launchArguments);
768 SysTryCatch(NID_SHELL, !IsFailed(r), r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] Failed to construct _AppArg.");
770 pBundle = arg.GetBundle();
772 service_create_request(pBundle, &hSvc);
773 SysTryCatch(NID_SHELL, hSvc != null, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_create_request failed.");
775 if (notifyType == NOTIFY_TYPE_SIMPLE || notifyType == NOTIFY_TYPE_APP_ID)
777 retVal = service_set_app_id(hSvc, pRequestImpl->IsAppBinding() ? pAppIdChar.get() : null);
778 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_set_app_id failed(%d).", retVal);
781 if (notifyType == NOTIFY_TYPE_APP_CONTROL)
783 std::unique_ptr<char[]> pOperationIdChar(_StringConverter::CopyToCharArrayN(*pOperationId));
784 retVal = service_set_operation(hSvc, pOperationIdChar.get());
785 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_set_operation failed(%d).", retVal);
789 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
790 retVal = service_set_uri(hSvc, pUri.get());
791 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_set_uri failed(%d).", retVal);
795 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pDataType));
796 retVal = service_set_mime(hSvc, pMime.get());
797 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_set_mime failed(%d).", retVal);
801 std::unique_ptr<Tizen::Base::Collection::IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
804 while (pMapEnum->MoveNext() == E_SUCCESS)
806 String* pKey = static_cast<String* > (pMapEnum->GetKey());
807 String* pValue = static_cast<String* > (pMapEnum->GetValue());
810 std::unique_ptr<char[]> pKeyString(_StringConverter::CopyToCharArrayN(*pKey));
811 std::unique_ptr<char[]> pValueString(_StringConverter::CopyToCharArrayN(*pValue));
812 retVal = service_add_extra_data(hSvc, pKeyString.get(), pValueString.get());
813 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_add_extra_data failed(%d).", retVal);
817 SysLog(NID_SHELL, "pKey or pValue is invalid.");
824 retVal = service_to_bundle(hSvc, &service_data);
825 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_to_bundle failed(%d).", retVal);
827 r = ConvertNotificationResult(notification_set_property(notiHandle, 0));
828 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification property failed.", GetErrorMessage(r));
830 r = ConvertNotificationResult(notification_set_execute_option(notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data));
831 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the execute option failed.", GetErrorMessage(r));
836 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
837 if (activityType == ONGOING_ACTIVITY_TYPE_TEXT)
839 layout = NOTIFICATION_LY_ONGOING_EVENT;
843 layout = NOTIFICATION_LY_ONGOING_PROGRESS;
846 r = ConvertNotificationResult(notification_set_layout(notiHandle, layout));
847 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification layout failed.", GetErrorMessage(r));
852 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
853 int progress = notifyRequest.GetOngoingActivityProgress();
855 switch (activityType)
857 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
860 r = ConvertNotificationResult(notification_set_size(notiHandle, 0)); // Reset for override BYTE type
861 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
863 r = ConvertNotificationResult(notification_set_progress(notiHandle, progress/100.));
864 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
867 case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
870 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset for override PERCENTAGE type
871 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
873 r = ConvertNotificationResult(notification_set_size(notiHandle, progress));
874 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
877 case ONGOING_ACTIVITY_TYPE_TEXT:
878 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset the progress
879 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
880 r = ConvertNotificationResult(notification_set_size(notiHandle, 0));
881 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
885 r = E_OPERATION_FAILED;
889 r = ConvertNotificationResult(notification_get_display_applist(notiHandle, &previousDisplaySet));
890 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
892 newDisplaySet = previousDisplaySet & ~NOTIFICATION_DISPLAY_APP_TICKER;
893 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, newDisplaySet));
894 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
897 // insert for new notification
900 r = ConvertNotificationResult(notification_insert(notiHandle, ¬iPrivateId));
901 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting new notification failed.", GetErrorMessage(r));
903 SysLog(NID_SHELL, "Getting new notiPrivateId(%d)", notiPrivateId);
907 __notifyPrivateIdForOngoing = notiPrivateId;
911 __notifyPrivateId = notiPrivateId;
916 r = ConvertNotificationResult(notification_update(notiHandle));
917 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Updating the notification failed. notiPrivateId(%d)", GetErrorMessage(r), notiPrivateId);
922 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, previousDisplaySet));
923 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
927 service_destroy(hSvc);
928 notification_free(notiHandle);
933 _NotificationManagerImpl::RemoveNotification(void)
935 return RemoveNotification(false);
939 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
941 return RemoveNotification(true);
945 _NotificationManagerImpl::RemoveNotification(bool onGoing)
947 result r = E_SUCCESS;
948 notification_error_e err = NOTIFICATION_ERROR_NONE;
949 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
950 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
952 if (notiPrivateId != -1)
954 notification_h notiHandle = notification_load(null, notiPrivateId);
957 err = notification_delete(notiHandle);
958 SysLog(NID_SHELL, "Notification deleted.");
962 SysLog(NID_SHELL, "Notification already deleted.");
964 err = notification_free(notiHandle);
968 err = notification_delete_all_by_type(null, notiType);
969 SysLog(NID_SHELL, "All [%s] notifications deleted.", onGoing ? "Ongoing" : "Normal");
972 SysTryReturnResult(NID_SHELL, err == NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Failed to RemoveNotification with reason (%d).", err);
977 _NotificationManagerImpl::RemoveNotificationByAppId(const Tizen::App::AppId& appId, bool onGoing)
979 result r = E_SUCCESS;
980 notification_error_e err = NOTIFICATION_ERROR_NONE;
981 bool isValidAppId = _Aul::IsInstalled(appId);
982 SysTryReturnResult(NID_SHELL, isValidAppId == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
984 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
985 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
986 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
988 if (notiPrivateId != -1)
990 notification_h notiHandle = notification_load(pAppId.get(), notiPrivateId);
993 err = notification_delete(notiHandle);
994 SysLog(NID_SHELL, "Notification deleted.");
998 SysLog(NID_SHELL, "Notification already deleted.");
1000 err = notification_free(notiHandle);
1004 err = notification_delete_all_by_type(pAppId.get(), notiType);
1005 SysLog(NID_SHELL, "All [%s] notifications deleted.", onGoing ? "Ongoing" : "Normal");
1008 SysTryReturnResult(NID_SHELL, err == NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Failed to RemoveNotificationByAppId with reason (%d).", err);
1013 _NotificationManagerImpl::RemoveBadge(const char* pkgName) const
1015 bool badgeExist = false;
1016 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1017 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_is_existing failed(%d).", badgeError);
1021 badgeError = badge_remove(pkgName);
1022 SysTryReturnResult(NID_SHELL, badgeError == BADGE_ERROR_NONE, E_OPERATION_FAILED, "badge_remove failed(%d).", badgeError);
1025 SysLog(NID_SHELL, "Badge is removed.");
1030 _NotificationManagerImpl::SetBadgeCount(const char* pkgName, int badgeCount) const
1033 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1034 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_is_existing failed(%d).", badgeError);
1038 badgeError = badge_create(pkgName, pkgName);
1039 SysTryReturnResult(NID_SHELL, badgeError == BADGE_ERROR_NONE, E_OPERATION_FAILED, "badge_create failed(%d).", badgeError);
1042 badgeError = badge_set_count(pkgName, badgeCount);
1043 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_set_count failed(%d).", badgeError);
1045 SysLog(NID_SHELL, "Badge count is %d.", badgeCount);
1050 _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
1052 unsigned int count = 0;
1054 badge_error_e badgeError = badge_get_count(pkgName, &count);
1055 if (badgeError == BADGE_ERROR_NONE)
1057 SysLog(NID_SHELL, "badge_get_count(%d)", count);
1062 SysLog(NID_SHELL, "badge_get_count failed(%d).", badgeError);
1068 _NotificationManagerImpl::AddBadgeEventListener(IBadgeEventListener& listener)
1070 SysTryReturnResult(NID_SHELL, !__badgeEventListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
1071 SysLog(NID_SHELL, "AddBadgeEventListener (%x)", &listener);
1073 result r = _BadgeManagerImpl::GetInstance()->AddPrimaryBadgeEventListener(*this);
1074 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to AddPrimaryBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1076 return __badgeEventListenerList.Add(&listener);
1080 _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener)
1082 SysLog(NID_SHELL, "RemoveBadgeEventListener (%x)", &listener);
1084 result r = __badgeEventListenerList.Remove(&listener); // Remove() can return E_SUCCESS and E_OBJ_NOT_FOUND.
1085 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "Failed to RemoveBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1087 return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
1091 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
1093 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(__badgeEventListenerList.GetEnumeratorN());
1094 SysTryReturnVoidResult(NID_SHELL, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
1096 IBadgeEventListener* pListener;
1097 while (pEnum->MoveNext() == E_SUCCESS)
1100 pEnum->GetCurrent(pListener);
1103 SysLog(NID_SHELL, "pListener is null!");
1106 pListener->OnBadgeUpdated(appId, badgeNumber);