From 5dc34acdbd70f9350f5ccdfa5ea53c86b1b65034 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 16 Mar 2017 13:39:26 +0900 Subject: Add a new API to get the focused application context This API returns the app context handle that the window of the application has focus. Change-Id: Iee5753c0d0092a2eb0f9e5ecb649f50a001b47ae Signed-off-by: Hwankyu Jhun --- include/app_manager_extension.h | 17 +++++++++++++++ src/app_context.c | 46 +++++++++++++++++++++++++++++++++++++++-- src/app_manager.c | 23 +++++++++++++++++++++ src/app_manager_internal.h | 2 ++ 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/include/app_manager_extension.h b/include/app_manager_extension.h index 671ef18..c77e354 100644 --- a/include/app_manager_extension.h +++ b/include/app_manager_extension.h @@ -120,6 +120,23 @@ int app_manager_set_app_context_status_cb(app_manager_app_context_status_cb call */ int app_manager_get_app_context_by_instance_id(const char *app_id, const char *instance_id, app_context_h *app_context); +/** + * @brief Gets the focused application context. + * @since_tizen 3.0 + * @remarks This function returns #APP_MANAGER_ERROR_NO_SUCH_APP if all applications don't have focus. \n + * You must release @a app_context using app_context_destroy(). + * + * @param[out] app_context The focused application context + * @return @c 0 on success, + * otherwise a negative error value + * @retval #APP_MANAGER_ERROR_NONE Successful + * @retval #APP_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #APP_MANAGER_ERROR_IO_ERROR Internal I/O error + * @retval #APP_MANAGER_ERROR_OUT_OF_MEMORY Out of memory + * @retval #APP_MANAGER_ERROR_NO_SUCH_APP No such application + */ +int app_manager_get_focused_app_context(app_context_h *app_context); + /** * @} */ diff --git a/src/app_context.c b/src/app_context.c index 88f63a3..31642b8 100644 --- a/src/app_context.c +++ b/src/app_context.c @@ -202,7 +202,7 @@ static int app_context_retrieve_app_context(const aul_app_info *aul_app_context, app_state_e app_state; if (aul_app_context != NULL && retrieval_context != NULL && retrieval_context->matched == false) { - if (retrieval_context->instance_id && + if (retrieval_context->instance_id && retrieval_context->app_id && !strcmp(aul_app_context->instance_id, retrieval_context->instance_id) && !strcmp(aul_app_context->appid, retrieval_context->app_id)) { app_state = app_context_get_app_status(aul_app_context->status); @@ -213,7 +213,7 @@ static int app_context_retrieve_app_context(const aul_app_info *aul_app_context, if (aul_app_context->is_sub_app) retrieval_context->is_sub_app = true; retrieval_context->matched = true; - } else if (retrieval_context->instance_id == NULL && + } else if (retrieval_context->instance_id == NULL && retrieval_context->app_id && !strcmp(aul_app_context->appid, retrieval_context->app_id)) { app_state = app_context_get_app_status(aul_app_context->status); @@ -223,6 +223,15 @@ static int app_context_retrieve_app_context(const aul_app_info *aul_app_context, if (aul_app_context->is_sub_app) retrieval_context->is_sub_app = true; retrieval_context->matched = true; + } else if (retrieval_context->pid > 0 && retrieval_context->pid == aul_app_context->pid) { + app_state = app_context_get_app_status(aul_app_context->status); + + retrieval_context->app_id = strdup(aul_app_context->appid); + retrieval_context->pkg_id = strdup(aul_app_context->pkgid); + retrieval_context->app_state = app_state; + if (aul_app_context->is_sub_app) + retrieval_context->is_sub_app = true; + retrieval_context->matched = true; } } @@ -707,3 +716,36 @@ int app_context_get_instance_id(app_context_h app_context, char **instance_id) return APP_MANAGER_ERROR_NONE; } + +int app_context_get_app_context_by_pid(pid_t pid, app_context_h *app_context) +{ + int ret; + retrieval_context_s retrieval_context = { + .app_id = NULL, + .pid = pid, + .pkg_id = NULL, + .app_state = APP_STATE_UNDEFINED, + .is_sub_app = false, + .matched = false, + .instance_id = NULL + }; + + if (pid <= 0 || app_context == NULL) + return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + aul_app_get_running_app_instance_info(app_context_retrieve_app_context, &retrieval_context); + if (retrieval_context.matched == false) + return app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL); + + ret = app_context_create(retrieval_context.app_id, + retrieval_context.pid, + retrieval_context.pkg_id, + retrieval_context.app_state, + retrieval_context.is_sub_app, + retrieval_context.instance_id, + app_context); + free((void *)retrieval_context.app_id); + free(retrieval_context.pkg_id); + + return ret; +} diff --git a/src/app_manager.c b/src/app_manager.c index bab2a6f..fa9cc01 100644 --- a/src/app_manager.c +++ b/src/app_manager.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -567,3 +568,25 @@ API int app_manager_get_app_context_by_instance_id(const char *app_id, const cha return APP_MANAGER_ERROR_NONE; } + +API int app_manager_get_focused_app_context(app_context_h *app_context) +{ + int ret; + pid_t pid = -1; + + if (app_context == NULL) + return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + ret = aul_window_get_focused_pid(&pid); + if (ret != 0) + return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); + + if (pid < 0) + return app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL); + + ret = app_context_get_app_context_by_pid(pid, app_context); + if (ret != APP_MANAGER_ERROR_NONE) + return app_manager_error(ret, __FUNCTION__, NULL); + + return APP_MANAGER_ERROR_NONE; +} diff --git a/src/app_manager_internal.h b/src/app_manager_internal.h index 5c41a6e..7a6100e 100644 --- a/src/app_manager_internal.h +++ b/src/app_manager_internal.h @@ -49,6 +49,8 @@ int app_context_get_app_context_by_instance_id(const char *app_id, const char *i int app_context_get_instance_id(app_context_h app_context, char **instance_id); +int app_context_get_app_context_by_pid(pid_t pid, app_context_h *app_context); + typedef struct app_manager_event_info_s { int req_id; app_manager_event_type_e event_type; -- cgit v1.2.3