Add new functions to handle the running instance 45/210045/8
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 15 Jul 2019 07:56:06 +0000 (16:56 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 23 Jul 2019 04:17:43 +0000 (13:17 +0900)
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 <h.jhun@samsung.com>
include/aul.h
include/aul_cmd.h
include/aul_comp_status.h
src/aul_cmd.c
src/aul_comp_status.c
src/launch.c
src/pkginfo.c

index 921c043..aabbd4c 100644 (file)
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <bundle.h>
 #include <sys/types.h>
+#include <stdbool.h>
 
 #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
index f7bc61c..47aad63 100755 (executable)
@@ -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
 };
index 83dbaec..2b1ed7a 100644 (file)
@@ -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
index 1b9dd1c..34fee98 100755 (executable)
@@ -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";
        }
index 8e72aa4..bff1de6 100644 (file)
@@ -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;
 }
index 02611d1..0dca6b4 100755 (executable)
@@ -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);
+}
index f327622..50b376f 100644 (file)
@@ -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;
+}