[Alarm] Changed behaviour of AlarmNotification 31/146031/2
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 24 Aug 2017 10:03:13 +0000 (12:03 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Thu, 31 Aug 2017 09:55:11 +0000 (11:55 +0200)
[Feature] addAlarmNotification can use both Status* and UserNotification
  getAlarmNotification creates UserNotification object.

[Verification] Code compiles without errors.
  Checked in Chrome console.
  Alarm TCTs - 97.10% (two tests need to be changed

Change-Id: I52c172f4a1c3068b105445ae7ee7c8aeb49df9bc
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/alarm/alarm_api.js
src/alarm/alarm_manager.cc

index 278719bb0d11518c3e47c5cdd7b0f0a24403f4a6..cfa5f987875950a7ef86eefab4823e1b132a4228 100755 (executable)
@@ -139,7 +139,7 @@ AlarmManager.prototype.addAlarmNotification = function() {
     }, {
         name: 'notification',
         type: AV.Types.PLATFORM_OBJECT,
-        values: tizen.StatusNotification
+        values: [tizen.StatusNotification, tizen.UserNotification]
     }]);
 
     var type = null, milliseconds = 0;
@@ -157,6 +157,9 @@ AlarmManager.prototype.addAlarmNotification = function() {
     callArgs.milliseconds = Converter.toString(milliseconds);
     callArgs.isPeriodSet = !T.isNullOrUndefined(args.alarm.period);
 
+    //add marker for UserNotification implementation
+    callArgs.newImpl = (callArgs.notification instanceof tizen.UserNotification);
+
     var result = native.callSync('AlarmManager_addAlarmNotification', callArgs);
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
@@ -221,6 +224,38 @@ AlarmManager.prototype.get = function () {
     }
 };
 
