Add APIs to close an application 24/68424/5 accepted/tizen/common/20160510.050928 accepted/tizen/ivi/20160510.002454 accepted/tizen/mobile/20160510.002439 accepted/tizen/tv/20160510.002446 accepted/tizen/wearable/20160510.002427 submit/tizen/20160509.084951
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 4 May 2016 07:31:41 +0000 (16:31 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Wed, 4 May 2016 08:54:32 +0000 (01:54 -0700)
- These APIs wait util the target application is terminated
successfully.
- Add new internal APIs
aul_terminate_pid_sync()
aul_terminate_pid_sync_for_uid()

Change-Id: I5c91924817b998bac636efe021c78b7bd06377a3
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/aul.h
include/aul_cmd.h
src/launch.c
tool/aul_test.c

index acc70fc..215855a 100644 (file)
@@ -776,6 +776,61 @@ int aul_terminate_pid_async(int pid);
 int aul_terminate_pid_async_for_uid(int pid, uid_t uid);
 
 /**
+ * @par Description:
+ *     This API trigger to terminate application synchronously
+ *
+ *     If the application is running, this API sends a terminate event to the application. \n
+ *     And then, this API waits until the application is terminated successfully. \n
+ *     If the app cannot receive the event, AUL kill forcely the application. \n
+ * @par Purpose:
+ *      This API's purpose is to kill application
+ * @par Typical use case:
+ *     In general, Application like Task Manager use this API.
+ *
+ *             This API need to require root or platform level permisssion. \n
+ *
+ * @param[in]  pid     application's pid to be terminated
+ * @return     0 if success, negative value(<0) if fail
+ * @retval     AUL_R_OK        - success
+ * @retval     AUL_R_EINVAL    - invaild pid
+ * @retval     AUL_R_ECOM      - internal AUL IPC error
+ * @retval     AUL_R_ERROR     - general error
+ * @warning    This API need to require root or platform level permisssion. \n
+ * @remark
+ *     If you have not the permission, this API return AUL_R_ERROR. \n
+ *     This API is only available in User Session.
+*/
+int aul_terminate_pid_sync(int pid);
+
+/**
+ * @par Description:
+ *     This API trigger to terminate application synchronously
+ *
+ *     If the application is running, this API send a terminate event to the application. \n
+ *     And then, this API waits until the application is terminated successfully. \n
+ *     If the app cannot receive the event, AUL kill forcely the application. \n
+ * @par Purpose:
+ *      This API's purpose is to kill application
+ * @par Typical use case:
+ *     In general, Application like Task Manager use this API.
+ *
+ *             This API need to require root or platform level permisssion. \n
+ *
+ * @param[in]  pid     application's pid to be terminated
+ * @param[in]  uid     User ID
+ * @return     0 if success, negative value(<0) if fail
+ * @retval     AUL_R_OK        - success
+ * @retval     AUL_R_EINVAL    - invaild pid
+ * @retval     AUL_R_ECOM      - internal AUL IPC error
+ * @retval     AUL_R_ERROR     - general error
+ * @warning    This API need to require root or platform level permisssion. \n
+ * @remark
+ *     If you have not the permission, this API return AUL_R_ERROR. \n
+ *     This API is only available to System user.
+ */
+int aul_terminate_pid_sync_for_uid(int pid, uid_t uid);
+
+/**
  *@brief Running application's information structure retrieved by AUL
  */
 typedef struct _aul_app_info {
index b94de2b..1fb6fc0 100644 (file)
@@ -91,6 +91,7 @@ enum app_cmd {
        APP_START_ASYNC,
        APP_SET_PROCESS_GROUP,
        APP_PREPARE_CANDIDATE_PROCESS,
+       APP_TERM_BY_PID_SYNC,
        APP_CMD_MAX
 };
 
index 9c2fdb8..01e5422 100644 (file)
@@ -440,6 +440,7 @@ int aul_sock_handler(int fd)
 
        case APP_TERM_BY_PID:   /* run in callee */
        case APP_TERM_BY_PID_ASYNC:
+       case APP_TERM_BY_PID_SYNC:
                app_terminate();
                break;
 
@@ -1050,3 +1051,22 @@ API int aul_prepare_candidate_process(void)
                        APP_PREPARE_CANDIDATE_PROCESS, dummy, 0, AUL_SOCK_NONE);
 }
 
+API int aul_terminate_pid_sync(int pid)
+{
+       return aul_terminate_pid_sync_for_uid(pid, getuid());
+}
+
+API int aul_terminate_pid_sync_for_uid(int pid, uid_t uid)
+{
+       char pid_str[MAX_PID_STR_BUFSZ];
+       int ret;
+
+       if (pid <= 0)
+               return AUL_R_EINVAL;
+
+       snprintf(pid_str, sizeof(pid_str), "%d", pid);
+       ret = app_request_to_launchpad_for_uid(APP_TERM_BY_PID_SYNC, pid_str,
+                       NULL, uid);
+       return ret;
+}
+
index fedf65e..42c52bb 100644 (file)
@@ -602,6 +602,22 @@ static int pause_pid_test_for_uid()
        return aul_pause_pid_for_uid(apn_pid, atoi(gargv[3]));
 }
 
+static int term_pid_sync_test()
+{
+       static int num = 0;
+
+       printf("[aul_terminate_pid_sync %d test] %d \n", num++, apn_pid);
+       return aul_terminate_pid_sync(apn_pid);
+}
+
+static int term_pid_sync_test_for_uid()
+{
+       static int num = 0;
+
+       printf("[aul_terminate_pid_sync_for_uid %d test] %d \n", num++, apn_pid);
+       return aul_terminate_pid_sync_for_uid(apn_pid, atoi(gargv[3]));
+}
+
 /*
 static int set_pkg_func()
 {
@@ -785,6 +801,10 @@ static test_func_t test_func[] = {
                "[usage] pasue_for_uid <appid> <uid>"},
        {"pause_pid_for_uid", pause_pid_test_for_uid, "aul_pause_pid_for_uid test",
                "[usage] pause_pid_for_uid <pid> <uid>"},
+       {"term_pid_sync", term_pid_sync_test, "aul_terminate_pid_sync test",
+               "[usage] term_pid_sync <pid>"},
+       {"term_pid_sync_for_uid", term_pid_sync_test_for_uid, "aul_terminate_pid_sync_for_uid test",
+               "[usage] term_pid_sync_for_uid <pid> <uid>"},
 };
 
 int callfunc(char *testname)