}
}
+var LogManager = function() {
+ this.enableLog = true;
+};
+
+LogManager.prototype.allow = function() {
+ this.enableLog = true;
+};
+
+LogManager.prototype.disallow = function() {
+ this.enableLog = false;
+};
+
+var _warningLogs = new LogManager();
+
//class AlarmManager ////////////////////////////////////////////////////
AlarmManager.prototype.add = function () {
var args = AV.validateMethod(arguments, [
}
};
+AlarmManager.prototype.addAlarmNotification = function() {
+ var args = AV.validateMethod(arguments, [
+ {
+ name: 'alarm',
+ type: AV.Types.PLATFORM_OBJECT,
+ values: [tizen.AlarmRelative, tizen.AlarmAbsolute]
+ }, {
+ name: 'notification',
+ type: AV.Types.PLATFORM_OBJECT,
+ values: tizen.StatusNotification
+ }]);
+
+ var type = null, milliseconds = 0;
+ if (args.alarm instanceof tizen.AlarmRelative) {
+ type = 'AlarmRelative';
+ } else if (args.alarm instanceof tizen.AlarmAbsolute) {
+ type = 'AlarmAbsolute';
+ milliseconds = args.alarm.date.getTime();
+ }
+
+ var callArgs = {};
+ callArgs.alarm = args.alarm;
+ callArgs.type = type;
+ callArgs.notification = args.notification;
+ callArgs.milliseconds = Converter.toString(milliseconds);
+ callArgs.isPeriodSet = !T.isNullOrUndefined(args.alarm.period);
+
+ var result = native.callSync('AlarmManager_addAlarmNotification', callArgs);
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ }
+ else {
+ _edit.allow();
+ UpdateInternalData_(args.alarm, native.getResultObject(result));
+ _edit.disallow();
+ }
+};
+
AlarmManager.prototype.remove = function () {
var args = AV.validateMethod(arguments, [
{
throw native.getErrorObject(result);
} else {
result = native.getResultObject(result);
+
+ var alarm;
+ _warningLogs.disallow();
if ('AlarmRelative' === result.type) {
- return new tizen.AlarmRelative(result.delay, result.period, InternalData_(result));
+ alarm = new tizen.AlarmRelative(result.delay, result.period, InternalData_(result));
} else {
var date = new Date(result.year, result.month, result.day,
result.hour, result.min, result.sec);
- return new tizen.AlarmAbsolute(date, result.second, InternalData_(result));
+ alarm = new tizen.AlarmAbsolute(date, result.second, InternalData_(result));
+ }
+ _warningLogs.allow();
+ return alarm;
+ }
+};
+
+AlarmManager.prototype.getAlarmNotification = function () {
+ var args = AV.validateMethod(arguments, [
+ {
+ name : 'id',
+ type : AV.Types.STRING,
+ }
+ ]);
+
+ var result = native.callSync('AlarmManager_getAlarmNotification', {id: Number(args.id)});
+
+ if (native.isFailure(result)) {
+ 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);
}
};
} else {
var data = native.getResultObject(result);
var md = [];
+ _warningLogs.disallow();
data.forEach(function (i) {
if ('AlarmRelative'=== i.type) {
md.push(new tizen.AlarmRelative(i.delay, i.period, InternalData_(i)));
md.push(new tizen.AlarmAbsolute(date, i.second, InternalData_(i)));
}
});
+ _warningLogs.allow();
return md;
}
};
} else {
if(!T.isNullOrUndefined(second)){
m_period = Converter.toLong(second);
+ if(_warningLogs.enableLog){
+ console.warn("This Constructor is deprecated since Tizen 4.0." +
+ " Please consider using other constructors or other type of an alarm.");
+ }
}
}
}
#include <app.h>
#include <app_alarm.h>
#include <app_control_internal.h>
+#include <notification_internal.h>
#include "common/logger.h"
#include "common/converter.h"
#include "alarm_instance.h"
#include "alarm_utils.h"
+#include "notification/status_notification.h"
+
using namespace common;
using namespace common::tools;
namespace {
const int kDateSize = 22; //"yyy mm dd hh mm ss dd" e.g 115 11 28 11 25 50 -1
const std::string kPrivilegeAlarm = "http://tizen.org/privilege/alarm";
+const std::string kPrivilegeNotification = "http://tizen.org/privilege/notification";
const std::string kAlarmRelative = "AlarmRelative";
const std::string kAlarmAbsolute = "AlarmAbsolute";
const char* kAlarmTypeValueRelative = "RELATIVE";
const char* kAlarmRelativeDelayKey = "RELATIVE_DELAY";
-
-const char* kSundayShort = "SU";
-const char* kMondayShort = "MO";
-const char* kTuesdayShort = "TU";
-const char* kWednesdayShort = "WE";
-const char* kThuesdayShort = "TH";
-const char* kFridayShort = "FR";
-const char* kSaturdayShort = "SA";
-
}
AlarmManager::AlarmManager() {
!(it_daysOfTheWeek->second.get<picojson::array>()).empty()) {
app_control_add_extra_data(
app_control, kAlarmAbsoluteRecurrenceTypeKey, kAlarmAbsoluteReccurrenceTypeByDayValue);
- picojson::array days_of_the_week = it_daysOfTheWeek->second.get<picojson::array>();
+ const picojson::array &days_of_the_week = it_daysOfTheWeek->second.get<picojson::array>();
int repeat_value = 0;
- for (auto iter = days_of_the_week.begin(); iter != days_of_the_week.end(); ++iter) {
- auto day = (*iter).get<std::string>();
- if (kSundayShort == day) {
- repeat_value |= ALARM_WEEK_FLAG_SUNDAY;
- } else if (kMondayShort == day) {
- repeat_value |= ALARM_WEEK_FLAG_MONDAY;
- } else if (kTuesdayShort == day) {
- repeat_value |= ALARM_WEEK_FLAG_TUESDAY;
- } else if (kWednesdayShort == day) {
- repeat_value |= ALARM_WEEK_FLAG_WEDNESDAY;
- } else if (kThuesdayShort == day) {
- repeat_value |= ALARM_WEEK_FLAG_THURSDAY;
- } else if (kFridayShort == day) {
- repeat_value |= ALARM_WEEK_FLAG_FRIDAY;
- } else if (kSaturdayShort == day) {
- repeat_value |= ALARM_WEEK_FLAG_SATURDAY;
- } else {
- LogAndReportError(PlatformResult(
- ErrorCode::TYPE_MISMATCH_ERR, "Invalid days of the week value."), &out);
- return;
- }
+ PlatformResult result = util::ArrayDaysToMask(days_of_the_week, &repeat_value);
+ if (!result) {
+ LogAndReportError(PlatformResult(result.error_code(), result.message()), &out);
+ return;
}
ret = alarm_schedule_with_recurrence_week_flag(
app_control, &start_date, repeat_value, &alarm_id);
ReportSuccess(result, out);
}
+void AlarmManager::AddAlarmNotification(const picojson::value& args, picojson::object& out) {
+ using namespace extension::notification;
+ LoggerD("Entered");
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeAlarm, &out);
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out);
+
+ if (!args.contains("alarm") || !args.contains("notification")) {
+ LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."),
+ &out);
+ return;
+ }
+
+ const picojson::object& alarm = args.get("alarm").get<picojson::object>();
+
+ std::string alarm_type;
+ if (args.contains("type")) {
+ alarm_type = args.get("type").get<std::string>();
+ }
+
+ notification_h notification_handle = nullptr;
+ app_control_h app_control = nullptr;
+
+ SCOPE_EXIT {
+ notification_free(notification_handle);
+ app_control_destroy(app_control);
+ };
+
+ PlatformResult platform_result = StatusNotification::GetNotiHandleFromJson(
+ args.get<picojson::object>(),
+ 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);
+
+ if (!platform_result) {
+ LogAndReportError(
+ PlatformResult(platform_result.error_code(), platform_result.message().c_str()), &out);
+ }
+
+ int alarm_id = 0;
+ int ret = 0;
+
+ if (kAlarmRelative == alarm_type) {
+ ret = app_control_add_extra_data(app_control, kAlarmKeyType, kAlarmTypeValueRelative);
+ if (ret != APP_CONTROL_ERROR_NONE) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::ABORT_ERR, "Fail to add data from app_control."), &out,
+ ("Fail to add data from app_control: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ const auto it_period = alarm.find("period");
+ const auto it_delay = alarm.find("delay");
+
+ if (alarm.end() == it_delay || alarm.end() == it_period || !it_delay->second.is<double>()) {
+ LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."),
+ &out);
+ return;
+ }
+
+ int delay = static_cast<int>(it_delay->second.get<double>());
+
+ std::string delay_str = std::to_string(delay);
+ ret = app_control_add_extra_data(app_control, kAlarmRelativeDelayKey, delay_str.c_str());
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::ABORT_ERR, "Fail to add data from app_control."), &out,
+ ("Fail to add data from app_control: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ platform_result = StatusNotification::SetAppControl(notification_handle, app_control);
+
+ if (!platform_result) {
+ LogAndReportError(
+ PlatformResult(platform_result.error_code(), platform_result.message().c_str()), &out);
+ }
+
+ int period = 0;
+ if (it_period->second.is<double>()) {
+ period = static_cast<int>(it_period->second.get<double>());
+ }
+
+ bool isPeriodSet = false;
+ if (args.contains("isPeriodSet")) {
+ isPeriodSet = args.get("isPeriodSet").get<bool>();
+ }
+
+ if (!isPeriodSet) {
+ ret = alarm_schedule_noti_once_after_delay(notification_handle, delay, &alarm_id);
+ } else {
+ ret = alarm_schedule_noti_after_delay(notification_handle, delay, period, &alarm_id);
+ }
+ } else {
+ if (alarm.find("period")->second.is<double>()) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_VALUES_ERR,
+ "AlarmAbsolute constructed by deprecated constructor."),
+ &out);
+ return;
+ }
+
+ ret = app_control_add_extra_data(app_control, kAlarmKeyType, kAlarmTypeValueAbsolute);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::ABORT_ERR, "Fail to add data from app_control."), &out,
+ ("Fail to add data from app_control: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ const auto it_daysOfTheWeek = alarm.find("daysOfTheWeek");
+ long long int milliseconds = 0;
+
+ if (args.contains("milliseconds")) {
+ milliseconds = strtoll(args.get("milliseconds").get<std::string>().c_str(), nullptr, 10);
+ }
+
+ time_t second = milliseconds / 1000;
+ struct tm start_date = { 0 };
+
+ tzset();
+ if (nullptr == localtime_r(&second, &start_date)) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Invalid date."), &out);
+ return;
+ }
+
+ mktime(&start_date);
+
+ char str_date[kDateSize];
+
+ snprintf(str_date, sizeof(str_date), "%d %d %d %d %d %d %d", start_date.tm_year,
+ start_date.tm_mon, start_date.tm_mday, start_date.tm_hour, start_date.tm_min,
+ start_date.tm_sec, start_date.tm_isdst);
+
+ ret = app_control_add_extra_data(app_control, kAlarmAbsoluteDateKey, str_date);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::ABORT_ERR, "Fail to add data from app_control."), &out,
+ ("Fail to add data from app_control: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ if (alarm.end() != it_daysOfTheWeek && it_daysOfTheWeek->second.is<picojson::array>()
+ && !(it_daysOfTheWeek->second.get<picojson::array>()).empty()) {
+ app_control_add_extra_data(app_control, kAlarmAbsoluteRecurrenceTypeKey,
+ kAlarmAbsoluteReccurrenceTypeByDayValue);
+
+ const picojson::array &days_of_the_week = it_daysOfTheWeek->second.get<picojson::array>();
+ int repeat_value = 0;
+ util::ArrayDaysToMask(days_of_the_week, &repeat_value);
+
+ platform_result = StatusNotification::SetAppControl(notification_handle, app_control);
+ if (!platform_result) {
+ LogAndReportError(
+ PlatformResult(platform_result.error_code(), platform_result.message().c_str()), &out);
+ }
+
+ ret = alarm_schedule_noti_with_recurrence_week_flag(notification_handle, &start_date,
+ repeat_value, &alarm_id);
+ } else {
+ ret = app_control_add_extra_data(app_control, kAlarmAbsoluteRecurrenceTypeKey,
+ kAlarmAbsoluteRecurrenceTypeNone);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::ABORT_ERR, "Fail to add data from app_control."), &out,
+ ("Fail to add data from app_control: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ platform_result = StatusNotification::SetAppControl(notification_handle, app_control);
+ if (!platform_result) {
+ LogAndReportError(
+ PlatformResult(platform_result.error_code(), platform_result.message().c_str()), &out);
+ }
+
+ ret = alarm_schedule_noti_once_at_date(notification_handle, &start_date, &alarm_id);
+ }
+ }
+
+ if (ALARM_ERROR_NONE != ret) {
+ if (ALARM_ERROR_INVALID_TIME == ret || ALARM_ERROR_INVALID_DATE == ret
+ || ALARM_ERROR_INVALID_PARAMETER == ret) {
+ platform_result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid data.");
+ } else {
+ platform_result = PlatformResult(ErrorCode::ABORT_ERR, "Error while adding alarm to server.");
+ }
+
+ LogAndReportError(platform_result, &out,
+ ("Error while add alarm to server: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ picojson::value result = picojson::value(picojson::object());
+ picojson::object& result_obj = result.get<picojson::object>();
+
+ if (alarm_type == kAlarmRelative) {
+ int period = 0;
+ ret = alarm_get_scheduled_period(alarm_id, &period);
+ if (ALARM_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occurred."), &out,
+ ("Unknown error occurred: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+ if (0 != period) {
+ result_obj.insert(std::make_pair("period", picojson::value(std::to_string(period))));
+ }
+ }
+
+ result_obj.insert(std::make_pair("id", picojson::value(std::to_string(alarm_id))));
+ ReportSuccess(result, out);
+}
+
void AlarmManager::Remove(const picojson::value& args, picojson::object& out) {
LoggerD("Entered");
CHECK_PRIVILEGE_ACCESS(kPrivilegeAlarm, &out);
char* alarm_type = nullptr;
char* date_string = nullptr;
char* delay_string = nullptr;
+ notification_h notification_handle = nullptr;
SCOPE_EXIT {
app_control_destroy(app_control);
free(alarm_type);
free(date_string);
free(delay_string);
+ notification_free(notification_handle);
};
- ret = alarm_get_app_control(id, &app_control);
- if (ALARM_ERROR_NONE != ret) {
- return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Alarm not found.",
- ("Alarm not found: %d (%s)", ret, get_error_message(ret)));
+ if (ALARM_ERROR_NONE != alarm_get_app_control(id, &app_control)) {
+ if (ALARM_ERROR_NONE != alarm_get_notification(id, ¬ification_handle)) {
+ 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(
+ notification_handle, &app_control);
+ if (!platform_result) {
+ return LogAndCreateResult(
+ platform_result.error_code(),
+ platform_result.message().c_str(),
+ ("Failed to get AppControl: %d (%s)", platform_result.error_code(),
+ platform_result.message().c_str()));
+ }
+ }
}
ret = app_control_get_extra_data(app_control, kAlarmKeyType, &alarm_type);
obj.insert(std::make_pair("second", picojson::value(picojson::array())))
.first->second.get<picojson::array>();
+ using namespace util;
if (byDayValue & ALARM_WEEK_FLAG_SUNDAY)
array.push_back(picojson::value(kSundayShort));
if (byDayValue & ALARM_WEEK_FLAG_MONDAY)
}
}
+void AlarmManager::GetAlarmNotification(const picojson::value& args, picojson::object& out) {
+ using namespace extension::notification;
+ LoggerD("Entered");
+
+ int alarm_id = 0;
+ int ret = ALARM_ERROR_NONE;
+ notification_h notification_handle = nullptr;
+ PlatformResult platform_result = PlatformResult(ErrorCode::NO_ERROR);
+
+ SCOPE_EXIT {
+ notification_free(notification_handle);
+ };
+
+ if (args.contains("id") && args.get("id").is<double>()) {
+ alarm_id = static_cast<int>(args.get("id").get<double>());
+ }
+
+ ret = alarm_get_notification(alarm_id, ¬ification_handle);
+
+ if (ALARM_ERROR_NONE != ret) {
+ if (ALARM_ERROR_INVALID_PARAMETER == ret) {
+ platform_result = PlatformResult(ErrorCode::NOT_FOUND_ERR,
+ "Alarm with given ID was not found.");
+ } else {
+ platform_result = PlatformResult(ErrorCode::ABORT_ERR, "Failed to get notification.");
+ }
+ LogAndReportError(platform_result, &out);
+ }
+
+ app_control_h app_control = nullptr;
+ platform_result = StatusNotification::GetAppControl(notification_handle, &app_control);
+
+ if (!platform_result) {
+ LogAndReportError(platform_result, &out);
+ }
+
+ 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);
+
+ if (ALARM_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed ToJson()."), &out);
+ }
+
+ ReportSuccess(result, out);
+}
+
static bool AlarmIterateCB(int alarm_id, void *user_data) {
LoggerD("Enter");