Add new alarm api to trigger notification 69/89869/12 accepted/tizen/3.0/common/20161114.081317 accepted/tizen/3.0/ivi/20161103.131751 accepted/tizen/3.0/mobile/20161103.131659 accepted/tizen/3.0/tv/20161103.131713 accepted/tizen/3.0/wearable/20161103.131734 submit/tizen/20161101.112858 submit/tizen_3.0/20161102.064015 submit/tizen_3.0_common/20161110.084657
authorJiwoong Im <jiwoong.im@samsung.com>
Tue, 27 Sep 2016 08:41:26 +0000 (17:41 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Tue, 1 Nov 2016 09:33:31 +0000 (18:33 +0900)
- 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 <jiwoong.im@samsung.com>
CMakeLists.txt
include/app_alarm.h
packaging/capi-appfw-alarm.spec
src/alarm.c

index e035ef0782d27330b0fdd3891fee5f80198b9765..c13372c09020ac8461f8421828b5ae59014500ff 100644 (file)
@@ -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})
index 15796ab3dda189d0f570b810d0d7e859c2c1d944..61dda96dd62f87861a34d245f35c8f677825040c 100644 (file)
@@ -21,6 +21,7 @@
 #include <tizen.h>
 #include <time.h>
 #include <app_control.h>
+#include <notification.h>
 
 #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);
+
 /**
  * @}
  */
index eea97234d51609d9a54a6f4b0621de3a6606edfd..d876c7976b9f7089d2955982f6aca5f135639770 100644 (file)
@@ -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.
index 7619dddcd51495c0dd1ebcb92aaf8316ec9e2059..8f7bbd47135573eb295a688f0584e70d4446d5f6 100644 (file)
@@ -28,6 +28,8 @@
 #include <app_alarm.h>
 #include <app_control_internal.h>
 
+#include <notification.h>
+
 #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;