From: Jiwoong Im Date: Mon, 31 Oct 2016 08:58:15 +0000 (+0900) Subject: handle app enable/disable signal X-Git-Tag: accepted/tizen/3.0/common/20161118.192940~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a30b1552fca95e1aeb07c818018ec2ef6917fee7;p=platform%2Fcore%2Fappfw%2Falarm-manager.git handle app enable/disable signal - backup/restore alarm to handle app enable/disable signal Change-Id: Id90b0004f7452ce1d93759e417eb79808865e5cf Signed-off-by: Jiwoong Im --- diff --git a/alarm-manager-registry.c b/alarm-manager-registry.c index 9268037..a9c7ce0 100644 --- a/alarm-manager-registry.c +++ b/alarm-manager-registry.c @@ -40,6 +40,8 @@ #define MAX_GCONF_PATH_LEN 256 #define MAX_QUERY_LEN 4096 +extern GSList *g_disabled_alarm_list; + extern __alarm_server_context_t alarm_context; extern sqlite3 *alarmmgr_db; @@ -57,11 +59,11 @@ bool _save_alarms(__alarm_info_t *__alarm_info) alarm_mode_t *mode = &alarm_info->mode; char *query = sqlite3_mprintf("insert into alarmmgr( alarm_id, start,\ - end, uid, pid, global, caller_pkgid, callee_pkgid, app_unique_name,\ + end, uid, pid, global, is_disabled, caller_pkgid, callee_pkgid, app_unique_name,\ app_service_name, app_service_name_mod, bundle, noti_len, noti, year,\ month, day, hour, min, sec, day_of_week, repeat,\ alarm_type, reserved_info, dst_service_name, dst_service_name_mod)\ - values (%d,%d,%d,%d,%d,%d,%Q,%Q,%Q,%Q,%Q,%Q,%d,%Q,%d,%d,%d,%d,%d,%d,%d,%d,\ + values (%d,%d,%d,%d,%d,%d,0,%Q,%Q,%Q,%Q,%Q,%Q,%d,%Q,%d,%d,%d,%d,%d,%d,%d,%d,\ %d,%d,%Q,%Q)",\ __alarm_info->alarm_id, (int)__alarm_info->start, @@ -116,7 +118,7 @@ bool _update_alarms(__alarm_info_t *__alarm_info) alarm_mode_t *mode = &alarm_info->mode; char *query = sqlite3_mprintf("update alarmmgr set start=%d, end=%d,\ - uid=%d, pid=%d, global=%d, caller_pkgid=%Q, callee_pkgid=%Q, app_unique_name=%Q, app_service_name=%Q, app_service_name_mod=%Q,\ + uid=%d, pid=%d, global=%d, is_disabled=0, caller_pkgid=%Q, callee_pkgid=%Q, app_unique_name=%Q, app_service_name=%Q, app_service_name_mod=%Q,\ bundle=%Q, noti_len=%d, noti=%Q, year=%d, month=%d, day=%d, hour=%d, min=%d, sec=%d,\ day_of_week=%d, repeat=%d, alarm_type=%d,\ reserved_info=%d, dst_service_name=%Q, dst_service_name_mod=%Q\ @@ -191,6 +193,7 @@ bool _load_alarms_from_registry() __alarm_info_t *__alarm_info = NULL; alarm_date_t *start = NULL; alarm_mode_t *mode = NULL; + int is_disabled; char caller_pkgid[MAX_PKG_ID_LEN] = {0,}; char callee_pkgid[MAX_PKG_ID_LEN] = {0,}; char app_unique_name[MAX_SERVICE_NAME_LEN] = {0,}; @@ -227,6 +230,7 @@ bool _load_alarms_from_registry() __alarm_info->uid = sqlite3_column_int(stmt, col_idx++); __alarm_info->pid = sqlite3_column_int(stmt, col_idx++); __alarm_info->global = sqlite3_column_int(stmt, col_idx++); + is_disabled = sqlite3_column_int(stmt, col_idx++); strncpy(caller_pkgid, (const char *)sqlite3_column_text(stmt, col_idx++), MAX_PKG_ID_LEN - 1); @@ -274,8 +278,14 @@ bool _load_alarms_from_registry() __alarm_info->quark_bundle = g_quark_from_string(bundle); __alarm_info->quark_noti = g_quark_from_string(noti); - _alarm_next_duetime(__alarm_info); - alarm_context.alarms = g_slist_append(alarm_context.alarms, __alarm_info); + if (is_disabled) { + _alarm_next_duetime(__alarm_info); + g_disabled_alarm_list = g_slist_append(g_disabled_alarm_list, __alarm_info); + ALARM_MGR_EXCEPTION_PRINT("Save alarm_id[%d] caller[%s] callee[%s]", __alarm_info->alarm_id, caller_pkgid, callee_pkgid); + } else { + _alarm_next_duetime(__alarm_info); + alarm_context.alarms = g_slist_append(alarm_context.alarms, __alarm_info); + } } @@ -287,3 +297,20 @@ bool _load_alarms_from_registry() return true; } + +void _update_db_for_disabled_alarm(alarm_id_t alarm_id, bool disabled) +{ + char *error_message = NULL; + + ALARM_MGR_EXCEPTION_PRINT("Update (%d) is_disabled to (%d)", alarm_id, disabled); + char *query = sqlite3_mprintf("update alarmmgr set is_disabled=%d where alarm_id=%d", disabled, alarm_id); + + if (SQLITE_OK != sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) { + SECURE_LOGE("Failed to update the DB table. error message = %s", error_message); + if (error_message) + sqlite3_free(error_message); + } + + sqlite3_free(query); + return; +} diff --git a/alarm-manager.c b/alarm-manager.c index fcf0929..0a375ce 100644 --- a/alarm-manager.c +++ b/alarm-manager.c @@ -67,6 +67,7 @@ bool g_dummy_timer_is_set = FALSE; GSList *g_scheduled_alarm_list = NULL; GSList *g_expired_alarm_list = NULL; +GSList *g_disabled_alarm_list; #ifndef RTC_WKALM_BOOT_SET #define RTC_WKALM_BOOT_SET _IOW('p', 0x80, struct rtc_wkalrm) @@ -1880,6 +1881,82 @@ static void __on_system_time_external_changed(keynode_t *node, void *data) return; } +static int __on_app_enable_cb(uid_t target_uid, int req_id, + const char *pkg_type, const char *pkgid, const char *appid, + const char *key, const char *val, const void *pmsg, void *data) +{ + SECURE_LOGD("appid:%s, key:%s, val:%s, req_id: %d", appid, key, val, req_id); + + GSList *gs_iter = NULL; + __alarm_info_t *entry = NULL; + int duetime = 0; + bool is_restored = false; + + if (key && strncmp(key, "end", 3) == 0 && val && strncmp(val, "ok", 2) == 0) { + SECURE_LOGD("Enable appid(%s)", appid); + for (gs_iter = g_disabled_alarm_list; gs_iter != NULL; ) { + entry = gs_iter->data; + + gs_iter = g_slist_next(gs_iter); + if (strncmp(appid, g_quark_to_string(entry->quark_app_unique_name), strlen(appid)) == 0) { + duetime = _alarm_next_duetime(entry); + SECURE_LOGD("Restore alarm_id(%d) duetime(%d) appid(%s)", entry->alarm_id, duetime, appid); + alarm_context.alarms = g_slist_append(alarm_context.alarms, entry); + g_disabled_alarm_list = g_slist_remove(g_disabled_alarm_list, entry); + + if (!(entry->alarm_info.alarm_type & ALARM_TYPE_VOLATILE)) + _update_db_for_disabled_alarm(entry->alarm_id, false); + is_restored = true; + } + } + + if (is_restored) { + _alarm_disable_timer(alarm_context); + _clear_scheduled_alarm_list(); + _alarm_schedule(); + __rtc_set(); + } + } + + return 0; +} + +static int __on_app_disable_cb(uid_t target_uid, int req_id, + const char *pkg_type, const char *pkgid, const char *appid, + const char *key, const char *val, const void *pmsg, void *data) +{ + SECURE_LOGD("appid:%s, key:%s, val:%s, req_id: %d", appid, key, val, req_id); + + GSList *gs_iter = NULL; + __alarm_info_t *entry = NULL; + bool is_disabled = false; + + if (key && strncmp(key, "end", 3) == 0 && val && strncmp(val, "ok", 2) == 0) { + SECURE_LOGD("Disable appid(%s)", appid); + for (gs_iter = alarm_context.alarms; gs_iter != NULL; ) { + entry = gs_iter->data; + + gs_iter = g_slist_next(gs_iter); + if (strncmp(appid, g_quark_to_string(entry->quark_app_unique_name), strlen(appid)) == 0) { + if (!(entry->alarm_info.alarm_type & ALARM_TYPE_VOLATILE)) + _update_db_for_disabled_alarm(entry->alarm_id, true); + g_disabled_alarm_list = g_slist_append(g_disabled_alarm_list, entry); + alarm_context.alarms = g_slist_remove(alarm_context.alarms, entry); + is_disabled = true; + } + } + + if (is_disabled) { + _alarm_disable_timer(alarm_context); + _clear_scheduled_alarm_list(); + _alarm_schedule(); + __rtc_set(); + } + } + + return 0; +} + static int __on_app_uninstalled(uid_t target_uid, int req_id, const char *pkg_type, const char *pkgid, const char *key, const char *val, const void *pmsg, void *user_data) @@ -3576,11 +3653,15 @@ static bool __initialize_noti() } /* If the caller or callee app is uninstalled, all registered alarms will be canceled. */ - int event_type = PKGMGR_CLIENT_STATUS_UNINSTALL; pkgmgr_client *pc = pkgmgr_client_new(PC_LISTENING); - pkgmgr_client_set_status_type(pc, event_type); + pkgmgr_client_set_status_type(pc, PKGMGR_CLIENT_STATUS_UNINSTALL); pkgmgr_client_listen_status(pc, __on_app_uninstalled, NULL); + pkgmgr_client_set_status_type(pc, PKGMGR_CLIENT_STATUS_ENABLE_APP); + pkgmgr_client_listen_app_status(pc, __on_app_enable_cb, NULL); + + pkgmgr_client_set_status_type(pc, PKGMGR_CLIENT_STATUS_DISABLE_APP); + pkgmgr_client_listen_app_status(pc, __on_app_disable_cb, NULL); return true; } @@ -3708,6 +3789,7 @@ static bool __initialize_dbus() uid integer,\ pid integer,\ global integer,\ + is_disabled integer,\ caller_pkgid text,\ callee_pkgid text,\ app_unique_name text,\ diff --git a/include/alarm-internal.h b/include/alarm-internal.h index 9d37168..1d3b623 100644 --- a/include/alarm-internal.h +++ b/include/alarm-internal.h @@ -245,6 +245,8 @@ bool _init_scheduled_alarm_list(); time_t _get_periodic_alarm_standard_time(void); +void _update_db_for_disabled_alarm(alarm_id_t alarm_id, bool disabled_by_ups); + #ifdef _DEBUG_MODE_ #define ALARM_MGR_LOG_PRINT(FMT, ARG...) do { printf("%5d", getpid()); printf ("%s() : "FMT"\n", __FUNCTION__, ##ARG); } while (false)