From: Piotr Kosko Date: Thu, 24 Aug 2017 10:03:13 +0000 (+0200) Subject: [Alarm] Changed behaviour of AlarmNotification X-Git-Tag: submit/tizen/20170906.125601~4^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F31%2F146031%2F2;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Alarm] Changed behaviour of AlarmNotification [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 --- diff --git a/src/alarm/alarm_api.js b/src/alarm/alarm_api.js index 278719bb..cfa5f987 100755 --- a/src/alarm/alarm_api.js +++ b/src/alarm/alarm_api.js @@ -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); } }; diff --git a/src/alarm/alarm_manager.cc b/src/alarm/alarm_manager.cc index 30698861..e4747cc9 100755 --- a/src/alarm/alarm_manager.cc +++ b/src/alarm/alarm_manager.cc @@ -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(), - false, - ¬ification_handle); + using namespace std::placeholders; + std::function impl {}; + if (args.contains("newImpl") && args.get("newImpl").is() + && args.get("newImpl").get()) { + 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(), + false, ¬ification_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(); - 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);