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 "FBase_StringConverter.h"
39 #include "FApp_AppInfo.h"
42 #include "FAppPkg_PackageManagerImpl.h"
43 #include "FApp_AppArg.h"
44 #include "FAppPkgPackageAppInfo.h"
45 #include "FAppPkg_PackageAppInfoImpl.h"
46 #include "FShell_NotificationManagerImpl.h"
47 #include "FShell_NotificationRequestImpl.h"
49 using namespace Tizen::Base;
50 using namespace Tizen::Base::Collection;
51 using namespace Tizen::App;
52 using namespace Tizen::App::Package;
53 using namespace Tizen::Io;
54 using namespace Tizen::Shell;
56 extern "C" int service_create_request(bundle *data, service_h *service);
57 extern "C" int service_to_bundle(service_h service, bundle** data);
63 ConvertNotificationResult(int error)
67 case NOTIFICATION_ERROR_NONE:
69 case NOTIFICATION_ERROR_INVALID_DATA:
71 case NOTIFICATION_ERROR_NO_MEMORY:
72 return E_OUT_OF_MEMORY;
73 case NOTIFICATION_ERROR_FROM_DB:
75 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
77 case NOTIFICATION_ERROR_NOT_EXIST_ID:
78 return E_OPERATION_FAILED;
80 return E_OPERATION_FAILED;
85 ConvertAppManagerResult(int error)
89 case APP_MANAGER_ERROR_NONE:
91 case APP_MANAGER_ERROR_INVALID_PARAMETER:
93 case APP_MANAGER_ERROR_INVALID_PACKAGE:
95 case NOTIFICATION_ERROR_NO_MEMORY:
96 return E_OUT_OF_MEMORY;
97 case APP_MANAGER_ERROR_DB_FAILED:
98 return E_OPERATION_FAILED;
100 return E_OPERATION_FAILED;
107 namespace Tizen { namespace Shell
110 ///////////////////////////////////////////////////////////////////
112 ///////////////////////////////////////////////////////////////////
114 BadgeChangedCallback(unsigned int action, const char *pkgname, unsigned int count, void *data)
116 Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>* pBadgeEventListenerList = static_cast<Tizen::Base::Collection::LinkedListT<Tizen::Shell::IBadgeEventListener*>*>(data);
117 SysAssert(pBadgeEventListenerList);
119 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(pBadgeEventListenerList->GetEnumeratorN());
120 SysTryReturnVoidResult(NID_SHELL, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
122 IBadgeEventListener* pListener;
123 while (pEnum->MoveNext() == E_SUCCESS)
126 pEnum->GetCurrent(pListener);
129 SysLog(NID_SHELL, "pListener is null!");
133 pListener->OnBadgeUpdated(pkgname, count);
138 _BadgeManagerImpl::GetInstance(void)
140 static _BadgeManagerImpl* pTheInstance = null;
141 if (pTheInstance == null)
143 pTheInstance = new (std::nothrow) _BadgeManagerImpl;
144 SysTryReturn(NID_SHELL, pTheInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
146 pTheInstance->Construct();
152 _BadgeManagerImpl::Construct(void)
158 _BadgeManagerImpl::AddPrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
160 if( __primaryBadgeEventListenerList.GetCount() == 0)
162 int ret = badge_register_changed_cb(BadgeChangedCallback, &__primaryBadgeEventListenerList);
163 SysTryReturnResult(NID_SHELL, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_register_changed_cb, (%d)", ret);
166 return __primaryBadgeEventListenerList.Add(&primaryListener);
170 _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryListener)
172 __primaryBadgeEventListenerList.Remove(&primaryListener);
173 if( __primaryBadgeEventListenerList.GetCount() == 0)
175 int ret = badge_unregister_changed_cb(BadgeChangedCallback);
176 SysTryReturnResult(NID_SHELL, ret == BADGE_ERROR_NONE, E_SYSTEM, "Failed to badge_unregister_changed_cb, (%d)", ret);
182 ///////////////////////////////////////////////////////////////////
183 // _NotificationManagerImpl
184 ///////////////////////////////////////////////////////////////////
185 _NotificationManagerImpl::_NotificationManagerImpl(void)
186 : __notifyPrivateId(-1)
187 , __notifyPrivateIdForOngoing(-1)
191 _NotificationManagerImpl::~_NotificationManagerImpl(void)
193 bool isListeningBadgeEvent = (__badgeEventListenerList.GetCount() > 0)? true : false;
194 if(isListeningBadgeEvent == true)
196 _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
201 _NotificationManagerImpl::Construct(void)
206 const _NotificationManagerImpl*
207 _NotificationManagerImpl::GetInstance(const NotificationManager& notiMgr)
209 return notiMgr.__pNotificationManagerImpl;
212 _NotificationManagerImpl*
213 _NotificationManagerImpl::GetInstance(NotificationManager& notiMgr)
215 return notiMgr.__pNotificationManagerImpl;
219 _NotificationManagerImpl::GetBadgeNumber(void) const
223 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
224 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
226 int count = GetBadgeCount(pAppId.get());
227 SysTryReturn(NID_SHELL, count != -1, count, E_OPERATION_FAILED, "[E_OPERATION_FAILED] The operation has failed. Badge may not exist.");
233 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
235 return NotifyMessage(NOTIFY_TYPE_SIMPLE, isOngoing, notiMessage);
239 _NotificationManagerImpl::NotifyMessageImpl(const AppId& appId, const NotificationRequest& notiMessage, bool isOngoing)
241 return NotifyMessage(NOTIFY_TYPE_APP_ID, isOngoing, notiMessage, &appId);
246 _NotificationManagerImpl::Notify(int badgeNumber)
248 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
249 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
251 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
252 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(pApp->GetAppId()));
254 result r = E_SUCCESS;
256 if (badgeNumber == 0)
258 r = RemoveBadge(pAppId.get());
259 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to remove the badge.");
264 r = SetBadgeCount(pAppId.get(), badgeNumber);
265 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to set the badge.");
272 _NotificationManagerImpl::Notify(const String& messageText)
274 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
275 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
277 NotificationRequest request;
278 request.SetAlertText(messageText);
279 request.SetAppMessage(L"");
281 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
285 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber)
287 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
288 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
289 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
290 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
292 NotificationRequest request;
293 request.SetAlertText(messageText);
294 request.SetBadgeNumber(badgeNumber);
295 request.SetAppMessage(L"");
297 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
301 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
303 SysTryReturnResult(NID_SHELL, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
304 "badgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
305 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
306 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
307 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() > 0 && launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
308 "launchArguments is less than 1 or greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
310 NotificationRequest request;
311 request.SetAlertText(messageText);
312 request.SetBadgeNumber(badgeNumber);
313 request.SetAppMessage(launchArguments);
315 return NotifyMessage(NOTIFY_TYPE_SIMPLE, false, request);
319 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
323 bool b = _Aul::IsInstalled(appId);
324 SysTryReturn(NID_SHELL, b == true, -1, E_APP_NOT_INSTALLED, "[E_APP_NOT_INSTALLED] The application %ls is not installed",
326 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
327 int count = GetBadgeCount(pAppId.get());
329 SysTryReturn(NID_SHELL, count != -1, count, E_OPERATION_FAILED, "[E_OPERATION_FAILED] The operation has failed. Badge may not exist.");
335 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText)
337 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
338 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
340 NotificationRequest request;
341 request.SetAlertText(messageText);
343 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
347 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
349 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
350 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
351 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() > 0, E_INVALID_ARG, "launchArguments is less than 0.");
352 SysTryReturnResult(NID_SHELL, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
353 "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
355 NotificationRequest request;
356 request.SetAlertText(messageText);
357 request.SetAppMessage(launchArguments);
359 return NotifyMessage(NOTIFY_TYPE_SIMPLE, true, request);
363 _NotificationManagerImpl::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
365 return RemoveNotificationByAppId(appId, true);
370 _NotificationManagerImpl::RemoveNotificationByAppId(const AppId& appId)
372 return RemoveNotificationByAppId(appId, false);
376 _NotificationManagerImpl::NotifyTextMessage(const String& messageText) const
378 SysTryReturnResult(NID_SHELL, messageText.GetLength() > 0 && messageText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
379 "messageText is less than 1 or greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
381 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
382 int res = notification_status_message_post(pMsg.get());
384 result r = E_SUCCESS;
387 case NOTIFICATION_ERROR_NONE:
390 case NOTIFICATION_ERROR_INVALID_DATA:
393 case NOTIFICATION_ERROR_IO:
394 r = E_OPERATION_FAILED;
397 r = E_OPERATION_FAILED;
401 SysLog(NID_SHELL, "[%s] %ls posted.", GetErrorMessage(r), messageText.GetPointer());
406 _NotificationManagerImpl::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
407 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
409 result r = E_SUCCESS;
411 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, false, request, null, &operationId, pUriData, pDataType, pExtraData);
416 _NotificationManagerImpl::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
417 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
419 result r = E_SUCCESS;
421 r = NotifyMessage(NOTIFY_TYPE_APP_CONTROL, true, request, null, &operationId, pUriData, pDataType, pExtraData);
428 // E_APP_NOT_INSTALLED - If AppId is invalid, it can occur.
429 // E_OPERATION_FAILED
433 _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing, const NotificationRequest& notifyRequest, const AppId* pAppId,
434 const Tizen::Base::String* pOperationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData)
436 result r = E_SUCCESS;
437 std::unique_ptr<char[]> pAppIdChar(null);
438 const _NotificationRequestImpl* pRequestImpl = _NotificationRequestImpl::GetInstance(notifyRequest);
439 SysTryReturnResult(NID_SHELL, pRequestImpl != null, E_INVALID_ARG, "Invalid argument is used.");
442 if ((notifyType == NOTIFY_TYPE_SIMPLE) || (notifyType == NOTIFY_TYPE_APP_CONTROL))
444 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
445 const String currentAppId = pApp->GetAppId();
446 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(currentAppId));
447 pAppIdChar = std::move(pAppIdTemp);
448 SysLog(NID_SHELL, "App ID is %ls.", currentAppId.GetPointer());
451 if (notifyType == NOTIFY_TYPE_APP_ID)
453 bool isAppInstalled = _Aul::IsInstalled(*pAppId);
454 SysTryReturnResult(NID_SHELL, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed.", pAppId->GetPointer());
455 std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(*pAppId));
456 pAppIdChar = std::move(pAppIdTemp);
460 SysTryReturnResult(NID_SHELL, false, E_INVALID_ARG, "Invalid argument is used.");
463 const int badgeNumber = notifyRequest.GetBadgeNumber();
464 const int badgeOffset = notifyRequest.GetBadgeOffset();
465 const String& contentText = notifyRequest.GetAlertText();
466 // Allow change the badge without other properties.
467 if (badgeNumber != -1 || badgeOffset != -1)
470 if (badgeOffset != 0)
472 int badgeNumber = GetBadgeCount(pAppIdChar.get());
473 if (badgeNumber <= 0)
475 SetBadgeCount(pAppIdChar.get(), badgeOffset);
479 SetBadgeCount(pAppIdChar.get(), badgeNumber + badgeOffset);
484 if (badgeNumber == 0)
486 r = RemoveBadge(pAppIdChar.get());
487 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to remove the badge.");
492 r = SetBadgeCount(pAppIdChar.get(), badgeNumber);
493 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to set the badge.");
496 if (!(isOngoing || !contentText.IsEmpty()))
498 SysLog(NID_SHELL, "No valid for Notification, just for set a badgeNumber update.");
502 SysTryReturnResult(NID_SHELL, (isOngoing || !contentText.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. MessageText is Empty");
504 const String& titleText = notifyRequest.GetTitleText();
505 const String& launchArguments = notifyRequest.GetAppMessage();
506 const String& iconPath = notifyRequest.GetIconFilePath();
507 const String& soundPath = notifyRequest.GetSoundFilePath();
508 const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
509 int notiPrivateId = isOngoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
510 notification_h notiHandle = null;
511 bundle* pBundle = null;
512 bool needUpdate = false;
513 bundle* service_data = null;
515 service_h hSvc = null;
516 notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
518 // Notification creation
519 if (notiPrivateId != -1)
521 notiHandle = notification_load(pAppIdChar.get(), notiPrivateId);
522 SysTryLog(NID_SHELL, notiHandle != null, "Get notiHandle(%d) from notiPrivateId(%d).", notiHandle, notiPrivateId);
525 if (notiHandle == null)
527 SysLog(NID_SHELL, "Previous notification(%d) no more valid - create new notification", notiPrivateId);
528 notiPrivateId = -1; // reset
529 notiHandle = notification_create(notiType);
533 needUpdate = true; // No need to notification_insert.
535 SysTryReturnResult(NID_SHELL, notiHandle != null, E_OPERATION_FAILED, "Notification creation or loading failed.");
537 // Content text(Alert text)
538 std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(contentText));
541 std::unique_ptr<char[]> pTitleText(null);
542 if (!titleText.IsEmpty())
544 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(titleText));
545 pTitleText = std::move(pTitleTextTemp);
549 char* pAppName = null;
550 r = ConvertAppManagerResult(app_manager_get_app_name(pAppIdChar.get(), &pAppName));
553 String appName(pAppName);
554 std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
555 pTitleText = std::move(pTitleTextTemp);
557 SysLog(NID_SHELL, "App name is %ls.", appName.GetPointer());
559 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Failed to get title from app_manager_get_app_name for default setting.", GetErrorMessage(r));
562 std::unique_ptr<char[]> pIconPath(null);
563 if (!iconPath.IsEmpty())
565 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
566 pIconPath = std::move(pIconPathTemp);
570 char* pDefaultIconPath = null;
571 r = ConvertAppManagerResult(app_manager_get_app_icon_path(pAppIdChar.get(), &pDefaultIconPath));
572 if (pDefaultIconPath)
574 String iconPath(pDefaultIconPath);
575 std::unique_ptr<char[]> pIconPathTemp(_StringConverter::CopyToCharArrayN(iconPath));
576 pIconPath = std::move(pIconPathTemp);
577 free(pDefaultIconPath);
579 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the icon path failed.", GetErrorMessage(r));
582 std::unique_ptr<char[]> pSoundPath(null);
583 if (!soundPath.IsEmpty())
585 std::unique_ptr<char[]> pSoundPathTemp(_StringConverter::CopyToCharArrayN(soundPath));
586 pSoundPath = std::move(pSoundPathTemp);
589 if (notifyType == NOTIFY_TYPE_APP_ID)
591 r = ConvertNotificationResult(notification_set_pkgname(notiHandle, pAppIdChar.get()));
592 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the package name failed.", GetErrorMessage(r));
595 if (pTitleText.get())
597 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
598 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the title text failed.", GetErrorMessage(r));
600 // Set - content text
603 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
604 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting content text failed.", GetErrorMessage(r));
606 // Set - icon file path
607 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath.get()));
608 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the icon path failed.", GetErrorMessage(r));
609 // Set - sound file path
610 if (pSoundPath.get())
612 if (isOngoing && needUpdate)
614 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
618 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath.get()));
623 if (isOngoing && needUpdate)
625 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
629 r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL));
632 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the sound failed.", GetErrorMessage(r));
634 // Set extended - text, thumbnail and background image
637 // Extended style set
638 String countText = notifyRequest.GetNotificationCountText();
639 NotificationStyle notiStyle= notifyRequest.GetNotificationStyle();
640 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
642 layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
645 if (notiStyle == NOTIFICATION_STYLE_NORMAL && !countText.IsEmpty())
647 layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
650 if (!countText.IsEmpty())
652 std::unique_ptr<char[]> text(_StringConverter::CopyToCharArrayN(countText));
653 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, text.get(),
654 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
657 String bgImageFilePath = notifyRequest.GetBackgroundImageFilePath();
658 if (!bgImageFilePath.IsEmpty() && File::IsFileExist(bgImageFilePath))
660 std::unique_ptr<char[]> pBgImageFilePath(_StringConverter::CopyToCharArrayN(bgImageFilePath));
661 r = ConvertNotificationResult(notification_set_image(notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, pBgImageFilePath.get()));
662 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the background image path failed.", GetErrorMessage(r));
666 if (notiStyle == NOTIFICATION_STYLE_THUMBNAIL)
668 const IList* pThumbnailList = pRequestImpl->GetMessageThumbnailFilePathList();
671 const static notification_image_type_e thumbnailListEnum[] = {NOTIFICATION_IMAGE_TYPE_LIST_1, NOTIFICATION_IMAGE_TYPE_LIST_2,
672 NOTIFICATION_IMAGE_TYPE_LIST_3, NOTIFICATION_IMAGE_TYPE_LIST_4, NOTIFICATION_IMAGE_TYPE_LIST_5 };
673 int itemCount = pThumbnailList->GetCount();
674 const int maxCount = sizeof(thumbnailListEnum)/sizeof(thumbnailListEnum[0]);
675 if (itemCount > maxCount)
677 itemCount = maxCount;
679 for (int i = 0; i < itemCount; i++)
681 const String* pThumbnailPath = static_cast<const String*>(pThumbnailList->GetAt(i));
682 std::unique_ptr<char[]> filePath(_StringConverter::CopyToCharArrayN(*pThumbnailPath));
683 r = ConvertNotificationResult(notification_set_image(notiHandle, thumbnailListEnum[i], filePath.get()));
684 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the thumbnail path failed.", GetErrorMessage(r));
690 const IList* pMessageTextList = pRequestImpl->GetMessageTextList();
691 if (pMessageTextList && pMessageTextList->GetCount())
693 const String* pText1 = static_cast<const String*>(pMessageTextList->GetAt(0));
697 if (E_SUCCESS == pText1->IndexOf(L'\t', 0, matchIndex))
701 pText1->SubString(0, matchIndex+1, subText);
702 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
703 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
704 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
705 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 text failed.", GetErrorMessage(r));
707 if (E_SUCCESS == pText1->SubString(matchIndex+1, subText))
709 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
710 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, rightText.get(),
711 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
712 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 sub text failed.", GetErrorMessage(r));
717 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText1));
718 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, leftText.get(),
719 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
720 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info1 text failed.", GetErrorMessage(r));
723 const String* pText2 = static_cast<const String*>(pMessageTextList->GetAt(1));
727 // 2.1: Multiple layout has single line text for 2nd information text.
728 if ((layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE) && (E_SUCCESS == (pText2->IndexOf(L'\t', 0, matchIndex))))
732 pText2->SubString(0, matchIndex+1, subText);
733 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(subText));
734 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
735 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
736 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 text failed.", GetErrorMessage(r));
738 if (E_SUCCESS == pText2->SubString(matchIndex+1, subText))
740 std::unique_ptr<char[]> rightText(_StringConverter::CopyToCharArrayN(subText));
741 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, rightText.get(),
742 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
743 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 sub text failed.", GetErrorMessage(r));
748 std::unique_ptr<char[]> leftText(_StringConverter::CopyToCharArrayN(*pText2));
749 r = ConvertNotificationResult(notification_set_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_2, leftText.get(),
750 NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
751 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the Info2 text failed.", GetErrorMessage(r));
757 { // Reset text for update case. also must be checked the previous text with get_text
758 char* pRetStr = null;
759 notification_get_text(notiHandle, NOTIFICATION_TEXT_TYPE_INFO_1, &pRetStr);
762 const static notification_text_type_e infoTextEnums[] = { NOTIFICATION_TEXT_TYPE_INFO_1, NOTIFICATION_TEXT_TYPE_INFO_SUB_1,
763 NOTIFICATION_TEXT_TYPE_INFO_2, NOTIFICATION_TEXT_TYPE_INFO_SUB_2 };
764 for (unsigned int i = 0; i < sizeof(infoTextEnums)/sizeof(infoTextEnums[0]); i++)
766 r = ConvertNotificationResult(notification_set_text(notiHandle, infoTextEnums[i], null, NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
767 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the initial text failed.", GetErrorMessage(r));
775 int retVal = SERVICE_ERROR_NONE;
777 r = arg.Construct(launchArguments);
778 SysTryCatch(NID_SHELL, !IsFailed(r), r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] Failed to construct _AppArg.");
780 pBundle = arg.GetBundle();
782 service_create_request(pBundle, &hSvc);
783 SysTryCatch(NID_SHELL, hSvc != null, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_create_request failed.");
785 if (notifyType == NOTIFY_TYPE_SIMPLE || notifyType == NOTIFY_TYPE_APP_ID)
787 retVal = service_set_app_id(hSvc, pRequestImpl->IsAppBinding() ? pAppIdChar.get() : null);
788 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_set_app_id failed(%d).", retVal);
791 if (notifyType == NOTIFY_TYPE_APP_CONTROL)
793 std::unique_ptr<char[]> pOperationIdChar(_StringConverter::CopyToCharArrayN(*pOperationId));
794 retVal = service_set_operation(hSvc, pOperationIdChar.get());
795 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_set_operation failed(%d).", retVal);
799 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
800 retVal = service_set_uri(hSvc, pUri.get());
801 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_set_uri failed(%d).", retVal);
805 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pDataType));
806 retVal = service_set_mime(hSvc, pMime.get());
807 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_set_mime failed(%d).", retVal);
811 std::unique_ptr<Tizen::Base::Collection::IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
814 while (pMapEnum->MoveNext() == E_SUCCESS)
816 String* pKey = static_cast<String* > (pMapEnum->GetKey());
817 String* pValue = static_cast<String* > (pMapEnum->GetValue());
820 std::unique_ptr<char[]> pKeyString(_StringConverter::CopyToCharArrayN(*pKey));
821 std::unique_ptr<char[]> pValueString(_StringConverter::CopyToCharArrayN(*pValue));
822 retVal = service_add_extra_data(hSvc, pKeyString.get(), pValueString.get());
823 SysTryLog(NID_SHELL, retVal == SERVICE_ERROR_NONE, "service_add_extra_data failed(%d).", retVal);
827 SysLog(NID_SHELL, "pKey or pValue is invalid.");
834 retVal = service_to_bundle(hSvc, &service_data);
835 SysTryCatch(NID_SHELL, retVal == SERVICE_ERROR_NONE, r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] service_to_bundle failed(%d).", retVal);
837 r = ConvertNotificationResult(notification_set_property(notiHandle, 0));
838 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification property failed.", GetErrorMessage(r));
840 r = ConvertNotificationResult(notification_set_execute_option(notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data));
841 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the execute option failed.", GetErrorMessage(r));
846 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
847 if (activityType == ONGOING_ACTIVITY_TYPE_TEXT)
849 layout = NOTIFICATION_LY_ONGOING_EVENT;
853 layout = NOTIFICATION_LY_ONGOING_PROGRESS;
856 r = ConvertNotificationResult(notification_set_layout(notiHandle, layout));
857 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification layout failed.", GetErrorMessage(r));
862 OngoingActivityType activityType = notifyRequest.GetOngoingActivityType();
863 int progress = notifyRequest.GetOngoingActivityProgress();
865 switch (activityType)
867 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
870 r = ConvertNotificationResult(notification_set_size(notiHandle, 0)); // Reset for override BYTE type
871 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
873 r = ConvertNotificationResult(notification_set_progress(notiHandle, progress/100.));
874 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
877 case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
880 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset for override PERCENTAGE type
881 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
883 r = ConvertNotificationResult(notification_set_size(notiHandle, progress));
884 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
887 case ONGOING_ACTIVITY_TYPE_TEXT:
888 r = ConvertNotificationResult(notification_set_progress(notiHandle, 0.0)); // Reset the progress
889 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification progress failed.", GetErrorMessage(r));
890 r = ConvertNotificationResult(notification_set_size(notiHandle, 0));
891 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification size failed.", GetErrorMessage(r));
895 r = E_OPERATION_FAILED;
900 // insert for new notification
903 r = ConvertNotificationResult(notification_insert(notiHandle, ¬iPrivateId));
904 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting new notification failed.", GetErrorMessage(r));
906 SysLog(NID_SHELL, "Getting new notiPrivateId(%d)", notiPrivateId);
910 __notifyPrivateIdForOngoing = notiPrivateId;
914 __notifyPrivateId = notiPrivateId;
919 int previousDisplaySet = NOTIFICATION_DISPLAY_APP_ALL;
922 r = ConvertNotificationResult(notification_get_display_applist(notiHandle, &previousDisplaySet));
923 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
925 int newDisplaySet = previousDisplaySet & ~NOTIFICATION_DISPLAY_APP_TICKER;
926 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, newDisplaySet));
927 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
930 r = ConvertNotificationResult(notification_update(notiHandle));
931 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Updating the notification failed. notiPrivateId(%d)", GetErrorMessage(r), notiPrivateId);
935 r = ConvertNotificationResult(notification_set_display_applist(notiHandle, previousDisplaySet));
936 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
941 service_destroy(hSvc);
942 notification_free(notiHandle);
947 _NotificationManagerImpl::RemoveNotification(void)
949 return RemoveNotification(false);
953 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
955 return RemoveNotification(true);
959 _NotificationManagerImpl::RemoveNotification(bool onGoing)
961 result r = E_SUCCESS;
962 notification_error_e err = NOTIFICATION_ERROR_NONE;
963 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
964 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
966 if (notiPrivateId != -1)
968 notification_h notiHandle = notification_load(null, notiPrivateId);
971 err = notification_delete(notiHandle);
972 SysLog(NID_SHELL, "Notification deleted.");
976 SysLog(NID_SHELL, "Notification already deleted.");
978 err = notification_free(notiHandle);
982 err = notification_delete_all_by_type(null, notiType);
983 SysLog(NID_SHELL, "All [%s] notifications deleted.", onGoing ? "Ongoing" : "Normal");
986 SysTryReturnResult(NID_SHELL, err == NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Failed to RemoveNotification with reason (%d).", err);
991 _NotificationManagerImpl::RemoveNotificationByAppId(const Tizen::App::AppId& appId, bool onGoing)
993 result r = E_SUCCESS;
994 notification_error_e err = NOTIFICATION_ERROR_NONE;
995 bool isValidAppId = _Aul::IsInstalled(appId);
996 SysTryReturnResult(NID_SHELL, isValidAppId == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
998 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
999 const notification_type_e notiType = onGoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
1000 const int notiPrivateId = onGoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
1002 if (notiPrivateId != -1)
1004 notification_h notiHandle = notification_load(pAppId.get(), notiPrivateId);
1007 err = notification_delete(notiHandle);
1008 SysLog(NID_SHELL, "Notification deleted.");
1012 SysLog(NID_SHELL, "Notification already deleted.");
1014 err = notification_free(notiHandle);
1018 err = notification_delete_all_by_type(pAppId.get(), notiType);
1019 SysLog(NID_SHELL, "All [%s] notifications deleted.", onGoing ? "Ongoing" : "Normal");
1022 SysTryReturnResult(NID_SHELL, err == NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Failed to RemoveNotificationByAppId with reason (%d).", err);
1027 _NotificationManagerImpl::RemoveBadge(const char* pkgName) const
1029 bool badgeExist = false;
1030 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1031 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_is_existing failed(%d).", badgeError);
1035 badgeError = badge_remove(pkgName);
1036 SysTryReturnResult(NID_SHELL, badgeError == BADGE_ERROR_NONE, E_OPERATION_FAILED, "badge_remove failed(%d).", badgeError);
1039 SysLog(NID_SHELL, "Badge is removed.");
1044 _NotificationManagerImpl::SetBadgeCount(const char* pkgName, int badgeCount) const
1047 badge_error_e badgeError = badge_is_existing(pkgName, &badgeExist);
1048 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_is_existing failed(%d).", badgeError);
1052 badgeError = badge_create(pkgName, pkgName);
1053 SysTryReturnResult(NID_SHELL, badgeError == BADGE_ERROR_NONE, E_OPERATION_FAILED, "badge_create failed(%d).", badgeError);
1056 badgeError = badge_set_count(pkgName, badgeCount);
1057 SysTryLog(NID_SHELL, badgeError == BADGE_ERROR_NONE, "badge_set_count failed(%d).", badgeError);
1059 SysLog(NID_SHELL, "Badge count is %d.", badgeCount);
1064 _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
1066 unsigned int count = 0;
1068 badge_error_e badgeError = badge_get_count(pkgName, &count);
1069 if (badgeError == BADGE_ERROR_NONE)
1071 SysLog(NID_SHELL, "badge_get_count(%d)", count);
1076 SysLog(NID_SHELL, "badge_get_count failed(%d).", badgeError);
1082 _NotificationManagerImpl::AddBadgeEventListener(IBadgeEventListener& listener)
1084 SysTryReturnResult(NID_SHELL, !__badgeEventListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
1085 SysLog(NID_SHELL, "AddBadgeEventListener (%x)", &listener);
1087 result r = _BadgeManagerImpl::GetInstance()->AddPrimaryBadgeEventListener(*this);
1088 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to AddPrimaryBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1090 return __badgeEventListenerList.Add(&listener);
1094 _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener)
1096 SysLog(NID_SHELL, "RemoveBadgeEventListener (%x)", &listener);
1098 result r = __badgeEventListenerList.Remove(&listener); // Remove() can return E_SUCCESS and E_OBJ_NOT_FOUND.
1099 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "Failed to RemoveBadgeEventListener with reason (%s)", GetErrorMessage(r) );
1101 return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
1105 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
1107 std::unique_ptr<IEnumeratorT<Tizen::Shell::IBadgeEventListener* > > pEnum(__badgeEventListenerList.GetEnumeratorN());
1108 SysTryReturnVoidResult(NID_SHELL, pEnum.get(), E_OUT_OF_MEMORY, "Failed to GetEnumeratorN()!");
1110 IBadgeEventListener* pListener;
1111 while (pEnum->MoveNext() == E_SUCCESS)
1114 pEnum->GetCurrent(pListener);
1117 SysLog(NID_SHELL, "pListener is null!");
1120 pListener->OnBadgeUpdated(appId, badgeNumber);