Add aul_get_default_app function 90/258290/3
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 13 May 2021 07:23:04 +0000 (16:23 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 18 May 2021 06:22:15 +0000 (15:22 +0900)
To get the default application ID, the function is added.

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

index 20b978d..41464ba 100644 (file)
@@ -3008,6 +3008,11 @@ int aul_prepare_app_defined_loader_for_uid(const char *loader_name, uid_t uid);
  */
 int aul_status_update_v2(int status);
 
+/**
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_get_default_app(bundle *b, char **appid);
+
 #ifdef __cplusplus
        }
 #endif
index 9346725..653ab30 100644 (file)
@@ -198,6 +198,7 @@ enum app_cmd {
        APP_STATUS_UPDATE_V2 = 156,
        APP_GET_APP_CONTROL_DEFAULT_APPS = 157,
        APP_GET_APPID_BY_ALIAS_APPID = 158,
+       APP_GET_APP_CONTROL_DEFAULT_APP = 159,
 
        APP_CMD_MAX
 };
index e064840..f479799 100644 (file)
@@ -200,6 +200,7 @@ API const char *aul_cmd_convert_to_string(int cmd)
                "APP_STATUS_UPDATE_V2",
                "APP_GET_APP_CONTROL_DEFAULT_APPS",
                "APP_GET_APPID_BY_ALIAS_APPID",
+               "APP_GET_APP_CONTROL_DEFAULT_APP",
 
                "CUSTOM_COMMAND"
        };
index 50b376f..d779820 100644 (file)
@@ -748,3 +748,64 @@ API int aul_app_is_running_with_instance_id(const char *appid,
 
        return AUL_R_OK;
 }
+
+API int aul_get_default_app(bundle *b, char **appid)
+{
+       app_pkt_t *pkt = NULL;
+       const char* val;
+       bundle *res_b;
+       int ret;
+       int fd;
+
+       if (!b || !appid) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+                       APP_GET_APP_CONTROL_DEFAULT_APP, b, AUL_SOCK_ASYNC);
+       if (fd < 0)
+               return aul_error_convert(fd);
+
+       ret = aul_sock_recv_reply_pkt(fd, &pkt);
+       if (ret < 0 || pkt == NULL) {
+               _E("Failed to get reply. error(%d)", ret);
+               return aul_error_convert(fd);
+       }
+
+       if (pkt->cmd != APP_GET_INFO_OK) {
+               _E("Failed to get default app. error(%d)", pkt->cmd);
+               ret = aul_error_convert(pkt->cmd);
+               free(pkt);
+               return ret;
+       }
+
+       if (!(pkt->opt & AUL_SOCK_BUNDLE)) {
+               _E("Invalid protocol");
+               free(pkt);
+               return AUL_R_ERROR;
+       }
+
+       res_b = bundle_decode(pkt->data, pkt->len);
+       free(pkt);
+       if (!res_b) {
+               _E("Failed to decode bundle data");
+               return AUL_R_ERROR;
+       }
+
+       val = bundle_get_val(res_b, AUL_K_APPID);
+       if (!val) {
+               _E("Failed to get appid");
+               bundle_free(res_b);
+               return AUL_R_ERROR;
+       }
+
+       *appid = strdup(val);
+       bundle_free(res_b);
+       if (*appid == NULL) {
+               _E("Out of memory");
+               return AUL_R_ENOMEM;
+       }
+
+       return AUL_R_OK;
+}
index b4ee278..1f0b26b 100644 (file)
 
 #include <bundle_internal.h>
 
-#include "menu_db_util.h"
 #include "aul.h"
 #include "aul/api/aul_app_lifecycle.h"
+#include "aul_svc.h"
+#include "menu_db_util.h"
 
 #define MAX_LOCAL_BUFSZ 128
 #define QUERY_LEN      10240
@@ -735,6 +736,65 @@ static int listen_app_lifecycle_test(void)
        return aul_app_lifecycle_register_state_changed_cb(app_lifecycle_state_changed_cb, NULL);
 }
 
+static int set_default_app_by_operation_test(void)
+{
+       bundle* kb;
+       int ret;
+
+       if (gargc < 4) {
+               fprintf(stderr, "[usage] set_default_app_by_operation <operation> <appid>\n");
+               return -EINVAL;
+       }
+
+       printf("aul_set_default_app_by_operation test] %s %s\n",
+                       gargv[2], gargv[3]);
+       kb = bundle_create();
+       if (!kb) {
+               fprintf(stderr, "bundle_create() is failed\n");
+               return -ENOMEM;
+       }
+
+       aul_svc_set_operation(kb, gargv[2]);
+       aul_svc_set_appid(kb, gargv[3]);
+       ret = aul_set_default_app_by_operation(kb);
+       bundle_free(kb);
+       return ret;
+}
+
+static int get_default_app_test(void)
+{
+       char *appid = NULL;
+       bundle* kb;
+       int ret;
+
+       if (gargc < 3) {
+               fprintf(stderr, "[usage] get_default_app <operation> <uri> <mime>\n");
+               return -EINVAL;
+       }
+
+       printf("[aul_get_default_app test] %s %s %s\n",
+                       gargv[2], gargc > 3 ? gargv[3] : "null",
+                       gargc > 4 ? gargv[4] : "null");
+       kb = bundle_create();
+       if (!kb) {
+               fprintf(stderr, "bundle_create() is failed\n");
+               return -ENOMEM;
+       }
+
+       aul_svc_set_operation(kb, gargv[2]);
+
+       if (gargc > 3)
+               aul_svc_set_uri(kb, gargv[3]);
+       if (gargc > 4)
+               aul_svc_set_mime(kb, gargv[4]);
+
+       ret = aul_get_default_app(kb, &appid);
+       bundle_free(kb);
+       printf("result: %s\n", appid);
+       free(appid);
+       return ret;
+}
+
 static int test_regex()
 {
        char *token;
@@ -876,7 +936,11 @@ static test_func_t test_func[] = {
        {"listen_app_status_for_uid", listen_app_status_for_uid_test, "aul_listen_app_status_for_uid",
                "[usage] listen_app_status_for_uid <appid> <uid>"},
        {"listen_app_lifecycle", listen_app_lifecycle_test, "aul_app_lifecycle_register_state_changed_cb",
-               "[usafe] listen_app_lifecycle"},
+               "[usage] listen_app_lifecycle"},
+       {"set_default_app_by_operation", set_default_app_by_operation_test, "aul_set_default_app_by_operation",
+               "[usage] set_default_app_by_operation <operation> <appid>"},
+       {"get_default_app", get_default_app_test, "aul_get_default_app",
+               "[usage] get_default_appid <operation> <uri> <mime>"},
 };
 
 int callfunc(char *testname)