From 5cf608e746efd00bae358ef3d67c5cd27ba97a4b Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 22 Sep 2016 18:22:25 +0900 Subject: [PATCH] Support listening the status of the specified app Change-Id: I3ee2aca6a0faad0dd2dc401cb4fb323694807e67 Signed-off-by: Hwankyu Jhun --- include/aul.h | 11 +++++++- include/aul_cmd.h | 2 ++ include/launch.h | 1 + packaging/aul.spec | 2 +- src/launch.c | 3 ++ src/status.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 98 insertions(+), 3 deletions(-) diff --git a/include/aul.h b/include/aul.h index 405bb00..5b3d09e 100644 --- a/include/aul.h +++ b/include/aul.h @@ -56,7 +56,8 @@ enum app_status { STATUS_DYING, STATUS_HOME, STATUS_NORESTART, - STATUS_SERVICE + STATUS_SERVICE, + STATUS_TERMINATE, }; typedef enum _aul_type { @@ -2944,6 +2945,14 @@ int aul_set_alias_appid(const char *alias_appid, const char *appid); */ int aul_unset_alias_appid(const char *alias_appid); +/* + * This API is only for Appfw internally. + */ +API int aul_listen_app_status(const char *appid, + int (*aul_handler)(const char *appid, const char *pkgid, + int pid, int status, int is_subapp, void *data), + void *data); + #ifdef __cplusplus } #endif diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 63f43fe..9fea3bd 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -111,6 +111,8 @@ enum app_cmd { APP_RESUME_BY_PID_ASYNC, APP_SET_ALIAS_APPID, APP_UNSET_ALIAS_APPID, + APP_LISTEN_STATUS, + APP_STATUS_NOTIFICATION, APP_CMD_MAX }; diff --git a/include/launch.h b/include/launch.h index ddcace4..d137267 100644 --- a/include/launch.h +++ b/include/launch.h @@ -45,4 +45,5 @@ int __call_aul_handler(aul_type type, bundle *kb); gboolean __aul_glib_handler(gpointer data); int app_com_recv(bundle *b); +void app_status_event(bundle *kb); diff --git a/packaging/aul.spec b/packaging/aul.spec index 61e512a..8f00e01 100644 --- a/packaging/aul.spec +++ b/packaging/aul.spec @@ -3,7 +3,7 @@ Name: aul Summary: App utility library -Version: 0.0.301 +Version: 0.0.302 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 diff --git a/src/launch.c b/src/launch.c index f542490..7106d61 100644 --- a/src/launch.c +++ b/src/launch.c @@ -448,6 +448,9 @@ int aul_sock_handler(int fd) case APP_SUSPEND: app_prepare_to_suspend(); break; + case APP_STATUS_NOTIFICATION: + app_status_event(kbundle); + break; default: _E("no support packet"); } diff --git a/src/status.c b/src/status.c index 6089f2d..42d3c51 100644 --- a/src/status.c +++ b/src/status.c @@ -33,9 +33,13 @@ typedef struct _app_status_cb_info_t { struct _app_status_cb_info_t *next; } app_status_cb_info_t; -app_status_cb_info_t *app_status_cb = NULL; +static int (*_aul_status_listen_handler)(const char *appid, const char *pkgid, + int pid, int status, int is_sub_app, void *data); +static void *_aul_status_listen_data; +static app_status_cb_info_t *app_status_cb; static int app_status = STATUS_LAUNCHING; +extern int aul_launch_fini(); API int aul_status_update(int status) { @@ -221,3 +225,79 @@ API int aul_set_process_group(int owner_pid, int child_pid) return ret; } +void app_status_event(bundle *kb) +{ + const char *appid; + const char *pkgid; + const char *val; + int pid = -1; + int status = -1; + int is_subapp = -1; + + if (kb == NULL) { + _E("Invalid parameter"); + return; + } + + appid = bundle_get_val(kb, AUL_K_APPID); + pkgid = bundle_get_val(kb, AUL_K_PKGID); + val = bundle_get_val(kb, AUL_K_PID); + if (val) + pid = atoi(val); + val = bundle_get_val(kb, AUL_K_STATUS); + if (val) + status = atoi(val); + val = bundle_get_val(kb, AUL_K_IS_SUBAPP); + if (val) + is_subapp = atoi(val); + + if (appid == NULL || pkgid == NULL || + pid == -1 || status == -1 || is_subapp == -1) { + _E("Failed to get app status info"); + return; + } + + if (_aul_status_listen_handler) { + _aul_status_listen_handler(appid, pkgid, pid, status, + is_subapp, _aul_status_listen_data); + } +} + +API int aul_listen_app_status(const char *appid, + int (*aul_handler)(const char *appid, const char *pkgid, + int pid, int status, int is_subapp, void *data), + void *data) +{ + int ret; + bundle *kb; + int initialized = 0; + + if (appid == NULL || aul_handler == NULL) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + if (!aul_is_initialized()) { + if (aul_launch_init(NULL, NULL) < 0) + return AUL_R_ENOINIT; + initialized = 1; + } + + kb = bundle_create(); + if (kb == NULL) { + _E("out of memory"); + if (initialized) + aul_launch_fini(); + return AUL_R_ERROR; + } + + bundle_add(kb, AUL_K_APPID, appid); + ret = app_send_cmd(AUL_UTIL_PID, APP_LISTEN_STATUS, kb); + bundle_free(kb); + + _aul_status_listen_handler = aul_handler; + _aul_status_listen_data = data; + + return ret; +} + -- 2.7.4