Modify the argument of notification_load for core-notification module requests. ...
[platform/framework/native/shell.git] / src / core / FShell_NotificationManagerImpl.cpp
index ff46cdb..a84a6f4 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
 //
 
 /**
- * @file               FShell_NotificationManagerImpl.cpp
- * @brief              This is the placeholder for _NotificationManagerImpl class.
+ * @file       FShell_NotificationManagerImpl.cpp
+ * @brief      This is the implementation for _NotificationManagerImpl class.
  */
 
 #include <unique_ptr.h>
-#include <appsvc/appsvc.h>
-#include <bundle.h>
 #include <notification/notification.h>
 #include <appfw/app.h>
 #include <appfw/app_manager.h>
-#include <appfw/app_ui_notification.h>
 #include <badge.h>
-
 #include <FBaseSysLog.h>
-#include <FApp.h>
+#include <FIoFile.h>
+#include <FAppApp.h>
+#include <FGrpColor.h>
 #include <FShellNotificationManager.h>
 #include <FShellNotificationRequest.h>
 #include <FShellIBadgeEventListener.h>
-
-#include "FBase_StringConverter.h"
-#include "FApp_AppInfo.h"
-#include "FApp_Aul.h"
-#include "FIoFile.h"
-#include "FAppPkg_PackageManagerImpl.h"
-#include "FApp_AppArg.h"
-#include "FAppPkgPackageAppInfo.h"
-#include "FAppPkg_PackageAppInfoImpl.h"
+#include <FBase_StringConverter.h>
+#include <FApp_Aul.h>
+#include <FApp_AppArg.h>
 #include "FShell_NotificationManagerImpl.h"
 #include "FShell_NotificationRequestImpl.h"
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::App;
-using namespace Tizen::App::Package;
 using namespace Tizen::Io;
-using namespace Tizen::Shell;
+using namespace Tizen::Graphics;
 
 extern "C" int service_create_request(bundle *data, service_h *service);
 extern "C" int service_to_bundle(service_h service, bundle** data);
@@ -185,6 +175,8 @@ _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryL
 _NotificationManagerImpl::_NotificationManagerImpl(void)
        : __notifyPrivateId(-1)
        , __notifyPrivateIdForOngoing(-1)
+       , __lastNotifyPrivateId(-1)
+       , __lightActivated(false)
 {
 }
 
@@ -459,12 +451,13 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
        {
                SysTryReturnResult(NID_SHELL, false, E_INVALID_ARG, "Invalid argument is used.");
        }
+       __lastAppId = pAppIdChar.get();
 
        const int badgeNumber = notifyRequest.GetBadgeNumber();
        const int badgeOffset = notifyRequest.GetBadgeOffset();
        const String& contentText = notifyRequest.GetAlertText();
        // Allow change the badge without other properties.
-       if (badgeNumber != -1 || badgeOffset != -1)
+       if (badgeNumber != -1 || badgeOffset != 0)
        {
                // Set - Badge
                if (badgeOffset != 0)
@@ -507,6 +500,7 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
        const String& soundPath = notifyRequest.GetSoundFilePath();
        const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
        int notiPrivateId = isOngoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
+       __lastNotifyPrivateId = notiPrivateId;
        notification_h notiHandle = null;
        bundle* pBundle = null;
        bool needUpdate = false;
@@ -554,7 +548,7 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
                        std::unique_ptr<char[]> pTitleTextTemp(_StringConverter::CopyToCharArrayN(appName));
                        pTitleText = std::move(pTitleTextTemp);
                        free(pAppName);
-                       SysLog(NID_SHELL, "App name is %ls.", appName.GetPointer());
+                       SysSecureLog(NID_SHELL, "App name is %ls.", appName.GetPointer());
                }
                SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Failed to get title from app_manager_get_app_name for default setting.", GetErrorMessage(r));
        }
@@ -620,7 +614,7 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
        }
        else
        {
-               if (isOngoing && needUpdate)
+               if (isOngoing)
                {
                        r = ConvertNotificationResult(notification_set_sound(notiHandle, NOTIFICATION_SOUND_TYPE_NONE, NULL));
                }
@@ -771,8 +765,14 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
                }
        }
 
+       // light
+       Color lightColor;
+       int lightColor32 = 0;
+
        // Set - service
        int retVal = SERVICE_ERROR_NONE;