+function _prepareAppControl(noti) {
+  if (!noti || !noti.actions || !noti.actions.appControl) {
+    privUtils_.log("Do nothing - appControl is NOT present");
+    return;
+  }
+  if (!T.isNullOrUndefined(noti.actions.appControl.operation)) {
+    noti.actions.appControl = new tizen.ApplicationControl(
+        noti.actions.appControl.operation,
+        noti.actions.appControl.uri,
+        noti.actions.appControl.mime,
+        noti.actions.appControl.category,
+        noti.actions.appControl.data,
+        noti.actions.appControl.launchMode);
+  }
+}
+
+function _prepareDetailInfo(noti) {
+  if (!noti || !noti.textContents || !noti.textContents.detailInfo) {
+    console.log("Do nothing - detailInfo is NOT present");
+    return;
+  }
+  var detailInfo = noti.textContents.detailInfo;
+  if (T.isArray(detailInfo)) {
+    var _d = [];
+    for (var i = 0; i < detailInfo.length; ++i) {
+      _d.push(new tizen.NotificationDetailInfo(detailInfo[i].mainText,
+          detailInfo[i].subText || null));
+    }
+    noti.textContents.detailInfo = _d;
+  }
+}
+
 AlarmManager.prototype.getAlarmNotification = function () {
     var args = AV.validateMethod(arguments, [
         {
@@ -235,16 +270,9 @@ AlarmManager.prototype.getAlarmNotification = function () {
         throw native.getErrorObject(result);
     } else {
         var noti = native.getResultObject(result);
-        if(!T.isNullOrUndefined(noti.appControl.operation)){
-            noti.appControl = new tizen.ApplicationControl(
-                    noti.appControl.operation,
-                    noti.appControl.uri,
-                    noti.appControl.mime,
-                    noti.appControl.category,
-                    noti.appControl.data,
-                    noti.appControl.launchMode);
-        }
-        return new tizen.StatusNotification('SIMPLE', noti.title, noti);
+        _prepareAppControl(noti);
+        _prepareDetailInfo(noti);
+        return new tizen.UserNotification(noti.userType, noti.title, noti);
     }
 };
 
index 306988612064c11f59eb16327938c01189fcfed1..e4747cc9456aebcbcf19ca175d6aefe21799f9c9 100755 (executable)
@@ -30,7 +30,9 @@
 #include "alarm_instance.h"
 #include "alarm_utils.h"
 
+#include "notification/common_notification.h"
 #include "notification/status_notification.h"
+#include "notification/user_notification.h"
 
 using namespace common;
 using namespace common::tools;
@@ -267,17 +269,26 @@ void AlarmManager::AddAlarmNotification(const picojson::value& args, picojson::o
     app_control_destroy(app_control);
   };
 
-  PlatformResult platform_result = StatusNotification::GetNotiHandleFromJson(
-      args.get<picojson::object>(),
-      false,
-      &notification_handle);
+  using namespace std::placeholders;
+  std::function <PlatformResult(const picojson::object& args,
+                                bool is_update,
+                                notification_h *noti_handle)> impl {};
+  if (args.contains("newImpl") && args.get("newImpl").is<bool>()
+      && args.get("newImpl").get<bool>()) {
+    LoggerD("New implementation");
+    impl = std::bind(&UserNotification::GetNotiHandleFromJson, _1, _2, _3);
+  } else {
+    LoggerW("Deprecated object used");
+    impl = std::bind(&StatusNotification::GetNotiHandleFromJson, _1, _2, _3);
+  }
 
+  PlatformResult platform_result = impl(args.get<picojson::object>(),
+                                        false, &notification_handle);
   if (!platform_result) {
     LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, platform_result.message().c_str()),
                       &out);
   }
-
-  platform_result = StatusNotification::GetAppControl(notification_handle, &app_control);
+  platform_result = CommonNotification::GetAppControl(notification_handle, &app_control);
 
   if (!platform_result) {
     LogAndReportError(
@@ -316,7 +327,7 @@ void AlarmManager::AddAlarmNotification(const picojson::value& args, picojson::o
       return;
     }
 
-    platform_result = StatusNotification::SetAppControl(notification_handle, app_control);
+    platform_result = CommonNotification::SetAppControl(notification_handle, app_control);
 
     if (!platform_result) {
       LogAndReportError(
@@ -396,7 +407,7 @@ void AlarmManager::AddAlarmNotification(const picojson::value& args, picojson::o
       int repeat_value = 0;
       util::ArrayDaysToMask(days_of_the_week, &repeat_value);
 
-      platform_result = StatusNotification::SetAppControl(notification_handle, app_control);
+      platform_result = CommonNotification::SetAppControl(notification_handle, app_control);
       if (!platform_result) {
         LogAndReportError(
             PlatformResult(platform_result.error_code(), platform_result.message().c_str()), &out);
@@ -414,7 +425,7 @@ void AlarmManager::AddAlarmNotification(const picojson::value& args, picojson::o
         return;
       }
 
-      platform_result = StatusNotification::SetAppControl(notification_handle, app_control);
+      platform_result = CommonNotification::SetAppControl(notification_handle, app_control);
       if (!platform_result) {
         LogAndReportError(
             PlatformResult(platform_result.error_code(), platform_result.message().c_str()), &out);
@@ -528,7 +539,7 @@ PlatformResult AlarmManager::GetAlarm(int id, picojson::object& obj) {
       return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Alarm not found.",
                                 ("Alarm not found: %d (%s)", ret, get_error_message(ret)));
     } else {
-      PlatformResult platform_result = extension::notification::StatusNotification::GetAppControl(
+      PlatformResult platform_result = extension::notification::CommonNotification::GetAppControl(
           notification_handle, &app_control);
       if (!platform_result) {
         return LogAndCreateResult(
@@ -694,7 +705,7 @@ void AlarmManager::GetAlarmNotification(const picojson::value& args, picojson::o
   }
 
   app_control_h app_control = nullptr;
-  platform_result = StatusNotification::GetAppControl(notification_handle, &app_control);
+  platform_result = CommonNotification::GetAppControl(notification_handle, &app_control);
 
   if (!platform_result) {
     LogAndReportError(platform_result, &out);
@@ -703,7 +714,7 @@ void AlarmManager::GetAlarmNotification(const picojson::value& args, picojson::o
   picojson::value result = picojson::value(picojson::object());
   picojson::object& result_obj = result.get<picojson::object>();
 
-  platform_result = StatusNotification::ToJson(-1, notification_handle, app_control, &result_obj);
+  platform_result = UserNotification::ToJson(-1, notification_handle, app_control, &result_obj);
 
   if (ALARM_ERROR_NONE != ret) {
     LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed ToJson()."), &out);