}
/* LCOV_EXCL_START */
-static int __get_ambient_tick_offset(struct _watch_base_time_s timeinfo,
+static alarm_entry_t* __get_ambient_tick_offset(struct _watch_base_time_s timeinfo,
int interval, int minute_base, int hour_base)
{
int remain_hour = 0;
int remain_min = 0;
int offset_sec = 0;
+ int ret;
+ time_t next;
+ struct tm next_tm;
+ alarm_entry_t *alarm_info = NULL;
+ alarm_date_t date = {0};
if (hour_base != 0) {
if (interval == ONE_DAY_IN_SEC) {
remain_min = minute_base - (timeinfo.minute % minute_base);
offset_sec = remain_min * ONE_MINUTE_IN_SEC - timeinfo.second;
}
- return offset_sec;
+
+ next = timeinfo.timestamp + offset_sec;
+ localtime_r(&next, &next_tm);
+
+ date.year = next_tm.tm_year + 1900;
+ date.month = next_tm.tm_mon + 1;
+ date.day = next_tm.tm_mday;
+ date.hour = next_tm.tm_hour;
+ date.min = next_tm.tm_min;
+ date.sec = next_tm.tm_sec;
+
+ alarm_info = alarmmgr_create_alarm();
+ if (!alarm_info)
+ return NULL;
+
+ alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
+
+ ret = alarmmgr_set_time(alarm_info, date);
+ if (ret != ALARMMGR_RESULT_SUCCESS) {
+ LOGE("Failed to alarmmgr_set_time : %d", ret);
+ alarmmgr_free_alarm(alarm_info);
+ return NULL;
+ }
+
+ ret = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_REPEAT,
+ interval);
+ if (ret != ALARMMGR_RESULT_SUCCESS) {
+ LOGE("Failed to alarmmgr_set_time : %d", ret);
+ alarmmgr_free_alarm(alarm_info);
+ return NULL;
+ }
+
+ LOGD("Next alarm tick [%d:%d:%d]", date.hour, date.min, date.sec);
+ return alarm_info;
}
/* LCOV_EXCL_STOP */
/* LCOV_EXCL_START */
static int __set_ambient_tick_cb(void *data)
{
- int offset_sec = 0;
int interval = 0;
struct _watch_base_time_s timeinfo = {
.timezone = NULL
};
int r;
struct ambient_tick_type_info info;
+ char appid_buf[APPID_BUFFER_MAX] = {0, };
+ alarm_entry_t *alarm_info = NULL;
_watch_base_time_get_timeinfo(&timeinfo);
info = ambient_tick_type_infos[ambient_tick_type];
if (interval == 0) {
__on_ambient_tick(&timeinfo, data);
} else {
- offset_sec = __get_ambient_tick_offset(timeinfo, info.interval,
+ alarm_info = __get_ambient_tick_offset(timeinfo, info.interval,
info.minute_base, info.hour_base);
- _D("next time tick: %d", offset_sec);
+ if (!alarm_info)
+ return -1;
+
+ alarmmgr_set_cb(__ambient_tick_cb, data);
/* Set a next alarm */
- r = alarmmgr_add_alarm_withcb(ALARM_TYPE_VOLATILE, offset_sec,
- interval, __ambient_tick_cb, data, &alarm_id);
+ if (aul_app_get_appid_bypid(getpid(), appid_buf, sizeof(appid_buf))
+ != AUL_R_OK) {
+ LOGE("Failed to get appid (%d)", getpid());
+ alarmmgr_free_alarm(alarm_info);
+ return -1;
+ }
+
+ r = alarmmgr_add_alarm_with_localtime(alarm_info, appid_buf, &alarm_id);
if (r < 0)
- _E("fail to alarmmgr_add_alarm_withcb : error_code : %d", r);
+ LOGE("fail to alarmmgr_add_alarm_with_localtime : error_code : %d", r);
__on_ambient_tick(&timeinfo, data);
}
+ alarmmgr_free_alarm(alarm_info);
if (timeinfo.timezone)
free(timeinfo.timezone);