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:
77 return E_OPERATION_FAILED;
78 case NOTIFICATION_ERROR_NOT_EXIST_ID:
79 return E_OPERATION_FAILED;
81 return E_OPERATION_FAILED;
86 IsPosted(ui_notification_h handle)
88 struct ui_notification_s
108 ui_notification_s* pStruct = reinterpret_cast<ui_notification_s*>(handle);
110 return pStruct->posted;
116 namespace Tizen { namespace Shell
119 ///////////////////////////////////////////////////////////////////
121 ///////////////////////////////////////////////////////////////////
123 BadgeChangedCallback(unsigned int action, const char *pkgname, unsigned int count, void *data)
125 Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>* pBadgeEventListenerList = static_cast<Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>*>(data);
126 SysAssert(pBadgeEventListenerList);
128 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(pBadgeEventListenerList->GetEnumeratorN());
129 SysTryReturnVoidResult(NID_APP, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
131 IBadgeEventListener* pListener;
132 while (pEnum->MoveNext() == E_SUCCESS)
135 pEnum->GetCurrent(pListener);
138 SysLog(NID_APP, "pListener is null!");
142 pListener->OnBadgeUpdated(pkgname, count);
147 _BadgeManagerImpl::GetInstance(void)
149 static _BadgeManagerImpl* pTheInstance = null;
150 if( pTheInstance == null)
152 pTheInstance = new (std::nothrow) _BadgeManagerImpl;
153 pTheInstance->Construct();
159 _BadgeManagerImpl::Construct(void)
165 _BadgeManagerImpl::AddPrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
167 if( __primaryBadgeEventListenerList.GetCount() == 0)
169 int ret = badge_register_changed_cb(BadgeChangedCallback, &__primaryBadgeEventListenerList);
170 SysTryReturnResult(NID_APP, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
173 return __primaryBadgeEventListenerList.Add(&primaryListener);
177 _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
179 __primaryBadgeEventListenerList.Remove(&primaryListener);
180 if( __primaryBadgeEventListenerList.GetCount() == 0)
182 int ret = badge_unregister_changed_cb(BadgeChangedCallback);
183 SysTryReturnResult(NID_APP, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
189 ///////////////////////////////////////////////////////////////////
190 // _NotificationManagerImpl
191 ///////////////////////////////////////////////////////////////////
192 _NotificationManagerImpl::_NotificationManagerImpl(void)
193 : __notifyPrivateId(-1)
194 , __notifyPrivateIdForOngoing(-1)
198 _NotificationManagerImpl::~_NotificationManagerImpl(void)
200 bool isListeningBadgeEvent = (__badgeEventListenerList.GetCount() > 0)? true : false;
201 if( isListeningBadgeEvent == true )
203 _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
208 _NotificationManagerImpl::Construct(void)
213 const _NotificationManagerImpl*
214 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
216 return notiMgr.__pNotificationManagerImpl;
219 _NotificationManagerImpl*
220 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
222 return notiMgr.__pNotificationManagerImpl;
226 _NotificationManagerImpl::GetBadgeNumber(void) const
228 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
229 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
231 int count = GetBadgeCount(pAppId.get());
232 SysTryReturn(NID_APP, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
233 GetErrorMessage(E_OPERATION_FAILED));
240 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
242 return NotifyMessage(NOTIFY_TYPE_SIMPLE, isOngoing, notiMessage);
246 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
248 return NotifyMessage(NOTIFY_TYPE_APP_ID, isOngoing, notiMessage, &appId);
253 _NotificationManagerImpl::Notify(int badgeNumber)
255 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
257 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
259 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
262 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
263 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
265 if (badgeNumber == 0)
267 RemoveBadge(pAppId.get());
272 SetBadgeCount(pAppId.get(), badgeNumber);
279 _NotificationManagerImpl::Notify(const String& messageText)
281 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
283 NotificationRequest request;
284 request.SetAlertText(messageText);
285 request.SetAppMessage(L"");
287 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
291 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber)
293 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
294 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
296 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
298 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
301 NotificationRequest request;
302 request.SetAlertText(messageText);
303 request.SetBadgeNumber(badgeNumber);
304 request.SetAppMessage(L"");
306 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
310 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
312 SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
313 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
314 SysTryReturnResult(NID_APP, launchArguments != null && launchArguments.GetLength() > 0, E_INVALID_ARG,
315 "launchArguments is less than 0.");
317 SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
318 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
320 if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER)
322 badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER;
325 NotificationRequest request;
326 request.SetAlertText(messageText);
327 request.SetBadgeNumber(badgeNumber);
328 request.SetAppMessage(launchArguments);
330 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
334 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
336 bool b = _Aul::IsInstalled(appId);
337 SysTryReturn(NID_APP, b == true, -1, E_APP_NOT_INSTALLED, "[E_OBJ_NOT_FOUND] The application %ls is not installed",
339 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
340 int count = GetBadgeCount(pAppId.get());
342 SysTryReturn(NID_APP, count != -1, count, E_OPERATION_FAILED, "[%s] The operation has failed. Badge may not exist.",
343 GetErrorMessage(E_OPERATION_FAILED));
350 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText)
352 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
354 NotificationRequest request;
355 request.SetAlertText(messageText);
357 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
361 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
363 SysTryReturnResult(NID_APP, messageText.GetLength() > 0, E_INVALID_ARG, "MessageText is less than 0.");
364 SysTryReturnResult(NID_APP, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
365 SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
366 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
368 NotificationRequest request;
369 request.SetAlertText(messageText);
370 request.SetAppMessage(launchArguments);
372 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
376 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
378 return RemoveNotificationByAppId(appId, true);
383 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
385 return RemoveNotificationByAppId(appId, false);
389 _NotificationManagerImpl::NotifyTextMessage(const String& messageText) const
391 SysTryReturnResult(NID_APP, !messageText.IsEmpty(), E_INVALID_ARG, "MessageText is less than 0.");
393 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
394 int res = notification_status_message_post(pMsg.get());
396 result r = E_SUCCESS;
399 case NOTIFICATION_ERROR_NONE:
402 case NOTIFICATION_ERROR_INVALID_DATA:
405 case NOTIFICATION_ERROR_IO:
413 SysLog(NID_APP, "[%s] %ls posted.", GetErrorMessage(r), messageText.GetPointer());
418 _NotificationManagerImpl::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
419 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
421 result r = E_SUCCESS;
423 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, false, request, null, &operationId, pUriData, pDataType, pExtraData);
428 _NotificationManagerImpl::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
429 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
431 result r = E_SUCCESS;
433 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, true, request, null, &operationId, pUriData, pDataType, pExtraData);
439 _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing, const NotificationRequest& notifyRequest, const AppId* pAppId,
440 const Tizen::Base::String* pOperationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData)
442 result r = E_SUCCESS;
443 std::unique_ptr<char[]> pAppIdChar(null);
444 const _NotificationRequestImpl* pRequestImpl = _NotificationRequestImpl::GetInstance(notifyRequest);
445 SysTryReturnResult(NID_APP, pRequestImpl != null, E_INVALID_ARG, "Invalid argument is used.");
448 if ((notifyType == NOTIFY_TYPE_SIMPLE) || (notifyType == NOTIFY_TYPE_APP_CONTROL))
450 // char* pkgname = null;
451 // app_get_id(&pkgname); // AppId. (Not package Id)
452 // SysTryReturnResult(NID_APP, pkgname != NULL, E_OBJ_NOT_FOUND,"Cannot acquire package name for current application.");
453 // const String currentAppId(pkgname);
455 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
456 const String currentAppId = pApp->GetAppId();
457 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(currentAppId));
458 pAppIdChar = std::move(pAppIdTemp);
459 SysLog(NID_APP, "app_get_id: %ls", currentAppId.GetPointer());
462 if (notifyType == NOTIFY_TYPE_APP_ID)
464 bool isAppInstalled = _Aul::IsInstalled(*pAppId);
465 SysTryReturnResult(NID_APP, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", pAppId->GetPointer());
466 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(*pAppId));
467 pAppIdChar = std::move(pAppIdTemp);
471 SysTryReturnResult(NID_APP, false, E_INVALID_ARG, "Invalid argument is used.");
474 const int badgeNumber = notifyRequest.GetBadgeNumber();
475 const int badgeOffset = notifyRequest.GetBadgeOffset();
476 const String& contentText = notifyRequest.GetAlertText();
477 // Allow change the badge without other properties.
478 if (badgeNumber != -1 || badgeOffset != -1)
481 if (badgeOffset != 0)
483 int badgeNumber = GetBadgeCount(pAppIdChar.get());
484 if (badgeNumber <= 0)
486 SetBadgeCount(pAppIdChar.get(), badgeOffset);
490 SetBadgeCount(pAppIdChar.get(), badgeNumber + badgeOffset);
495 if (badgeNumber == 0)
497 RemoveBadge(pAppIdChar.get());
502 SetBadgeCount(pAppIdChar.get(), badgeNumber);
505 if (!(isOngoing || !contentText.IsEmpty()))
507 SysLog(NID_APP, "No valid for Notification, just for set a badgeNumber update.");
511 SysTryReturnResult(NID_APP, (isOngoing || !contentText.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. MessageText is Empty");
513 const String& titleText = notifyRequest.GetTitleText();
514 const String& launchArguments = notifyRequest.GetAppMessage();
515 const String& iconPath = notifyRequest.GetIconFilePath();
516 const String& soundPath = notifyRequest.GetSoundFilePath();
517 const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
518 int notiPrivateId = isOngoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
519 notification_h notiHandle = null;
520 bundle* pBundle = null;
521 bool needUpdate = false;
522 bundle* service_data = null;
524 service_h hSvc = null;
525 notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
527 // Notification creation
528 if (notiPrivateId != -1)
530 notiHandle = notification_load(pAppIdChar.get(), notiPrivateId);
531 SysTryLog(NID_APP, notiHandle != null, "Get notiHandle(%d) from notiPrivateId(%d).", notiHandle, notiPrivateId);
534 if (notiHandle == null)
536 SysLog(NID_APP, "Previous notification(%d) no more valid - create new notification", notiPrivateId);
537 notiPrivateId = -1; // reset
538 notiHandle = notification_create(notiType);
542 needUpdate = true; // No need to notification_insert.
544 SysTryReturnResult(NID_APP, notiHandle != null , E_SYSTEM, "A system error has been occurred. Notification creation/load failed ");
546 // Content text(Alert text)
547 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(contentText));
550 std::unique_ptr<char[]> pTitleText(null);
551 if (!titleText.IsEmpty())
553 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(titleText));
554 pTitleText = std::move(pTitleTextTemp);
558 char* pAppName = null;
559 app_manager_get_app_name(pAppIdChar.get(), &pAppName);
562 String appName(pAppName);
563 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
564 pTitleText = std::move(pTitleTextTemp);
566 //SysLog(NID_APP, "Application Id is %ls.", appName.GetPointer());
570 SysTryLog(NID_APP, pTitleText, "Failed to get title from app_manager_get_app_name for default setting.");
574 std::unique_ptr<char[]> pIconPath(null);
575 if (!iconPath.IsEmpty())
577 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
578 pIconPath = std::move(pIconPathTemp);
582 std::unique_ptr<PackageAppInfo> pPackageAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(pAppIdChar.get()));
583 const String& appIconPath(_PackageAppInfoImpl::GetInstance(pPackageAppInfo.get())->GetAppNotificationIconPath());
585 if (!appIconPath.IsEmpty() && File::IsFileExist(appIconPath))
587 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(appIconPath));
588 pIconPath = std::move(pIconPathTemp);
592 char* pDefaultIconPath = null;
593 app_manager_get_app_icon_path(pAppIdChar.get(), &pDefaultIconPath);
594 if (pDefaultIconPath)
596 String iconPath(pDefaultIconPath);
597 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
598 pIconPath = std::move(pIconPathTemp);
599 free(pDefaultIconPath);
601 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
605 std::unique_ptr<char[]> pSoundPath(null);
606 if (!soundPath.IsEmpty())
608 std::unique_ptr<char[]> pSoundPathTemp(_StringConverter::CopyToCharArrayN(soundPath));
609 pSoundPath = std::move(pSoundPathTemp);
612 if (notifyType == NOTIFY_TYPE_APP_ID)
614 r = ConvertNotificationResult(notification_set_pkgname(notiHandle, pAppIdChar.get()));
615 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Package name failed.", GetErrorMessage(r));
618 if (pTitleText.get())
620 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
621 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
623 // Set - content text
626 r = notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
627 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
629 // Set - icon file path
630 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath.get()));
631 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
632 // Set - sound file path
633 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath.get()));
634 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set sound failed.", GetErrorMessage(r));
636 // Set extended - text, thumbnail and background image
639 // Extended style set
640 String countText = notifyRequest.GetNotificationCountText();
641 NotificationStyle notiStyle= notifyRequest.GetNotificationStyle();
642 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
644 layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
647 if (notiStyle == NOTIFICATION_STYLE_NORMAL && !countText.IsEmpty())
649 layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
652 if (!countText.IsEmpty())
654 std::unique_ptr<char[]> text(_StringConverter::CopyToCharArrayN(countText));
655 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, text.get(),
656 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
659 String bgImageFilePath = notifyRequest.GetBackgroundImageFilePath();
660 if (!bgImageFilePath.IsEmpty() && File::IsFileExist(bgImageFilePath))
662 std::unique_ptr<char[]> pBgImageFilePath(_StringConverter::CopyToCharArrayN(bgImageFilePath));
663 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, pBgImageFilePath.get()));
664 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Background image path failed.", GetErrorMessage(r));
668 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
670 const IList* pThumbnailList = pRequestImpl->GetMessageThumbnailFilePathList();
673 const static notification_image_type_e thumbnailListEnum[] = {NOTIFICATION_IMAGE_TYPE_LIST_1, NOTIFICATION_IMAGE_TYPE_LIST_2,
674 NOTIFICATION_IMAGE_TYPE_LIST_3, NOTIFICATION_IMAGE_TYPE_LIST_4, NOTIFICATION_IMAGE_TYPE_LIST_5 };
675 int itemCount = pThumbnailList->GetCount();
676 const int maxCount = sizeof(thumbnailListEnum)/sizeof(thumbnailListEnum[0]);
677 if (itemCount > maxCount)
679 itemCount = maxCount;
681 for (int i = 0; i < itemCount; i++)
683 const String* pThumbnailPath = static_cast<const String*>(pThumbnailList->GetAt(i));
684 // TODO: check pThumbnailPath
685 std::unique_ptr<char[]> filePath(_StringConverter::CopyToCharArrayN(*pThumbnailPath));
686 r = ConvertNotificationResult(notification_set_image(notiHandle, thumbnailListEnum[i], filePath.get()));
687 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set thumnail path failed.", GetErrorMessage(r));
693 // TODO: Check the valid
694 const IList* pMessageTextList = pRequestImpl->GetMessageTextList();
695 if (pMessageTextList && pMessageTextList->GetCount())
697 const String* pText1 = static_cast<const String*>(pMessageTextList->GetAt(0));
701 if (E_SUCCESS == pText1->IndexOf(L'\t', 0, matchIndex))
705 pText1->SubString(0, matchIndex+1, subText);
706 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
707 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
708 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
709 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
711 if (E_SUCCESS == pText1->SubString(matchIndex+1, subText))
713 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
714 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, rightText.get(),
715 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
716 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Sub Text failed.", GetErrorMessage(r));
721 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText1));
722 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
723 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
724 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
727 const String* pText2 = static_cast<const String*>(pMessageTextList->GetAt(1));
731 // 2.1: Multiple layout has single line text for 2nd information text.
732 if ((layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE && E_SUCCESS) == (pText2->IndexOf(L'\t', 0, matchIndex)))
736 pText2->SubString(0, matchIndex+1, subText);
737 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
738 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
739 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
740 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
742 if (E_SUCCESS == pText2->SubString(matchIndex+1, subText))
744 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
745 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, rightText.get(),
746 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
747 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Sub Text failed.", GetErrorMessage(r));
752 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText2));
753 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
754 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
755 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Info1 Text failed.", GetErrorMessage(r));
761 { // Reset text for update case. also must be check the previous text with get_text
762 char* pRetStr = null;
763 notification_get_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, &pRetStr);
766 const static notification_text_type_e infoTextEnums[] = { NOTIFICATION_TEXT_TYPE_INFO_1, NOTIFICATION_TEXT_TYPE_INFO_SUB_1,
767 NOTIFICATION_TEXT_TYPE_INFO_2, NOTIFICATION_TEXT_TYPE_INFO_SUB_2 };
768 for (unsigned int i = 0; i < sizeof(infoTextEnums)/sizeof(infoTextEnums[0]); i++)
770 notification_set_text(notiHandle, infoTextEnums[i], null, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
778 r = arg.Construct(launchArguments);
779 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
781 pBundle = arg.GetBundle();
783 service_create_request(pBundle, &hSvc);
784 SysTryCatch(NID_APP, hSvc != null, r = E_SYSTEM, r, "[%s] A system error has been occurred. service_create_request failed.", GetErrorMessage(E_SYSTEM));
786 if (notifyType == NOTIFY_TYPE_SIMPLE || notifyType == NOTIFY_TYPE_APP_ID)
788 service_set_app_id(hSvc, pRequestImpl->IsAppBinding() ? pAppIdChar.get() : null);
791 if (notifyType == NOTIFY_TYPE_APP_CONTROL)
794 std::unique_ptr<char[]> pOperationIdChar(_StringConverter::CopyToCharArrayN(*pOperationId));
795 service_set_operation(hSvc, pOperationIdChar.get());
798 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
799 service_set_uri(hSvc, pUri.get());
803 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pDataType));
804 service_set_mime(hSvc, pMime.get());
808 std::unique_ptr<Tizen::Base::Collection::IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
811 while (pMapEnum->MoveNext() == E_SUCCESS)
813 String* pKey = static_cast<String* > (pMapEnum->GetKey());
814 String* pValue = static_cast<String* > (pMapEnum->GetValue());
817 std::unique_ptr<char[]> pKeyString(_StringConverter::CopyToCharArrayN(*pKey));
818 std::unique_ptr<char[]> pValueString(_StringConverter::CopyToCharArrayN(*pValue));
819 service_add_extra_data(hSvc, pKeyString.get(), pValueString.get());
823 SysLog(NID_APP, "pKey or pValue is ivalid.");
830 if (service_to_bundle(hSvc, &service_data) == SERVICE_ERROR_NONE)
832 notification_set_property(notiHandle, 0);
833 notification_set_execute_option(notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
837 SysLog(NID_APP, "service_to_bundle failed");
843 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
844 if (activityType == ONGOING_ACTIVITY_TYPE_TEXT)
846 layout = NOTIFICATION_LY_ONGOING_EVENT;
850 layout = NOTIFICATION_LY_ONGOING_PROGRESS;
853 notification_set_layout(notiHandle, layout);
858 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
859 int progress = notifyRequest.GetOngoingActivityProgress();
861 switch (activityType)
863 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
866 ConvertNotificationResult(notification_update_size(notiHandle, notiPrivateId, 0)); // Reset for override BYTE type
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 ConvertNotificationResult(notification_update_progress(notiHandle, notiPrivateId, 0.0)); // Reset for override PERCENTAGE type
880 r = ConvertNotificationResult(notification_update_size(notiHandle, notiPrivateId, progress));
884 r = ConvertNotificationResult(notification_set_size(notiHandle, progress));
886 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
889 case ONGOING_ACTIVITY_TYPE_TEXT:
890 ConvertNotificationResult(notification_update_progress(notiHandle, notiPrivateId, 0.0)); // Reset the progress
891 ConvertNotificationResult(notification_update_size(notiHandle, notiPrivateId, 0));
895 r = E_OPERATION_FAILED;
900 r = ConvertNotificationResult(notification_update_content(notiHandle, notiPrivateId, pMsg.get()));
902 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
905 // insert for new notification
908 r = ConvertNotificationResult(notification_insert(notiHandle, ¬iPrivateId));
909 SysLog(NID_APP, "Insert notification and get new notiPrivateId(%d)", notiPrivateId);
910 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
913 __notifyPrivateIdForOngoing = notiPrivateId;
917 __notifyPrivateId = notiPrivateId;
921 // notification_update just for non ongoing and text type ongoing only.
922 if (needUpdate && !isOngoing)
924 notification_update(notiHandle);
925 SysLog(NID_APP, "Notification update from notiPrivateId(%d)", notiPrivateId);
930 service_destroy(hSvc);
931 notification_free(notiHandle);
936 _NotificationManagerImpl::RemoveNotification(void)
938 return RemoveNotification(false);
942 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
944 return RemoveNotification(true);
948 _NotificationManagerImpl::RemoveNotification(bool onGoing)
950 result r = E_SUCCESS;
951 notification_error_e err = NOTIFICATION_ERROR_NONE;
952 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
953 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
955 if (notiPrivateId != -1)
957 notification_h notiHandle = notification_load(null, notiPrivateId);
960 err = notification_delete(notiHandle);
961 SysLog(NID_APP, "Notification deleted.");
965 SysLog(NID_APP, "Notification already deleted.");
967 notification_free(notiHandle);
971 err = notification_delete_all_by_type(null, notiType);
972 SysLog(NID_APP, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
977 case NOTIFICATION_ERROR_NONE:
981 case NOTIFICATION_ERROR_INVALID_DATA:
994 _NotificationManagerImpl::RemoveNotificationByAppId(const Tizen::App::AppId& appId, bool onGoing)
996 result r = E_SUCCESS;
997 notification_error_e err = NOTIFICATION_ERROR_NONE;
998 bool isValidAppId = _Aul::IsInstalled(appId);
999 SysTryReturnResult(NID_APP, isValidAppId == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
1001 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
1002 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
1003 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
1005 if (notiPrivateId != -1)
1007 notification_h notiHandle = notification_load(pAppId.get(), notiPrivateId);
1010 err = notification_delete(notiHandle);
1011 SysLog(NID_APP, "Notification deleted.");
1015 SysLog(NID_APP, "Notification already deleted.");
1017 notification_free(notiHandle);
1021 err = notification_delete_all_by_type(pAppId.get(), notiType);
1022 SysLog(NID_APP, "All [%s] notification deleted.", onGoing ? "Ongoing" : "Normal");
1027 case NOTIFICATION_ERROR_NONE:
1031 case NOTIFICATION_ERROR_INVALID_DATA:
1044 _NotificationManagerImpl::RemoveBadge(const char* pkgName) const
1046 bool badgeExist = false;
1047 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1048 SysLog(NID_APP, "badge_is_existing: exitst= %d, error= %d.", badgeExist, badgeError); //#####
1051 badgeError = badge_remove(pkgName);
1052 SysLog(NID_APP, "badge_remove: error= %d.", badgeError); //#####
1054 SysLog(NID_APP, "Badge removed.");
1058 _NotificationManagerImpl::SetBadgeCount(const char* pkgName, int badgeCount) const
1061 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1062 SysLog(NID_APP, "badge_is_existing: error= %d.", badgeError); //#####
1065 badgeError = badge_create(pkgName, pkgName);
1066 SysLog(NID_APP, "badge_create: error= %d.", badgeError); //#####
1069 badge_set_count(pkgName, badgeCount);
1070 SysLog(NID_APP, "badge_set_count: badgeNumber= %d.", badgeCount);
1074 _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
1076 unsigned int count = 0;
1078 badge_error_e badgeError = badge_get_count(pkgName, &count);
1079 if (badgeError == BADGE_ERROR_NONE)
1081 SysLog(NID_APP, "badge_get_count: ret= %d.", count);
1086 SysLog(NID_APP, "badge_get_count: error= %d.", badgeError);
1092 _NotificationManagerImpl::AddBadgeEventListener(IBadgeEventListener& listener)
1094 SysTryReturnResult(NID_APP, !__badgeEventListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
1095 SysLog(NID_APP, "(%x)", &listener);
1097 result r = _BadgeManagerImpl::GetInstance()->AddPrimaryBadgeEventListener(*this);
1098 SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "Failed to AddPrimaryBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1100 return __badgeEventListenerList.Add(&listener);
1104 _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener)
1106 SysLog(NID_APP, "(%x)", &listener);
1107 result r = __badgeEventListenerList.Remove(&listener);
1108 SysTryReturn(NID_APP, !IsFailed(r), r, r, "Failed to RemoveBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1110 return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
1114 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
1116 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(__badgeEventListenerList.GetEnumeratorN());
1117 SysTryReturnVoidResult(NID_APP, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
1119 IBadgeEventListener* pListener;
1120 while (pEnum->MoveNext() == E_SUCCESS)
1123 pEnum->GetCurrent(pListener);
1126 SysLog(NID_APP, "pListener is null!");
1129 pListener->OnBadgeUpdated(appId, badgeNumber);