From 7f9eff4cabc9f8455111841217bb08d341a243ce Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 27 May 2016 10:32:54 +0900 Subject: [PATCH] add new option to get pkgsize for pkgcmd new option calls api which is called by application. fix the problem that the value of result_file for some request is always 0. Change-Id: I30c0a0cc697a86e75bd8e3b88f56f1db43b2ada8 Signed-off-by: jongmyeongko --- src/pkg_cmd.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/pkg_getsize.c | 40 +++++++++++++++++++++++------------ 2 files changed, 89 insertions(+), 14 deletions(-) diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index bafde0d..ea086ac 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -64,7 +64,7 @@ static int __convert_to_absolute_path(char *path); /* Supported options */ /* Note: 'G' is reserved */ -const char *short_options = "iurwmcgCkaADL:lsd:p:t:n:T:S:e:M:X:Y:Z:qhG"; +const char *short_options = "iurwmcgxCkaADL:lsd:p:t:n:T:S:e:M:X:Y:Z:qhG"; const struct option long_options[] = { {"install", 0, NULL, 'i'}, {"uninstall", 0, NULL, 'u'}, @@ -97,6 +97,7 @@ const struct option long_options[] = { {"quiet", 0, NULL, 'q'}, {"help", 0, NULL, 'h'}, {"debug-mode", 0, NULL, 'G'}, + {"getsizeinfo", 0, NULL, 'x'}, {0, 0, 0, 0} /* sentinel */ }; @@ -118,6 +119,7 @@ enum pm_tool_request_e { SHOW_REQ, HELP_REQ, CREATE_DELTA, + GET_PKG_SIZE_INFO_REQ }; typedef enum pm_tool_request_e req_type; @@ -496,6 +498,28 @@ static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data) return 0; } +static void __pkg_size_info_recv_cb(pkgmgr_client *pc, const char *pkgid, const pkg_size_info_t *size_info, void *user_data) +{ + printf("Called sizeinfo callback for pkgid(%s)\n", pkgid); + printf("Internal > data size: %lld, cache size: %lld, app size: %lld\n", + size_info->data_size, size_info->cache_size, size_info->app_size); + printf("External > data size: %lld, cache size: %lld, app size: %lld\n", + size_info->ext_data_size, size_info->ext_cache_size, size_info->ext_app_size); + + g_main_loop_quit(main_loop); +} + +static void __total_pkg_size_info_recv_cb(pkgmgr_client *pc, const pkg_size_info_t *size_info, void *user_data) +{ + printf("Called sizeinfo callback for total packages\n"); + printf("Internal > data size: %lld, cache size: %lld, app size: %lld\n", + size_info->data_size, size_info->cache_size, size_info->app_size); + printf("External > data size: %lld, cache size: %lld, app size: %lld\n", + size_info->ext_data_size, size_info->ext_cache_size, size_info->ext_app_size); + + g_main_loop_quit(main_loop); +} + static int __process_request(uid_t uid) { int ret = -1; @@ -975,6 +999,39 @@ static int __process_request(uid_t uid) ret = data.result; break; + case GET_PKG_SIZE_INFO_REQ: + if (data.pkgid[0] == '\0') { + printf("Please provide the arguments.\n"); + printf("use -h option to see usage\n"); + ret = -1; + break; + } + + main_loop = g_main_loop_new(NULL, FALSE); + pc = pkgmgr_client_new(PC_REQUEST); + if (pc == NULL) { + printf("PkgMgr Client Creation Failed\n"); + data.result = PKGCMD_ERR_FATAL_ERROR; + break; + } + + if (strcmp(data.pkgid, PKG_SIZE_INFO_TOTAL) == 0) { + ret = pkgmgr_client_get_total_package_size_info(pc, __total_pkg_size_info_recv_cb, NULL); + + } else { + ret = pkgmgr_client_get_package_size_info(pc, data.pkgid, __pkg_size_info_recv_cb, NULL); + } + if (ret < 0) { + data.result = PKGCMD_ERR_FATAL_ERROR; + break; + } + + printf("pkg[%s] ret: %d\n", data.pkgid, ret); + ret = data.result; + + g_main_loop_run(main_loop); + break; + case HELP_REQ: __print_usage(); ret = 0; @@ -1063,6 +1120,10 @@ int main(int argc, char *argv[]) data.request = GETSIZE_REQ; break; + case 'x': /* get pkg size info */ + data.request = GET_PKG_SIZE_INFO_REQ; + break; + case 'm': /* move */ data.request = MOVE_REQ; break; diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index 0cd90d7..c0106de 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -53,7 +53,7 @@ #define OWNER_ROOT 0 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) -#if 0 /* installed at external storage is not supported yet */ +#if 0 /* TODO: installed at external storage is not supported yet */ #define APP_BASE_EXTERNAL_PATH "" #endif @@ -282,7 +282,7 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid, tzplatform_mkpath(__is_global(uid) ? TZ_SYS_RW_APP : TZ_USER_APP, pkgid)); tzplatform_reset_user(); -#if 0 /* installed at external storage is not supported yet */ +#if 0 /* TODO: installed at external storage is not supported yet */ } else if (type == STORAGE_TYPE_EXTERNAL) { snprintf(app_root_dir, MAX_PATH_LENGTH, "%s%s/", APP_BASE_EXTERNAL_PATH, pkgid); @@ -423,12 +423,14 @@ static int __get_pkg_size_info(const char *pkgid, ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL, pkgid, &pkg_size_info->data_size, &pkg_size_info->cache_size, &pkg_size_info->app_size); - if (ret < 0) - LOGD("Calculating internal package size info failed: %d", ret); - LOGD("size_info: %lld %lld %lld", pkg_size_info->data_size, + if (ret < 0) { + LOGE("Calculating internal package size info failed: %d", ret); + } else { + LOGD("size_info: %lld %lld %lld", pkg_size_info->data_size, pkg_size_info->cache_size, pkg_size_info->app_size); + } -#if 0 +#if 0 /* TODO */ ret = __calculate_pkg_size_info(STORAGE_TYPE_EXTERNAL, pkgid, &pkg_size_info->ext_data_size, &pkg_size_info->ext_cache_size, @@ -456,7 +458,11 @@ static int __get_total_pkg_size_info_cb(const pkgmgrinfo_pkginfo_h handle, return -1; } - __get_pkg_size_info(pkgid, &temp_pkg_size_info); + ret = __get_pkg_size_info(pkgid, &temp_pkg_size_info); + if (ret < 0) { + LOGE("failed to get size"); + return -1; + } pkg_size_info->app_size += temp_pkg_size_info.app_size; pkg_size_info->data_size += temp_pkg_size_info.data_size; @@ -480,7 +486,7 @@ int __make_size_info_file(char *req_key, long long size) snprintf(info_file, sizeof(info_file), "%s/%s", PKG_SIZE_INFO_PATH, req_key); - LOGE("File path = %s", info_file); + LOGD("File path = (%s), size = (%lld)", info_file, size); file = fopen(info_file, "w"); if (file == NULL) { @@ -518,7 +524,11 @@ static int __send_sizeinfo_cb(const pkgmgrinfo_pkginfo_h handle, return -1; } - __get_pkg_size_info(pkgid, &temp_pkg_size_info); + ret = __get_pkg_size_info(pkgid, &temp_pkg_size_info); + if (ret < 0) { + LOGE("failed to get size"); + return -1; + } total_size = temp_pkg_size_info.app_size + temp_pkg_size_info.data_size + temp_pkg_size_info.cache_size; @@ -617,19 +627,23 @@ int main(int argc, char *argv[]) case PM_GET_PKG_SIZE_INFO: /* send result to signal */ ret = __get_pkg_size_info(pkgid, &info); - if (ret == 0) + if (ret == 0) { ret = __send_result_to_signal(pi, req_key, pkgid, &info); - ret = __make_size_info_file(req_key, 0); + size = info.app_size + info.data_size + info.cache_size; + } + ret = __make_size_info_file(req_key, size); break; case PM_GET_TOTAL_PKG_SIZE_INFO: /* send result to signal */ ret = pkgmgrinfo_pkginfo_get_usr_list( __get_total_pkg_size_info_cb, &info, getuid()); - if (ret == 0) + if (ret == 0) { ret = __send_result_to_signal(pi, req_key, PKG_SIZE_INFO_TOTAL, &info); - ret = __make_size_info_file(req_key, 0); + size = info.app_size + info.data_size + info.cache_size; + } + ret = __make_size_info_file(req_key, size); break; default: ret = -1; -- 2.7.4