2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FShell_NotificationManagerImpl.cpp
20 * @brief This is the placeholder for _NotificationManagerImpl class.
23 #include <unique_ptr.h>
24 #include <appsvc/appsvc.h>
26 #include <notification/notification.h>
27 #include <appfw/app.h>
28 #include <appfw/app_manager.h>
29 #include <appfw/app_ui_notification.h>
32 #include <FBaseSysLog.h>
34 #include <FShellNotificationManager.h>
35 #include <FShellNotificationRequest.h>
36 #include <FShellIBadgeEventListener.h>
38 //#include <FBaseInternalTypes.h>
39 #include <FBase_StringConverter.h>
40 #include "FApp_AppInfo.h"
43 #include "FAppPkg_PackageManagerImpl.h"
44 #include "FApp_AppArg.h"
45 #include "FAppPkgPackageAppInfo.h"
46 #include "FAppPkg_PackageAppInfoImpl.h"
47 #include "FShell_NotificationManagerImpl.h"
48 #include "FShell_NotificationRequestImpl.h"
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::App;
53 using namespace Tizen::App::Package;
54 using namespace Tizen::Io;
55 using namespace Tizen::Shell;
57 extern "C" int service_create_request(bundle *data, service_h *service);
58 extern "C" int service_to_bundle(service_h service, bundle** data);
64 ConvertNotificationResult(int error)
68 case NOTIFICATION_ERROR_NONE:
70 case NOTIFICATION_ERROR_INVALID_DATA:
72 case NOTIFICATION_ERROR_NO_MEMORY:
73 return E_OUT_OF_MEMORY;
74 case NOTIFICATION_ERROR_FROM_DB:
76 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
78 case NOTIFICATION_ERROR_NOT_EXIST_ID:
79 return E_OPERATION_FAILED;
81 return E_OPERATION_FAILED;
86 ConvertAppManagerResult(int error)
90 case APP_MANAGER_ERROR_NONE:
92 case APP_MANAGER_ERROR_INVALID_PARAMETER:
94 case APP_MANAGER_ERROR_INVALID_PACKAGE:
96 case NOTIFICATION_ERROR_NO_MEMORY:
97 return E_OUT_OF_MEMORY;
98 case APP_MANAGER_ERROR_DB_FAILED:
99 return E_OPERATION_FAILED;
101 return E_OPERATION_FAILED;
106 IsPosted(ui_notification_h handle)
108 struct ui_notification_s
128 ui_notification_s* pStruct = reinterpret_cast<ui_notification_s*>(handle);
130 return pStruct->posted;
136 namespace Tizen { namespace Shell
139 ///////////////////////////////////////////////////////////////////
141 ///////////////////////////////////////////////////////////////////
143 BadgeChangedCallback(unsigned int action, const char *pkgname, unsigned int count, void *data)
145 Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>* pBadgeEventListenerList = static_cast<Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>*>(data);
146 SysAssert(pBadgeEventListenerList);
148 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(pBadgeEventListenerList->GetEnumeratorN());
149 SysTryReturnVoidResult(NID_APP, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
151 IBadgeEventListener* pListener;
152 while (pEnum->MoveNext() == E_SUCCESS)
155 pEnum->GetCurrent(pListener);
158 SysLog(NID_APP, "pListener is null!");
162 pListener->OnBadgeUpdated(pkgname, count);
167 _BadgeManagerImpl::GetInstance(void)
169 static _BadgeManagerImpl* pTheInstance = null;
170 if( pTheInstance == null)
172 pTheInstance = new (std::nothrow) _BadgeManagerImpl;
173 pTheInstance->Construct();
179 _BadgeManagerImpl::Construct(void)
185 _BadgeManagerImpl::AddPrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
187 if( __primaryBadgeEventListenerList.GetCount() == 0)
189 int ret = badge_register_changed_cb(BadgeChangedCallback, &__primaryBadgeEventListenerList);
190 SysTryReturnResult(NID_APP, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
193 return __primaryBadgeEventListenerList.Add(&primaryListener);
197 _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
199 __primaryBadgeEventListenerList.Remove(&primaryListener);
200 if( __primaryBadgeEventListenerList.GetCount() == 0)
202 int ret = badge_unregister_changed_cb(BadgeChangedCallback);
203 SysTryReturnResult(NID_APP, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
209 ///////////////////////////////////////////////////////////////////
210 // _NotificationManagerImpl
211 ///////////////////////////////////////////////////////////////////
212 _NotificationManagerImpl::_NotificationManagerImpl(void)
213 : __notifyPrivateId(-1)
214 , __notifyPrivateIdForOngoing(-1)
218 _NotificationManagerImpl::~_NotificationManagerImpl(void)
220 bool isListeningBadgeEvent = (__badgeEventListenerList.GetCount() > 0)? true : false;
221 if(isListeningBadgeEvent == true)
223 _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
228 _NotificationManagerImpl::Construct(void)
233 const _NotificationManagerImpl*
234 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
236 return notiMgr.__pNotificationManagerImpl;
239 _NotificationManagerImpl*
240 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
242 return notiMgr.__pNotificationManagerImpl;
246 _NotificationManagerImpl::GetBadgeNumber(void) const
248 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
249 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
251 int count = GetBadgeCount(pAppId.get());
252 SysTryReturn(NID_APP, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
253 GetErrorMessage(E_OPERATION_FAILED));
260 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
262 return NotifyMessage(NOTIFY_TYPE_SIMPLE, isOngoing, notiMessage);
266 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
268 return NotifyMessage(NOTIFY_TYPE_APP_ID, isOngoing, notiMessage, &appId);
273 _NotificationManagerImpl::Notify(int badgeNumber)
275 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
277 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
279 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
282 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
283 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
285 if (badgeNumber == 0)
287 RemoveBadge(pAppId.get());
292 SetBadgeCount(pAppId.get(), badgeNumber);
299 _NotificationManagerImpl::Notify(const String& messageText)
301 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
303 NotificationRequest request;
304 request.SetAlertText(messageText);
305 request.SetAppMessage(L"");
307 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
311 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber)
313 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
314 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
316 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
318 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
321 NotificationRequest request;
322 request.SetAlertText(messageText);
323 request.SetBadgeNumber(badgeNumber);
324 request.SetAppMessage(L"");
326 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
330 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
332 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
333 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
334 SysTryReturnResult(NID_APP, launchArguments != null && launchArguments.GetLength() > 0, E_INVALID_ARG,
335 "launchArguments is less than 0.");
337 SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
338 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
340 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
342 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
345 NotificationRequest request;
346 request.SetAlertText(messageText);
347 request.SetBadgeNumber(badgeNumber);
348 request.SetAppMessage(launchArguments);
350 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
354 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
356 bool b = _Aul::IsInstalled(appId);
357 SysTryReturn(NID_APP, b == true, -1, E_APP_NOT_INSTALLED, "[E_OBJ_NOT_FOUND] The application %ls is not installed",
359 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
360 int count = GetBadgeCount(pAppId.get());
362 SysTryReturn(NID_APP, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
363 GetErrorMessage(E_OPERATION_FAILED));
370 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText)
372 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
374 NotificationRequest request;
375 request.SetAlertText(messageText);
377 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
381 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
383 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
384 SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
385 SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
386 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
388 NotificationRequest request;
389 request.SetAlertText(messageText);
390 request.SetAppMessage(launchArguments);
392 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
396 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
398 return RemoveNotificationByAppId(appId, true);
403 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
405 return RemoveNotificationByAppId(appId, false);
409 _NotificationManagerImpl::NotifyTextMessage(const String& messageText) const
411 SysTryReturnResult(NID_APP, !messageText.IsEmpty(), E_INVALID_ARG, "MessageText is less than 0.");
413 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
414 int res = notification_status_message_post(pMsg.get());
416 result r = E_SUCCESS;
419 case NOTIFICATION_ERROR_NONE:
422 case NOTIFICATION_ERROR_INVALID_DATA:
425 case NOTIFICATION_ERROR_IO:
433 SysLog(NID_APP, "[%s] %ls posted.", GetErrorMessage(r), messageText.GetPointer());
438 _NotificationManagerImpl::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
439 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
441 result r = E_SUCCESS;
443 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, false, request, null, &operationId, pUriData, pDataType, pExtraData);
448 _NotificationManagerImpl::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
449 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
451 result r = E_SUCCESS;
453 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, true, request, null, &operationId, pUriData, pDataType, pExtraData);
459 _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing, const NotificationRequest& notifyRequest, const AppId* pAppId,
460 const Tizen::Base::String* pOperationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData)
462 result r = E_SUCCESS;
463 std::unique_ptr<char[]> pAppIdChar(null);
464 const _NotificationRequestImpl* pRequestImpl = _NotificationRequestImpl::GetInstance(notifyRequest);
465 SysTryReturnResult(NID_APP, pRequestImpl != null, E_INVALID_ARG, "Invalid argument is used.");
468 if ((notifyType == NOTIFY_TYPE_SIMPLE) || (notifyType == NOTIFY_TYPE_APP_CONTROL))
470 // char* pkgname = null;
471 // app_get_id(&pkgname); // AppId. (Not package Id)
472 // SysTryReturnResult(NID_APP, pkgname != NULL, E_OBJ_NOT_FOUND,"Cannot acquire package name for current application.");
473 // const String currentAppId(pkgname);
475 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
476 const String currentAppId = pApp->GetAppId();
477 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(currentAppId));
478 pAppIdChar = std::move(pAppIdTemp);
479 SysLog(NID_APP, "app_get_id: %ls", currentAppId.GetPointer());
482 if (notifyType == NOTIFY_TYPE_APP_ID)
484 bool isAppInstalled = _Aul::IsInstalled(*pAppId);
485 SysTryReturnResult(NID_APP, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", pAppId->GetPointer());
486 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(*pAppId));
487 pAppIdChar = std::move(pAppIdTemp);
491 SysTryReturnResult(NID_APP, false, E_INVALID_ARG, "Invalid argument is used.");
494 const int badgeNumber = notifyRequest.GetBadgeNumber();
495 const int badgeOffset = notifyRequest.GetBadgeOffset();
496 const String& contentText = notifyRequest.GetAlertText();
497 // Allow change the badge without other properties.
498 if (badgeNumber != -1 || badgeOffset != -1)
501 if (badgeOffset != 0)
503 int badgeNumber = GetBadgeCount(pAppIdChar.get());
504 if (badgeNumber <= 0)
506 SetBadgeCount(pAppIdChar.get(), badgeOffset);
510 SetBadgeCount(pAppIdChar.get(), badgeNumber + badgeOffset);
515 if (badgeNumber == 0)
517 RemoveBadge(pAppIdChar.get());
522 SetBadgeCount(pAppIdChar.get(), badgeNumber);
525 if (!(isOngoing || !contentText.IsEmpty()))
527 SysLog(NID_APP, "No valid for Notification, just for set a badgeNumber update.");
531 SysTryReturnResult(NID_APP, (isOngoing || !contentText.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. MessageText is Empty");
533 const String& titleText = notifyRequest.GetTitleText();
534 const String& launchArguments = notifyRequest.GetAppMessage();
535 const String& iconPath = notifyRequest.GetIconFilePath();
536 const String& soundPath = notifyRequest.GetSoundFilePath();
537 const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
538 int notiPrivateId = isOngoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
539 notification_h notiHandle = null;
540 bundle* pBundle = null;
541 bool needUpdate = false;
542 bundle* service_data = null;
544 service_h hSvc = null;
545 notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
547 // Notification creation
548 if (notiPrivateId != -1)
550 notiHandle = notification_load(pAppIdChar.get(), notiPrivateId);
551 SysTryLog(NID_APP, notiHandle != null, "Get notiHandle(%d) from notiPrivateId(%d).", notiHandle, notiPrivateId);
554 if (notiHandle == null)
556 SysLog(NID_APP, "Previous notification(%d) no more valid - create new notification", notiPrivateId);
557 notiPrivateId = -1; // reset
558 notiHandle = notification_create(notiType);
562 needUpdate = true; // No need to notification_insert.
564 SysTryReturnResult(NID_APP, notiHandle != null , E_SYSTEM, "A system error has been occurred. Notification creation/load failed ");
566 // Content text(Alert text)
567 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(contentText));
570 std::unique_ptr<char[]> pTitleText(null);
571 if (!titleText.IsEmpty())
573 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(titleText));
574 pTitleText = std::move(pTitleTextTemp);
578 char* pAppName = null;
579 r = ConvertAppManagerResult(app_manager_get_app_name(pAppIdChar.get(), &pAppName));
582 String appName(pAppName);
583 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
584 pTitleText = std::move(pTitleTextTemp);
586 //SysLog(NID_APP, "Application Id is %ls.", appName.GetPointer());
588 SysTryLog(NID_APP, !IsFailed(r), "[%s] Failed to get title from app_manager_get_app_name for default setting.", GetErrorMessage(r));
591 std::unique_ptr<char[]> pIconPath(null);
592 if (!iconPath.IsEmpty())
594 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
595 pIconPath = std::move(pIconPathTemp);
599 char* pDefaultIconPath = null;
600 r = ConvertAppManagerResult(app_manager_get_app_icon_path(pAppIdChar.get(), &pDefaultIconPath));
601 if (pDefaultIconPath)
603 String iconPath(pDefaultIconPath);
604 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
605 pIconPath = std::move(pIconPathTemp);
606 free(pDefaultIconPath);
608 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
611 std::unique_ptr<char[]> pSoundPath(null);
612 if (!soundPath.IsEmpty())
614 std::unique_ptr<char[]> pSoundPathTemp(_StringConverter::CopyToCharArrayN(soundPath));
615 pSoundPath = std::move(pSoundPathTemp);
618 if (notifyType == NOTIFY_TYPE_APP_ID)
620 r = ConvertNotificationResult(notification_set_pkgname(notiHandle, pAppIdChar.get()));
621 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Package name failed.", GetErrorMessage(r));
624 if (pTitleText.get())
626 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
627 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
629 // Set - content text
632 r = notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
633 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
635 // Set - icon file path
636 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath.get()));
637 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
638 // Set - sound file path
639 if (pSoundPath.get())
641 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath.get()));
645 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL));
647 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set sound failed.", GetErrorMessage(r));
649 // Set extended - text, thumbnail and background image
652 // Extended style set
653 String countText = notifyRequest.GetNotificationCountText();
654 NotificationStyle notiStyle= notifyRequest.GetNotificationStyle();
655 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
657 layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
660 if (notiStyle == NOTIFICATION_STYLE_NORMAL && !countText.IsEmpty())
662 layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
665 if (!countText.IsEmpty())
667 std::unique_ptr<char[]> text(_StringConverter::CopyToCharArrayN(countText));
668 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, text.get(),
669 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
672 String bgImageFilePath = notifyRequest.GetBackgroundImageFilePath();
673 if (!bgImageFilePath.IsEmpty() && File::IsFileExist(bgImageFilePath))
675 std::unique_ptr<char[]> pBgImageFilePath(_StringConverter::CopyToCharArrayN(bgImageFilePath));
676 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, pBgImageFilePath.get()));
677 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Background image path failed.", GetErrorMessage(r));
681 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
683 const IList* pThumbnailList = pRequestImpl->GetMessageThumbnailFilePathList();
686 const static notification_image_type_e thumbnailListEnum[] = {NOTIFICATION_IMAGE_TYPE_LIST_1, NOTIFICATION_IMAGE_TYPE_LIST_2,
687 NOTIFICATION_IMAGE_TYPE_LIST_3, NOTIFICATION_IMAGE_TYPE_LIST_4, NOTIFICATION_IMAGE_TYPE_LIST_5 };
688 int itemCount = pThumbnailList->GetCount();
689 const int maxCount = sizeof(thumbnailListEnum)/sizeof(thumbnailListEnum[0]);
690 if (itemCount > maxCount)
692 itemCount = maxCount;
694 for (int i = 0; i < itemCount; i++)
696 const String* pThumbnailPath = static_cast<const String*>(pThumbnailList->GetAt(i));
697 // TODO: check pThumbnailPath
698 std::unique_ptr<char[]> filePath(_StringConverter::CopyToCharArrayN(*pThumbnailPath));
699 r = ConvertNotificationResult(notification_set_image(notiHandle, thumbnailListEnum[i], filePath.get()));
700 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set thumnail path failed.", GetErrorMessage(r));
706 // TODO: Check the valid
707 const IList* pMessageTextList = pRequestImpl->GetMessageTextList();
708 if (pMessageTextList && pMessageTextList->GetCount())
710 const String* pText1 = static_cast<const String*>(pMessageTextList->GetAt(0));
714 if (E_SUCCESS == pText1->IndexOf(L'\t', 0, matchIndex))
718 pText1->SubString(0, matchIndex+1, subText);
719 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
720 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
721 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
722 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
724 if (E_SUCCESS == pText1->SubString(matchIndex+1, subText))
726 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
727 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, rightText.get(),
728 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
729 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Sub Text failed.", GetErrorMessage(r));
734 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText1));
735 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
736 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
737 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
740 const String* pText2 = static_cast<const String*>(pMessageTextList->GetAt(1));
744 // 2.1: Multiple layout has single line text for 2nd information text.
745 if ((layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE && E_SUCCESS) == (pText2->IndexOf(L'\t', 0, matchIndex)))
749 pText2->SubString(0, matchIndex+1, subText);
750 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
751 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
752 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
753 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
755 if (E_SUCCESS == pText2->SubString(matchIndex+1, subText))
757 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
758 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, rightText.get(),
759 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
760 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Sub Text failed.", GetErrorMessage(r));
765 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText2));
766 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
767 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
768 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
774 { // Reset text for update case. also must be check the previous text with get_text
775 char* pRetStr = null;
776 notification_get_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, &pRetStr);
779 const static notification_text_type_e infoTextEnums[] = { NOTIFICATION_TEXT_TYPE_INFO_1, NOTIFICATION_TEXT_TYPE_INFO_SUB_1,
780 NOTIFICATION_TEXT_TYPE_INFO_2, NOTIFICATION_TEXT_TYPE_INFO_SUB_2 };
781 for (unsigned int i = 0; i < sizeof(infoTextEnums)/sizeof(infoTextEnums[0]); i++)
783 notification_set_text(notiHandle, infoTextEnums[i], null, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
791 r = arg.Construct(launchArguments);
792 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
794 pBundle = arg.GetBundle();
796 service_create_request(pBundle, &hSvc);
797 SysTryCatch(NID_APP, hSvc != null, r = E_SYSTEM, r, "[%s] A system error has been occurred. service_create_request failed.", GetErrorMessage(E_SYSTEM));
799 if (notifyType == NOTIFY_TYPE_SIMPLE || notifyType == NOTIFY_TYPE_APP_ID)
801 service_set_app_id(hSvc, pRequestImpl->IsAppBinding() ? pAppIdChar.get() : null);
804 if (notifyType == NOTIFY_TYPE_APP_CONTROL)
807 std::unique_ptr<char[]> pOperationIdChar(_StringConverter::CopyToCharArrayN(*pOperationId));
808 service_set_operation(hSvc, pOperationIdChar.get());
811 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
812 service_set_uri(hSvc, pUri.get());
816 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pDataType));
817 service_set_mime(hSvc, pMime.get());
821 std::unique_ptr<Tizen::Base::Collection::IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
824 while (pMapEnum->MoveNext() == E_SUCCESS)
826 String* pKey = static_cast<String* > (pMapEnum->GetKey());
827 String* pValue = static_cast<String* > (pMapEnum->GetValue());
830 std::unique_ptr<char[]> pKeyString(_StringConverter::CopyToCharArrayN(*pKey));
831 std::unique_ptr<char[]> pValueString(_StringConverter::CopyToCharArrayN(*pValue));
832 service_add_extra_data(hSvc, pKeyString.get(), pValueString.get());
836 SysLog(NID_APP, "pKey or pValue is ivalid.");
843 if (service_to_bundle(hSvc, &service_data) == SERVICE_ERROR_NONE)
845 r = ConvertNotificationResult(notification_set_property(notiHandle, 0));
846 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_set_property failed.", GetErrorMessage(r));
847 r = ConvertNotificationResult(notification_set_execute_option(notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
848 NULL, NULL, service_data));
849 SysTryLog(NID_APP, !IsFailed(r), "[%s] Nnotification_set_execute_option failed.", GetErrorMessage(r));
850 SysLog(NID_APP, "notification_set_execute_option");
854 SysLog(NID_APP, "service_to_bundle failed");
860 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
861 if (activityType == ONGOING_ACTIVITY_TYPE_TEXT)
863 layout = NOTIFICATION_LY_ONGOING_EVENT;
867 layout = NOTIFICATION_LY_ONGOING_PROGRESS;
870 notification_set_layout(notiHandle, layout);
875 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
876 int progress = notifyRequest.GetOngoingActivityProgress();
878 switch (activityType)
880 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
883 r = ConvertNotificationResult(notification_set_size(notiHandle, 0)); // Reset for override BYTE type
884 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_set_size failure.", GetErrorMessage(r));
886 r = ConvertNotificationResult(notification_set_progress(notiHandle, progress/100.));
887 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_set_progress failure.", GetErrorMessage(r));
890 case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
893 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset for override PERCENTAGE type
894 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_set_progress failure.", GetErrorMessage(r));
896 r = ConvertNotificationResult(notification_set_size(notiHandle, progress));
897 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_set_size failure.", GetErrorMessage(r));
900 case ONGOING_ACTIVITY_TYPE_TEXT:
901 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset the progress
902 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_set_size failure.", GetErrorMessage(r));
903 r = ConvertNotificationResult(notification_set_size(notiHandle, 0));
904 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_set_size failure.", GetErrorMessage(r));
908 r = E_OPERATION_FAILED;
913 // insert for new notification
916 r = ConvertNotificationResult(notification_insert(notiHandle, ¬iPrivateId));
917 SysLog(NID_APP, "Insert notification and get new notiPrivateId(%d)", notiPrivateId);
918 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
921 __notifyPrivateIdForOngoing = notiPrivateId;
925 __notifyPrivateId = notiPrivateId;
930 int previousDisplaySet = NOTIFICATION_DISPLAY_APP_ALL;
933 r = ConvertNotificationResult(notification_get_display_applist(notiHandle, &previousDisplaySet));
934 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_set_display_applist failure.", GetErrorMessage(r));
935 int newDisplaySet = previousDisplaySet & ~NOTIFICATION_DISPLAY_APP_TICKER;
936 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, newDisplaySet));
937 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_set_display_applist failure.", GetErrorMessage(r));
940 r = ConvertNotificationResult(notification_update(notiHandle));
941 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_update failure. notiPrivateId(%d)", GetErrorMessage(r), notiPrivateId);
945 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, previousDisplaySet));
946 SysTryLog(NID_APP, !IsFailed(r), "[%s] notification_set_display_applist failure.", GetErrorMessage(r));
952 service_destroy(hSvc);
953 notification_free(notiHandle);
958 _NotificationManagerImpl::RemoveNotification(void)
960 return RemoveNotification(false);
964 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
966 return RemoveNotification(true);
970 _NotificationManagerImpl::RemoveNotification(bool onGoing)
972 result r = E_SUCCESS;
973 notification_error_e err = NOTIFICATION_ERROR_NONE;
974 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
975 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
977 if (notiPrivateId != -1)
979 notification_h notiHandle = notification_load(null, notiPrivateId);
982 err = notification_delete(notiHandle);
983 SysLog(NID_APP, "Notification deleted.");
987 SysLog(NID_APP, "Notification already deleted.");
989 notification_free(notiHandle);
993 err = notification_delete_all_by_type(null, notiType);
994 SysLog(NID_APP, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
999 case NOTIFICATION_ERROR_NONE:
1003 case NOTIFICATION_ERROR_INVALID_DATA:
1016 _NotificationManagerImpl::RemoveNotificationByAppId(const Tizen::App::AppId& appId, bool onGoing)
1018 result r = E_SUCCESS;
1019 notification_error_e err = NOTIFICATION_ERROR_NONE;
1020 bool isValidAppId = _Aul::IsInstalled(appId);
1021 SysTryReturnResult(NID_APP, isValidAppId == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
1023 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
1024 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
1025 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
1027 if (notiPrivateId != -1)
1029 notification_h notiHandle = notification_load(pAppId.get(), notiPrivateId);
1032 err = notification_delete(notiHandle);
1033 SysLog(NID_APP, "Notification deleted.");
1037 SysLog(NID_APP, "Notification already deleted.");
1039 notification_free(notiHandle);
1043 err = notification_delete_all_by_type(pAppId.get(), notiType);
1044 SysLog(NID_APP, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
1049 case NOTIFICATION_ERROR_NONE:
1053 case NOTIFICATION_ERROR_INVALID_DATA:
1066 _NotificationManagerImpl::RemoveBadge(const char* pkgName) const
1068 bool badgeExist = false;
1069 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1070 SysLog(NID_APP, "badge_is_existing: exitst= %d, error= %d.", badgeExist, badgeError); //#####
1073 badgeError = badge_remove(pkgName);
1074 SysLog(NID_APP, "badge_remove: error= %d.", badgeError); //#####
1076 SysLog(NID_APP, "Badge removed.");
1080 _NotificationManagerImpl::SetBadgeCount(const char* pkgName, int badgeCount) const
1083 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1084 SysLog(NID_APP, "badge_is_existing: error= %d.", badgeError); //#####
1087 badgeError = badge_create(pkgName, pkgName);
1088 SysLog(NID_APP, "badge_create: error= %d.", badgeError); //#####
1091 badge_set_count(pkgName, badgeCount);
1092 SysLog(NID_APP, "badge_set_count: badgeNumber= %d.", badgeCount);
1096 _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
1098 unsigned int count = 0;
1100 badge_error_e badgeError = badge_get_count(pkgName, &count);
1101 if (badgeError == BADGE_ERROR_NONE)
1103 SysLog(NID_APP, "badge_get_count: ret= %d.", count);
1108 SysLog(NID_APP, "badge_get_count: error= %d.", badgeError);
1114 _NotificationManagerImpl::AddBadgeEventListener(IBadgeEventListener& listener)
1116 SysTryReturnResult(NID_APP, !__badgeEventListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
1117 SysLog(NID_APP, "(%x)", &listener);
1119 result r = _BadgeManagerImpl::GetInstance()->AddPrimaryBadgeEventListener(*this);
1120 SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "Failed to AddPrimaryBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1122 return __badgeEventListenerList.Add(&listener);
1126 _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener)
1128 SysLog(NID_APP, "(%x)", &listener);
1129 result r = __badgeEventListenerList.Remove(&listener);
1130 SysTryReturn(NID_APP, !IsFailed(r), r, r, "Failed to RemoveBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1132 return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
1136 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
1138 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(__badgeEventListenerList.GetEnumeratorN());
1139 SysTryReturnVoidResult(NID_APP, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
1141 IBadgeEventListener* pListener;
1142 while (pEnum->MoveNext() == E_SUCCESS)
1145 pEnum->GetCurrent(pListener);
1148 SysLog(NID_APP, "pListener is null!");
1151 pListener->OnBadgeUpdated(appId, badgeNumber);