From: Jiwoong Im Date: Tue, 27 Sep 2016 08:41:26 +0000 (+0900) Subject: Add new alarm api to trigger notification X-Git-Tag: submit/tizen/20161101.112858^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09344f8c88e215b5e691d4d5b0c32fc3d09299ab;p=platform%2Fcore%2Fapi%2Falarm.git Add new alarm api to trigger notification - int alarm_schedule_noti_once_at_date() int alarm_schedule_noti_after_delay() int alarm_schedule_noti_once_after_delay() int alarm_schedule_noti_with_recurrence_week_flag() int alarm_get_notification() Change-Id: Ib8dea6579277ee47b919bcf6996e0ef7224e0b7e Signed-off-by: Jiwoong Im --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e035ef0..c13372c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,8 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(requires "dlog bundle aul alarm-service capi-base-common capi-appfw-app-control") -SET(pc_requires "capi-base-common capi-appfw-app-control") +SET(requires "dlog bundle aul alarm-service capi-base-common capi-appfw-app-control notification") +SET(pc_requires "capi-base-common capi-appfw-app-control notification") INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${requires}) diff --git a/include/app_alarm.h b/include/app_alarm.h index 15796ab..61dda96 100644 --- a/include/app_alarm.h +++ b/include/app_alarm.h @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -452,6 +453,150 @@ int alarm_set_global(int alarm_id, bool global); */ int alarm_get_global(int alarm_id, bool *global); + +/** + * @brief Sets a notification alarm to be triggered at a specific time. + * @details The @a date describes the time of the alarm occurrence. + * To cancel the alarm, call alarm_cancel() with @a alarm_id. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/alarm.set + * @privilege %http://tizen.org/privilege/notification + * @remarks If application is uninstalled after setting an alarm, the alarm is cancelled automatically. + * When the alarm goes off, Alarm Manager will turn on LCD to prohibit background jobs. + * + * @param[in] noti The notification to be posted when the alarm is triggered + * @param[in] date The active alarm time + * @param[out] alarm_id The ID which uniquely identifies the scheduled alarm + * @return @c 0 on success, + * otherwise a negative error value + * @retval #ALARM_ERROR_NONE Successful + * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ALARM_ERROR_INVALID_DATE Triggered date is invalid + * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server + * @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied + * @see alarm_cancel() + * @see alarm_cancel_all() + * @see alarm_get_scheduled_date() + */ +int alarm_schedule_noti_once_at_date(notification_h noti, struct tm *date, int *alarm_id); + +/** + * @brief Sets a notification alarm to be triggered after a specific delay. + * @details The alarm will first go off after @a delay seconds. + * The alarm will then go off every @period seconds until canceled. + * To cancel the alarm, call alarm_cancel() with @a alarm_id. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/alarm.set + * @privilege %http://tizen.org/privilege/notification + * @remarks If the application is uninstalled after setting an alarm, the alarm is cancelled automatically. + * This function is a minimally intrusive way to trigger alarms when precision is not important. + * The system will adjust the @a delay and @a period requests to suit internal needs; the requests + * will be treated as minimum values. Note that @a period cannot be less than 600 seconds, if + * a smaller request is supplied it will be silently adjusted to a request of 600. + * When the alarm goes off, Alarm Manager will turn on LCD to prohibit background jobs. + * + * @param[in] noti The notification to be posted when the alarm is triggered + * @param[in] delay The amount of time before the first execution (in seconds). + * @param[in] period The amount of time between subsequent alarms (in seconds). + * @param[out] alarm_id The ID which uniquely identifies the scheduled alarm + * @return @c 0 on success, + * otherwise a negative error value + * @retval #ALARM_ERROR_NONE Successful + * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ALARM_ERROR_INVALID_TIME Triggered time is invalid + * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server + * @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied + * @see alarm_cancel() + * @see alarm_cancel_all() + * @see alarm_get_scheduled_date() + * @see alarm_get_scheduled_period() + * @see alarm_schedule_noti_once_after_delay() + */ +int alarm_schedule_noti_after_delay(notification_h noti, int delay, int period, int *alarm_id); + +/** + * @brief Sets a notification alarm to be triggered after a specific delay. + * @details The alarm will go off @a delay seconds later. + * To cancel the alarm, call alarm_cancel() with @a alarm_id. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/alarm.set + * @privilege %http://tizen.org/privilege/notification + * @remarks If the application is uninstalled after setting an alarm, the alarm is cancelled automatically. + * When the alarm goes off, Alarm Manager will turn on LCD to prohibit background jobs. + * + * @param[in] noti The notification to be posted when the alarm is triggered + * @param[in] delay The amount of time before the execution (in seconds) + * @param[out] alarm_id The ID which uniquely identifies the scheduled alarm + * @return @c 0 on success, + * otherwise a negative error value + * @retval #ALARM_ERROR_NONE Successful + * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ALARM_ERROR_INVALID_TIME Triggered time is invalid + * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server + * @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied + * @see alarm_cancel() + * @see alarm_cancel_all() + * @see alarm_get_scheduled_date() + */ +int alarm_schedule_noti_once_after_delay(notification_h noti, int delay, int *alarm_id); + +/** + * @brief Sets a notification to be triggered periodically, starting at a specific time. + * @details The @a date describes the time of the first occurrence. + * @a week_flag describes the day(s) of the week when the notification recurs. + * If @a week_flag is #ALARM_WEEK_FLAG_TUESDAY, the alarm will repeat every Tuesday at a specific time. + * If @a week_flag is less than or equal to zero, the alarm is not repeated. + * To cancel the alarm, call alarm_cancel() with @a alarm_id. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/alarm.set + * @privilege %http://tizen.org/privilege/notification + * @remarks If the application is uninstalled after setting an alarm, the alarm is cancelled automatically. + * + * @param[in] noti The notification to be posted when the alarm is triggered + * @param[in] date The first active alarm time + * @param[in] week_flag The day of the week the notification recurs. @a week_flag may be a combination of days, like #ALARM_WEEK_FLAG_TUESDAY | #ALARM_WEEK_FLAG_FRIDAY + * @param[out] alarm_id The ID which uniquely identifies the scheduled alarm + * @return @c 0 on success, + * otherwise a negative error value + * @retval #ALARM_ERROR_NONE Successful + * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ALARM_ERROR_INVALID_DATE Triggered date is invalid + * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server + * @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied + * @see alarm_cancel() + * @see alarm_cancel_all() + * @see alarm_get_scheduled_recurrence_week_flag() + * @see alarm_get_scheduled_date() + * @see #alarm_week_flag_e + */ +int alarm_schedule_noti_with_recurrence_week_flag(notification_h noti, struct tm *date, int week_flag, int *alarm_id); + +/** + * @brief Gets the notification to be posted when an alarm is triggered. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/alarm.get + * @remarks @a noti must be released using notification_free(). + * + * @param[in] alarm_id The ID which uniquely identifies a scheduled alarm + * @param[out] noti The notification to be posted when the alarm is triggered + * @return @c 0 on success, + * otherwise a negative error value + * @retval #ALARM_ERROR_NONE Successful + * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ALARM_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied + * @see alarm_schedule_noti_once_at_date() + * @see alarm_schedule_noti_after_delay() + * @see alarm_schedule_noti_once_after_delay() + * @see alarm_schedule_noti_with_recurrence_week_flag() + */ +int alarm_get_notification(int alarm_id, notification_h *noti); + /** * @} */ diff --git a/packaging/capi-appfw-alarm.spec b/packaging/capi-appfw-alarm.spec index eea9723..d876c79 100644 --- a/packaging/capi-appfw-alarm.spec +++ b/packaging/capi-appfw-alarm.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(capi-appfw-app-control) BuildRequires: pkgconfig(alarm-service) BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(notification) %description An Alarm library in C API package. diff --git a/src/alarm.c b/src/alarm.c index 7619ddd..8f7bbd4 100644 --- a/src/alarm.c +++ b/src/alarm.c @@ -28,6 +28,8 @@ #include #include +#include + #ifdef LOG_TAG #undef LOG_TAG #endif @@ -177,6 +179,20 @@ int alarm_schedule_after_delay(app_control_h app_control, int delay, int period, return convert_error_code_to_alarm(__FUNCTION__, result); } +int alarm_schedule_noti_after_delay(notification_h noti, int delay, int period, int *alarm_id) +{ + int result; + + if (noti == NULL) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + result = alarmmgr_add_alarm_noti(ALARM_TYPE_DEFAULT | ALARM_TYPE_INEXACT, delay, period, noti, alarm_id); + + return convert_error_code_to_alarm(__FUNCTION__, result); +} + int alarm_schedule_at_date(app_control_h app_control, struct tm *date, int period_in_second, int *alarm_id) { dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: alarm_schedule_at_date() is deprecated and will be removed from next release. Use alarm_schedule_once_at_date() instead."); @@ -259,6 +275,20 @@ int alarm_schedule_once_after_delay(app_control_h app_control, int delay, int *a return convert_error_code_to_alarm(__FUNCTION__, result); } +int alarm_schedule_noti_once_after_delay(notification_h noti, int delay, int *alarm_id) +{ + int result; + + if (noti == NULL) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + result = alarmmgr_add_alarm_noti(ALARM_TYPE_DEFAULT, delay, 0, noti, alarm_id); + + return convert_error_code_to_alarm(__FUNCTION__, result); +} + int alarm_schedule_once_at_date(app_control_h app_control, struct tm *date, int *alarm_id) { alarm_date_t internal_time; @@ -319,6 +349,59 @@ int alarm_schedule_once_at_date(app_control_h app_control, struct tm *date, int return ALARM_ERROR_NONE; } +int alarm_schedule_noti_once_at_date(notification_h noti, struct tm *date, int *alarm_id) +{ + alarm_date_t internal_time; + alarm_entry_t *alarm_info; + int result; + + if (noti == NULL || date == NULL) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + alarm_info = alarmmgr_create_alarm(); + if (alarm_info == NULL) { + LOGE("OUT_OF_MEMORY(0x%08x)", ALARM_ERROR_OUT_OF_MEMORY); + return ALARM_ERROR_OUT_OF_MEMORY; + } + + internal_time.year = date->tm_year + 1900; + internal_time.month = date->tm_mon + 1; + internal_time.day = date->tm_mday; + + internal_time.hour = date->tm_hour; + internal_time.min = date->tm_min; + internal_time.sec = date->tm_sec; + + result = alarmmgr_set_time(alarm_info, internal_time); + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0); + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT); + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_add_alarm_noti_with_localtime(alarm_info, noti, alarm_id); + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + alarmmgr_free_alarm(alarm_info); + return ALARM_ERROR_NONE; +} + int alarm_cancel(int alarm_id) { int result; @@ -406,6 +489,53 @@ int alarm_schedule_with_recurrence_week_flag(app_control_h app_control, struct t return convert_error_code_to_alarm(__FUNCTION__, result); } + if (week_flag > 0) { + result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag); + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + } + + result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT); + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id); + alarmmgr_free_alarm(alarm_info); + + return convert_error_code_to_alarm(__FUNCTION__, result); +} + +int alarm_schedule_noti_with_recurrence_week_flag(notification_h noti, struct tm *date, int week_flag, int *alarm_id) +{ + alarm_date_t internal_time; + alarm_entry_t *alarm_info; + int result; + + if (noti == NULL || date == NULL) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + alarm_info = alarmmgr_create_alarm(); + + internal_time.year = date->tm_year + 1900; + internal_time.month = date->tm_mon + 1; + internal_time.day = date->tm_mday; + + internal_time.hour = date->tm_hour; + internal_time.min = date->tm_min; + internal_time.sec = date->tm_sec; + + result = alarmmgr_set_time(alarm_info, internal_time); + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + if (week_flag > 0) result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag); @@ -420,7 +550,7 @@ int alarm_schedule_with_recurrence_week_flag(app_control_h app_control, struct t return convert_error_code_to_alarm(__FUNCTION__, result); } - result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id); + result = alarmmgr_add_alarm_noti_with_localtime(alarm_info, noti, alarm_id); alarmmgr_free_alarm(alarm_info); return convert_error_code_to_alarm(__FUNCTION__, result); @@ -497,6 +627,17 @@ int alarm_get_app_control(int alarm_id, app_control_h *app_control) return ALARM_ERROR_NONE; } +int alarm_get_notification(int alarm_id, notification_h *noti) +{ + int error_code = 0; + + error_code = alarmmgr_get_alarm_noti_info(alarm_id, noti); + if (error_code != ALARMMGR_RESULT_SUCCESS) + return convert_error_code_to_alarm(__FUNCTION__, error_code); + + return ALARM_ERROR_NONE; +} + int alarm_set_global(int alarm_id, bool global) { int ret;