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>
35 #include <FShellNotificationManager.h>
36 #include <FShellNotificationRequest.h>
37 #include <FShellIBadgeEventListener.h>
39 //#include <FBaseInternalTypes.h>
40 #include <FBase_StringConverter.h>
41 #include "FApp_AppInfo.h"
44 #include "FAppPkg_PackageManagerImpl.h"
45 #include "FApp_AppArg.h"
46 #include "FAppPkgPackageAppInfo.h"
47 #include "FAppPkg_PackageAppInfoImpl.h"
48 #include "FShell_NotificationManagerImpl.h"
49 #include "FShell_NotificationRequestImpl.h"
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::App;
54 using namespace Tizen::App::Package;
55 using namespace Tizen::Io;
56 using namespace Tizen::Shell;
58 extern "C" int service_create_request(bundle *data, service_h *service);
59 extern "C" int service_to_bundle(service_h service, bundle** data);
65 ConvertNotificationResult(int error)
69 case NOTIFICATION_ERROR_NONE:
71 case NOTIFICATION_ERROR_INVALID_DATA:
73 case NOTIFICATION_ERROR_NO_MEMORY:
74 return E_OUT_OF_MEMORY;
75 case NOTIFICATION_ERROR_FROM_DB:
77 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
78 return E_OPERATION_FAILED;
79 case NOTIFICATION_ERROR_NOT_EXIST_ID:
80 return E_OPERATION_FAILED;
82 return E_OPERATION_FAILED;
87 IsPosted(ui_notification_h handle)
89 struct ui_notification_s
109 ui_notification_s* pStruct = reinterpret_cast<ui_notification_s*>(handle);
111 return pStruct->posted;
117 namespace Tizen { namespace Shell
120 ///////////////////////////////////////////////////////////////////
122 ///////////////////////////////////////////////////////////////////
124 BadgeChangedCallback(unsigned int action, const char *pkgname, unsigned int count, void *data)
126 Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>* pBadgeEventListenerList = static_cast<Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>*>(data);
127 SysAssert(pBadgeEventListenerList);
129 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(pBadgeEventListenerList->GetEnumeratorN());
130 SysTryReturnVoidResult(NID_APP, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
132 IBadgeEventListener* pListener;
133 while (pEnum->MoveNext() == E_SUCCESS)
136 pEnum->GetCurrent(pListener);
139 SysLog(NID_APP, "pListener is null!");
143 pListener->OnBadgeUpdated(pkgname, count);
148 _BadgeManagerImpl::GetInstance(void)
150 static _BadgeManagerImpl* pTheInstance = null;
151 if( pTheInstance == null)
153 pTheInstance = new (std::nothrow) _BadgeManagerImpl;
154 pTheInstance->Construct();
160 _BadgeManagerImpl::Construct(void)
166 _BadgeManagerImpl::AddPrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
168 if( __primaryBadgeEventListenerList.GetCount() == 0)
170 int ret = badge_register_changed_cb(BadgeChangedCallback, &__primaryBadgeEventListenerList);
171 SysTryReturnResult(NID_APP, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
174 return __primaryBadgeEventListenerList.Add(&primaryListener);
178 _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
180 __primaryBadgeEventListenerList.Remove(&primaryListener);
181 if( __primaryBadgeEventListenerList.GetCount() == 0)
183 int ret = badge_unregister_changed_cb(BadgeChangedCallback);
184 SysTryReturnResult(NID_APP, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
190 ///////////////////////////////////////////////////////////////////
191 // _NotificationManagerImpl
192 ///////////////////////////////////////////////////////////////////
193 _NotificationManagerImpl::_NotificationManagerImpl(void)
194 : __notifyPrivitId(-1)
195 , __notifyPrivitIdForOngoing(-1)
199 _NotificationManagerImpl::~_NotificationManagerImpl(void)
201 bool isListeningBadgeEvent = (__badgeEventListenerList.GetCount() > 0)? true : false;
202 if( isListeningBadgeEvent == true )
204 _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
209 _NotificationManagerImpl::Construct(void)
214 const _NotificationManagerImpl*
215 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
217 return notiMgr.__pNotificationManagerImpl;
220 _NotificationManagerImpl*
221 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
223 return notiMgr.__pNotificationManagerImpl;
227 _NotificationManagerImpl::GetBadgeNumber(void) const
229 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
230 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
232 int count = GetBadgeCount(pAppId.get());
233 SysTryReturn(NID_APP, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
234 GetErrorMessage(E_OPERATION_FAILED));
241 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
243 return NotifyMessage(NOTIFY_TYPE_SIMPLE, isOngoing, notiMessage);
247 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
249 return NotifyMessage(NOTIFY_TYPE_APP_ID, isOngoing, notiMessage, &appId);
254 _NotificationManagerImpl::Notify(int badgeNumber)
256 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
258 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
260 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
263 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
264 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
266 if (badgeNumber == 0)
268 RemoveBadge(pAppId.get());
273 SetBadgeCount(pAppId.get(), badgeNumber);
280 _NotificationManagerImpl::Notify(const String& messageText)
282 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
284 NotificationRequest request;
285 request.SetAlertText(messageText);
286 request.SetAppMessage(L"");
288 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
292 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber)
294 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
295 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
297 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
299 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
302 NotificationRequest request;
303 request.SetAlertText(messageText);
304 request.SetBadgeNumber(badgeNumber);
305 request.SetAppMessage(L"");
307 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
311 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
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.");
315 SysTryReturnResult(NID_APP, launchArguments != null && launchArguments.GetLength() > 0, E_INVALID_ARG,
316 "launchArguments is less than 0.");
318 SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
319 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
321 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
323 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
326 NotificationRequest request;
327 request.SetAlertText(messageText);
328 request.SetBadgeNumber(badgeNumber);
329 request.SetAppMessage(launchArguments);
331 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
335 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
337 bool b = _Aul::IsInstalled(appId);
338 SysTryReturn(NID_APP, b == true, -1, E_APP_NOT_INSTALLED, "[E_OBJ_NOT_FOUND] The application %ls is not installed",
340 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
341 int count = GetBadgeCount(pAppId.get());
343 SysTryReturn(NID_APP, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
344 GetErrorMessage(E_OPERATION_FAILED));
351 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText)
353 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
355 NotificationRequest request;
356 request.SetAlertText(messageText);
358 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
362 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
364 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
365 SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
366 SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
367 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
369 NotificationRequest request;
370 request.SetAlertText(messageText);
371 request.SetAppMessage(launchArguments);
373 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
377 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
379 return RemoveNotificationByAppId(appId, true);
384 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
386 return RemoveNotificationByAppId(appId, false);
390 _NotificationManagerImpl::NotifyTextMessage(const String& messageText) const
392 SysTryReturnResult(NID_APP, !messageText.IsEmpty(), E_INVALID_ARG, "MessageText is less than 0.");
394 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
395 int res = notification_status_message_post(pMsg.get());
397 result r = E_SUCCESS;
400 case NOTIFICATION_ERROR_NONE:
403 case NOTIFICATION_ERROR_INVALID_DATA:
406 case NOTIFICATION_ERROR_IO:
414 SysLog(NID_APP, "[%s] %ls posted.", GetErrorMessage(r), messageText.GetPointer());
419 _NotificationManagerImpl::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
420 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
422 result r = E_SUCCESS;
424 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, false, request, null, &operationId, pUriData, pDataType, pExtraData);
429 _NotificationManagerImpl::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
430 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
432 result r = E_SUCCESS;
434 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, true, request, null, &operationId, pUriData, pDataType, pExtraData);
440 _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing, const NotificationRequest& notifyRequest, const AppId* pAppId,
441 const Tizen::Base::String* pOperationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData)
443 result r = E_SUCCESS;
444 std::unique_ptr<char[]> pAppIdChar(null);
445 const _NotificationRequestImpl* pRequestImpl = _NotificationRequestImpl::GetInstance(notifyRequest);
446 SysTryReturnResult(NID_APP, pRequestImpl != null, E_INVALID_ARG, "Invalid argument is used.");
449 if ((notifyType == NOTIFY_TYPE_SIMPLE) || (notifyType == NOTIFY_TYPE_APP_CONTROL))
451 // char* pkgname = null;
452 // app_get_id(&pkgname); // AppId. (Not package Id)
453 // SysTryReturnResult(NID_APP, pkgname != NULL, E_OBJ_NOT_FOUND,"Cannot acquire package name for current application.");
454 // const String currentAppId(pkgname);
456 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
457 const String currentAppId = pApp->GetAppId();
458 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(currentAppId));
459 pAppIdChar = std::move(pAppIdTemp);
460 SysLog(NID_APP, "app_get_id: %ls", currentAppId.GetPointer());
463 if (notifyType == NOTIFY_TYPE_APP_ID)
465 bool isAppInstalled = _Aul::IsInstalled(*pAppId);
466 SysTryReturnResult(NID_APP, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", pAppId->GetPointer());
467 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(*pAppId));
468 pAppIdChar = std::move(pAppIdTemp);
472 SysTryReturnResult(NID_APP, false, E_INVALID_ARG, "Invalid argument is used.");
475 const int badgeNumber = notifyRequest.GetBadgeNumber();
476 const int badgeOffset = notifyRequest.GetBadgeOffset();
477 const String& contentText = notifyRequest.GetAlertText();
478 // Allow change the badge without other properties.
479 if (badgeNumber != -1 || badgeOffset != -1)
482 if (badgeOffset != 0)
484 int badgeNumber = GetBadgeCount(pAppIdChar.get());
485 if (badgeNumber <= 0)
487 SetBadgeCount(pAppIdChar.get(), badgeOffset);
491 SetBadgeCount(pAppIdChar.get(), badgeNumber + badgeOffset);
496 if (badgeNumber == 0)
498 RemoveBadge(pAppIdChar.get());
503 SetBadgeCount(pAppIdChar.get(), badgeNumber);
506 if (!(isOngoing || !contentText.IsEmpty()))
508 SysLog(NID_APP, "No valid for Notification, just for set a badgeNumber update.");
512 SysTryReturnResult(NID_APP, (isOngoing || !contentText.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. MessageText is Empty");
514 const String& titleText = notifyRequest.GetTitleText();
515 const String& launchArguments = notifyRequest.GetAppMessage();
516 const String& iconPath = notifyRequest.GetIconFilePath();
517 const String& soundPath = notifyRequest.GetSoundFilePath();
518 const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
519 int notiPrivateId = isOngoing ? __notifyPrivitIdForOngoing : __notifyPrivitId;
520 notification_h notiHandle = null;
521 bundle* pBundle = null;
522 bool needUpdate = false;
523 bundle* service_data = null;
525 service_h hSvc = null;
526 notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
528 // Notification creation
529 if (notiPrivateId != -1)
531 notiHandle = notification_load(pAppIdChar.get(), notiPrivateId);
532 SysTryLog(NID_APP, notiHandle != null, "Get notiHandle(%d) from notiPrivateId(%d).", notiHandle, notiPrivateId);
535 if (notiHandle == null)
537 SysLog(NID_APP, "Previous notification(%d) no more valid - create new notification", notiPrivateId);
538 notiPrivateId = -1; // reset
539 notiHandle = notification_create(notiType);
543 needUpdate = true; // No need to notification_insert.
545 SysTryReturnResult(NID_APP, notiHandle != null , E_SYSTEM, "A system error has been occurred. Notification creation/load failed ");
547 // Content text(Alert text)
548 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(contentText));
551 std::unique_ptr<char[]> pTitleText(null);
552 if (!titleText.IsEmpty())
554 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(titleText));
555 pTitleText = std::move(pTitleTextTemp);
559 char* pAppName = null;
560 app_manager_get_app_name(pAppIdChar.get(), &pAppName);
563 String appName(pAppName);
564 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
565 pTitleText = std::move(pTitleTextTemp);
567 //SysLog(NID_APP, "Application Id is %ls.", appName.GetPointer());
571 SysTryLog(NID_APP, pTitleText, "Failed to get title from app_manager_get_app_name for default setting.");
575 std::unique_ptr<char[]> pIconPath(null);
576 if (!iconPath.IsEmpty())
578 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
579 pIconPath = std::move(pIconPathTemp);
583 std::unique_ptr<PackageAppInfo> pPackageAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(pAppIdChar.get()));
584 const String& appIconPath(_PackageAppInfoImpl::GetInstance(pPackageAppInfo.get())->GetAppNotificationIconPath());
586 if (!appIconPath.IsEmpty() && File::IsFileExist(appIconPath))
588 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(appIconPath));
589 pIconPath = std::move(pIconPathTemp);
593 char* pDefaultIconPath = null;
594 app_manager_get_app_icon_path(pAppIdChar.get(), &pDefaultIconPath);
595 if (pDefaultIconPath)
597 String iconPath(pDefaultIconPath);
598 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
599 pIconPath = std::move(pIconPathTemp);
600 free(pDefaultIconPath);
602 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
606 std::unique_ptr<char[]> pSoundPath(null);
607 if (!soundPath.IsEmpty())
609 std::unique_ptr<char[]> pSoundPathTemp(_StringConverter::CopyToCharArrayN(soundPath));
610 pSoundPath = std::move(pSoundPathTemp);
613 if (notifyType == NOTIFY_TYPE_APP_ID)
615 r = ConvertNotificationResult(notification_set_pkgname(notiHandle, pAppIdChar.get()));
616 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Package name failed.", GetErrorMessage(r));
619 if (pTitleText.get())
621 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
622 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
624 // Set - content text
627 r = notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
628 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
630 // Set - icon file path
631 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath.get()));
632 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
633 // Set - sound file path
634 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath.get()));
635 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set sound failed.", GetErrorMessage(r));
637 // Set extended - text, thumbnail and background image
640 // Extended style set
641 String countText = notifyRequest.GetNotificationCountText();
642 NotificationStyle notiStyle= notifyRequest.GetNotificationStyle();
643 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
645 layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
648 if (notiStyle == NOTIFICATION_STYLE_NORMAL && !countText.IsEmpty())
650 layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
653 if (!countText.IsEmpty())
655 std::unique_ptr<char[]> text(_StringConverter::CopyToCharArrayN(countText));
656 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, text.get(),
657 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
660 String bgImageFilePath = notifyRequest.GetBackgroundImageFilePath();
661 if (!bgImageFilePath.IsEmpty() && File::IsFileExist(bgImageFilePath))
663 std::unique_ptr<char[]> pBgImageFilePath(_StringConverter::CopyToCharArrayN(bgImageFilePath));
664 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, pBgImageFilePath.get()));
665 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Background image path failed.", GetErrorMessage(r));
669 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
671 const IList* pThumbnailList = pRequestImpl->GetMessageThumbnailFilePathList();
674 const static notification_image_type_e thumbnailListEnum[] = {NOTIFICATION_IMAGE_TYPE_LIST_1, NOTIFICATION_IMAGE_TYPE_LIST_2,
675 NOTIFICATION_IMAGE_TYPE_LIST_3, NOTIFICATION_IMAGE_TYPE_LIST_4, NOTIFICATION_IMAGE_TYPE_LIST_5 };
676 int itemCount = pThumbnailList->GetCount();
677 const int maxCount = sizeof(thumbnailListEnum)/sizeof(thumbnailListEnum[0]);
678 if (itemCount > maxCount)
680 itemCount = maxCount;
682 for (int i = 0; i < itemCount; i++)
684 const String* pThumbnailPath = static_cast<const String*>(pThumbnailList->GetAt(i));
685 // TODO: check pThumbnailPath
686 std::unique_ptr<char[]> filePath(_StringConverter::CopyToCharArrayN(*pThumbnailPath));
687 r = ConvertNotificationResult(notification_set_image(notiHandle, thumbnailListEnum[i], filePath.get()));
688 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set thumnail path failed.", GetErrorMessage(r));
694 // TODO: Check the valid
695 const IList* pMessageTextList = pRequestImpl->GetMessageTextList();
696 if (pMessageTextList && pMessageTextList->GetCount())
698 const String* pText1 = static_cast<const String*>(pMessageTextList->GetAt(0));
702 if (E_SUCCESS == pText1->IndexOf(L'\t', 0, matchIndex))
706 pText1->SubString(0, matchIndex+1, subText);
707 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
708 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
709 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
710 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
712 if (E_SUCCESS == pText1->SubString(matchIndex+1, subText))
714 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
715 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, rightText.get(),
716 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
717 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Sub Text failed.", GetErrorMessage(r));
722 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText1));
723 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
724 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
725 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
728 const String* pText2 = static_cast<const String*>(pMessageTextList->GetAt(1));
732 // 2.1: Multiple layout has single line text for 2nd information text.
733 if ((layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE && E_SUCCESS) == (pText2->IndexOf(L'\t', 0, matchIndex)))
737 pText2->SubString(0, matchIndex+1, subText);
738 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
739 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
740 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
741 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
743 if (E_SUCCESS == pText2->SubString(matchIndex+1, subText))
745 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
746 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, rightText.get(),
747 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
748 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Sub Text failed.", GetErrorMessage(r));
753 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText2));
754 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
755 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
756 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
762 { // Reset text for update case. also must be check the previous text with get_text
763 char* pRetStr = null;
764 notification_get_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, &pRetStr);
767 const static notification_text_type_e infoTextEnums[] = { NOTIFICATION_TEXT_TYPE_INFO_1, NOTIFICATION_TEXT_TYPE_INFO_SUB_1,
768 NOTIFICATION_TEXT_TYPE_INFO_2, NOTIFICATION_TEXT_TYPE_INFO_SUB_2 };
769 for (unsigned int i = 0; i < sizeof(infoTextEnums)/sizeof(infoTextEnums[0]); i++)
771 notification_set_text(notiHandle, infoTextEnums[i], null, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
779 r = arg.Construct(launchArguments);
780 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
782 pBundle = arg.GetBundle();
784 service_create_request(pBundle, &hSvc);
785 SysTryCatch(NID_APP, hSvc != null, r = E_SYSTEM, r, "[%s] A system error has been occurred. service_create_request failed.", GetErrorMessage(E_SYSTEM));
787 if (notifyType == NOTIFY_TYPE_SIMPLE || notifyType == NOTIFY_TYPE_APP_ID)
789 service_set_app_id(hSvc, pRequestImpl->IsAppBinding() ? pAppIdChar.get() : null);
792 if (notifyType == NOTIFY_TYPE_APP_CONTROL)
795 std::unique_ptr<char[]> pOperationIdChar(_StringConverter::CopyToCharArrayN(*pOperationId));
796 service_set_operation(hSvc, pOperationIdChar.get());
799 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
800 service_set_uri(hSvc, pUri.get());
804 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pDataType));
805 service_set_mime(hSvc, pMime.get());
809 std::unique_ptr<Tizen::Base::Collection::IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
812 while (pMapEnum->MoveNext() == E_SUCCESS)
814 String* pKey = static_cast<String* > (pMapEnum->GetKey());
815 String* pValue = static_cast<String* > (pMapEnum->GetValue());
818 std::unique_ptr<char[]> pKeyString(_StringConverter::CopyToCharArrayN(*pKey));
819 std::unique_ptr<char[]> pValueString(_StringConverter::CopyToCharArrayN(*pValue));
820 service_add_extra_data(hSvc, pKeyString.get(), pValueString.get());
824 SysLog(NID_APP, "pKey or pValue is ivalid.");
831 if (service_to_bundle(hSvc, &service_data) == SERVICE_ERROR_NONE)
833 notification_set_property(notiHandle, 0);
834 notification_set_execute_option(notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
838 SysLog(NID_APP, "service_to_bundle failed");
844 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
845 if (activityType == ONGOING_ACTIVITY_TYPE_TEXT)
847 layout = NOTIFICATION_LY_ONGOING_EVENT;
851 layout = NOTIFICATION_LY_ONGOING_PROGRESS;
854 notification_set_layout(notiHandle, layout);
859 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
860 int progress = notifyRequest.GetOngoingActivityProgress();
862 switch (activityType)
864 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
867 r = ConvertNotificationResult(notification_update_progress(notiHandle, notiPrivateId, progress/100.));
871 r = ConvertNotificationResult(notification_set_progress(notiHandle, progress/100.));
873 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
876 case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
879 r = ConvertNotificationResult(notification_update_size(notiHandle, notiPrivateId, progress));
883 r = ConvertNotificationResult(notification_set_size(notiHandle, progress));
885 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
888 case ONGOING_ACTIVITY_TYPE_TEXT:
893 r = E_OPERATION_FAILED;
898 r = ConvertNotificationResult(notification_update_content(notiHandle, notiPrivateId, pMsg.get()));
900 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
903 // insert for new notification
906 r = ConvertNotificationResult(notification_insert(notiHandle, ¬iPrivateId));
907 SysLog(NID_APP, "Insert notification and get new notiPrivateId(%d)", notiPrivateId);
908 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
911 __notifyPrivitIdForOngoing = notiPrivateId;
915 __notifyPrivitId = notiPrivateId;
919 // notification_update just for non ongoing and text type ongoing only.
920 if (needUpdate && !isOngoing)
922 notification_update(notiHandle);
923 SysLog(NID_APP, "Notification update from notiPrivateId(%d)", notiPrivateId);
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 ? __notifyPrivitIdForOngoing : __notifyPrivitId;
953 if (notiPrivateId != -1)
955 notification_h notiHandle = notification_load(null, notiPrivateId);
958 err = notification_delete(notiHandle);
959 SysLog(NID_APP, "Notification deleted.");
963 SysLog(NID_APP, "Notification already deleted.");
965 notification_free(notiHandle);
969 err = notification_delete_all_by_type(null, notiType);
970 SysLog(NID_APP, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
975 case NOTIFICATION_ERROR_NONE:
979 case NOTIFICATION_ERROR_INVALID_DATA:
992 _NotificationManagerImpl::RemoveNotificationByAppId(const Tizen::App::AppId& appId, bool onGoing)
994 result r = E_SUCCESS;
995 notification_error_e err = NOTIFICATION_ERROR_NONE;
996 bool isValidAppId = _Aul::IsInstalled(appId);
997 SysTryReturnResult(NID_APP, isValidAppId == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
999 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
1000 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
1001 const int notiPrivateId = onGoing ? __notifyPrivitIdForOngoing : __notifyPrivitId;
1003 if (notiPrivateId != -1)
1005 notification_h notiHandle = notification_load(pAppId.get(), notiPrivateId);
1008 err = notification_delete(notiHandle);
1009 SysLog(NID_APP, "Notification deleted.");
1013 SysLog(NID_APP, "Notification already deleted.");
1015 notification_free(notiHandle);
1019 err = notification_delete_all_by_type(pAppId.get(), notiType);
1020 SysLog(NID_APP, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
1025 case NOTIFICATION_ERROR_NONE:
1029 case NOTIFICATION_ERROR_INVALID_DATA:
1042 _NotificationManagerImpl::RemoveBadge(const char* pkgName) const
1044 bool badgeExist = false;
1045 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1046 SysLog(NID_APP, "badge_is_existing: exitst= %d, error= %d.", badgeExist, badgeError); //#####
1049 badgeError = badge_remove(pkgName);
1050 SysLog(NID_APP, "badge_remove: error= %d.", badgeError); //#####
1052 SysLog(NID_APP, "Badge removed.");
1056 _NotificationManagerImpl::SetBadgeCount(const char* pkgName, int badgeCount) const
1059 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1060 SysLog(NID_APP, "badge_is_existing: error= %d.", badgeError); //#####
1063 badgeError = badge_create(pkgName, pkgName);
1064 SysLog(NID_APP, "badge_create: error= %d.", badgeError); //#####
1067 badge_set_count(pkgName, badgeCount);
1068 SysLog(NID_APP, "badge_set_count: badgeNumber= %d.", badgeCount);
1072 _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
1074 unsigned int count = 0;
1076 badge_error_e badgeError = badge_get_count(pkgName, &count);
1077 if (badgeError == BADGE_ERROR_NONE)
1079 SysLog(NID_APP, "badge_get_count: ret= %d.", count);
1084 SysLog(NID_APP, "badge_get_count: error= %d.", badgeError);
1090 _NotificationManagerImpl::AddBadgeEventListener(IBadgeEventListener& listener)
1092 SysTryReturnResult(NID_APP, !__badgeEventListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
1093 SysLog(NID_APP, "(%x)", &listener);
1095 result r = _BadgeManagerImpl::GetInstance()->AddPrimaryBadgeEventListener(*this);
1096 SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "Failed to AddPrimaryBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1098 return __badgeEventListenerList.Add(&listener);
1102 _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener)
1104 SysLog(NID_APP, "(%x)", &listener);
1105 result r = __badgeEventListenerList.Remove(&listener);
1106 SysTryReturn(NID_APP, !IsFailed(r), r, r, "Failed to RemoveBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1108 return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
1112 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
1114 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(__badgeEventListenerList.GetEnumeratorN());
1115 SysTryReturnVoidResult(NID_APP, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
1117 IBadgeEventListener* pListener;
1118 while (pEnum->MoveNext() == E_SUCCESS)
1121 pEnum->GetCurrent(pListener);
1124 SysLog(NID_APP, "pListener is null!");
1127 pListener->OnBadgeUpdated(appId, badgeNumber);