From: Inkyun Kil Date: Tue, 16 Jun 2020 02:20:41 +0000 (+0900) Subject: Improve registering ambient alarm X-Git-Tag: accepted/tizen/unified/20210428.040333~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f76d960cb6a6b0f664fe63f7461faf6ca1a2d27;p=platform%2Fcore%2Fapi%2Fapplication.git Improve registering ambient alarm When call set_lifecycle api -> After getting "ui.ambientchange" signal Change-Id: I9896a709b58afba07b47d0f9706fef759e6fd8c6 Signed-off-by: Inkyun Kil --- diff --git a/appcore_ui_app_ambient/src/ui_app_ambient.c b/appcore_ui_app_ambient/src/ui_app_ambient.c index b256c26..2046d7c 100644 --- a/appcore_ui_app_ambient/src/ui_app_ambient.c +++ b/appcore_ui_app_ambient/src/ui_app_ambient.c @@ -71,6 +71,7 @@ static struct ambient_tick_type_info { static aul_app_com_connection_h __conn; static bool __initialized = false; +static bool __is_ambient_mode = false; static void __alarm_init(void) { @@ -206,13 +207,31 @@ int __on_change_signal(const char *endpoint, aul_app_com_result_e e, bundle *b = NULL; char *extra; char *mode; + ui_app_ambient_state_e state; bundle_get_str(envelope, "__AMBIENT_MODE__", &mode); bundle_get_str(envelope, "__AMBIENT_EXTRA__", &extra); b = bundle_decode((bundle_raw *)extra, strlen(extra)); + state = (ui_app_ambient_state_e)atoi(mode); + if (ambient_lifecycle.ambient_changed) - ambient_lifecycle.ambient_changed((ui_app_ambient_state_e)atoi(mode), b, user_data); + ambient_lifecycle.ambient_changed(state, b, user_data); + + if (state == UI_APP_AMBIENT_STATE_ENTER && !__is_ambient_mode) { + int ret = __set_ambient_tick_cb(); + if (ret != 0) + LOGE("Failed to set ambient tick cb : %d", ret); + else + __is_ambient_mode = true; + } else if (state == UI_APP_AMBIENT_STATE_LEAVE && __is_ambient_mode) { + if (ambient_lifecycle.alarm_id) { + alarmmgr_remove_alarm(ambient_lifecycle.alarm_id); + ambient_lifecycle.alarm_id = 0; + } + + __is_ambient_mode = false; + } if (b) bundle_free(b); @@ -259,12 +278,6 @@ int ui_app_ambient_set_lifecycle(ui_app_ambient_lifecycle_callback_s *lifecycle, ambient_lifecycle.ambient_changed = lifecycle->ambient_changed; ambient_lifecycle.user_data = user_data; - ret = __set_ambient_tick_cb(); - if (ret != 0) { - LOGE("Failed to set ambient tick cb : %d", ret); - return ret; - } - ret = __set_ambient_changed_cb(); if (ret != 0) { LOGE("Failed to set ambient changed cb : %d", ret); @@ -308,9 +321,11 @@ int ui_app_ambient_set_update_period(ui_app_ambient_update_period_e period) LOGD("set update period : %d", period); ambient_lifecycle.period_type = period; - if (ambient_lifecycle.alarm_id) { - alarmmgr_remove_alarm(ambient_lifecycle.alarm_id); - ambient_lifecycle.alarm_id = 0; + if (__is_ambient_mode) { + if (ambient_lifecycle.alarm_id) { + alarmmgr_remove_alarm(ambient_lifecycle.alarm_id); + ambient_lifecycle.alarm_id = 0; + } if (ambient_lifecycle.period_type != UI_APP_AMBIENT_UPDATE_NONE) ret = __set_ambient_tick_cb();