Modify app_manager_resume_app API 25/114725/3
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 14 Feb 2017 23:14:06 +0000 (08:14 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 14 Feb 2017 23:32:39 +0000 (08:32 +0900)
If the app_context handle has an instance id, the API
uses the aul_resume_app_with_instance_id API to resume app instance.

Change-Id: I548b6e12af4407342e017878a03dcad79bd149b3
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/app_context.c
src/app_manager.c
src/app_manager_internal.h

index 7014c47..88f63a3 100644 (file)
@@ -39,7 +39,7 @@
 
 #define APPID_MAX 128
 
-static int app_context_create(const char *app_id, pid_t pid, const char *pkg_id, app_state_e app_state, bool is_sub_app, app_context_h *app_context);
+static int app_context_create(const char *app_id, pid_t pid, const char *pkg_id, app_state_e app_state, bool is_sub_app, const char *instance_id, app_context_h *app_context);
 
 struct app_context_s {
        char *app_id;
@@ -47,6 +47,7 @@ struct app_context_s {
        char *pkg_id;
        app_state_e app_state;
        bool is_sub_app;
+       char *instance_id;
 };
 
 typedef struct _foreach_context_ {
@@ -116,6 +117,7 @@ static int app_context_foreach_app_context_cb(const aul_app_info *aul_app_contex
                                        aul_app_context->pkgid,
                                        app_state,
                                        is_sub_app,
+                                       aul_app_context->instance_id,
                                        &app_context) == APP_MANAGER_ERROR_NONE) {
                        foreach_context->iteration = foreach_context->callback(app_context, foreach_context->user_data);
                        app_context_destroy(app_context);
@@ -165,6 +167,7 @@ static int app_context_foreach_running_app_context_cb(const aul_app_info *aul_ap
                                        aul_app_context->pkgid,
                                        app_state,
                                        is_sub_app,
+                                       aul_app_context->instance_id,
                                        &app_context) == APP_MANAGER_ERROR_NONE) {
                        foreach_context->iteration = foreach_context->callback(app_context, foreach_context->user_data);
                        app_context_destroy(app_context);
@@ -255,13 +258,14 @@ int app_context_get_app_context(const char *app_id, app_context_h *app_context)
                                        retrieval_context.pkg_id,
                                        retrieval_context.app_state,
                                        retrieval_context.is_sub_app,
-                                        app_context);
+                                       retrieval_context.instance_id,
+                                       app_context);
        free(retrieval_context.pkg_id);
 
        return ret;
 }
 
-static int app_context_create(const char *app_id, pid_t pid, const char *pkg_id, app_state_e app_state, bool is_sub_app, app_context_h *app_context)
+static int app_context_create(const char *app_id, pid_t pid, const char *pkg_id, app_state_e app_state, bool is_sub_app, const char *instance_id, app_context_h *app_context)
 {
        app_context_h app_context_created;
 
@@ -285,6 +289,16 @@ static int app_context_create(const char *app_id, pid_t pid, const char *pkg_id,
                return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
        }
 
+       if (instance_id) {
+               app_context_created->instance_id = strdup(instance_id);
+               if (app_context_created->instance_id == NULL) {
+                       free(app_context_created->pkg_id);
+                       free(app_context_created->app_id);
+                       free(app_context_created);
+                       return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+               }
+       }
+
        app_context_created->pid = pid;
        app_context_created->app_state = app_state;
        app_context_created->is_sub_app = is_sub_app;
@@ -301,6 +315,7 @@ API int app_context_destroy(app_context_h app_context)
 
        free(app_context->app_id);
        free(app_context->pkg_id);
+       free(app_context->instance_id);
        free(app_context);
 
        return APP_MANAGER_ERROR_NONE;
@@ -420,6 +435,7 @@ API int app_context_clone(app_context_h *clone, app_context_h app_context)
                                        app_context->pkg_id,
                                        app_context->app_state,
                                        app_context->is_sub_app,
+                                       app_context->instance_id,
                                        clone);
        if (retval != APP_MANAGER_ERROR_NONE)
                return app_manager_error(retval, __FUNCTION__, NULL);
