From: Hwankyu Jhun Date: Mon, 15 Jul 2019 07:56:06 +0000 (+0900) Subject: Add new functions to handle the running instance X-Git-Tag: accepted/tizen/unified/20190729.011440~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1aceb57a7b35c73fab02aeb373db163b2de968fe;p=platform%2Fcore%2Fappfw%2Faul-1.git Add new functions to handle the running instance Adds: - aul_comp_resume() - aul_comp_terminate() - aul_comp_is_running() - aul_terminate_app_with_instance_id() - aul_terminate_app_with_instance_id_for_uid() - aul_terminate_app() - aul_terminate_app_for_uid() - aul_app_is_running_with_instance_id() Change-Id: Ie8c23c87fbb808da8c43cdf966418a82aae67edf Signed-off-by: Hwankyu Jhun --- diff --git a/include/aul.h b/include/aul.h index 921c043..aabbd4c 100644 --- a/include/aul.h +++ b/include/aul.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "aul_key.h" @@ -2911,6 +2912,84 @@ int aul_terminate_instance_async(const char *instance_id, int pid); int aul_terminate_instance_async_for_uid(const char *instance_id, int pid, uid_t uid); +/** + * @brief Sends the terminate request. + * @since_tizen 5.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/appmanager.kill + * + * @param[in] appid The application ID + * @param[in] instance_id The instance ID + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks This function is only for App Framework internally. + */ +int aul_terminate_app_with_instance_id(const char *appid, + const char *instance_id); + +/** + * @brief Sends the terminate request. + * @since_tizen 5.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/appmanager.kill + * + * @param[in] appid The application ID + * @param[in] instance_id The instance ID + * @param[in] uid The user ID + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks This function is only for App Framework internally. + */ +int aul_terminate_app_with_instance_id_for_uid(const char *appid, + const char *instance_id, uid_t uid); + +/** + * @brief Sends the terminate request. + * @since_tizen 5.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/appmanager.kill + * + * @param[in] appid The application ID + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks This function is only for App Framework internally. + */ +int aul_terminate_app(const char *appid); + +/** + * @brief Sends the terminate request. + * @since_tizen 5.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/appmanager.kill + * + * @param[in] appid The application ID + * @param[in] uid The user ID + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks This function is only for App Framework internally. + */ +int aul_terminate_app_for_uid(const char *appid, uid_t uid); + +/** + * @brief Checks whether the application is running or not. + * @since_tizen 5.5 + * + * @param[in] appid The application ID + * @param[in] instance_id The instance ID + * @param[out] running @c true if the instance is running, \n + * otherwise @c false if not running + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks This function is only for App Framework internally. + */ +int aul_app_is_running_with_instance_id(const char *appid, + const char *instance_id, bool *running); + #ifdef __cplusplus } #endif diff --git a/include/aul_cmd.h b/include/aul_cmd.h index f7bc61c..47aad63 100755 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -165,6 +165,8 @@ enum app_cmd { COMP_INFO_GET = 131, COMP_INFO_FOREACH = 132, + APP_TERMINATE = 133, + APP_IS_RUNNING_V2 = 134, APP_CMD_MAX }; diff --git a/include/aul_comp_status.h b/include/aul_comp_status.h index 83dbaec..2b1ed7a 100644 --- a/include/aul_comp_status.h +++ b/include/aul_comp_status.h @@ -60,6 +60,48 @@ int aul_comp_notify_start(const char *instance_id); */ int aul_comp_notify_exit(const char *instance_id); +/** + * @brief Sends the resume request. + * @since_tizen 5.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/appmanager.launch + * + * @param[in] instance_id The instance ID + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks This function is only for App Framework internally. + */ +int aul_comp_resume(const char *instance_id); + +/** + * @brief Sends the terminate request. + * @since_tizen 5.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/appmanager.kill + * + * @param[in] instance_id The instance ID + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks This function is only for App Framework internally. + */ +int aul_comp_terminate(const char *instance_id); + +/** + * @brief Checks whether the instance of the component is running or not. + * @since_tizen 5.5 + * + * @param[in] instance_id The instance ID + * @param[out] running @c true if the instance is running, \n + * otherwise @c false if not running + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks This function is only for App Framework internally. + */ +int aul_comp_is_running(const char *instance_id, bool *running); + #ifdef __cplusplus } #endif diff --git a/src/aul_cmd.c b/src/aul_cmd.c index 1b9dd1c..34fee98 100755 --- a/src/aul_cmd.c +++ b/src/aul_cmd.c @@ -290,6 +290,10 @@ API const char *aul_cmd_convert_to_string(int cmd) return "COMP_INFO_GET"; case COMP_INFO_FOREACH: return "COMP_INFO_FOREACH"; + case APP_TERMINATE: + return "APP_TERMINATE"; + case APP_IS_RUNNING_V2: + return "APP_IS_RUNNING_V2"; default: return "CUSTOM_COMMAND"; } diff --git a/src/aul_comp_status.c b/src/aul_comp_status.c index 8e72aa4..bff1de6 100644 --- a/src/aul_comp_status.c +++ b/src/aul_comp_status.c @@ -26,6 +26,7 @@ #include "aul_util.h" #include "aul_sock.h" #include "aul_api.h" +#include "aul_error.h" #include "aul.h" API int aul_comp_status_update(const char *instance_id, int status) @@ -61,62 +62,121 @@ API int aul_comp_status_update(const char *instance_id, int status) return AUL_R_OK; } -API int aul_comp_notify_start(const char *instance_id) +static int __send_request(int cmd, int opt, const char *instance_id) { bundle *b; - int r; - - if (!instance_id) { - _E("Invalid parameter"); - return AUL_R_EINVAL; - } + int ret; b = bundle_create(); if (!b) { _E("Failed to create bundle"); - return AUL_R_ERROR; + return AUL_R_ENOMEM; } - bundle_add(b, AUL_K_INSTANCE_ID, instance_id); - - r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), - COMP_NOTIFY_START, b, AUL_SOCK_NOREPLY); - if (r < 0) { - _E("Failed to send the update request. error(%d)", r); + ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id); + if (ret != BUNDLE_ERROR_NONE) { bundle_free(b); - return r; + if (ret == BUNDLE_ERROR_OUT_OF_MEMORY) + return AUL_R_ENOMEM; + else if (ret == BUNDLE_ERROR_INVALID_PARAMETER) + return AUL_R_EINVAL; + + return AUL_R_ERROR; } + + ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), cmd, b, opt); bundle_free(b); + if (ret < 0) { + _E("Failed to send command(%d). error(%d)", cmd, ret); + return aul_error_convert(ret); + } + + return ret; +} + +API int aul_comp_notify_start(const char *instance_id) +{ + int ret; + + if (!instance_id) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + ret = __send_request(COMP_NOTIFY_START, AUL_SOCK_NOREPLY, + instance_id); + if (ret < 0) + return ret; return AUL_R_OK; } API int aul_comp_notify_exit(const char *instance_id) { - bundle *b; - int r; + int ret; if (!instance_id) { _E("Invalid parameter"); return AUL_R_EINVAL; } - b = bundle_create(); - if (!b) { - _E("Failed to create bundle"); - return AUL_R_ERROR; + ret = __send_request(COMP_NOTIFY_EXIT, AUL_SOCK_NOREPLY, + instance_id); + if (ret < 0) + return ret; + + return AUL_R_OK; +} + +API int aul_comp_resume(const char *instance_id) +{ + int ret; + + if (!instance_id) { + _E("Invalid parameter"); + return AUL_R_EINVAL; } - bundle_add(b, AUL_K_INSTANCE_ID, instance_id); + ret = __send_request(COMP_CONTEXT_RESUME, AUL_SOCK_NONE, + instance_id); + if (ret < 0) + return ret; - r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), - COMP_NOTIFY_EXIT, b, AUL_SOCK_NOREPLY); - if (r < 0) { - _E("Failed to send the update request. error(%d)", r); - bundle_free(b); - return r; + return AUL_R_OK; +} + +API int aul_comp_terminate(const char *instance_id) +{ + int ret; + + if (!instance_id) { + _E("Invalid parameter"); + return AUL_R_EINVAL; } - bundle_free(b); + + ret = __send_request(COMP_CONTEXT_TERMINATE, AUL_SOCK_NONE, + instance_id); + if (ret < 0) + return ret; + + return AUL_R_OK; +} + +API int aul_comp_is_running(const char *instance_id, bool *running) +{ + int ret; + + if (!instance_id || !running) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + ret = __send_request(COMP_CONTEXT_IS_RUNNING, AUL_SOCK_NONE, + instance_id); + if (ret < 0) + return ret; + + *running = (bool)ret; return AUL_R_OK; } diff --git a/src/launch.c b/src/launch.c index 02611d1..0dca6b4 100755 --- a/src/launch.c +++ b/src/launch.c @@ -952,3 +952,69 @@ API int aul_terminate_instance_async_for_uid(const char *instance_id, int pid, return ret; } + +static int __send_request(int cmd, uid_t uid, const char *appid, + const char *instance_id) +{ + bundle *b; + int ret; + + b = bundle_create(); + if (!b) { + _E("Out of memory"); + return AUL_R_ENOMEM; + } + + if (instance_id) { + ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id); + if (ret != BUNDLE_ERROR_NONE) { + _E("Failed to add instance ID"); + if (ret == BUNDLE_ERROR_OUT_OF_MEMORY) + return AUL_R_ENOMEM; + else if (ret == BUNDLE_ERROR_INVALID_PARAMETER) + return AUL_R_EINVAL; + + return AUL_R_ERROR; + } + } + + ret = app_request_to_launchpad_for_uid(cmd, appid, b, uid); + bundle_free(b); + if (ret < 0) + _E("Failed to send request(%d). error(%d)", cmd, ret); + + return ret; +} + +API int aul_terminate_app_with_instance_id(const char *appid, + const char *instance_id) +{ + return aul_terminate_app_with_instance_id_for_uid(appid, instance_id, + getuid()); +} + +API int aul_terminate_app_with_instance_id_for_uid(const char *appid, + const char *instance_id, uid_t uid) +{ + if (!appid || !instance_id) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + return __send_request(APP_TERMINATE, uid, appid, instance_id); +} + +API int aul_terminate_app(const char *appid) +{ + return aul_terminate_app_for_uid(appid, getuid()); +} + +API int aul_terminate_app_for_uid(const char *appid, uid_t uid) +{ + if (!appid) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + return __send_request(APP_TERMINATE, uid, appid, NULL); +} diff --git a/src/pkginfo.c b/src/pkginfo.c index f327622..50b376f 100644 --- a/src/pkginfo.c +++ b/src/pkginfo.c @@ -717,3 +717,34 @@ API int aul_app_get_instance_id_bypid(int pid, char *instance_id, int len) return aul_app_get_instance_id_bypid_for_uid(pid, instance_id, len, getuid()); } + +API int aul_app_is_running_with_instance_id(const char *appid, + const char *instance_id, bool *running) +{ + bundle *b; + int ret; + + if (!appid || !instance_id) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + b = bundle_create(); + if (!b) { + _E("out of memory"); + return AUL_R_ENOMEM; + } + + bundle_add(b, AUL_K_APPID, appid); + bundle_add(b, AUL_K_INSTANCE_ID, instance_id); + + ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), APP_IS_RUNNING, + b, AUL_SOCK_NONE); + bundle_free(b); + if (ret < 0) + return aul_error_convert(ret); + + *running = (bool)ret; + + return AUL_R_OK; +}