+       int previousDisplaySet = NOTIFICATION_DISPLAY_APP_ALL;
+       int newDisplaySet = 0;
 
        r = arg.Construct(launchArguments);
        SysTryCatch(NID_SHELL, !IsFailed(r), r = E_OPERATION_FAILED, r, "[E_OPERATION_FAILED] Failed to construct _AppArg.");
@@ -895,6 +895,36 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
                        r = E_OPERATION_FAILED;
                        break;
                }
+
+               r = ConvertNotificationResult(notification_get_display_applist(notiHandle, &previousDisplaySet));
+               SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
+
+               newDisplaySet = previousDisplaySet & ~NOTIFICATION_DISPLAY_APP_TICKER;
+               r = ConvertNotificationResult(notification_set_display_applist(notiHandle, newDisplaySet));
+               SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
+       }
+
+       // Set LED
+       lightColor = pRequestImpl->GetColor();
+       lightColor32 = lightColor.GetRGB32();
+
+       if (lightColor32 == 0 || (pRequestImpl->GetOnTime() == 0))
+       {       // Turn off case
+               if (needUpdate && __lightActivated)
+               {       // Not for first insertion
+                       r = ConvertNotificationResult(notification_set_led(notiHandle, NOTIFICATION_LED_OP_OFF, 0x00000000));
+                       SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification led failed.", GetErrorMessage(r));
+                       __lightActivated = false;
+               }
+       }
+       else
+       {
+               r = ConvertNotificationResult(notification_set_led(notiHandle, NOTIFICATION_LED_OP_ON_CUSTOM_COLOR, lightColor32));
+               SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification led failed.", GetErrorMessage(r));
+
+               r = ConvertNotificationResult(notification_set_led_time_period(notiHandle, pRequestImpl->GetOnTime(), pRequestImpl->GetOffTime()));
+               SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification led time period failed.", GetErrorMessage(r));
+               __lightActivated = true;
        }
 
        // insert for new notification
@@ -913,28 +943,18 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
                {
                        __notifyPrivateId = notiPrivateId;
                }
+               __lastNotifyPrivateId = notiPrivateId;
        }
        else
        {
-               int previousDisplaySet = NOTIFICATION_DISPLAY_APP_ALL;
-               if (isOngoing)
-               {
-                       r = ConvertNotificationResult(notification_get_display_applist(notiHandle, &previousDisplaySet));
-                       SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
-
-                       int newDisplaySet = previousDisplaySet & ~NOTIFICATION_DISPLAY_APP_TICKER;
-                       r = ConvertNotificationResult(notification_set_display_applist(notiHandle, newDisplaySet));
-                       SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
-               }
-
                r = ConvertNotificationResult(notification_update(notiHandle));
                SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Updating the notification failed. notiPrivateId(%d)", GetErrorMessage(r), notiPrivateId);
+       }
 
-               if (isOngoing)
-               {
-                       r = ConvertNotificationResult(notification_set_display_applist(notiHandle, previousDisplaySet));
-                       SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
-               }
+       if (isOngoing)
+       {
+               r = ConvertNotificationResult(notification_set_display_applist(notiHandle, previousDisplaySet));
+               SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
        }
 
 CATCH:
@@ -965,7 +985,8 @@ _NotificationManagerImpl::RemoveNotification(bool onGoing)
 
        if (notiPrivateId != -1)
        {
-               notification_h notiHandle = notification_load(null, notiPrivateId);
+               std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(__lastAppId));
+               notification_h notiHandle = notification_load(pAppIdTemp.get(), notiPrivateId);
                if (notiHandle)
                {
                        err = notification_delete(notiHandle);
@@ -1073,7 +1094,7 @@ _NotificationManagerImpl::GetBadgeCount(const char* pkgName) const
        }
        else
        {
-               SysLog(NID_SHELL, "badge_get_count(%d)", badgeError);
+               SysLog(NID_SHELL, "badge_get_count failed(%d).", badgeError);
                return -1;
        }
 }
@@ -1101,6 +1122,18 @@ _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener
        return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
 }
 
+int
+_NotificationManagerImpl::GetLastNotificationId(void) const
+{
+       return __lastNotifyPrivateId;
+}
+
+const Tizen::Base::String&
+_NotificationManagerImpl::GetLastAppId(void) const
+{
+       return __lastAppId;
+}
+
 void
 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
 {