@@ -507,7 +523,7 @@ static int app_context_launched_event_cb(pid_t pid, const char *app_id, void *da
 
        app_context_lock_event_cb_context();
 
-       if (app_context_create(app_id, pid, pkg_id, APP_STATE_UNDEFINED, false, &app_context) == APP_MANAGER_ERROR_NONE) {
+       if (app_context_create(app_id, pid, pkg_id, APP_STATE_UNDEFINED, false, NULL, &app_context) == APP_MANAGER_ERROR_NONE) {
                if (event_cb_context != NULL && event_cb_context->pid_table != NULL) {
                        g_hash_table_insert(event_cb_context->pid_table, GINT_TO_POINTER(&(app_context->pid)), app_context);
                        event_cb_context->callback(app_context, APP_CONTEXT_EVENT_LAUNCHED, event_cb_context->user_data);
@@ -613,7 +629,7 @@ static int app_context_status_cb(const char *appid, const char *pkgid, int pid,
        else
                context_status = APP_CONTEXT_STATUS_LAUNCHED;
 
-       ret = app_context_create(appid, pid, pkgid, state, is_subapp, &app_context);
+       ret = app_context_create(appid, pid, pkgid, state, is_subapp, NULL, &app_context);
        if (ret != APP_MANAGER_ERROR_NONE)
                return app_manager_error(ret, __FUNCTION__, NULL);
 
@@ -673,8 +689,21 @@ int app_context_get_app_context_by_instance_id(const char *app_id, const char *i
                        retrieval_context.pkg_id,
                        retrieval_context.app_state,
                        retrieval_context.is_sub_app,
+                       retrieval_context.instance_id,
                        app_context);
        free(retrieval_context.pkg_id);
 
        return ret;
 }
+
+int app_context_get_instance_id(app_context_h app_context, char **instance_id)
+{
+       if (app_context == NULL || app_context->instance_id == NULL || instance_id == NULL)
+               return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       *instance_id = strdup(app_context->instance_id);
+       if (*instance_id == NULL)
+               return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+
+       return APP_MANAGER_ERROR_NONE;
+}
index f6fc27f..dbcc133 100644 (file)
@@ -125,7 +125,8 @@ API int app_manager_get_app_context(const char *app_id, app_context_h *app_conte
 
 API int app_manager_resume_app(app_context_h app_context)
 {
-       char *app_id;
+       char *app_id = NULL;
+       char *instance_id = NULL;
        int retval = APP_MANAGER_ERROR_NONE;
 
        if (app_context == NULL)
@@ -134,15 +135,21 @@ API int app_manager_resume_app(app_context_h app_context)
        if (app_context_get_app_id(app_context, &app_id) != APP_MANAGER_ERROR_NONE)
                return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to get the application ID");
 
-       if (aul_app_is_running(app_id) == 0) {
-               if (app_id) {
-                       free(app_id);
-                       app_id = NULL;
+       app_context_get_instance_id(app_context, &instance_id);
+       if (instance_id) {
+               retval = aul_resume_app_by_instance_id(app_id, instance_id);
+               free(instance_id);
+       } else {
+               if (aul_app_is_running(app_id) == 0) {
+                       if (app_id) {
+                               free(app_id);
+                               app_id = NULL;
+                       }
+                       return app_manager_error(APP_MANAGER_ERROR_APP_NO_RUNNING, __FUNCTION__, NULL);
                }
-               return app_manager_error(APP_MANAGER_ERROR_APP_NO_RUNNING, __FUNCTION__, NULL);
-       }
 
-       retval = aul_resume_app(app_id);
+               retval = aul_resume_app(app_id);
+       }
 
        if (app_id)
                free(app_id);
index d6192f7..cbe1c67 100644 (file)
@@ -58,6 +58,8 @@ int app_info_get_app_info(const char *app_id, app_info_h *app_info);
 
 int app_context_get_app_context_by_instance_id(const char *app_id, const char *instance_id, app_context_h *app_context);
 
+int app_context_get_instance_id(app_context_h app_context, char **instance_id);
+
 /**
  * @}
  */