summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInkyun Kil <inkyun.kil@samsung.com>2019-09-27 13:18:31 +0900
committerInkyun Kil <inkyun.kil@samsung.com>2019-09-30 13:30:42 +0900
commit1a391e08c6fb9d93a2672b051ab3d358526a3e3a (patch)
tree883f4f74e5b4ccf8c859764b69e337a4e6d7c6f2
parent5a5813e30a9dd5d99ff7057a5c0501f544c96fa9 (diff)
downloadalarm-manager-1a391e08c6fb9d93a2672b051ab3d358526a3e3a.tar.gz
alarm-manager-1a391e08c6fb9d93a2672b051ab3d358526a3e3a.tar.bz2
alarm-manager-1a391e08c6fb9d93a2672b051ab3d358526a3e3a.zip
Splits long function
Change-Id: I9993f1d900d8b3f3875dc73c4dffcaedbf1637a0 Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
-rwxr-xr-xserver/alarm-manager.c400
1 files changed, 210 insertions, 190 deletions
diff --git a/server/alarm-manager.c b/server/alarm-manager.c
index d3c43b2..6849c0f 100755
--- a/server/alarm-manager.c
+++ b/server/alarm-manager.c
@@ -1363,15 +1363,27 @@ static notification_h __get_notification(guchar *data, int datalen)
return noti;
}
-static int __post_notification(guchar *data, int datalen, uid_t uid)
+static void __expire_notification(__alarm_info_t *alarm_info)
{
int ret;
+ int datalen;
notification_h noti;
+ guchar *noti_data;
int expire_mode = ALARM_EXPIRE_MODE_NORMAL;
- noti = __get_notification(data, datalen);
- if (noti == NULL)
- return -1;
+ noti_data = g_base64_decode(alarm_info->noti,
+ (gsize *)&datalen);
+ if (!noti_data) {
+ LOGE("Failed to decode noti data");
+ return;
+ }
+
+ noti = __get_notification(noti_data, datalen);
+ if (noti == NULL) {
+ LOGE("Failed to get notification");
+ g_free(noti_data);
+ return;
+ }
if (vconf_get_int(VCONFKEY_ALARM_EXPIRE_MODE, &expire_mode) != 0)
LOGE("Failed to get value of VCONFKEY_ALARM_EXPIRE_MODE");
@@ -1381,11 +1393,92 @@ static int __post_notification(guchar *data, int datalen, uid_t uid)
if (expire_mode == ALARM_EXPIRE_MODE_NORMAL)
device_display_change_state(DISPLAY_STATE_NORMAL);
- ret = notification_post_for_uid(noti, uid);
+ ret = notification_post_for_uid(noti, alarm_info->uid);
+ if (ret != NOTIFICATION_ERROR_NONE)
+ LOGE("Failed to post notification");
notification_free(noti);
+ g_free(noti_data);
+}
- return ret;
+static void __expire_app_control(__alarm_info_t *alarm_info)
+{
+ char alarm_id_val[32];
+ bundle *b = NULL;
+ char *appid = NULL;
+ int b_len = 0;
+ int app_pid = 0;
+ int ret;
+ int result = 0;
+ int expire_mode = ALARM_EXPIRE_MODE_NORMAL;
+ uid_t target_uid;
+
+ b_len = strlen(alarm_info->bundle);
+ b = bundle_decode((bundle_raw *)(alarm_info->bundle), b_len);
+ if (b == NULL) {
+ LOGE("Error!!!..Unable to decode the bundle!!\n");
+ return;
+ }
+
+ snprintf(alarm_id_val, sizeof(alarm_id_val), "%d", alarm_info->alarm_id);
+
+ if (bundle_add_str(b, "http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)) {
+ LOGE("Unable to add alarm id to the bundle\n");
+ bundle_free(b);
+ return;
+ }
+
+ app_pid = _get_pid_from_appid(alarm_info->app_unique_name,
+ alarm_info->uid);
+ SECURE_LOGW("alarm_expired : from [uid : %d, pid : %d, pkgid : %s, "
+ "unique_name : %s]", alarm_info->uid, app_pid,
+ alarm_info->caller_pkgid, alarm_info->app_unique_name);
+
+ if (_compare_api_version(&result, app_pid, alarm_info->uid) < 0) {
+ LOGE("Unable to check api version\n");
+ result = -1;
+ }
+
+ if (result < 0) {
+ /* before 2.4 */
+ if (aul_svc_run_service_async_for_uid(b, 0, NULL, NULL, alarm_info->uid) < 0)
+ LOGE("Unable to run app svc\n");
+ else
+ LOGD("Successfuly run app svc\n");
+ } else {
+ /* since 2.4 */
+ appid = (char *)appsvc_get_appid(b);
+ if ((alarm_info->alarm_info.alarm_type & ALARM_TYPE_NOLAUNCH) && !aul_app_is_running(appid)) {
+ LOGE("This alarm is ignored\n");
+ } else if (!(alarm_info->alarm_info.alarm_type & ALARM_TYPE_INEXACT) ||
+ !_can_skip_expired_cb(alarm_info->alarm_id)) {
+ if (alarm_info->global) {
+ if (__find_login_user(&target_uid) < 0) {
+ LOGE("Fail to get login user\n");
+ ret = -1;
+ } else {
+ ret = aul_svc_run_service_async_for_uid(b, 0, NULL, NULL, target_uid);
+ }
+ } else {
+ ret = aul_svc_run_service_async_for_uid(b, 0, NULL, NULL, alarm_info->uid);
+ }
+
+ if (ret < 0) {
+ LOGE("Unable to launch app [%s] \n", appid);
+ } else {
+ if (vconf_get_int(VCONFKEY_ALARM_EXPIRE_MODE, &expire_mode) != 0)
+ LOGE("Failed to get value of VCONFKEY_ALARM_EXPIRE_MODE");
+
+ LOGD("Successfuly ran app svc (expire_mode : %d)", expire_mode);
+
+ if (_is_ui_app(appid, alarm_info->uid) &&
+ expire_mode == ALARM_EXPIRE_MODE_NORMAL)
+ device_display_change_state(DISPLAY_STATE_NORMAL);
+ }
+ }
+ }
+
+ bundle_free(b);
}
static int __app_info_iter(const aul_app_info *info, void *data)
@@ -1398,22 +1491,113 @@ static int __app_info_iter(const aul_app_info *info, void *data)
return 0;
}
-void _alarm_expired()
+static void __expire_dbus_activation(__alarm_info_t *alarm_info)
{
- int ret;
- bool is_app = false;
const char *destination_app_service_name = NULL;
- alarm_id_t alarm_id = -1;
- int app_pid = 0;
+ char appid[MAX_SERVICE_NAME_LEN] = { 0, };
+ struct running_info_t app_info;
+ bundle *kb;
+ uid_t target_uid;
+ bool is_app = false;
+
+ if (alarm_info->dst_service_name == NULL) {
+ SECURE_LOGD("[alarm-server]:destination is null, so we send expired alarm to %s.",
+ alarm_info->app_service_name);
+ destination_app_service_name = alarm_info->app_service_name_mod;
+ } else {
+ SECURE_LOGD("[alarm-server]:destination :%s",
+ alarm_info->dst_service_name);
+ destination_app_service_name = alarm_info->dst_service_name_mod;
+ }
+
+ /*
+ * we should consider a situation that
+ * destination_app_service_name is owner_name like (:xxxx) and
+ * application's pid which registered this alarm was killed.In that case,
+ * we don't need to send the expire event because the process was killed.
+ * this causes needless message to be sent.
+ */
+
+ if (alarm_info->dst_service_name == NULL) {
+ if (alarm_info->app_service_name != NULL && strlen(alarm_info->app_service_name) > 6)
+ strncpy(appid, alarm_info->app_service_name + 6, sizeof(appid) - 1);
+ } else {
+ if (strlen(alarm_info->dst_service_name) > 6)
+ strncpy(appid, alarm_info->dst_service_name + 6, sizeof(appid) - 1);
+ }
+
+ if (alarm_info->uid >= REGULAR_UID_MIN) {
+ is_app = _is_app(appid, alarm_info->uid);
+ }
+ LOGD("appid : %s app?(%d)", appid, is_app);
+
+ /* Case #3-1. The process was killed && App type
+ * This app is launched and owner of DBus connection is changed. and then, expiration noti is sent by DBus. */
+ app_info.is_running = false;
+ if (is_app) {
+ app_info.appid = appid;
+ aul_app_get_all_running_app_info_for_uid(__app_info_iter,
+ &app_info, alarm_info->uid);
+
+ SECURE_LOGD("[alarm-server]: destination_app_id :%s", appid);
+ }
+
+ if (is_app && !app_info.is_running) {
+ __expired_alarm_t *expire_info;
+ char alarm_id_str[32] = { 0, };
+
+ if (alarm_info->alarm_info.alarm_type & ALARM_TYPE_WITHCB) {
+ __alarm_remove_from_list(alarm_info->uid, alarm_info->alarm_id, NULL);
+ LOGW("[alarm-server]:This alarm_type is WITHCB");
+ return;
+ }
+
+ expire_info = (__expired_alarm_t *)malloc(sizeof(__expired_alarm_t));
+ if (G_UNLIKELY(NULL == expire_info)) {
+ LOGE("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n");
+ return;
+ }
+ memset(expire_info, '\0', sizeof(__expired_alarm_t));
+ strncpy(expire_info->service_name, destination_app_service_name, MAX_SERVICE_NAME_LEN-1);
+ expire_info->alarm_id = alarm_info->alarm_id;
+ expire_info->uid = alarm_info->uid;
+ g_expired_alarm_list = g_slist_append(g_expired_alarm_list, expire_info);
+
+ snprintf(alarm_id_str, 31, "%d", alarm_info->alarm_id);
+
+ SECURE_LOGD("before aul_launch appid(%s) alarm_id_str(%s)", appid, alarm_id_str);
+
+ kb = bundle_create();
+ bundle_add_str(kb, "__ALARM_MGR_ID", alarm_id_str);
+
+ if (alarm_info->global) {
+ if (__find_login_user(&target_uid) < 0)
+ LOGE("Fail to get login user\n");
+ else
+ aul_launch_app_for_uid(appid, kb, target_uid); /* on_bus_name_owner_changed will be called. */
+ } else {
+ aul_launch_app_for_uid(appid, kb, alarm_info->uid); /* on_bus_name_owner_changed will be called. */
+ }
+
+ bundle_free(kb);
+ } else {
+ /* Case #3-2. The process is alive or was killed && non-app type(daemon)
+ * Expiration noti is sent by DBus. it makes the process alive. (dbus auto activation) */
+ LOGD("before alarm_send_noti_to_application");
+
+ _alarm_send_noti_to_application_by_dbus(destination_app_service_name,
+ alarm_info->alarm_id, alarm_info->alarm_info.msec, alarm_info->uid); /* dbus auto activation */
+ LOGD("after _alarm_send_noti_to_application_by_dbus");
+ }
+
+ return 0;
+}
+
+void _alarm_expired()
+{
__alarm_info_t *__alarm_info = NULL;
GSList *iter = NULL;
__scheduled_alarm_t *alarm = NULL;
- char alarm_id_val[32];
- int b_len = 0;
- bundle *b = NULL;
- bundle *kb;
- char *appid = NULL;
- uid_t target_uid;
LOGD("[alarm-server]: Enter");
@@ -1440,192 +1624,28 @@ void _alarm_expired()
for (iter = g_scheduled_alarm_list; iter != NULL; iter = g_slist_next(iter)) {
alarm = (__scheduled_alarm_t *)iter->data;
- alarm_id = alarm->alarm_id;
__alarm_info = alarm->__alarm_info;
- app_pid = _get_pid_from_appid(__alarm_info->app_unique_name,
- __alarm_info->uid);
/* Case #1. The process is an application launched by app_control.
* It registered an alarm using launch-based APIs like alarm_schedule_xxx, alarmmgr_xxx_appsvc. */
if (__alarm_info->bundle != NULL) {
- b_len = strlen(__alarm_info->bundle);
-
- b = bundle_decode((bundle_raw *)(__alarm_info->bundle), b_len);
-
- if (b == NULL) {
- LOGE("Error!!!..Unable to decode the bundle!!\n");
- } else {
- snprintf(alarm_id_val, sizeof(alarm_id_val), "%d", alarm_id);
-
- if (bundle_add_str(b, "http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)) {
- LOGE("Unable to add alarm id to the bundle\n");
- } else {
- int result = 0;
- int expire_mode = ALARM_EXPIRE_MODE_NORMAL;
- if (vconf_get_int(VCONFKEY_ALARM_EXPIRE_MODE, &expire_mode) != 0)
- LOGE("Failed to get value of VCONFKEY_ALARM_EXPIRE_MODE");
-
- LOGD("Value of alarm_expire_mode [%d]", expire_mode);
- SECURE_LOGW("alarm_expired : from [uid : %d, pid : %d, pkgid : %s, "
- "unique_name : %s]", __alarm_info->uid, app_pid,
- __alarm_info->caller_pkgid, __alarm_info->app_unique_name);
-
- if (_compare_api_version(&result, app_pid, __alarm_info->uid) < 0) {
- LOGE("Unable to check api version\n");
- result = -1;
- }
-
- if (result < 0) {
- /* before 2.4 */
- if (aul_svc_run_service_async_for_uid(b, 0, NULL, NULL, __alarm_info->uid) < 0)
- LOGE("Unable to run app svc\n");
- else
- LOGD("Successfuly run app svc\n");
- } else {
- /* since 2.4 */
- appid = (char *)appsvc_get_appid(b);
- if ((__alarm_info->alarm_info.alarm_type & ALARM_TYPE_NOLAUNCH) && !aul_app_is_running(appid)) {
- LOGE("This alarm is ignored\n");
- } else if (!(__alarm_info->alarm_info.alarm_type & ALARM_TYPE_INEXACT) ||
- !_can_skip_expired_cb(__alarm_info->alarm_id)) {
- if (__alarm_info->global) {
- if (__find_login_user(&target_uid) < 0) {
- LOGE("Fail to get login user\n");
- ret = -1;
- } else {
- ret = aul_svc_run_service_async_for_uid(b, 0, NULL, NULL, target_uid);
- }
- } else {
- ret = aul_svc_run_service_async_for_uid(b, 0, NULL, NULL, __alarm_info->uid);
- }
-
- if (ret < 0) {
- LOGE("Unable to launch app [%s] \n", appid);
- } else {
- LOGD("Successfuly ran app svc\n");
- if (_is_ui_app(appid, __alarm_info->uid) &&
- expire_mode == ALARM_EXPIRE_MODE_NORMAL)
- device_display_change_state(DISPLAY_STATE_NORMAL);
- }
- }
- }
- }
- bundle_free(b);
- }
+ __expire_app_control(__alarm_info);
} else if (__alarm_info->noti != NULL) {
- guchar *noti_data;
- int datalen;
- ret = -1;
-
- noti_data = g_base64_decode(__alarm_info->noti,
- (gsize *)&datalen);
- if (noti_data) {
- ret = __post_notification(noti_data, datalen, __alarm_info->uid);
- free(noti_data);
- }
-
- if (ret < 0)
- LOGE("Failed to post notification\n");
+ /* Case #2. The process is an application launched by notification. */
+ __expire_notification(__alarm_info);
} else {
- char appid[MAX_SERVICE_NAME_LEN] = { 0, };
- struct running_info_t app_info;
-
- if (__alarm_info->dst_service_name == NULL) {
- SECURE_LOGD("[alarm-server]:destination is null, so we send expired alarm to %s.",
- __alarm_info->app_service_name);
- destination_app_service_name = __alarm_info->app_service_name_mod;
- } else {
- SECURE_LOGD("[alarm-server]:destination :%s",
- __alarm_info->dst_service_name);
- destination_app_service_name = __alarm_info->dst_service_name_mod;
- }
-
- /*
- * we should consider a situation that
- * destination_app_service_name is owner_name like (:xxxx) and
- * application's pid which registered this alarm was killed.In that case,
- * we don't need to send the expire event because the process was killed.
- * this causes needless message to be sent.
- */
-
- if (__alarm_info->dst_service_name == NULL) {
- if (__alarm_info->app_service_name != NULL && strlen(__alarm_info->app_service_name) > 6)
- strncpy(appid, __alarm_info->app_service_name + 6, sizeof(appid) - 1);
- } else {
- if (strlen(__alarm_info->dst_service_name) > 6)
- strncpy(appid, __alarm_info->dst_service_name + 6, sizeof(appid) - 1);
- }
-
- if (__alarm_info->uid >= REGULAR_UID_MIN) {
- is_app = _is_app(appid, __alarm_info->uid);
- }
- LOGD("appid : %s app?(%d)", appid, is_app);
-
- /* Case #2. The process was killed && App type
- * This app is launched and owner of DBus connection is changed. and then, expiration noti is sent by DBus. */
- app_info.is_running = false;
- if (is_app) {
- app_info.appid = appid;
- aul_app_get_all_running_app_info_for_uid(__app_info_iter,
- &app_info, __alarm_info->uid);
-
- SECURE_LOGD("[alarm-server]: destination_app_id :%s", appid);
- }
-
- if (is_app && !app_info.is_running) {
- __expired_alarm_t *expire_info;
- char alarm_id_str[32] = { 0, };
-
- if (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_WITHCB) {
- __alarm_remove_from_list(__alarm_info->uid, alarm_id, NULL);
- goto done;
- }
-
- expire_info = (__expired_alarm_t *)malloc(sizeof(__expired_alarm_t));
- if (G_UNLIKELY(NULL == expire_info)) {
- LOGE("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n");
- goto done;
- }
- memset(expire_info, '\0', sizeof(__expired_alarm_t));
- strncpy(expire_info->service_name, destination_app_service_name, MAX_SERVICE_NAME_LEN-1);
- expire_info->alarm_id = alarm_id;
- expire_info->uid = __alarm_info->uid;
- g_expired_alarm_list = g_slist_append(g_expired_alarm_list, expire_info);
-
- snprintf(alarm_id_str, 31, "%d", alarm_id);
-
- SECURE_LOGD("before aul_launch appid(%s) alarm_id_str(%s)", appid, alarm_id_str);
-
- kb = bundle_create();
- bundle_add_str(kb, "__ALARM_MGR_ID", alarm_id_str);
-
- if (__alarm_info->global) {
- if (__find_login_user(&target_uid) < 0)
- LOGE("Fail to get login user\n");
- else
- aul_launch_app_for_uid(appid, kb, target_uid); /* on_bus_name_owner_changed will be called. */
- } else {
- aul_launch_app_for_uid(appid, kb, __alarm_info->uid); /* on_bus_name_owner_changed will be called. */
- }
-
- bundle_free(kb);
- } else {
- /* Case #3. The process is alive or was killed && non-app type(daemon)
- * Expiration noti is sent by DBus. it makes the process alive. (dbus auto activation) */
- LOGD("before alarm_send_noti_to_application");
-
- _alarm_send_noti_to_application_by_dbus(destination_app_service_name,
- alarm_id, __alarm_info->alarm_info.msec, __alarm_info->uid); /* dbus auto activation */
- LOGD("after _alarm_send_noti_to_application_by_dbus");
- }
+ /* Case #3. Expiration noti is sent by DBus.
+ * 3-1. The process was killed && App type
+ * 3-2. The process is alive or was killed && non-app type(daemon) */
+ __expire_dbus_activation(__alarm_info);
}
- LOGD("alarm_id[%d] is expired.", alarm_id);
+ LOGD("alarm_id[%d] is expired.", __alarm_info->alarm_id);
_save_alarm_info_log("EXPIRED", __alarm_info);
if (__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_ONCE) {
- __alarm_remove_from_list(__alarm_info->uid, alarm_id, NULL);
+ __alarm_remove_from_list(__alarm_info->uid, __alarm_info->alarm_id, NULL);
} else {
_alarm_set_next_duetime(__alarm_info);
_save_alarm_info_log("DUETIME", __alarm_info);