From: Jiwoong Im Date: Wed, 21 Sep 2016 05:32:43 +0000 (+0900) Subject: Add extension APIs for exact alarms of service app X-Git-Tag: accepted/tizen/3.0/ivi/20161011.053539^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F89%2F88889%2F1;p=platform%2Fcore%2Fapi%2Falarm.git Add extension APIs for exact alarms of service app Change-Id: I5f4fd15c806c8f7f1a91d099178f90fe723fb5c8 Signed-off-by: Jiwoong Im --- diff --git a/include/app_alarm_extension.h b/include/app_alarm_extension.h new file mode 100644 index 0000000..b9abadf --- /dev/null +++ b/include/app_alarm_extension.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2011 - 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __TIZEN_APPFW_ALARM_EXTENSION_H +#define __TIZEN_APPFW_ALARM_EXTENSION_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file app_alarm_extension.h + */ + +/** + * @addtogroup CAPI_ALARM_MODULE + * @{ + */ + +/** + * @brief Sets an exact alarm to be triggered after a specific time. + * @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 + * @remarks This API only allows service application which has Background Category to set an exact alarm. + * If the application is uninstalled after setting an alarm, the alarm is cancelled automatically. + * If the operation of @a app_control is not specified, #APP_CONTROL_OPERATION_DEFAULT is used r the launch request. + * If the operation of @a app_control is #APP_CONTROL_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application. + * If the appid of @a app_control is not specified, this api is not allowed. In other words, the explicit @a app_control is only allowed. + * The @a app_control only supports service application which has Background Category with this api. + * + * @param[in] app_control The destination app_control to perform a specific task when the alarm is triggered + * @param[in] delay The amount of time before the execution (in seconds) + * @param[out] alarm_id The alarm ID that uniquely identifies an 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_service_once_after_delay(app_control_h app_control, int delay, int *alarm_id); + +/** + * @brief Sets an alarm to be triggered at a specific time. + * @details The @a date describes the time of the first 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 + * @remarks This API only allows service application which has Background Category to set an exact alarm. + * If application is uninstalled after setting an alarm, the alarm is cancelled automatically. + * If the operation of @a app_control is not specified, #APP_CONTROL_OPERATION_DEFAULT is used for the launch request. + * If the operation of @a app_control is #APP_CONTROL_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application. + * If the appid of @a app_control is not specified, this api is not allowed. In other words, the explicit @a app_control is only allowed. + * The @a app_control only supports service application which has Background Category with this api. + * + * @param[in] app_control The destination app_control to perform specific work when the alarm is triggered + * @param[in] date The first active alarm time + * @param[out] alarm_id The alarm ID that uniquely identifies an 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_service_once_at_date(app_control_h app_control, struct tm *date, int *alarm_id); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_APPFW_ALARM_EXTENSION_H */ diff --git a/src/alarm.c b/src/alarm.c index 73858ec..7619ddd 100644 --- a/src/alarm.c +++ b/src/alarm.c @@ -514,3 +514,83 @@ int alarm_get_global(int alarm_id, bool *global) return convert_error_code_to_alarm(__FUNCTION__, ret); } + +/* extension API */ +int alarm_schedule_service_once_after_delay(app_control_h app_control, int delay, int *alarm_id) +{ + bundle *bundle_data; + int result = 0; + + if (app_control == NULL) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT | ALARM_TYPE_EXACT_SERVICE_APP, delay, 0, bundle_data, alarm_id); + + return convert_error_code_to_alarm(__FUNCTION__, result); +} + +int alarm_schedule_service_once_at_date(app_control_h app_control, struct tm *date, int *alarm_id) +{ + alarm_date_t internal_time; + alarm_entry_t* alarm_info; + bundle *bundle_data; + int result; + + if (app_control == NULL || date == NULL) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE) { + 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); + } + + 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 | ALARM_TYPE_EXACT_SERVICE_APP); + + 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); + + 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; +}