Add alarm update API 86/118686/19
authorJiwoong Im <jiwoong.im@samsung.com>
Mon, 13 Mar 2017 13:49:24 +0000 (22:49 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Wed, 19 Apr 2017 12:11:25 +0000 (21:11 +0900)
- API list
  int alarm_update_delay(int alarm_id, int delay)
  int alarm_update_date(int alarm_id, struct tm *date)
  int alarm_update_period(int alarm_id, int period)
  int alarm_update_week_flag(int alarm_id, int week_flag)

Change-Id: I4a8db54ef66e84b33aa8f043c73d2376ad85a050
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
include/app_alarm.h
src/alarm.c

index ff79f62..76e7965 100644 (file)
@@ -337,6 +337,7 @@ int alarm_foreach_registered_alarm(alarm_registered_alarm_cb callback, void *use
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @privlevel public
  * @privilege %http://tizen.org/privilege/alarm.get
+ * @remarks @a date is not needed by the function after the call.
  * @param[in] alarm_id The alarm ID returned when the alarm is scheduled
  * @param[out] date The time value of the next alarm event
  * @return @c 0 on success,
@@ -597,6 +598,114 @@ int alarm_schedule_noti_with_recurrence_week_flag(notification_h noti, struct tm
 int alarm_get_notification(int alarm_id, notification_h *noti);
 
 /**
+ * @brief Updates the delay of the registered alarm.
+ * @details The @a delay is the time (in seconds) before the alarm's first setting off.
+ *          The delay is an exact value, see alarm_schedule_once_after_delay() for details.
+ *          This function can be called for any alarm.
+ *          If the delay was set before, it will be overwritten. If it was not, it will be set.
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/alarm.set
+ * @remarks This function can be called only for alarms whose app control launches an UI application.
+ *          If this condition is not met, #ALARM_ERROR_NOT_PERMITTED_APP is returned.
+ * @param[in] alarm_id  The ID which uniquely identifies the scheduled alarm
+ * @param[in] delay     The amount of time before the first execution (in seconds).
+ * @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_CONNECTION_FAIL    Failed to connect to an alarm server
+ * @retval #ALARM_ERROR_OUT_OF_MEMORY      Out of memory
+ * @retval #ALARM_ERROR_PERMISSION_DENIED  Permission denied
+ * @retval #ALARM_ERROR_NOT_PERMITTED_APP  App control does not launch an UI application
+ */
+int alarm_update_delay(int alarm_id, int delay);
+
+/**
+ * @brief Updates the date of the registered alarm.
+ * @details The @a date describes the date on which the alarm is set off for the first time.
+ *          This function can be called for any alarm.
+ *          If the date was set before, it will be overwritten. If it was not, it will be set.
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/alarm.set
+ * @remarks This function can be called only for alarms whose app control launches an UI application.
+ *          If this condition is not met, #ALARM_ERROR_NOT_PERMITTED_APP is returned.
+ * @param[in] alarm_id  The ID which uniquely identifies the scheduled alarm
+ * @param[in] date      The time value of the next alarm event
+ * @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_INVALID_DATE       Triggered time is invalid
+ * @retval #ALARM_ERROR_CONNECTION_FAIL    Failed to connect to an alarm server
+ * @retval #ALARM_ERROR_OUT_OF_MEMORY      Out of memory
+ * @retval #ALARM_ERROR_PERMISSION_DENIED  Permission denied
+ * @retval #ALARM_ERROR_NOT_PERMITTED_APP  App control does not launch an UI application
+ */
+int alarm_update_date(int alarm_id, struct tm *date);
+
+/**
+ * @brief Updates the period of the registered alarm.
+ * @details The alarm will then go off every @a period seconds until canceled.
+ *          This function can be called for any alarm.
+ *          If the week recurrence flag was set before, it will be removed and the period will be set.
+ *          If the period was set before, it will be overwritten. If it was not, it will be set.
+ *          If the @a period argument is 0 and the period was previously set,
+ *          the period attribute will be cleared and the alarm will be changed to one-time.
+ *          If the @a period argument is 0 and the period was not set,
+ *          or the week recurrence flag was set, the alarm will be unchanged.
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/alarm.set
+ * @param[in] alarm_id  The ID which uniquely identifies the scheduled alarm
+ * @param[in] period    The amount of time between subsequent alarms (in seconds).
+ *                      Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif, this
+ *                      value does not guarantee the accuracy. The actual interval
+ *                      is calculated by the OS. The minimum value is 600sec.
+ * @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_CONNECTION_FAIL    Failed to connect to an alarm server
+ * @retval #ALARM_ERROR_OUT_OF_MEMORY      Out of memory
+ * @retval #ALARM_ERROR_PERMISSION_DENIED  Permission denied
+ */
+int alarm_update_period(int alarm_id, int period);
+
+/**
+ * @brief Updates the week recurrence flag of the registered alarm.
+ * @details @a week_flag is the repeat value of the days of the week.
+ *          For example, if @a week_flag is #ALARM_WEEK_FLAG_TUESDAY, the alarm will repeat every
+ *          Tuesday at a specific time.
+ *          This function can be called for any alarm.
+ *          If the period was set before, it will be removed and the week recurrence flag will be set.
+ *          If the week recurrence flag was set before, it will be overwritten. If it was not, it will be set.
+ *          If the @a week_flag argument is 0 and the flag was previously set,
+ *          the flag attribute will be cleared and the alarm will be changed to one-time.
+ *          If the @a week_flag argument is 0 and the flag was not set,
+ *          or the period was set, the alarm will be unchanged.
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/alarm.set
+ * @remarks This function can be called only for alarms whose app control launches an UI application.
+ *          If this condition is not met, #ALARM_ERROR_NOT_PERMITTED_APP is returned.
+ * @param[in] alarm_id   The ID which uniquely identifies the scheduled alarm
+ * @param[in] week_flag  The day of the week, @a week_flag may be a combination
+ *                       of days, like #ALARM_WEEK_FLAG_TUESDAY | #ALARM_WEEK_FLAG_FRIDAY
+ * @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_CONNECTION_FAIL    Failed to connect to an alarm server
+ * @retval #ALARM_ERROR_OUT_OF_MEMORY      Out of memory
+ * @retval #ALARM_ERROR_PERMISSION_DENIED  Permission denied
+ * @retval #ALARM_ERROR_NOT_PERMITTED_APP  App control does not launch an UI application
+ */
+int alarm_update_week_flag(int alarm_id, int week_flag);
+
+/**
  * @}
  */
 
index 8f7bbd4..ca08093 100644 (file)
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <time.h>
+#include <sys/time.h>
 
 #include <bundle.h>
 #include <alarm.h>
@@ -735,3 +736,162 @@ int alarm_schedule_service_once_at_date(app_control_h app_control, struct tm *da
        alarmmgr_free_alarm(alarm_info);
        return ALARM_ERROR_NONE;
 }
+
+int alarm_update_delay(int alarm_id, int delay)
+{
+       alarm_date_t internal_time;
+       alarm_entry_t *alarm_info;
+       int result;
+       struct timeval current_time;
+       struct tm date;
+
+       if (delay < 0 || alarm_id < 0) {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       gettimeofday(&current_time, NULL);
+       if (current_time.tv_usec > 500 * 1000)
+               current_time.tv_sec += (delay + 1);
+       else
+               current_time.tv_sec += delay;
+
+       localtime_r(&current_time.tv_sec, &date);
+
+       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;
+
+       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;
+       }
+
+       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_update_alarm(alarm_id, alarm_info,
+                       ALARM_UPDATE_FLAG_TIME);
+       alarmmgr_free_alarm(alarm_info);
+
+       return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_update_date(int alarm_id, struct tm *date)
+{
+       alarm_date_t internal_time;
+       alarm_entry_t *alarm_info;
+       int result;
+
+       if (date == NULL || alarm_id < 0) {
+               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_update_alarm(alarm_id, alarm_info,
+                       ALARM_UPDATE_FLAG_TIME);
+       alarmmgr_free_alarm(alarm_info);
+
+       return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_update_period(int alarm_id, int period)
+{
+       alarm_entry_t *alarm_info;
+       int result;
+
+       if (period < 0 || alarm_id < 0) {
+               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;
+       }
+
+       if (period == 0) {
+               result = alarmmgr_update_alarm(alarm_id, alarm_info,
+                               ALARM_UPDATE_FLAG_CLEAR_PERIOD);
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_set_repeat_mode(alarm_info,
+                       ALARM_REPEAT_MODE_REPEAT, period);
+       if (result < 0) {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_update_alarm(alarm_id, alarm_info,
+                       ALARM_UPDATE_FLAG_PERIOD);
+       alarmmgr_free_alarm(alarm_info);
+
+       return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_update_week_flag(int alarm_id, int week_flag)
+{
+       alarm_entry_t *alarm_info;
+       int result;
+
+       if (week_flag < 0 || alarm_id < 0) {
+               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;
+       }
+
+       if (week_flag == 0) {
+               result = alarmmgr_update_alarm(alarm_id, alarm_info,
+                               ALARM_UPDATE_FLAG_CLEAR_WEEK_FLAG);
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       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_update_alarm(alarm_id, alarm_info,
+                       ALARM_UPDATE_FLAG_WEEK);
+       alarmmgr_free_alarm(alarm_info);
+
+       return convert_error_code_to_alarm(__FUNCTION__, result);
+}