Add APIs to get the status of an application 57/69657/4 accepted/tizen/common/20160518.124854 accepted/tizen/ivi/20160518.004228 accepted/tizen/mobile/20160518.004354 accepted/tizen/tv/20160518.004244 accepted/tizen/wearable/20160518.004214 submit/tizen/20160517.084446
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 16 May 2016 09:13:08 +0000 (18:13 +0900)
committerHawnkyu Jhun <h.jhun@samsung.com>
Mon, 16 May 2016 14:14:44 +0000 (23:14 +0900)
- Add new APIs
aul_app_get_status()
aul_app_get_status_for_uid()

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

index 2f8f1e9..f35a81c 100644 (file)
@@ -1813,6 +1813,63 @@ int aul_app_get_status_bypid(int pid);
 int aul_app_get_status_bypid_for_uid(int pid, uid_t uid);
 
 /**
+ * @par Description:
+ *     This API gets the status of specified application id.
+ * @par Purpose:
+ *     This API's purpose is to get the status of the application.
+ *
+ * @param[in]  appid   application ID
+ * @return     0 or greater if success, nagative value if fail
+ * @retval     STATUS_LAUNCHING
+ * @retval     STATUS_FOCUS
+ * @retval     STATUS_VISIBLE
+ * @retval     STATUS_BG
+ * @retval     STATUS_DYING
+ * @retval     STATUS_NORESTART
+ * @see
+ *     aul_status_update
+ * @code
+ * #include <aul.h>
+ *
+ * int func(void)
+ * {
+ *     int status;
+ *
+ *     status = aul_app_get_status("org.tizen.helloworld");
+ *     if (status == STATUS_FOCUS)
+ *             printf("org.tizen.helloworld has focus");
+ *
+ *     return 0;
+ * }
+ *
+ * @endcode
+ * @remark
+ *     This API is only available in User Session.
+ */
+int aul_app_get_status(const char *appid);
+
+/**
+ * @par Description:
+ *     This API gets the status of specified application id.
+ * @par Purpose:
+ *     This API's purpose is to get the status of the application
+ *
+ * @param[in]  appid   application ID
+ * @param[in]  uid     User ID
+ * @return     0 or greater if success, nagative value if fail
+ * @retval     STATUS_LAUNCHING
+ * @retval     STATUS_FOCUS
+ * @retval     STATUS_VISIBLE
+ * @retval     STATUS_BG
+ * @retval     STATUS_DYING
+ * @retval     STATUS_NORESTART
+ *
+ * @remark
+ *     This API is only available to System user.
+ */
+int aul_app_get_status_for_uid(const char *appid, uid_t uid);
+
+/**
  * @par Description
  *     This API sets callback function that on application status changed.
  * @par Purpose:
index 1fb6fc0..7eff16d 100644 (file)
@@ -92,6 +92,7 @@ enum app_cmd {
        APP_SET_PROCESS_GROUP,
        APP_PREPARE_CANDIDATE_PROCESS,
        APP_TERM_BY_PID_SYNC,
+       APP_GET_STATUS_BY_APPID,
        APP_CMD_MAX
 };
 
index 9e570ad..6089f2d 100644 (file)
@@ -61,12 +61,12 @@ API int aul_status_update(int status)
        return ret;
 }
 
-API  int aul_app_get_status_bypid(int pid)
+API int aul_app_get_status_bypid(int pid)
 {
        return aul_app_get_status_bypid_for_uid(pid, getuid());
 }
 
-API  int aul_app_get_status_bypid_for_uid(int pid, uid_t uid)
+API int aul_app_get_status_bypid_for_uid(int pid, uid_t uid)
 {
        int ret;
 
@@ -79,6 +79,33 @@ API  int aul_app_get_status_bypid_for_uid(int pid, uid_t uid)
        return ret;
 }
 
+API int aul_app_get_status(const char *appid)
+{
+       return aul_app_get_status_for_uid(appid, getuid());
+}
+
+API int aul_app_get_status_for_uid(const char *appid, uid_t uid)
+{
+       int ret;
+       bundle *kb;
+
+       if (appid == NULL)
+               return AUL_R_EINVAL;
+
+       kb = bundle_create();
+       if (kb == NULL) {
+               _E("out of memory");
+               return AUL_R_ERROR;
+       }
+
+       bundle_add(kb, AUL_K_APPID, appid);
+       ret = app_send_cmd_for_uid(AUL_UTIL_PID, uid,
+                       APP_GET_STATUS_BY_APPID, kb);
+       bundle_free(kb);
+
+       return ret;
+}
+
 API int aul_add_status_local_cb(int (*func)(int status, void *data), void *data)
 {
        app_status_cb_info_t *cb = app_status_cb;
index 42c52bb..ae50976 100644 (file)
@@ -618,65 +618,37 @@ static int term_pid_sync_test_for_uid()
        return aul_terminate_pid_sync_for_uid(apn_pid, atoi(gargv[3]));
 }
 
-/*
-static int set_pkg_func()
-{
-       char* pkgname;
-       char* apppath;
-       char* appname;
-       char query[QUERY_LEN];
-
-       pkgname = gargv[2];
-       apppath = gargv[3];
-
-       appname = strrchr(apppath,'/')+1;
-       snprintf(ai.app_icon_path, PATH_LEN, "aul_test_icon_path/%d",getpid());
-       snprintf(ai.desktop_path, PATH_LEN,
-               "aul_test_desktop_path/%d",getpid());
-
-       snprintf (query, sizeof(query), "insert into "TABLE_MENU"(\
-       pkg_name,\
-       app_path,\
-       app_name,\
-       app_icon_path,\
-       desktop_path)\
-       values ('%s', '%s', '%s', '%s', '%s')",
-       pkgname,
-       apppath,
-       appname,
-       record->app_icon_path,
-       record->desktop_path,
-       );
-
-       // TODO: record_add is not supported anymore; use AIL
-       if (record_add(ADD_ICON, &ai)){
-               printf("set pkg success\n");
-               return 0;
-       }
-       else{
-               printf("set pkg fail\n");
-               return -1;
-       }
+static int get_status_test(void)
+{
+       static int num;
+       int ret;
+
+       printf("[aul_app_get_status %d test] %s \n", num++, gargv[2]);
+
+       ret = aul_app_get_status(gargv[2]);
+       printf("appid: %s, status: %d", gargv[2], ret);
+       if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART)
+               printf("(%s)", status_text[ret]);
+       printf("\n");
+
+       return 0;
 }
 
-static int del_pkg_func()
+static int get_status_test_for_uid(void)
 {
-       app_info ai;
+       static int num;
+       int ret;
 
-       memset(&ai, 0, sizeof(app_info));
-       snprintf(ai.pkg_name, NAME_LEN, "%s", gargv[2]);
+       printf("[aul_app_get_status %d test] %s \n", num++, gargv[2]);
 
-       // TODO: record_add is not supported anymore; use AIL
-       if(record_delete(DELETE_MENU, &ai)){
-               printf("del pkg success\n");
-               return 0;
-       }
-       else {
-               printf("del pkg fail\n");
-               return -1;
-       }
+       ret = aul_app_get_status_for_uid(gargv[2], atoi(gargv[3]));
+       printf("appid: %s, uid: %d, status: %d", gargv[2], atoi(gargv[3]), ret);
+       if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART)
+               printf("(%s)", status_text[ret]);
+       printf("\n");
+
+       return 0;
 }
-*/
 
 static int test_regex()
 {
@@ -805,6 +777,10 @@ static test_func_t test_func[] = {
                "[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>"},
+       {"get_status", get_status_test, "aul_app_get_status test",
+               "[usage] get_status <appid>"},
+       {"get_status_for_uid", get_status_test_for_uid, "aul_app_get_status_for_uid test",
+               "[usage] get_status_for_uid <appid> <uid>"},
 };
 
 int callfunc(char *testname)