From e2956501e9f6f6f0aa288be98d4d9bb347cebc93 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 13 May 2021 16:23:04 +0900 Subject: [PATCH] Add aul_get_default_app function To get the default application ID, the function is added. Change-Id: I47f4d668c672986513c2e625ee8ebe9cb26655d4 Signed-off-by: Hwankyu Jhun --- include/aul.h | 5 ++++ include/aul_cmd.h | 1 + src/aul_cmd.c | 1 + src/pkginfo.c | 61 +++++++++++++++++++++++++++++++++++++++++++ tool/aul_test/aul_test.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 134 insertions(+), 2 deletions(-) diff --git a/include/aul.h b/include/aul.h index 20b978d..41464ba 100644 --- a/include/aul.h +++ b/include/aul.h @@ -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 diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 9346725..653ab30 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -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 }; diff --git a/src/aul_cmd.c b/src/aul_cmd.c index e064840..f479799 100644 --- a/src/aul_cmd.c +++ b/src/aul_cmd.c @@ -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" }; diff --git a/src/pkginfo.c b/src/pkginfo.c index 50b376f..d779820 100644 --- a/src/pkginfo.c +++ b/src/pkginfo.c @@ -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; +} diff --git a/tool/aul_test/aul_test.c b/tool/aul_test/aul_test.c index b4ee278..1f0b26b 100644 --- a/tool/aul_test/aul_test.c +++ b/tool/aul_test/aul_test.c @@ -23,9 +23,10 @@ #include -#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 \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 \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 "}, {"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 "}, + {"get_default_app", get_default_app_test, "aul_get_default_app", + "[usage] get_default_appid "}, }; int callfunc(char *testname) -- 2.7.4