Support listening the status of the specified app 50/89150/2 accepted/tizen/common/20160926.154000 accepted/tizen/ivi/20160926.001027 accepted/tizen/mobile/20160926.000912 accepted/tizen/tv/20160926.000956 accepted/tizen/wearable/20160926.001010 submit/tizen/20160925.092015
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 22 Sep 2016 09:22:25 +0000 (18:22 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 22 Sep 2016 23:10:37 +0000 (08:10 +0900)
Change-Id: I3ee2aca6a0faad0dd2dc401cb4fb323694807e67
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/aul.h
include/aul_cmd.h
include/launch.h
packaging/aul.spec
src/launch.c
src/status.c

index 405bb00..5b3d09e 100644 (file)
@@ -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
index 63f43fe..9fea3bd 100644 (file)
@@ -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
 };
 
index ddcace4..d137267 100644 (file)
@@ -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);
 
index 61e512a..8f00e01 100644 (file)
@@ -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
index f542490..7106d61 100644 (file)
@@ -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");
        }
index 6089f2d..42d3c51 100644 (file)
@@ -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;
+}
+