SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -fPIE")
SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIE")
-ADD_EXECUTABLE(pkgcmd src/pkg_cmd.c src/delta.c)
+ADD_EXECUTABLE(pkgcmd src/pkgcmd/pkg_cmd.c src/pkgcmd/delta.c)
TARGET_LINK_LIBRARIES(pkgcmd ${pkgs_test_LDFLAGS})
INSTALL(TARGETS pkgcmd DESTINATION bin)
-ADD_EXECUTABLE(pkginfo src/pkg_info.c)
+ADD_EXECUTABLE(pkginfo src/pkginfo/pkg_info.c)
TARGET_LINK_LIBRARIES(pkginfo ${pkgs_test_LDFLAGS})
INSTALL(TARGETS pkginfo DESTINATION bin)
-ADD_EXECUTABLE(pkg_getsize src/pkg_getsize.c)
+ADD_EXECUTABLE(pkg_getsize src/pkg_getsize/pkg_getsize.c)
TARGET_LINK_LIBRARIES(pkg_getsize ${pkgs_test_LDFLAGS})
INSTALL(TARGETS pkg_getsize DESTINATION bin)
-ADD_EXECUTABLE(pkg_cleardata src/pkg_cleardata.c)
+ADD_EXECUTABLE(pkg_cleardata src/pkg_cleardata/pkg_cleardata.c)
TARGET_LINK_LIBRARIES(pkg_cleardata ${pkgs_test_LDFLAGS})
INSTALL(TARGETS pkg_cleardata DESTINATION bin)
-ADD_EXECUTABLE(install_preload_pkg src/install_preload_pkg.c)
+ADD_EXECUTABLE(install_preload_pkg src/install_preload_pkg/install_preload_pkg.c)
TARGET_LINK_LIBRARIES(install_preload_pkg ${pkgs_test_LDFLAGS})
INSTALL(TARGETS install_preload_pkg DESTINATION bin)
-ADD_EXECUTABLE(pkg_upgrade src/pkg_upgrade.c)
+ADD_EXECUTABLE(pkg_upgrade src/pkg_upgrade/pkg_upgrade.c)
TARGET_LINK_LIBRARIES(pkg_upgrade ${pkgs_test_LDFLAGS})
INSTALL(TARGETS pkg_upgrade DESTINATION bin)
-ADD_EXECUTABLE(rsc-slice src/pkg_rsc_slice.c)
+ADD_EXECUTABLE(rsc-slice src/rsc-slice/pkg_rsc_slice.c)
TARGET_LINK_LIBRARIES(rsc-slice ${pkgs_test_LDFLAGS})
INSTALL(TARGETS rsc-slice DESTINATION bin)
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Vivek Kumar <vivek.kumar2@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <dirent.h>
-#include <glib.h>
-#include <glib-object.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/wait.h>
-#include "delta.h"
-
-static GList *__list_directory(const char *dir_name, const char *tpk_path, GList *list);
-static int __compare_files(char *path1, char *path2);
-static void __print_to_file(char *msg);
-static void __free_g_list(GList *list);
-
-static void __free_g_list(GList *list)
-{
- GList *iter = NULL;
-
- for (iter = list; iter != NULL; iter = iter->next) {
- if (iter->data)
- free(iter->data);
- }
- g_list_free(list);
-
- return;
-}
-
-static GList *__list_directory(const char *dir_name, const char *tpk_path, GList *list)
-{
- DIR *dir = NULL;
- struct dirent *file_info = NULL;
- char path[PATH_MAX] = {0, };
- char rel_path_old_tpk_file[PATH_MAX] = {0, };
- char *file_path = NULL;
- char buf[BUF_SIZE] = {0};
- const char *d_name = NULL;
- int path_length;
-
- dir = opendir(dir_name);
- if (!dir) {
- if (strerror_r(errno, buf, sizeof(buf)) == 0)
- printf("Cannot open directory '%s': %s\n", dir_name, buf);
- exit(EXIT_FAILURE);
- }
-
- while ((file_info = readdir(dir)) != NULL) {
- d_name = file_info->d_name;
- if (!(file_info->d_type & DT_DIR)) {
- snprintf(rel_path_old_tpk_file, PATH_MAX, "%s/%s", dir_name, d_name);
- strncpy(path, rel_path_old_tpk_file + strlen(tpk_path),
- strlen(rel_path_old_tpk_file));
- file_path = strndup(path, sizeof(path));
- list = g_list_append(list, file_path);
- memset(path, 0, PATH_MAX);
- memset(rel_path_old_tpk_file, 0, PATH_MAX);
- }
-
- if (file_info->d_type & DT_DIR) {
- if (strcmp(d_name, "..") != 0 && strcmp(d_name, ".") != 0) {
- path_length = snprintf(path, PATH_MAX, "%s/%s", dir_name, d_name);
- if (path_length >= PATH_MAX) {
- printf("Path length has got too long.\n");
- exit(EXIT_FAILURE);
- }
- list = __list_directory(path, tpk_path, list);
- memset(path, 0, PATH_MAX);
- }
- }
- }
-
- if (closedir(dir)) {
- if (strerror_r(errno, buf, sizeof(buf)) == 0)
- printf("Could not close '%s': %s\n", dir_name, buf);
- exit(EXIT_FAILURE);
- }
-
- return list;
-}
-
-static char *__create_md5Hash(char *file_name)
-{
- FILE *inFile = fopen(file_name, "rb");
- unsigned char data[1024] = {0, };
- int bytes = 0;
-
- GChecksum *checksum = NULL;
- char *checksum_val = NULL;
- char *return_val = NULL;
-
- if (inFile == NULL) {
- printf("%s can't be opened.\n", file_name);
- return 0;
- }
-
- checksum = g_checksum_new(G_CHECKSUM_MD5);
- if (checksum == NULL) {
- printf("failed to create a new GChecksum\n");
- fclose(inFile);
- return 0;
- }
-
- while ((bytes = fread(data, 1, 1024, inFile)) != 0)
- g_checksum_update(checksum, (const guchar *)data, bytes);
-
- checksum_val = (char *)g_checksum_get_string(checksum);
- if (checksum_val)
- return_val = strdup(checksum_val);
-
- g_checksum_free(checksum);
- fclose(inFile);
-
- return return_val;
-}
-
-static int __compare_files(char *old_file, char *new_file)
-{
- char *md5_old_file = NULL;
- char *md5_new_file = NULL;
-
- md5_old_file = __create_md5Hash(old_file);
- if (md5_old_file == NULL) {
- printf("md5checksum failed for %s.\n", old_file);
- exit(EXIT_FAILURE);
- }
-
- md5_new_file = __create_md5Hash(new_file);
- if (md5_new_file == NULL) {
- printf("md5checksum failed for %s.\n", new_file);
- exit(EXIT_FAILURE);
- }
-
- if (strcmp(md5_old_file, md5_new_file) == 0) {
- free(md5_old_file);
- free(md5_new_file);
- return 0;
- } else {
- free(md5_old_file);
- free(md5_new_file);
- return 1;
- }
-}
-
-static void __print_to_file(char *msg)
-{
- FILE *fp;
-
- fp = fopen(DIFF_FILE, "a");
-
- if (fp == NULL) {
- printf("Cannot open %s for writing ", DIFF_FILE);
- exit(1);
- }
-
- fprintf(fp, "%s \n", msg);
- memset(msg, 0, MAX_MESSAGE_LEN);
- fclose(fp);
-}
-
-void __create_diff_file(char *old_tpk_path, char *new_tpk_path)
-{
- char rel_path_old_tpk_file[PATH_MAX] = {0, };
- char rel_path_new_tpk_file[PATH_MAX] = {0, };
- GList *list_dir_old_tpk = NULL;
- GList *list_dir_new_tpk = NULL;
- GList *iterator_old_tpk = NULL;
- GList *iterator_new_tpk = NULL;
- GList *next_iterator_old_tpk = NULL;
- GList *next_iterator_new_tpk = NULL;
- int ret = -1;
- char message[MAX_MESSAGE_LEN];
-
- list_dir_old_tpk = __list_directory(old_tpk_path, old_tpk_path, list_dir_old_tpk);
- if (list_dir_old_tpk == NULL) {
- printf("Could Not read %s\n", old_tpk_path);
- return;
- }
-
- list_dir_new_tpk = __list_directory(new_tpk_path, new_tpk_path, list_dir_new_tpk);
- if (list_dir_new_tpk == NULL) {
- printf("Could Not read %s\n", new_tpk_path);
- __free_g_list(list_dir_old_tpk);
- return;
- }
-
- iterator_old_tpk = list_dir_old_tpk;
- iterator_new_tpk = list_dir_new_tpk;
-
- while (iterator_old_tpk != NULL) {
- next_iterator_old_tpk = iterator_old_tpk->next;
-
- iterator_new_tpk = list_dir_new_tpk;
- while (iterator_new_tpk != NULL) {
- next_iterator_new_tpk = iterator_new_tpk->next;
-
- if (strcmp((char *)iterator_old_tpk->data,
- (char *)iterator_new_tpk->data) == 0) {
- snprintf(rel_path_old_tpk_file, PATH_MAX, "%s%s", old_tpk_path,
- (char *)iterator_old_tpk->data);
- snprintf(rel_path_new_tpk_file, PATH_MAX, "%s%s", new_tpk_path,
- (char *)iterator_new_tpk->data);
- ret = 0;
- if (rel_path_new_tpk_file[strlen(rel_path_new_tpk_file) - 1]
- != '/') {
- ret = __compare_files(rel_path_old_tpk_file,
- rel_path_new_tpk_file);
- if (ret == 1) {
- ret = snprintf(message, MAX_MESSAGE_LEN,
- "Files %s and %s differ",
- rel_path_old_tpk_file,
- rel_path_new_tpk_file);
- if (ret < 0 || ret > MAX_MESSAGE_LEN)
- printf("snprintf fail\n");
- __print_to_file(message);
- } else {
- ret = snprintf(message, MAX_MESSAGE_LEN,
- "Files %s and %s are the same",
- rel_path_old_tpk_file,
- rel_path_new_tpk_file);
- if (ret < 0 || ret > MAX_MESSAGE_LEN)
- printf("snprintf fail\n");
- __print_to_file(message);
- }
- }
- list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk,
- iterator_new_tpk);
- list_dir_old_tpk = g_list_delete_link(list_dir_old_tpk,
- iterator_old_tpk);
- iterator_new_tpk = next_iterator_new_tpk;
- iterator_old_tpk = next_iterator_old_tpk;
- break;
- }
- iterator_new_tpk = next_iterator_new_tpk;
- }
- iterator_old_tpk = next_iterator_old_tpk;
- }
-
- /* find if new file or new directory */
- iterator_old_tpk = list_dir_old_tpk;
- while (iterator_old_tpk != NULL) {
- iterator_new_tpk = iterator_old_tpk->next;
- while (iterator_new_tpk != NULL) {
- next_iterator_new_tpk = iterator_new_tpk->next;
- if (strstr(iterator_new_tpk->data, iterator_old_tpk->data) != NULL)
- list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk,
- iterator_new_tpk);
- iterator_new_tpk = next_iterator_new_tpk;
- }
- iterator_old_tpk = iterator_old_tpk->next;
- }
-
- iterator_old_tpk = list_dir_new_tpk;
- while (iterator_old_tpk != NULL) {
- iterator_new_tpk = iterator_old_tpk->next;
- while (iterator_new_tpk != NULL) {
- next_iterator_new_tpk = iterator_new_tpk->next;
- if (strstr(iterator_new_tpk->data, iterator_old_tpk->data) != NULL)
- list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk,
- iterator_new_tpk);
- iterator_new_tpk = next_iterator_new_tpk;
- }
- iterator_old_tpk = iterator_old_tpk->next;
- }
-
- iterator_old_tpk = list_dir_old_tpk;
- while (iterator_old_tpk != NULL) {
- snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", old_tpk_path,
- (char *)iterator_old_tpk->data);
- __print_to_file(message);
- iterator_old_tpk = iterator_old_tpk->next;
- }
-
- iterator_new_tpk = list_dir_new_tpk;
- while (iterator_new_tpk != NULL) {
- snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", new_tpk_path,
- (char *)iterator_new_tpk->data);
- __print_to_file(message);
- iterator_new_tpk = iterator_new_tpk->next;
- }
-
- /* to free GSList */
- __free_g_list(list_dir_old_tpk);
- __free_g_list(list_dir_new_tpk);
-}
-
-int __xsystem(const char *argv[])
-{
- char buf[BUF_SIZE] = {0};
- int status = 0;
- pid_t pid;
-
- pid = fork();
-
- switch (pid) {
- case -1:
- perror("fork failed");
- return -1;
- case 0:
- /* child */
- if (execvp(argv[0], (char *const *)argv) < 0) {
- if (strerror_r(errno, buf, sizeof(buf)) == 0)
- fprintf(stderr, "execvp failed %d....%s\n", errno, buf);
- }
- _exit(-1);
- default:
- /* parent */
- break;
- }
-
- if (waitpid(pid, &status, 0) == -1) {
- perror("waitpid failed");
- return -1;
- }
-
- if (WIFSIGNALED(status)) {
- perror("signal");
- return -1;
- }
-
- if (!WIFEXITED(status)) {
- /* shouldn't happen */
- perror("should not happen");
- return -1;
- }
-
- return WEXITSTATUS(status);
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Vivek Kumar <vivek.kumar2@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef DELTA_H_
-#define DELTA_H_
-
-#define DIFF_FILE "/opt/usr/temp_delta/difffile.txt"
-#define TEMP_DELTA_REPO "/opt/usr/temp_delta/"
-#define UNZIPFILE "_FILES"
-#define MAX_MESSAGE_LEN 1024
-#define BUF_SIZE 1024
-
-void __create_diff_file(char *old_tpk_path, char *new_tpk_path);
-int __xsystem(const char *argv[]);
-
-#endif /* DELTA_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <glib.h>
-
-#include <tzplatform_config.h>
-
-#include "package-manager.h"
-#include "package-manager-types.h"
-
-#define OWNER_ROOT 0
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-#define BUFSZE 4096
-
-#ifdef _E
-#undef _E
-#endif
-#define _E(fmt, arg...) fprintf(stderr, "[PKG_PRELOAD_INSTALL][E][%s,%d] \
- "fmt"\n", __FUNCTION__, __LINE__, ##arg);
-
-#ifdef _D
-#undef _D
-#endif
-#define _D(fmt, arg...) fprintf(stderr, "[PKG_PRELOAD_INSTALL][D][%s,%d] \
- "fmt"\n", __FUNCTION__, __LINE__, ##arg);
-
-#define TPK_BACKEND_CMD "/usr/bin/tpk-backend"
-#define WGT_BACKEND_CMD "/usr/bin/wgt-backend"
-#define TPK_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-tpk")
-#define WGT_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-wgt")
-#define TPK_RW_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-tpk")
-#define WGT_RW_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-wgt")
-#define ALL_PRELOAD_RW_PKG_LIST "/opt/usr/share/.all_preload_rw_list"
-
-struct pkginfo {
- char *pkgid;
- char *version;
- char *type;
-};
-
-static void __free_pkginfo(gpointer data)
-{
- struct pkginfo *info = (struct pkginfo *)data;
- free(info->pkgid);
- free(info->version);
- free(info->type);
- free(info);
-}
-
-static void __make_preload_rw_list(GList *pkg_list)
-{
- FILE *file;
- char err_buf[BUFSZE];
- char pkg_info[BUFSZE];
- struct pkginfo *info;
-
- if (pkg_list == NULL)
- return;
-
- file = fopen(ALL_PRELOAD_RW_PKG_LIST, "a");
- if (file == NULL) {
- _E("can not open [%s]: %s\n", ALL_PRELOAD_RW_PKG_LIST,
- strerror_r(errno, err_buf, sizeof(err_buf)));
- return;
- }
-
- for (; pkg_list != NULL; pkg_list = pkg_list->next) {
- info = (struct pkginfo *)pkg_list->data;
- _D("Add [%s][%s][%s] to preload-rw list", info->pkgid,
- info->version, info->type);
- snprintf(pkg_info, BUFSZE, "package=\"%s\"\tversion=\"%s\"\t"
- "type=\"%s\":\n",
- info->pkgid, info->version, info->type);
- fwrite(pkg_info, 1, strlen(pkg_info), file);
- }
-
- fclose(file);
-}
-
-static int _install_preload_pkg(const char *backend, const char *directory,
- bool readonly, bool skip_check_reference)
-{
- DIR *dir;
- struct dirent *file_info;
- int ret;
- char file_path[BUFSZE];
- char err_buf[BUFSZE];
- GList *preload_rw_pkg_list = NULL;
- package_manager_pkg_detail_info_t *pkg_info;
- struct pkginfo *info;
-
- dir = opendir(directory);
- if (!dir) {
- if (errno == ENOENT) {
- _D("Directory[%s] doesn't exist", directory);
- return 0;
- } else {
- _E("Failed to access [%s]: [%s]", directory,
- strerror_r(errno, err_buf, sizeof(err_buf)));
- return -1;
- }
- }
-
- _D("Loading pkg files from %s", directory);
-
- while ((file_info = readdir(dir)) != NULL) {
- if (file_info->d_name[0] == '.')
- continue;
-
- snprintf(file_path, sizeof(file_path), "%s/%s", directory,
- file_info->d_name);
- _D("pkg file %s", file_path);
-
- pid_t pid = fork();
- if (pid == 0) {
- execl(backend, backend, "-i", file_path,
- readonly ? "--preload" : "--preload-rw",
- skip_check_reference ?
- "--skip-check-reference" :
- "",
- (char *)NULL);
- } else if (pid < 0) {
- _E("failed to fork and execute %s!", backend);
- closedir(dir);
- g_list_free_full(preload_rw_pkg_list, __free_pkginfo);
- return -1;
- }
-
- if (pid > 0) {
- int status = 0;
- waitpid(pid, &status, 0);
- }
-
- if (!readonly) {
- // make the preload-rw list
- pkg_info = pkgmgr_client_check_pkginfo_from_file(file_path);
- if (pkg_info == NULL) {
- _E("can not get pkg_info from [%s]\n", file_path);
- continue;
- }
-
- info = calloc(1, sizeof(struct pkginfo));
- if (info == NULL) {
- _E("out of memory");
- pkgmgr_client_free_pkginfo(pkg_info);
- continue;
- }
- info->pkgid = strdup(pkg_info->pkgid);
- if (info->pkgid == NULL) {
- _E("out of memory");
- __free_pkginfo((struct pkginfo *)info);
- pkgmgr_client_free_pkginfo(pkg_info);
- continue;
- }
- info->version = strdup(pkg_info->version);
- if (info->version == NULL) {
- _E("out of memory");
- __free_pkginfo((struct pkginfo *)info);
- pkgmgr_client_free_pkginfo(pkg_info);
- continue;
- }
- info->type = strdup(pkg_info->pkg_type);
- if (info->type == NULL) {
- _E("out of memory");
- __free_pkginfo((struct pkginfo *)info);
- pkgmgr_client_free_pkginfo(pkg_info);
- continue;
- }
- preload_rw_pkg_list = g_list_append(preload_rw_pkg_list,
- info);
- pkgmgr_client_free_pkginfo(pkg_info);
- pkg_info = NULL;
- }
-
- /* remove a file after installation */
- ret = remove(file_path);
- if (ret < 0) {
- _E("Failed to remove [%s]: [%s]", file_path,
- strerror_r(errno, err_buf,
- sizeof(err_buf)));
- closedir(dir);
- g_list_free_full(preload_rw_pkg_list, __free_pkginfo);
- return -1;
- }
- }
-
- closedir(dir);
-
- __make_preload_rw_list(preload_rw_pkg_list);
- g_list_free_full(preload_rw_pkg_list, __free_pkginfo);
- return 0;
-}
-
-static int _is_authorized(uid_t uid)
-{
- /* install_preload_pkg should be called by as root privilege. */
- if ((uid_t)OWNER_ROOT == uid)
- return 1;
- else
- return 0;
-}
-
-int main(int argc, char *argv[])
-{
- char err_msg[BUFSZE];
- int handle = -1;
- int ret;
- bool skip_check_reference = false;
-
- if (!_is_authorized(getuid())) {
- _E("You are not an authorized user!");
- return -1;
- }
-
- if (argc > 1 && !strcmp(argv[1], "--skip-check-reference"))
- skip_check_reference = true;
-
- if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_DIR, true,
- skip_check_reference) < 0)
- goto error;
-
- if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_DIR, true,
- skip_check_reference) < 0)
- goto error;
-
- if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_RW_DIR, false,
- skip_check_reference) < 0)
- goto error;
-
- if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_RW_DIR, false,
- skip_check_reference) < 0)
- goto error;
-
- return 0;
-
-error:
- handle = open("/tmp/.preload_install_error",
- O_WRONLY | O_CREAT | O_APPEND | O_TRUNC, 0644);
- if (handle == -1) {
- _E("Failed to open error file");
- return -1;
- }
- snprintf(err_msg, sizeof(err_msg), "install_preload_pkg error!\n");
- ret = write(handle, err_msg, strlen(err_msg));
- if (ret == -1)
- _E("Failed to write an error message. (%d)", errno);
- close(handle);
-
- return -1;
-}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <glib.h>
+
+#include <tzplatform_config.h>
+
+#include "package-manager.h"
+#include "package-manager-types.h"
+
+#define OWNER_ROOT 0
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+#define BUFSZE 4096
+
+#ifdef _E
+#undef _E
+#endif
+#define _E(fmt, arg...) fprintf(stderr, "[PKG_PRELOAD_INSTALL][E][%s,%d] \
+ "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+#ifdef _D
+#undef _D
+#endif
+#define _D(fmt, arg...) fprintf(stderr, "[PKG_PRELOAD_INSTALL][D][%s,%d] \
+ "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+#define TPK_BACKEND_CMD "/usr/bin/tpk-backend"
+#define WGT_BACKEND_CMD "/usr/bin/wgt-backend"
+#define TPK_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-tpk")
+#define WGT_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-wgt")
+#define TPK_RW_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-tpk")
+#define WGT_RW_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-wgt")
+#define ALL_PRELOAD_RW_PKG_LIST "/opt/usr/share/.all_preload_rw_list"
+
+struct pkginfo {
+ char *pkgid;
+ char *version;
+ char *type;
+};
+
+static void __free_pkginfo(gpointer data)
+{
+ struct pkginfo *info = (struct pkginfo *)data;
+ free(info->pkgid);
+ free(info->version);
+ free(info->type);
+ free(info);
+}
+
+static void __make_preload_rw_list(GList *pkg_list)
+{
+ FILE *file;
+ char err_buf[BUFSZE];
+ char pkg_info[BUFSZE];
+ struct pkginfo *info;
+
+ if (pkg_list == NULL)
+ return;
+
+ file = fopen(ALL_PRELOAD_RW_PKG_LIST, "a");
+ if (file == NULL) {
+ _E("can not open [%s]: %s\n", ALL_PRELOAD_RW_PKG_LIST,
+ strerror_r(errno, err_buf, sizeof(err_buf)));
+ return;
+ }
+
+ for (; pkg_list != NULL; pkg_list = pkg_list->next) {
+ info = (struct pkginfo *)pkg_list->data;
+ _D("Add [%s][%s][%s] to preload-rw list", info->pkgid,
+ info->version, info->type);
+ snprintf(pkg_info, BUFSZE, "package=\"%s\"\tversion=\"%s\"\t"
+ "type=\"%s\":\n",
+ info->pkgid, info->version, info->type);
+ fwrite(pkg_info, 1, strlen(pkg_info), file);
+ }
+
+ fclose(file);
+}
+
+static int _install_preload_pkg(const char *backend, const char *directory,
+ bool readonly, bool skip_check_reference)
+{
+ DIR *dir;
+ struct dirent *file_info;
+ int ret;
+ char file_path[BUFSZE];
+ char err_buf[BUFSZE];
+ GList *preload_rw_pkg_list = NULL;
+ package_manager_pkg_detail_info_t *pkg_info;
+ struct pkginfo *info;
+
+ dir = opendir(directory);
+ if (!dir) {
+ if (errno == ENOENT) {
+ _D("Directory[%s] doesn't exist", directory);
+ return 0;
+ } else {
+ _E("Failed to access [%s]: [%s]", directory,
+ strerror_r(errno, err_buf, sizeof(err_buf)));
+ return -1;
+ }
+ }
+
+ _D("Loading pkg files from %s", directory);
+
+ while ((file_info = readdir(dir)) != NULL) {
+ if (file_info->d_name[0] == '.')
+ continue;
+
+ snprintf(file_path, sizeof(file_path), "%s/%s", directory,
+ file_info->d_name);
+ _D("pkg file %s", file_path);
+
+ pid_t pid = fork();
+ if (pid == 0) {
+ execl(backend, backend, "-i", file_path,
+ readonly ? "--preload" : "--preload-rw",
+ skip_check_reference ?
+ "--skip-check-reference" :
+ "",
+ (char *)NULL);
+ } else if (pid < 0) {
+ _E("failed to fork and execute %s!", backend);
+ closedir(dir);
+ g_list_free_full(preload_rw_pkg_list, __free_pkginfo);
+ return -1;
+ }
+
+ if (pid > 0) {
+ int status = 0;
+ waitpid(pid, &status, 0);
+ }
+
+ if (!readonly) {
+ // make the preload-rw list
+ pkg_info = pkgmgr_client_check_pkginfo_from_file(file_path);
+ if (pkg_info == NULL) {
+ _E("can not get pkg_info from [%s]\n", file_path);
+ continue;
+ }
+
+ info = calloc(1, sizeof(struct pkginfo));
+ if (info == NULL) {
+ _E("out of memory");
+ pkgmgr_client_free_pkginfo(pkg_info);
+ continue;
+ }
+ info->pkgid = strdup(pkg_info->pkgid);
+ if (info->pkgid == NULL) {
+ _E("out of memory");
+ __free_pkginfo((struct pkginfo *)info);
+ pkgmgr_client_free_pkginfo(pkg_info);
+ continue;
+ }
+ info->version = strdup(pkg_info->version);
+ if (info->version == NULL) {
+ _E("out of memory");
+ __free_pkginfo((struct pkginfo *)info);
+ pkgmgr_client_free_pkginfo(pkg_info);
+ continue;
+ }
+ info->type = strdup(pkg_info->pkg_type);
+ if (info->type == NULL) {
+ _E("out of memory");
+ __free_pkginfo((struct pkginfo *)info);
+ pkgmgr_client_free_pkginfo(pkg_info);
+ continue;
+ }
+ preload_rw_pkg_list = g_list_append(preload_rw_pkg_list,
+ info);
+ pkgmgr_client_free_pkginfo(pkg_info);
+ pkg_info = NULL;
+ }
+
+ /* remove a file after installation */
+ ret = remove(file_path);
+ if (ret < 0) {
+ _E("Failed to remove [%s]: [%s]", file_path,
+ strerror_r(errno, err_buf,
+ sizeof(err_buf)));
+ closedir(dir);
+ g_list_free_full(preload_rw_pkg_list, __free_pkginfo);
+ return -1;
+ }
+ }
+
+ closedir(dir);
+
+ __make_preload_rw_list(preload_rw_pkg_list);
+ g_list_free_full(preload_rw_pkg_list, __free_pkginfo);
+ return 0;
+}
+
+static int _is_authorized(uid_t uid)
+{
+ /* install_preload_pkg should be called by as root privilege. */
+ if ((uid_t)OWNER_ROOT == uid)
+ return 1;
+ else
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ char err_msg[BUFSZE];
+ int handle = -1;
+ int ret;
+ bool skip_check_reference = false;
+
+ if (!_is_authorized(getuid())) {
+ _E("You are not an authorized user!");
+ return -1;
+ }
+
+ if (argc > 1 && !strcmp(argv[1], "--skip-check-reference"))
+ skip_check_reference = true;
+
+ if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_DIR, true,
+ skip_check_reference) < 0)
+ goto error;
+
+ if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_DIR, true,
+ skip_check_reference) < 0)
+ goto error;
+
+ if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_RW_DIR, false,
+ skip_check_reference) < 0)
+ goto error;
+
+ if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_RW_DIR, false,
+ skip_check_reference) < 0)
+ goto error;
+
+ return 0;
+
+error:
+ handle = open("/tmp/.preload_install_error",
+ O_WRONLY | O_CREAT | O_APPEND | O_TRUNC, 0644);
+ if (handle == -1) {
+ _E("Failed to open error file");
+ return -1;
+ }
+ snprintf(err_msg, sizeof(err_msg), "install_preload_pkg error!\n");
+ ret = write(handle, err_msg, strlen(err_msg));
+ if (ret == -1)
+ _E("Failed to write an error message. (%d)", errno);
+ close(handle);
+
+ return -1;
+}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <dirent.h>
-#include <getopt.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <dlog.h>
-#include <tzplatform_config.h>
-#include <pkgmgr-info.h>
-#include <pkgmgr_installer.h>
-#include <package-manager.h>
-#include <storage-internal.h>
-
-#define MAX_PKG_NAME_LEN 256
-#define INTERNAL_CACHE_PATH_PREFIX tzplatform_getenv(TZ_USER_APP)
-#define CACHE_PATH_POSTFIX "/cache"
-#define SHARED_PATH_POSTFIX "/shared/cache"
-#define REGULAR_USER 5000
-
-#undef LOG_TAG
-#ifndef LOG_TAG
-#define LOG_TAG "PKGMGR_CLEARDATA"
-#endif /* LOG_TAG */
-
-static uid_t uid;
-
-static pkgmgr_installer *pi;
-
-static int __get_sdcard_path(char **sdpath)
-{
- int ret;
- int storage_id;
-
- if (sdpath == NULL)
- return -1;
-
- ret = storage_get_primary_sdcard(&storage_id, sdpath);
- if (ret != STORAGE_ERROR_NONE)
- return -1;
-
- return 0;
-}
-
-static void __send_signal(const char *pkgid, const char *event_type,
- const char *key, const char *val)
-{
- pkgmgr_installer_send_signal(pi, event_type, pkgid, key, val);
- pkgmgr_installer_send_signal_for_uid(pi, uid, event_type, pkgid, key,
- val);
-}
-
-static int __clear_dir(const char *dirname)
-{
- int ret = 0;
- DIR *dp = NULL;
- char buf[1024] = {0, };
- struct dirent *ep = NULL;
- char *abs_filename = NULL;
- struct stat stFileInfo;
-
- LOGD("Directory name to clear [%s]\n", dirname);
-
- abs_filename = (char *)malloc(sizeof(char) * PATH_MAX);
- if (abs_filename == NULL) {
- LOGE("Memory allocation failed\n");
- goto err;
- }
-
- dp = opendir(dirname);
- if (dp == NULL) {
- if (errno == ENOENT) {
- LOGD("no entry, path(%s)", dirname);
- free(abs_filename);
- return 0;
- }
- LOGE("Couldn't open the directory. errno : %d (%s)\n", errno,
- strerror_r(errno, buf, sizeof(buf)));
- goto err;
- }
-
- while ((ep = readdir(dp)) != NULL) {
- snprintf(abs_filename, PATH_MAX - 1, "%s/%s", dirname,
- ep->d_name);
- if (lstat(abs_filename, &stFileInfo) < 0)
- perror(abs_filename);
-
- if (S_ISDIR(stFileInfo.st_mode)) {
- if (strcmp(ep->d_name, ".") &&
- strcmp(ep->d_name, "..")) {
- ret = __clear_dir(abs_filename);
- if (ret != 0)
- LOGE("Couldn't remove the directory. "
- "errno : %d (%s)\n",
- errno, strerror_r(errno, buf, sizeof(buf)));
-
- ret = remove(abs_filename);
- if (ret != 0) {
- LOGE("Couldn't remove the directory. "
- "errno : %d (%s)\n",
- errno, strerror_r(errno, buf, sizeof(buf)));
- goto err;
- }
- }
- } else {
- ret = remove(abs_filename);
- if (ret != 0) {
- LOGE("Couldn't remove the directory. errno : "
- "%d (%s)\n", errno,
- strerror_r(errno, buf, sizeof(buf)));
- goto err;
- }
- }
- }
- closedir(dp);
- free(abs_filename);
-
- return 0;
-
-err:
- if (abs_filename)
- free(abs_filename);
- if (dp)
- closedir(dp);
-
- return -1;
-}
-
-static int __clear_cache_dir(const char *pkgid)
-{
- int ret = 0;
- char dirname[PATH_MAX] = {0,};
- char *sdpath = NULL;
-
- if (pkgid == NULL) {
- LOGE("pkgid is NULL\n");
- return -1;
- }
-
- tzplatform_set_user(uid);
-
- /* cache internal */
- snprintf(dirname, sizeof(dirname), "%s/%s%s",
- INTERNAL_CACHE_PATH_PREFIX, pkgid, CACHE_PATH_POSTFIX);
-
- ret = __clear_dir(dirname);
- if (ret < 0)
- LOGE("Failed to clear internal cache dir.");
-
- /* shared/cache internal */
- snprintf(dirname, sizeof(dirname), "%s/%s%s",
- INTERNAL_CACHE_PATH_PREFIX, pkgid, SHARED_PATH_POSTFIX);
-
- ret = __clear_dir(dirname);
- if (ret < 0)
- LOGE("Failed to clear internal shared cache dir.");
-
- /* cache external */
- ret = __get_sdcard_path(&sdpath);
- if (ret != 0 || sdpath == NULL) {
- LOGW("Unable to retrieve external storage path");
- tzplatform_reset_user();
- return 0;
- }
-
- snprintf(dirname, sizeof(dirname), "%s/%s%s%s",
- sdpath, "apps",
- tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid),
- CACHE_PATH_POSTFIX);
- ret = __clear_dir(dirname);
- if (ret < 0)
- LOGE("Failed to clear external cache dir.");
-
- /* shared/cache external */
- snprintf(dirname, sizeof(dirname), "%s/%s%s%s",
- sdpath, "apps",
- tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid),
- SHARED_PATH_POSTFIX);
- tzplatform_reset_user();
- free(sdpath);
-
- ret = __clear_dir(dirname);
- if (ret < 0)
- LOGE("Failed to clear external shared cache dir.");
-
- return 0;
-}
-
-static int __clear_data_dir(const char *pkgid)
-{
- int ret = 0;
- char dirname[PATH_MAX] = {0,};
- const char *rootpath;
- pkgmgrinfo_pkginfo_h pkg_handle = NULL;
- char *pkg_type = NULL;
- char *sdpath = NULL;
-
- if (pkgid == NULL) {
- LOGE("pkgid is NULL\n");
- return -1;
- }
-
- ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkg_handle);
- if (ret != PMINFO_R_OK) {
- LOGE("Failed to get pkginfo");
- ret = -1;
- goto catch;
- }
-
- ret = pkgmgrinfo_pkginfo_get_type(pkg_handle, &pkg_type);
- if (ret != PMINFO_R_OK) {
- LOGE("Failed to get type");
- ret = -1;
- goto catch;
- }
-
- tzplatform_set_user(uid);
- rootpath = tzplatform_getenv(TZ_USER_APP);
-
- __send_signal(pkgid, pkg_type,
- PKGMGR_INSTALLER_START_KEY_STR,
- PKGMGR_INSTALLER_CLEAR_EVENT_STR);
-
- snprintf(dirname, sizeof(dirname), "%s/%s/data", rootpath, pkgid);
- ret = __clear_dir(dirname);
- if (ret != 0) {
- LOGE("Failed to clear data for pkg %s", pkgid);
- __send_signal(pkgid, pkg_type,
- PKGMGR_INSTALLER_END_KEY_STR,
- PKGMGR_INSTALLER_FAIL_EVENT_STR);
- ret = -1;
- goto catch;
- }
-
- snprintf(dirname, sizeof(dirname), "%s/%s/shared/data", rootpath,
- pkgid);
- ret = __clear_dir(dirname);
- if (ret != 0) {
- LOGE("Failed to clear data for pkg %s", pkgid);
- __send_signal(pkgid, pkg_type,
- PKGMGR_INSTALLER_END_KEY_STR,
- PKGMGR_INSTALLER_FAIL_EVENT_STR);
- ret = -1;
- goto catch;
- }
-
- snprintf(dirname, sizeof(dirname), "%s/%s/shared/trusted", rootpath,
- pkgid);
- ret = __clear_dir(dirname);
- if (ret != 0) {
- LOGE("Failed to clear data for pkg %s", pkgid);
- __send_signal(pkgid, pkg_type,
- PKGMGR_INSTALLER_END_KEY_STR,
- PKGMGR_INSTALLER_FAIL_EVENT_STR);
- ret = -1;
- goto catch;
- }
-
- /* external data */
- ret = __get_sdcard_path(&sdpath);
- if (ret != 0 || sdpath == NULL) {
- LOGW("Unable to retrieve external storage path");
- __send_signal(pkgid, pkg_type, PKGMGR_INSTALLER_END_KEY_STR,
- PKGMGR_INSTALLER_OK_EVENT_STR);
- ret = 0;
- goto catch;
- }
-
- snprintf(dirname, sizeof(dirname), "%s/%s%s/data",
- sdpath, "apps",
- tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid));
- ret = __clear_dir(dirname);
- if (ret < 0)
- LOGE("Failed to clear external data dir.");
-
- /* external shared/data */
- snprintf(dirname, sizeof(dirname), "%s/%s%s/shared/data",
- sdpath, "apps",
- tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid));
- ret = __clear_dir(dirname);
- if (ret < 0)
- LOGE("Failed to clear external shared data dir.");
-
- /* external shared/trusted */
- snprintf(dirname, sizeof(dirname), "%s/%s%s/shared/trusted",
- sdpath, "apps",
- tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid));
- ret = __clear_dir(dirname);
- if (ret < 0)
- LOGE("Failed to clear external shared trusted dir.");
-
- __send_signal(pkgid, pkg_type, PKGMGR_INSTALLER_END_KEY_STR,
- PKGMGR_INSTALLER_OK_EVENT_STR);
-
-catch:
- tzplatform_reset_user();
- if (sdpath)
- free(sdpath);
- if (pkg_handle)
- pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
- return ret;
-}
-
-static int __clear_all_cache_dir_cb(const pkgmgrinfo_pkginfo_h handle,
- void *user_data)
-{
- int res = 0;
- char *pkgid;
- int *err_cnt = (int *)user_data;
-
- res = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (res != PMINFO_R_OK) {
- LOGE("pkgmgr_pkginfo_get_pkgid() failed");
- --(*err_cnt);
- return 0;
- }
-
- res = __clear_cache_dir(pkgid);
- if (res != 0) {
- LOGE("Failed to clear cache dir of %s", pkgid);
- --(*err_cnt);
- return 0;
- }
-
- return 0;
-}
-
-static int __clear_all_cache_dir(void)
-{
- int err_cnt = 0;
- int res;
-
- res = pkgmgrinfo_pkginfo_get_usr_list(__clear_all_cache_dir_cb,
- &err_cnt, uid);
- if (res != PMINFO_R_OK) {
- LOGE("Failed to get pkg list. (%d)", res);
- return -1;
- } else if (err_cnt != 0) {
- LOGE("Error occured in %d packages.", err_cnt);
- return -1;
- }
-
- return 0;
-}
-
-static void print_usage(void)
-{
- printf("pkg data/cache clear tool\n");
-
- printf("\n");
- printf("-c, --cache clear pkg's cache\n");
- printf("-d, --data clear pkg's data\n");
- printf("-h, --help print this help\n");
- printf("-n, --pkgid package id\n");
- printf("-u, --uid user id\n");
-
- printf("\n");
- printf("Usage: pkg_cleardata [options]\n");
- printf("pkg_cleardata -c -n <pkgid> -u <uid>\n");
- printf("pkg_cleardata -d -n <pkgid> -u <uid>\n");
- printf("pkg_cleardata -cd -n <pkgid> -u <uid>\n");
- printf("\n");
-}
-
-int main(int argc, char *argv[])
-{
- int ret = -1;
- int c = -1;
- int opt_idx = 0;
- char pkgid[MAX_PKG_NAME_LEN] = { 0, };
- bool clear_cache = false;
- bool clear_data = false;
- const char short_options[] = "cdhn:u:";
- const struct option long_options[] = {
- {"cache", 0, NULL, 'c'},
- {"data", 0, NULL, 'd'},
- {"help", 0, NULL, 'h'},
- {"pkgid", 1, NULL, 'n'},
- {"uid", 1, NULL, 'u'},
- {0, 0, 0, 0} /* sentinel */
- };
-
- if (argc < 3) {
- print_usage();
- return -1;
- }
-
- if (getuid() >= REGULAR_USER) {
- LOGE("Regular user cannot run this tool");
- return -1;
- }
-
- while (1) {
- c = getopt_long(argc, argv, short_options, long_options,
- &opt_idx);
- if (c == -1)
- break; /* Parse end */
- switch (c) {
- case 'c': /* cache */
- clear_cache = true;
- break;
- case 'd': /* data */
- clear_data = true;
- break;
- case 'h': /* help */
- print_usage();
- ret = 0;
- break;
- case 'n': /* pkgid */
- if (optarg) {
- snprintf(pkgid, sizeof(pkgid), "%s", optarg);
- } else {
- print_usage();
- return -1;
- }
- break;
- case 'u': /* uid */
- if (optarg) {
- uid = atoi(optarg);
- } else {
- print_usage();
- return -1;
- }
- default:
- break;
- }
- }
-
- if ((!clear_cache && !clear_data) || (pkgid[0] == '\0') || uid == 0) {
- print_usage();
- return -1;
- }
-
- pi = pkgmgr_installer_new();
- if (pi == NULL) {
- LOGE("Failed to create installer");
- return -1;
- }
-
- ret = pkgmgr_installer_set_uid(pi, uid);
- if (ret != 0) {
- LOGE("Failed to set uid[%d]", (int)uid);
- pkgmgr_installer_free(pi);
- return -1;
- }
-
- if (clear_cache) {
- __send_signal(pkgid, PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR,
- PKGMGR_INSTALLER_START_KEY_STR,
- PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR);
- if (strcmp(pkgid, PKG_CLEAR_ALL_CACHE) == 0)
- ret = __clear_all_cache_dir();
- else
- ret = __clear_cache_dir(pkgid);
-
- if (ret)
- __send_signal(pkgid,
- PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR,
- PKGMGR_INSTALLER_END_KEY_STR,
- PKGMGR_INSTALLER_FAIL_EVENT_STR);
- else
- __send_signal(pkgid,
- PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR,
- PKGMGR_INSTALLER_END_KEY_STR,
- PKGMGR_INSTALLER_OK_EVENT_STR);
- }
-
- if (clear_data) {
- pkgmgr_installer_set_request_type(pi, PKGMGR_REQ_CLEAR);
- ret = __clear_data_dir(pkgid);
- }
-
- pkgmgr_installer_free(pi);
-
- return ret;
-}
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <dirent.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <dlog.h>
+#include <tzplatform_config.h>
+#include <pkgmgr-info.h>
+#include <pkgmgr_installer.h>
+#include <package-manager.h>
+#include <storage-internal.h>
+
+#define MAX_PKG_NAME_LEN 256
+#define INTERNAL_CACHE_PATH_PREFIX tzplatform_getenv(TZ_USER_APP)
+#define CACHE_PATH_POSTFIX "/cache"
+#define SHARED_PATH_POSTFIX "/shared/cache"
+#define REGULAR_USER 5000
+
+#undef LOG_TAG
+#ifndef LOG_TAG
+#define LOG_TAG "PKGMGR_CLEARDATA"
+#endif /* LOG_TAG */
+
+static uid_t uid;
+
+static pkgmgr_installer *pi;
+
+static int __get_sdcard_path(char **sdpath)
+{
+ int ret;
+ int storage_id;
+
+ if (sdpath == NULL)
+ return -1;
+
+ ret = storage_get_primary_sdcard(&storage_id, sdpath);
+ if (ret != STORAGE_ERROR_NONE)
+ return -1;
+
+ return 0;
+}
+
+static void __send_signal(const char *pkgid, const char *event_type,
+ const char *key, const char *val)
+{
+ pkgmgr_installer_send_signal(pi, event_type, pkgid, key, val);
+ pkgmgr_installer_send_signal_for_uid(pi, uid, event_type, pkgid, key,
+ val);
+}
+
+static int __clear_dir(const char *dirname)
+{
+ int ret = 0;
+ DIR *dp = NULL;
+ char buf[1024] = {0, };
+ struct dirent *ep = NULL;
+ char *abs_filename = NULL;
+ struct stat stFileInfo;
+
+ LOGD("Directory name to clear [%s]\n", dirname);
+
+ abs_filename = (char *)malloc(sizeof(char) * PATH_MAX);
+ if (abs_filename == NULL) {
+ LOGE("Memory allocation failed\n");
+ goto err;
+ }
+
+ dp = opendir(dirname);
+ if (dp == NULL) {
+ if (errno == ENOENT) {
+ LOGD("no entry, path(%s)", dirname);
+ free(abs_filename);
+ return 0;
+ }
+ LOGE("Couldn't open the directory. errno : %d (%s)\n", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto err;
+ }
+
+ while ((ep = readdir(dp)) != NULL) {
+ snprintf(abs_filename, PATH_MAX - 1, "%s/%s", dirname,
+ ep->d_name);
+ if (lstat(abs_filename, &stFileInfo) < 0)
+ perror(abs_filename);
+
+ if (S_ISDIR(stFileInfo.st_mode)) {
+ if (strcmp(ep->d_name, ".") &&
+ strcmp(ep->d_name, "..")) {
+ ret = __clear_dir(abs_filename);
+ if (ret != 0)
+ LOGE("Couldn't remove the directory. "
+ "errno : %d (%s)\n",
+ errno, strerror_r(errno, buf, sizeof(buf)));
+
+ ret = remove(abs_filename);
+ if (ret != 0) {
+ LOGE("Couldn't remove the directory. "
+ "errno : %d (%s)\n",
+ errno, strerror_r(errno, buf, sizeof(buf)));
+ goto err;
+ }
+ }
+ } else {
+ ret = remove(abs_filename);
+ if (ret != 0) {
+ LOGE("Couldn't remove the directory. errno : "
+ "%d (%s)\n", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto err;
+ }
+ }
+ }
+ closedir(dp);
+ free(abs_filename);
+
+ return 0;
+
+err:
+ if (abs_filename)
+ free(abs_filename);
+ if (dp)
+ closedir(dp);
+
+ return -1;
+}
+
+static int __clear_cache_dir(const char *pkgid)
+{
+ int ret = 0;
+ char dirname[PATH_MAX] = {0,};
+ char *sdpath = NULL;
+
+ if (pkgid == NULL) {
+ LOGE("pkgid is NULL\n");
+ return -1;
+ }
+
+ tzplatform_set_user(uid);
+
+ /* cache internal */
+ snprintf(dirname, sizeof(dirname), "%s/%s%s",
+ INTERNAL_CACHE_PATH_PREFIX, pkgid, CACHE_PATH_POSTFIX);
+
+ ret = __clear_dir(dirname);
+ if (ret < 0)
+ LOGE("Failed to clear internal cache dir.");
+
+ /* shared/cache internal */
+ snprintf(dirname, sizeof(dirname), "%s/%s%s",
+ INTERNAL_CACHE_PATH_PREFIX, pkgid, SHARED_PATH_POSTFIX);
+
+ ret = __clear_dir(dirname);
+ if (ret < 0)
+ LOGE("Failed to clear internal shared cache dir.");
+
+ /* cache external */
+ ret = __get_sdcard_path(&sdpath);
+ if (ret != 0 || sdpath == NULL) {
+ LOGW("Unable to retrieve external storage path");
+ tzplatform_reset_user();
+ return 0;
+ }
+
+ snprintf(dirname, sizeof(dirname), "%s/%s%s%s",
+ sdpath, "apps",
+ tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid),
+ CACHE_PATH_POSTFIX);
+ ret = __clear_dir(dirname);
+ if (ret < 0)
+ LOGE("Failed to clear external cache dir.");
+
+ /* shared/cache external */
+ snprintf(dirname, sizeof(dirname), "%s/%s%s%s",
+ sdpath, "apps",
+ tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid),
+ SHARED_PATH_POSTFIX);
+ tzplatform_reset_user();
+ free(sdpath);
+
+ ret = __clear_dir(dirname);
+ if (ret < 0)
+ LOGE("Failed to clear external shared cache dir.");
+
+ return 0;
+}
+
+static int __clear_data_dir(const char *pkgid)
+{
+ int ret = 0;
+ char dirname[PATH_MAX] = {0,};
+ const char *rootpath;
+ pkgmgrinfo_pkginfo_h pkg_handle = NULL;
+ char *pkg_type = NULL;
+ char *sdpath = NULL;
+
+ if (pkgid == NULL) {
+ LOGE("pkgid is NULL\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkg_handle);
+ if (ret != PMINFO_R_OK) {
+ LOGE("Failed to get pkginfo");
+ ret = -1;
+ goto catch;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_type(pkg_handle, &pkg_type);
+ if (ret != PMINFO_R_OK) {
+ LOGE("Failed to get type");
+ ret = -1;
+ goto catch;
+ }
+
+ tzplatform_set_user(uid);
+ rootpath = tzplatform_getenv(TZ_USER_APP);
+
+ __send_signal(pkgid, pkg_type,
+ PKGMGR_INSTALLER_START_KEY_STR,
+ PKGMGR_INSTALLER_CLEAR_EVENT_STR);
+
+ snprintf(dirname, sizeof(dirname), "%s/%s/data", rootpath, pkgid);
+ ret = __clear_dir(dirname);
+ if (ret != 0) {
+ LOGE("Failed to clear data for pkg %s", pkgid);
+ __send_signal(pkgid, pkg_type,
+ PKGMGR_INSTALLER_END_KEY_STR,
+ PKGMGR_INSTALLER_FAIL_EVENT_STR);
+ ret = -1;
+ goto catch;
+ }
+
+ snprintf(dirname, sizeof(dirname), "%s/%s/shared/data", rootpath,
+ pkgid);
+ ret = __clear_dir(dirname);
+ if (ret != 0) {
+ LOGE("Failed to clear data for pkg %s", pkgid);
+ __send_signal(pkgid, pkg_type,
+ PKGMGR_INSTALLER_END_KEY_STR,
+ PKGMGR_INSTALLER_FAIL_EVENT_STR);
+ ret = -1;
+ goto catch;
+ }
+
+ snprintf(dirname, sizeof(dirname), "%s/%s/shared/trusted", rootpath,
+ pkgid);
+ ret = __clear_dir(dirname);
+ if (ret != 0) {
+ LOGE("Failed to clear data for pkg %s", pkgid);
+ __send_signal(pkgid, pkg_type,
+ PKGMGR_INSTALLER_END_KEY_STR,
+ PKGMGR_INSTALLER_FAIL_EVENT_STR);
+ ret = -1;
+ goto catch;
+ }
+
+ /* external data */
+ ret = __get_sdcard_path(&sdpath);
+ if (ret != 0 || sdpath == NULL) {
+ LOGW("Unable to retrieve external storage path");
+ __send_signal(pkgid, pkg_type, PKGMGR_INSTALLER_END_KEY_STR,
+ PKGMGR_INSTALLER_OK_EVENT_STR);
+ ret = 0;
+ goto catch;
+ }
+
+ snprintf(dirname, sizeof(dirname), "%s/%s%s/data",
+ sdpath, "apps",
+ tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid));
+ ret = __clear_dir(dirname);
+ if (ret < 0)
+ LOGE("Failed to clear external data dir.");
+
+ /* external shared/data */
+ snprintf(dirname, sizeof(dirname), "%s/%s%s/shared/data",
+ sdpath, "apps",
+ tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid));
+ ret = __clear_dir(dirname);
+ if (ret < 0)
+ LOGE("Failed to clear external shared data dir.");
+
+ /* external shared/trusted */
+ snprintf(dirname, sizeof(dirname), "%s/%s%s/shared/trusted",
+ sdpath, "apps",
+ tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid));
+ ret = __clear_dir(dirname);
+ if (ret < 0)
+ LOGE("Failed to clear external shared trusted dir.");
+
+ __send_signal(pkgid, pkg_type, PKGMGR_INSTALLER_END_KEY_STR,
+ PKGMGR_INSTALLER_OK_EVENT_STR);
+
+catch:
+ tzplatform_reset_user();
+ if (sdpath)
+ free(sdpath);
+ if (pkg_handle)
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+ return ret;
+}
+
+static int __clear_all_cache_dir_cb(const pkgmgrinfo_pkginfo_h handle,
+ void *user_data)
+{
+ int res = 0;
+ char *pkgid;
+ int *err_cnt = (int *)user_data;
+
+ res = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+ if (res != PMINFO_R_OK) {
+ LOGE("pkgmgr_pkginfo_get_pkgid() failed");
+ --(*err_cnt);
+ return 0;
+ }
+
+ res = __clear_cache_dir(pkgid);
+ if (res != 0) {
+ LOGE("Failed to clear cache dir of %s", pkgid);
+ --(*err_cnt);
+ return 0;
+ }
+
+ return 0;
+}
+
+static int __clear_all_cache_dir(void)
+{
+ int err_cnt = 0;
+ int res;
+
+ res = pkgmgrinfo_pkginfo_get_usr_list(__clear_all_cache_dir_cb,
+ &err_cnt, uid);
+ if (res != PMINFO_R_OK) {
+ LOGE("Failed to get pkg list. (%d)", res);
+ return -1;
+ } else if (err_cnt != 0) {
+ LOGE("Error occured in %d packages.", err_cnt);
+ return -1;
+ }
+
+ return 0;
+}
+
+static void print_usage(void)
+{
+ printf("pkg data/cache clear tool\n");
+
+ printf("\n");
+ printf("-c, --cache clear pkg's cache\n");
+ printf("-d, --data clear pkg's data\n");
+ printf("-h, --help print this help\n");
+ printf("-n, --pkgid package id\n");
+ printf("-u, --uid user id\n");
+
+ printf("\n");
+ printf("Usage: pkg_cleardata [options]\n");
+ printf("pkg_cleardata -c -n <pkgid> -u <uid>\n");
+ printf("pkg_cleardata -d -n <pkgid> -u <uid>\n");
+ printf("pkg_cleardata -cd -n <pkgid> -u <uid>\n");
+ printf("\n");
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = -1;
+ int c = -1;
+ int opt_idx = 0;
+ char pkgid[MAX_PKG_NAME_LEN] = { 0, };
+ bool clear_cache = false;
+ bool clear_data = false;
+ const char short_options[] = "cdhn:u:";
+ const struct option long_options[] = {
+ {"cache", 0, NULL, 'c'},
+ {"data", 0, NULL, 'd'},
+ {"help", 0, NULL, 'h'},
+ {"pkgid", 1, NULL, 'n'},
+ {"uid", 1, NULL, 'u'},
+ {0, 0, 0, 0} /* sentinel */
+ };
+
+ if (argc < 3) {
+ print_usage();
+ return -1;
+ }
+
+ if (getuid() >= REGULAR_USER) {
+ LOGE("Regular user cannot run this tool");
+ return -1;
+ }
+
+ while (1) {
+ c = getopt_long(argc, argv, short_options, long_options,
+ &opt_idx);
+ if (c == -1)
+ break; /* Parse end */
+ switch (c) {
+ case 'c': /* cache */
+ clear_cache = true;
+ break;
+ case 'd': /* data */
+ clear_data = true;
+ break;
+ case 'h': /* help */
+ print_usage();
+ ret = 0;
+ break;
+ case 'n': /* pkgid */
+ if (optarg) {
+ snprintf(pkgid, sizeof(pkgid), "%s", optarg);
+ } else {
+ print_usage();
+ return -1;
+ }
+ break;
+ case 'u': /* uid */
+ if (optarg) {
+ uid = atoi(optarg);
+ } else {
+ print_usage();
+ return -1;
+ }
+ default:
+ break;
+ }
+ }
+
+ if ((!clear_cache && !clear_data) || (pkgid[0] == '\0') || uid == 0) {
+ print_usage();
+ return -1;
+ }
+
+ pi = pkgmgr_installer_new();
+ if (pi == NULL) {
+ LOGE("Failed to create installer");
+ return -1;
+ }
+
+ ret = pkgmgr_installer_set_uid(pi, uid);
+ if (ret != 0) {
+ LOGE("Failed to set uid[%d]", (int)uid);
+ pkgmgr_installer_free(pi);
+ return -1;
+ }
+
+ if (clear_cache) {
+ __send_signal(pkgid, PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR,
+ PKGMGR_INSTALLER_START_KEY_STR,
+ PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR);
+ if (strcmp(pkgid, PKG_CLEAR_ALL_CACHE) == 0)
+ ret = __clear_all_cache_dir();
+ else
+ ret = __clear_cache_dir(pkgid);
+
+ if (ret)
+ __send_signal(pkgid,
+ PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR,
+ PKGMGR_INSTALLER_END_KEY_STR,
+ PKGMGR_INSTALLER_FAIL_EVENT_STR);
+ else
+ __send_signal(pkgid,
+ PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR,
+ PKGMGR_INSTALLER_END_KEY_STR,
+ PKGMGR_INSTALLER_OK_EVENT_STR);
+ }
+
+ if (clear_data) {
+ pkgmgr_installer_set_request_type(pi, PKGMGR_REQ_CLEAR);
+ ret = __clear_data_dir(pkgid);
+ }
+
+ pkgmgr_installer_free(pi);
+
+ return ret;
+}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <getopt.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <dlfcn.h>
-#include <sys/types.h>
-#include <sys/time.h>
-
-#include <glib.h>
-#include <glib-object.h>
-
-#include <pkgmgr-info.h>
-#include <pkgmgr_installer_error.h>
-/* For multi-user support */
-#include <tzplatform_config.h>
-
-#include <package-manager.h>
-#include <package-manager-types.h>
-#include "delta.h"
-
-#define PKG_TOOL_VERSION "0.1"
-#define APP_INSTALLATION_PATH_RW tzplatform_getenv(TZ_USER_APP)
-#define MAX_QUERY_LEN 4096
-
-#define OWNER_ROOT 0
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-#define DEFAULT_USER tzplatform_getuid(TZ_SYS_DEFAULT_USER)
-
-#define OPTVAL_GLOBAL 1000
-#define OPTVAL_CLEAR_ALL 1001
-#define OPTVAL_UID 1002
-
-static int __is_app_installed(char *pkgid, uid_t uid);
-static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type,
- const char *pkgid, const char *key, const char *val,
- const void *pmsg, void *data);
-
-enum pm_tool_request_e {
- INSTALL_REQ = 1,
- UNINSTALL_REQ,
- REINSTALL_REQ,
- MOUNT_INSTALL_REQ,
- GETSIZE_REQ,
- CLEAR_REQ,
- CLEAR_ALL_REQ,
- MOVE_REQ,
- ACTIVATE_REQ,
- DEACTIVATE_REQ,
- APPPATH_REQ,
- CHECKAPP_REQ,
- KILLAPP_REQ,
- LIST_REQ,
- SHOW_REQ,
- CREATE_DELTA,
- GET_PKG_SIZE_INFO_REQ
-};
-typedef enum pm_tool_request_e req_type;
-
-struct pm_tool_args_t {
- req_type request;
- char pkg_path[PATH_MAX];
- char pkg_type[PKG_TYPE_STRING_LEN_MAX];
- char pkgid[PKG_NAME_STRING_LEN_MAX];
- char des_path[PATH_MAX];
- char pkg_old[PATH_MAX];
- char pkg_new[PATH_MAX];
- char delta_pkg[PATH_MAX];
- char *resolved_path_pkg_old;
- char *resolved_path_pkg_new;
- char *resolved_path_delta_pkg;
- char label[PKG_NAME_STRING_LEN_MAX];
- char tep_path[PATH_MAX];
- GList *pkgs;
- int start_count;
- int end_count;
-
- bool tep_move;
- int global;
- int type;
- int result;
- int uid;
- bool debug_mode;
- bool skip_optimization;
-};
-typedef struct pm_tool_args_t pm_tool_args;
-
-typedef int (*dispatch_func)(pm_tool_args *data, uid_t target_uid);
-
-static GMainLoop *main_loop = NULL;
-
-static void __free_data(pm_tool_args *data)
-{
- if (data->resolved_path_pkg_old)
- free(data->resolved_path_pkg_old);
- if (data->resolved_path_pkg_new)
- free(data->resolved_path_pkg_new);
- if (data->resolved_path_delta_pkg)
- free(data->resolved_path_delta_pkg);
- if (data->pkgs)
- g_list_free_full(data->pkgs, free);
-}
-
-static void __error_no_to_string(int errnumber, char **errstr)
-{
- if (errstr == NULL)
- return;
- switch (errnumber) {
- case PKGMGR_INSTALLER_ERRCODE_GLOBALSYMLINK_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_GLOBALSYMLINK_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_GRANT_PERMISSION_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_GRANT_PERMISSION_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_IMAGE_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_IMAGE_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_UNZIP_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_UNZIP_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_SECURITY_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_SECURITY_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_REGISTER_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_REGISTER_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_PRIVILEGE_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_PRIVILEGE_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_PARSE_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_PARSE_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_RECOVERY_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_RECOVERY_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_DELTA_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_DELTA_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_APP_DIR_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_APP_DIR_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_CONFIG_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_CONFIG_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_SIGNATURE_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_SIGNATURE_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_SIGNATURE_INVALID:
- *errstr = PKGMGR_INSTALLER_ERRCODE_SIGNATURE_INVALID_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_CERT_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_CERT_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_MATCH:
- *errstr = PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_MATCH_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_FOUND:
- *errstr = PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_FOUND_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_ICON_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_ICON_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_ICON_NOT_FOUND:
- *errstr = PKGMGR_INSTALLER_ERRCODE_ICON_NOT_FOUND_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_MANIFEST_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_MANIFEST_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_MANIFEST_NOT_FOUND:
- *errstr = PKGMGR_INSTALLER_ERRCODE_MANIFEST_NOT_FOUND_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND:
- *errstr = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_OPERATION_NOT_ALLOWED:
- *errstr = PKGMGR_INSTALLER_ERRCODE_OPERATION_NOT_ALLOWED_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_OUT_OF_SPACE:
- *errstr = PKGMGR_INSTALLER_ERRCODE_OUT_OF_SPACE_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_INVALID_VALUE:
- *errstr = PKGMGR_INSTALLER_ERRCODE_INVALID_VALUE_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_ERROR:
- *errstr = PKGMGR_INSTALLER_ERRCODE_ERROR_STR;
- break;
- case PKGMGR_INSTALLER_ERRCODE_OK:
- *errstr = PKGMGR_INSTALLER_ERRCODE_OK_STR;
- break;
- default:
- *errstr = "Undefined Error";
- break;
- }
-}
-
-static uid_t __get_current_user_id(void)
-{
- uid_t uid = getuid();
-
- if (uid == OWNER_ROOT)
- uid = DEFAULT_USER;
-
- return uid;
-}
-
-static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type,
- const char *pkgid, const char *key, const char *val,
- const void *pmsg, void *priv_data)
-{
- int ret_val;
- char delims[] = ":";
- char *ret_result = NULL;
- pm_tool_args *data = (pm_tool_args *)priv_data;
-
- if (strncmp(key, "error", strlen("error")) == 0) {
- ret_val = atoi(val);
- data->result = ret_val;
-
- ret_result = strstr((char *)val, delims);
- if (ret_result)
- printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d] error message: %s\n",
- req_id, pkg_type, pkgid, key, ret_val, ret_result);
- else
- printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d]\n",
- req_id, pkg_type, pkgid, key, ret_val);
- } else
- printf("__return_cb req_id[%d] pkg_type[%s] "
- "pkgid[%s] key[%s] val[%s]\n",
- req_id, pkg_type, pkgid, key, val);
-
- if (strncmp(key, "start", strlen("start")) == 0)
- data->start_count++;
-
- if (strncmp(key, "end", strlen("end")) == 0) {
- data->end_count++;
- if ((strncmp(val, "fail", strlen("fail")) == 0) && data->result == 0)
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- if (data->start_count == data->end_count)
- g_main_loop_quit(main_loop);
- }
-
- return 0;
-}
-
-static int __app_return_cb(uid_t target_uid, int req_id, const char *pkg_type,
- const char *pkgid, const char *appid, const char *key, const char *val,
- const void *pmsg, void *priv_data)
-{
- int ret_val;
- pm_tool_args *data = (pm_tool_args *)priv_data;
-
- if (strncmp(key, "error", strlen("error")) == 0) {
- ret_val = atoi(val);
- data->result = ret_val;
- }
-
- printf("__app_return_cb req_id[%d] pkg_type[%s] pkgid[%s] appid[%s] " \
- "key[%s] val[%s]\n",
- req_id, pkg_type, pkgid, appid, key, val);
-
- if (strncmp(key, "end", strlen("end")) == 0) {
- if ((strncmp(val, "fail", strlen("fail")) == 0) && data->result == 0)
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- g_main_loop_quit(main_loop);
- }
-
- return 0;
-}
-
-static int __convert_to_absolute_path(pm_tool_args *data)
-{
- char abs[PATH_MAX] = {'\0'};
- char *temp;
- char *ptr = NULL;
- int ret;
- GList *list;
-
- ptr = realpath(data->pkg_path, abs);
- if (ptr == NULL) {
- printf("realpath fail: %d\n", errno);
- return -1;
- }
- ret = snprintf(data->pkg_path, PATH_MAX - 1, "%s", abs);
- if (ret < 0 || ret > PATH_MAX - 1) {
- printf("snprintf fail\n");
- return -1;
- }
-
- for (list = data->pkgs; list; list = list->next) {
- ptr = realpath(list->data, abs);
- if (ptr == NULL) {
- printf("realpath fail: %d\n", errno);
- return -1;
- }
- temp = list->data;
- list->data = strdup(abs);
- if (list->data == NULL) {
- printf("out of memory\n");
- return -1;
- }
- free(temp);
- }
-
- return 0;
-}
-
-static int __convert_to_absolute_tep_path(pm_tool_args *data)
-{
- char abs[PATH_MAX] = {'\0'};
- char temp[PATH_MAX] = {'\0'};
- char *ptr = NULL;
- int ret;
- if (data->tep_path[0] == '\0') {
- printf("path is NULL\n");
- return -1;
- }
- ret = snprintf(temp, PATH_MAX - 1, "%s", data->tep_path);
- if (ret < 0 || ret > PATH_MAX - 1) {
- printf("snprintf fail\n");
- return -1;
- }
- if (strchr(data->tep_path, '/') == NULL) {
- if (getcwd(abs, PATH_MAX - 1) == NULL || abs[0] == '\0') {
- printf("getcwd() failed\n");
- return -1;
- }
- memset(data->tep_path, '\0', PATH_MAX);
- ret = snprintf(data->tep_path, PATH_MAX - 1, "%s/%s", abs, temp);
- if (ret < 0 || ret > PATH_MAX - 1) {
- printf("snprintf fail\n");
- return -1;
- }
- return 0;
- }
- if (strncmp(data->tep_path, "./", 2) == 0) {
- ptr = temp;
- if (getcwd(abs, PATH_MAX - 1) == NULL || abs[0] == '\0') {
- printf("getcwd() failed\n");
- return -1;
- }
- ptr = ptr + 2;
- memset(data->tep_path, '\0', PATH_MAX);
- ret = snprintf(data->tep_path, PATH_MAX - 1, "%s/%s", abs, ptr);
- if (ret < 0 || ret > PATH_MAX - 1) {
- printf("snprintf fail\n");
- return -1;
- }
- return 0;
- }
- return 0;
-}
-
-static int __is_app_installed(char *pkgid, uid_t uid)
-{
- pkgmgrinfo_pkginfo_h handle;
- int ret;
-
- ret = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, uid, &handle);
- if (ret < 0) {
- printf("package is not in pkgmgr_info DB\n");
- return -1;
- } else {
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- }
-
- return 0;
-}
-
-static void __print_usage()
-{
- printf("\nPackage Manager Tool Version: %s\n", PKG_TOOL_VERSION);
-
- printf("\n");
- printf("-i, --install install the package\n");
- printf("-u, --uninstall uninstall the package\n");
- printf("-r, --reinstall reinstall the package\n");
- printf("-w, --mount-install mount install the package\n");
- printf("-c, --clear clear user data\n");
- printf(" --clear-all clear user data for all packages or packages type\n");
- printf("-m, --move move package\n");
- printf("-g, --getsize get size of given package\n");
- printf("-T, --getsize-type get type [0: total size / 1: data size]\n");
- printf("-l, --list display list of installed packages available for the current user\n");
- printf(" i.e. user's specific apps and global apps\n");
- printf("-s, --show show detail package info\n");
- printf("-a, --app-path show app installation path\n");
- printf("-C, --check check if applications belonging to a package are running or not\n");
- printf("-k, --kill terminate applications belonging to a package\n");
- printf("-d, --descriptor provide descriptor path\n");
- printf("-p, --package-path provide package path\n");
- printf("-n, --package-name provide package name\n");
- printf("-t, --package-type provide package type\n");
- printf("-T, --move-type provide move type [0: move to internal / 1: move to external / 2: move to extended]\n");
- printf(" --global Global Mode [Warning: user should be privilegied to use this mode]\n");
- printf(" --uid Specify target user's id. This only affect app activation/deactivation.\n");
- printf("-e, --tep-path provide TEP package path\n");
- printf("-M, --tep-move decide move/copy of TEP package [0: copy TEP package / 1: move TEP package]\n");
- printf("-G, --debug-mode install the package with debug mode for sdk\n");
- printf("-D, --deactivate disable package or app\n");
- printf("-A, --activate enable package or app\n");
- printf("-S, --skip-optimization install the package with skip optimization for sdk\n");
- printf("-h, --help print this help\n");
-
- printf("\n");
- printf("Usage: pkgcmd [options]\n");
- printf("pkgcmd -i -t <pkg type> (-d <descriptor path>) -p <pkg path> (--global)\n");
- printf("pkgcmd -u -n <pkgid> (--global)\n");
- printf("pkgcmd -r -t <pkg type> -n <pkgid> (--global)\n");
- printf("pkgcmd -w -t <pkg type> (-d <descriptor path>) -p <pkg path> (--global)\n");
- printf("pkgcmd -l (-t <pkg type>)\n");
- printf("pkgcmd -s -t <pkg type> -p <pkg path>\n");
- printf("pkgcmd -s -t <pkg type> -n <pkg name>\n");
- printf("pkgcmd -m -t <pkg type> -T <move type> -n <pkg name>\n");
- printf("pkgcmd -g -T <getsize type> -n <pkgid>\n");
- printf("pkgcmd -C -n <pkgid>\n");
- printf("pkgcmd -k -n <pkgid>\n");
- printf("pkgcmd --clear-all (-t <pkg type>)\n");
- printf("pkgcmd -X <old_pkg> -Y <new_pkg> -Z <delta_pkg>\n");
- printf("pkgcmd -D -t <pkg type> -n <pkgid> (--global) (--uid <uid>)\n");
-
- printf("\n");
- printf("Example:\n");
- printf("pkgcmd -u -n org.example.hello\n");
- printf("pkgcmd -i -t tpk -p /tmp/org.example.hello-1.0.0-arm.tpk\n");
- printf("pkgcmd -r -t tpk -n org.example.hello\n");
- printf("pkgcmd -w -t tpk -p /tmp/org.example.hello-1.0.0-arm.tpk\n");
- printf("pkgcmd -c -t tpk -n org.example.hello\n");
- printf("pkgcmd --clear-all -t wgt\n");
- printf("pkgcmd -m -t tpk -T 1 -n org.example.hello\n");
- printf("pkgcmd -C -n org.example.hello\n");
- printf("pkgcmd -k -n org.example.hello\n");
- printf("pkgcmd -a\n");
- printf("pkgcmd -a -t tpk -n org.example.hello\n");
- printf("pkgcmd -l\n");
- printf("pkgcmd -l -t tpk\n");
- printf("pkgcmd -g -T 0 -n org.example.hello\n");
- printf("pkgcmd -D -t tpk -n org.example.hellopkg\n");
- printf("pkgcmd -D -t app -n org.example.helloapp --global\n");
-
- printf("\n");
- exit(0);
-}
-
-static int __pkgmgr_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
-{
- int ret = -1;
- char *pkgid = NULL;
- char *pkg_type = NULL;
- char *pkg_version = NULL;
- char *pkg_label = NULL;
- bool for_all_users = 0;
- pkgmgrinfo_installed_storage storage;
-
- ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (ret == -1) {
- printf("Failed to get pkgmgrinfo_pkginfo_get_pkgid\n");
- return ret;
- }
- ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type);
- if (ret == -1) {
- printf("Failed to get pkgmgrinfo_pkginfo_get_type\n");
- return ret;
- }
- ret = pkgmgrinfo_pkginfo_get_version(handle, &pkg_version);
- if (ret == -1) {
- printf("Failed to get pkgmgrinfo_pkginfo_get_version\n");
- return ret;
- }
- ret = pkgmgrinfo_pkginfo_get_label(handle, &pkg_label);
- if (ret == -1)
- pkg_label = "(null)";
-
- ret = pkgmgrinfo_pkginfo_is_for_all_users(handle, &for_all_users);
- if (ret == -1) {
- printf("Failed to get pkgmgrinfo_pkginfo_is_for_all_users\n");
- return ret;
- }
-
- ret = pkgmgrinfo_pkginfo_get_installed_storage(handle, &storage);
- if (ret == -1) {
- printf("Failed to get pkgmgrinfo_pkginfo_get_installed_storage\n");
- return ret;
- }
-
- printf("%s\tpkg_type [%s]\tpkgid [%s]\tname [%s]\tversion [%s]\tstorage [%s]\n",
- for_all_users ? "system apps" : "user apps ", pkg_type, pkgid, pkg_label, pkg_version,
- (storage == PMINFO_EXTERNAL_STORAGE) ? "external" : "internal");
- return ret;
-}
-
-static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
-{
- int ret = -1;
- char *pkgid;
- pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle;
-
- ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (ret < 0)
- printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n");
-
- ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE,
- (pkgmgr_client *)user_data, NULL, pkgid, uid_info->uid, NULL, NULL, NULL);
- if (ret < 0) {
- printf("pkgmgr_client_request_service Failed\n");
- return -1;
- }
-
- printf("pkg[%s] size = %d\n", pkgid, ret);
-
- 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 __pkgmgr_list_clear_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
-{
- int ret = -1;
- char *pkgid = NULL;
- char *pkg_type = NULL;
- pm_tool_args *data = (pm_tool_args *)user_data;
-
- ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (ret == -1) {
- printf("Failed to get pkgmgrinfo_pkginfo_get_pkgid\n");
- return ret;
- }
- ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type);
- if (ret == -1) {
- printf("Failed to get pkgmgrinfo_pkginfo_get_type\n");
- return ret;
- }
-
- pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle;
- uid_t uid = uid_info->uid;
-
- pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST);
- if (pc == NULL) {
- printf("PkgMgr Client Creation Failed\n");
- return -1;
- }
- ret = pkgmgr_client_usr_clear_user_data(pc, pkg_type, pkgid, PM_QUIET,
- uid);
- if (ret >= 0)
- ret = data->result;
- pkgmgr_client_free(pc);
-
- return ret;
-}
-
-static void __invalid_arg_handler(pm_tool_args *data)
-{
- printf("Please provide the arguments.\n");
- printf("use -h option to see usage\n");
- data->result = PKGMGR_INSTALLER_ERRCODE_INVALID_VALUE;
-}
-
-static int __install_single_pkg(pkgmgr_client *pc, pm_tool_args *data,
- uid_t target_uid)
-{
- int ret;
-
- if (data->des_path[0] == '\0')
- ret = pkgmgr_client_usr_install(pc,
- data->pkg_type[0] != '\0' ? data->pkg_type : NULL,
- NULL, data->pkg_path, NULL, PM_QUIET,
- __return_cb, data, target_uid);
- else
- ret = pkgmgr_client_usr_install(pc,
- data->pkg_type[0] != '\0' ? data->pkg_type : NULL,
- data->des_path, data->pkg_path,
- NULL, PM_QUIET, __return_cb, data, target_uid);
-
- return ret;
-}
-
-static int __install_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data,
- uid_t target_uid)
-{
- int ret;
- const char **pkgs;
- int n_pkgs;
- GList *l;
- int i;
-
- n_pkgs = g_list_length(data->pkgs);
-
- pkgs = malloc(sizeof(char *) * n_pkgs);
- for (l = data->pkgs, i = 0; l; l = l->next, i++)
- pkgs[i] = (char *)l->data;
-
- ret = pkgmgr_client_usr_install_packages(pc, pkgs, n_pkgs, __return_cb,
- data, target_uid);
-
- free(pkgs);
-
- return ret;
-}
-
-static int __install_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- pkgmgr_client *pc;
- GList *list;
- char *pkg;
-
- if (data->pkg_path[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
- 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 = PKGMGR_INSTALLER_ERRCODE_ERROR;
- return -1;
- }
-
- if (data->debug_mode)
- pkgmgr_client_set_debug_mode(pc, true);
-
- if (data->skip_optimization)
- pkgmgr_client_set_skip_optimization(pc, true);
-
- if (data->tep_path[0] != '\0')
- pkgmgr_client_set_tep_path(pc, data->tep_path, data->tep_move);
-
- if (g_list_length(data->pkgs) > 1)
- ret = __install_multiple_pkgs(pc, data, target_uid);
- else
- ret = __install_single_pkg(pc, data, target_uid);
-
- if (ret < 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- if (access(data->pkg_path, F_OK) != 0)
- data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
- for (list = data->pkgs; list; list = list->next) {
- pkg = (char *)list->data;
- if (access(pkg, F_OK) != 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
- break;
- }
- }
- pkgmgr_client_free(pc);
- return ret;
- }
- g_main_loop_run(main_loop);
- pkgmgr_client_free(pc);
- return data->result;
-}
-
-static int __uninstall_single_pkg(pkgmgr_client *pc, pm_tool_args *data,
- uid_t target_uid)
-{
- return pkgmgr_client_usr_uninstall(pc, data->pkg_type, data->pkgid,
- PM_QUIET, __return_cb, data, target_uid);
-}
-
-static int __uninstall_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data,
- uid_t target_uid)
-{
- int ret;
- const char **pkgs;
- int n_pkgs;
- GList *l;
- int i;
-
- n_pkgs = g_list_length(data->pkgs);
-
- pkgs = malloc(sizeof(char *) * n_pkgs);
- for (l = data->pkgs, i = 0; l; l = l->next, i++)
- pkgs[i] = (char *)l->data;
-
- ret = pkgmgr_client_usr_uninstall_packages(pc, pkgs, n_pkgs,
- __return_cb, data, target_uid);
-
- free(pkgs);
-
- return ret;
-}
-
-static int __uninstall_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- pkgmgr_client *pc;
-
- if (data->pkgid[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
- 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 = PKGMGR_INSTALLER_ERRCODE_ERROR;
- return -1;
- }
-
- ret = __is_app_installed(data->pkgid, target_uid);
- if (ret == -1) {
- printf("package is not installed\n");
- pkgmgr_client_free(pc);
- return ret;
- }
-
- if (g_list_length(data->pkgs) > 1)
- ret = __uninstall_multiple_pkgs(pc, data, target_uid);
- else
- ret = __uninstall_single_pkg(pc, data, target_uid);
-
- if (ret < 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- if (access(data->pkg_path, F_OK) != 0)
- data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
- pkgmgr_client_free(pc);
- return ret;
- }
- g_main_loop_run(main_loop);
- pkgmgr_client_free(pc);
- return data->result;
-}
-
-static int __reinstall_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- pkgmgr_client *pc;
-
- if (data->pkgid[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
- 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 = PKGMGR_INSTALLER_ERRCODE_ERROR;
- return -1;
- }
-
- if (data->debug_mode)
- pkgmgr_client_set_debug_mode(pc, true);
-
- if (data->skip_optimization)
- pkgmgr_client_set_skip_optimization(pc, true);
-
- ret = pkgmgr_client_usr_reinstall(pc, NULL,
- data->pkgid, NULL, PM_QUIET, __return_cb, data, target_uid);
- if (ret < 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- if (access(data->pkg_path, F_OK) != 0)
- data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
- pkgmgr_client_free(pc);
- return ret;
- }
- g_main_loop_run(main_loop);
- pkgmgr_client_free(pc);
- return data->result;
-}
-
-static int __mount_install_single_pkg(pkgmgr_client *pc, pm_tool_args *data,
- uid_t target_uid)
-{
- int ret;
-
- if (data->des_path[0] == '\0')
- ret = pkgmgr_client_usr_mount_install(pc,
- data->pkg_type[0] != '\0' ? data->pkg_type : NULL,
- NULL, data->pkg_path, NULL, PM_QUIET,
- __return_cb, data, target_uid);
- else
- ret = pkgmgr_client_usr_mount_install(pc,
- data->pkg_type[0] != '\0' ? data->pkg_type : NULL,
- data->des_path, data->pkg_path,
- NULL, PM_QUIET, __return_cb, data, target_uid);
-
- return ret;
-}
-
-static int __mount_install_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data,
- uid_t target_uid)
-{
- int ret;
- const char **pkgs;
- int n_pkgs;
- GList *l;
- int i;
-
- n_pkgs = g_list_length(data->pkgs);
-
- pkgs = malloc(sizeof(char *) * n_pkgs);
- for (l = data->pkgs, i = 0; l; l = l->next, i++)
- pkgs[i] = (char *)l->data;
-
- ret = pkgmgr_client_usr_mount_install_packages(pc, pkgs, n_pkgs,
- __return_cb, data, target_uid);
-
- free(pkgs);
-
- return ret;
-}
-
-static int __mount_install_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- pkgmgr_client *pc;
- GList *list;
- char *pkg;
-
- if (data->pkg_path[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
- 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 = PKGMGR_INSTALLER_ERRCODE_ERROR;
- return -1;
- }
-
- if (data->debug_mode)
- pkgmgr_client_set_debug_mode(pc, true);
-
- if (data->skip_optimization)
- pkgmgr_client_set_skip_optimization(pc, true);
-
- if (data->tep_path[0] != '\0')
- pkgmgr_client_set_tep_path(pc, data->tep_path, data->tep_move);
-
- if (g_list_length(data->pkgs) > 1)
- ret = __mount_install_multiple_pkgs(pc, data, target_uid);
- else
- ret = __mount_install_single_pkg(pc, data, target_uid);
-
- if (ret < 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- if (access(data->pkg_path, F_OK) != 0)
- data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
- for (list = data->pkgs; list; list = list->next) {
- pkg = (char *)list->data;
- if (access(pkg, F_OK) != 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
- break;
- }
- }
- pkgmgr_client_free(pc);
- return ret;
- }
- g_main_loop_run(main_loop);
- pkgmgr_client_free(pc);
- return data->result;
-}
-
-static int __getsize_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- pkgmgr_client *pc;
-
- if (data->pkgid[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
-
- pc = pkgmgr_client_new(PC_REQUEST);
- if (pc == NULL) {
- printf("PkgMgr Client Creation Failed\n");
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- return -1;
- }
-
- if (data->type == 9) {
- ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb,
- (void *)(pc), target_uid);
- pkgmgr_client_free(pc);
- return ret;
- }
- ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, data->type,
- pc, NULL, data->pkgid, target_uid, NULL, NULL, NULL);
- if (ret < 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- pkgmgr_client_free(pc);
- return ret;
- }
-
- printf("pkg[%s] size = %d\n", data->pkgid, ret);
- pkgmgr_client_free(pc);
- return data->result;
-}
-
-static int __clear_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- pkgmgr_client *pc;
-
- if (data->pkg_type[0] == '\0' || data->pkgid[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
-
- pc = pkgmgr_client_new(PC_REQUEST);
- if (pc == NULL) {
- printf("PkgMgr Client Creation Failed\n");
- return -1;
- }
- ret = __is_app_installed(data->pkgid, target_uid);
- if (ret == -1) {
- printf("package is not installed\n");
- pkgmgr_client_free(pc);
- return ret;
- }
- ret = pkgmgr_client_usr_clear_user_data(pc, data->pkg_type,
- data->pkgid, PM_QUIET, target_uid);
- if (ret < 0) {
- pkgmgr_client_free(pc);
- return ret;
- }
- pkgmgr_client_free(pc);
- return data->result;
-}
-
-static int __clear_all_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
-
- if (data->pkg_type[0] == '\0') {
- ret = pkgmgrinfo_pkginfo_get_usr_list(__pkgmgr_list_clear_cb,
- data, target_uid);
- if (ret == -1)
- printf("no packages found\n");
- return ret;
- }
- pkgmgrinfo_pkginfo_filter_h handle;
-
- ret = pkgmgrinfo_pkginfo_filter_create(&handle);
- if (ret == -1) {
- printf("Failed to get package filter handle\n");
- return ret;
- }
-
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data->pkg_type);
- if (ret == -1) {
- printf("Failed to add package type filter\n");
- pkgmgrinfo_pkginfo_filter_destroy(handle);
- return ret;
- }
-
- ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle,
- __pkgmgr_list_clear_cb, data, target_uid);
- if (ret != PMINFO_R_OK)
- printf("no package filter list\n");
-
- pkgmgrinfo_pkginfo_filter_destroy(handle);
- return ret;
-}
-
-static int __move_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- pkgmgr_client *pc;
-
- if (data->pkg_type[0] == '\0' || data->pkgid[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
- if (data->type < 0 || data->type > 2) {
- printf("Invalid move type...See usage\n");
- return -1;
- }
-
- main_loop = g_main_loop_new(NULL, FALSE);
- pc = pkgmgr_client_new(PC_REQUEST);
- if (pc == NULL) {
- printf("PkgMgr Client Creation Failed\n");
- return -1;
- }
- ret = __is_app_installed(data->pkgid, target_uid);
- if (ret == -1) {
- printf("package is not installed\n");
- pkgmgr_client_free(pc);
- return ret;
- }
- ret = pkgmgr_client_usr_request_service(PM_REQUEST_MOVE, data->type, pc,
- data->pkg_type, data->pkgid, target_uid, NULL, __return_cb, data);
-
- if (ret < 0) {
- pkgmgr_client_free(pc);
- return ret;
- }
-
- g_main_loop_run(main_loop);
- pkgmgr_client_free(pc);
- return data->result;
-}
-
-static int __activate_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- pkgmgrinfo_appinfo_h appinfo_h;
- pkgmgr_client *pc;
- pkgmgr_client *listen_pc = NULL;
-
- if (data->pkg_type[0] == '\0' || data->pkgid[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
-
- main_loop = g_main_loop_new(NULL, FALSE);
- pc = pkgmgr_client_new(PC_REQUEST);
- if (pc == NULL) {
- printf("PkgMgr Client Creation Failed\n");
- return -1;
- }
-
- if (strlen(data->label) != 0) {
- printf("requested label = %s\n", data->label);
-
- ret = pkgmgr_client_usr_set_app_label(pc, data->pkgid,
- data->label, target_uid);
- if (ret < 0) {
- printf("set_app_label is failed\n");
- pkgmgr_client_free(pc);
- return ret;
- }
-
- printf("set_app_label is done\n");
- }
-
- if (strcmp(data->pkg_type, "app") == 0) {
- if (data->global && data->uid != -1) {
- if (data->uid != __get_current_user_id()) {
- printf("Invalid uid : %d\n", data->uid);
- pkgmgr_client_free(pc);
- return -1;
- }
- target_uid = data->uid;
- }
- ret = pkgmgrinfo_appinfo_get_usr_disabled_appinfo(data->pkgid,
- target_uid, &appinfo_h);
- if (ret != PMINFO_R_OK) {
- printf("Failed to get appinfo[%s]\n", data->pkgid);
- pkgmgr_client_free(pc);
- return -1;
- }
-
- if (data->global) {
- if (data->uid != -1)
- /* enable global app for this user only */
- ret = pkgmgr_client_activate_global_app_for_uid(pc,
- data->pkgid, __app_return_cb, data,
- __get_current_user_id());
- else
- /* enable global app for all user */
- ret = pkgmgr_client_usr_activate_app(pc, data->pkgid,
- __app_return_cb, data, GLOBAL_USER);
- } else {
- /* enable local app */
- ret = pkgmgr_client_usr_activate_app(pc, data->pkgid,
- __app_return_cb, data, target_uid);
- }
- pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
- } else {
- listen_pc = pkgmgr_client_new(PC_LISTENING);
- if (listen_pc == NULL) {
- printf("PkgMgr Client Creation Failed\n");
- pkgmgr_client_free(pc);
- return -1;
- }
- ret = pkgmgr_client_listen_status(listen_pc, __return_cb, data);
- if (ret < 0) {
- printf("Failed to set callback[%d]\n", ret);
- pkgmgr_client_free(pc);
- pkgmgr_client_free(listen_pc);
- return ret;
- }
- ret = pkgmgr_client_usr_activate(pc, data->pkg_type, data->pkgid,
- target_uid);
- }
- if (ret < 0) {
- pkgmgr_client_free(pc);
- if (listen_pc)
- pkgmgr_client_free(listen_pc);
- return ret;
- }
-
- g_main_loop_run(main_loop);
-
- pkgmgr_client_free(pc);
- if (listen_pc)
- pkgmgr_client_free(listen_pc);
- return data->result;
-}
-
-static int __deactivate_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- pkgmgrinfo_appinfo_h appinfo_h;
- pkgmgr_client *pc;
- pkgmgr_client *listen_pc = NULL;
-
- if (data->pkg_type[0] == '\0' || data->pkgid[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
-
- main_loop = g_main_loop_new(NULL, FALSE);
- pc = pkgmgr_client_new(PC_REQUEST);
- if (pc == NULL) {
- printf("PkgMgr Client Creation Failed\n");
- return -1;
- }
-
- if (strcmp(data->pkg_type, "app") == 0) {
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(data->pkgid,
- target_uid, &appinfo_h);
- if (ret != PMINFO_R_OK) {
- printf("Failed to get appinfo[%s]\n", data->pkgid);
- pkgmgr_client_free(pc);
- return -1;
- }
-
- if (data->global) {
- if (data->uid != -1 && data->uid != getuid()) {
- printf("Invalid uid : %d\n", data->uid);
- pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
- pkgmgr_client_free(pc);
- return -1;
- }
- if (data->uid != -1)
- /* disable global app for this user only */
- ret = pkgmgr_client_deactivate_global_app_for_uid(pc,
- data->pkgid, __app_return_cb, NULL,
- __get_current_user_id());
- else
- /* disable global app for all user */
- ret = pkgmgr_client_usr_deactivate_app(pc, data->pkgid,
- __app_return_cb, NULL, GLOBAL_USER);
- } else {
- /* disable local app */
- ret = pkgmgr_client_usr_deactivate_app(pc, data->pkgid,
- __app_return_cb, NULL, target_uid);
- }
-
- pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
- } else {
- listen_pc = pkgmgr_client_new(PC_LISTENING);
- if (listen_pc == NULL) {
- printf("PkgMgr Client Creation Failed\n");
- pkgmgr_client_free(pc);
- return -1;
- }
- ret = pkgmgr_client_listen_status(listen_pc, __return_cb, data);
- if (ret < 0) {
- printf("Failed to set callback[%d]\n", ret);
- pkgmgr_client_free(pc);
- pkgmgr_client_free(listen_pc);
- return ret;
- }
- ret = pkgmgr_client_usr_deactivate(pc, data->pkg_type, data->pkgid,
- target_uid);
- }
- if (ret < 0) {
- pkgmgr_client_free(pc);
- if (listen_pc)
- pkgmgr_client_free(listen_pc);
- return ret;
- }
-
- g_main_loop_run(main_loop);
-
- pkgmgr_client_free(pc);
- if (listen_pc)
- pkgmgr_client_free(listen_pc);
- return data->result;
-}
-
-static int __apppath_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- char buf[1024];
-
- if (data->pkg_type[0] == '\0' && data->pkgid[0] == '\0') {
- printf("Tizen Application Installation Path: %s\n",
- APP_INSTALLATION_PATH_RW);
- return 0;
- }
- if ((data->pkg_type[0] == '\0') || (data->pkgid[0] == '\0')) {
- printf("Use -h option to see usage\n");
- return -1;
- }
- if (strncmp(data->pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
- snprintf(buf, 1023, "%s/%s/res/wgt",
- APP_INSTALLATION_PATH_RW, data->pkgid);
- printf("Tizen Application Installation Path: %s\n", buf);
- return 0;
- } else if (strncmp(data->pkg_type, "tpk", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
- snprintf(buf, 1023, "%s/%s", APP_INSTALLATION_PATH_RW, data->pkgid);
- printf("Tizen Application Installation Path: %s\n", buf);
- return 0;
- } else {
- printf("Invalid package type.\n");
- printf("use -h option to see usage\n");
- return -1;
- }
-}
-
-static int __checkapp_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- int pid = -1;
- pkgmgr_client *pc;
-
- if (data->pkgid[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
-
- pc = pkgmgr_client_new(PC_REQUEST);
- if (pc == NULL) {
- printf("PkgMgr Client Creation Failed\n");
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- return -1;
- }
-
- if (data->request == KILLAPP_REQ) {
- ret = pkgmgr_client_usr_request_service(PM_REQUEST_KILL_APP, 0, pc,
- NULL, data->pkgid, target_uid, NULL, NULL, &pid);
- if (ret < 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- pkgmgr_client_free(pc);
- return ret;
- }
- if (pid)
- printf("Pkgid: %s is Terminated\n", data->pkgid);
- else
- printf("Pkgid: %s is already Terminated\n", data->pkgid);
- } else if (data->request == CHECKAPP_REQ) {
- ret = pkgmgr_client_usr_request_service(PM_REQUEST_CHECK_APP, 0, pc,
- NULL, data->pkgid, target_uid, NULL, NULL, &pid);
- if (ret < 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- pkgmgr_client_free(pc);
- return ret;
- }
-
- if (pid)
- printf("Pkgid: %s is Running\n", data->pkgid);
- else
- printf("Pkgid: %s is Not Running\n", data->pkgid);
- }
- pkgmgr_client_free(pc);
- return data->result;
-}
-
-static int __killapp_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- int pid = -1;
- pkgmgr_client *pc;
-
- if (data->pkgid[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
-
- pc = pkgmgr_client_new(PC_REQUEST);
- if (pc == NULL) {
- printf("PkgMgr Client Creation Failed\n");
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- return -1;
- }
-
- if (data->request == KILLAPP_REQ) {
- ret = pkgmgr_client_usr_request_service(PM_REQUEST_KILL_APP, 0, pc,
- NULL, data->pkgid, target_uid, NULL, NULL, &pid);
- if (ret < 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- pkgmgr_client_free(pc);
- return ret;
- }
- if (pid)
- printf("Pkgid: %s is Terminated\n", data->pkgid);
- else
- printf("Pkgid: %s is already Terminated\n", data->pkgid);
- } else if (data->request == CHECKAPP_REQ) {
- ret = pkgmgr_client_usr_request_service(PM_REQUEST_CHECK_APP, 0, pc,
- NULL, data->pkgid, target_uid, NULL, NULL, &pid);
- if (ret < 0) {
- data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
- pkgmgr_client_free(pc);
- return ret;
- }
-
- if (pid)
- printf("Pkgid: %s is Running\n", data->pkgid);
- else
- printf("Pkgid: %s is Not Running\n", data->pkgid);
- }
- pkgmgr_client_free(pc);
- return data->result;
-}
-
-static int __list_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
-
- if (data->pkg_type[0] == '\0') {
- ret = pkgmgrinfo_pkginfo_get_usr_list(__pkgmgr_list_cb,
- NULL, target_uid);
- if (ret == -1)
- printf("no packages found\n");
- return ret;
- }
- pkgmgrinfo_pkginfo_filter_h handle;
-
- ret = pkgmgrinfo_pkginfo_filter_create(&handle);
- if (ret == -1) {
- printf("Failed to get package filter handle\n");
- return ret;
- }
-
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data->pkg_type);
- if (ret == -1) {
- printf("Failed to add package type filter\n");
- pkgmgrinfo_pkginfo_filter_destroy(handle);
- return ret;
- }
-
- ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle,
- __pkgmgr_list_cb, NULL, target_uid);
- if (ret != PMINFO_R_OK)
- printf("no package filter list\n");
-
- pkgmgrinfo_pkginfo_filter_destroy(handle);
- return ret;
-}
-
-/* unsupported */
-static int __show_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- return -1;
-}
-
-static int __create_delta_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- char pkg_old[PATH_MAX];
- char pkg_new[PATH_MAX];
-
- printf("CREATE_DELTA\n");
- if (data->pkg_old[0] == '\0' || data->pkg_new[0] == '\0') {
- printf("tpk pkg missing\n");
- return -1;
- }
- if (data->delta_pkg[0] == '\0') {
- data->resolved_path_delta_pkg = strdup("/tmp/delta_pkg");
- printf("output file will be /tmp/delta_pkg.delta\n");
- }
- const char *unzip_argv[] = {"sh",
- "/etc/package-manager/pkgmgr-unzip-pkg.sh", "-a",
- data->resolved_path_pkg_old, "-b", data->resolved_path_pkg_new, "-p",
- data->resolved_path_delta_pkg, NULL};
- ret = __xsystem(unzip_argv);
- if (ret != 0) {
- printf("unzip is fail .\n");
- return ret;
- }
- printf("unzip is success .\n");
- char *ptr_old_pkg = NULL;
- ptr_old_pkg = strrchr(data->resolved_path_pkg_old, '/');
-
- if (!ptr_old_pkg) {
- printf("not able to extract package name.\n");
- return ret;
- }
- ptr_old_pkg++;
- char *ptr_new_pkg = NULL;
- ptr_new_pkg = strrchr(data->resolved_path_pkg_new, '/');
-
- if (!ptr_new_pkg) {
- printf("not able to extract package name.\n");
- return ret;
- }
- ptr_new_pkg++;
-
- snprintf(pkg_old, PATH_MAX, "%s%s%s", TEMP_DELTA_REPO,
- ptr_old_pkg, UNZIPFILE);
- snprintf(pkg_new, PATH_MAX, "%s%s%s", TEMP_DELTA_REPO,
- ptr_new_pkg, UNZIPFILE);
- __create_diff_file(pkg_old, pkg_new);
-
- const char *delta_argv[] = {"sh",
- "/etc/package-manager/pkgmgr-create-delta.sh", "-a",
- data->resolved_path_pkg_old, "-b", data->resolved_path_pkg_new, "-p",
- data->resolved_path_delta_pkg, NULL};
- ret = __xsystem(delta_argv);
- if (ret != 0) {
- printf("create delta script fail .\n");
- return ret;
- }
- printf("create delta script success .\n");
- return ret;
-}
-
-static int __get_pkg_size_info_req_dispatcher(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
- pkgmgr_client *pc;
-
- if (data->pkgid[0] == '\0') {
- __invalid_arg_handler(data);
- return -1;
- }
-
- 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 = PKGMGR_INSTALLER_ERR_FATAL_ERROR;
- return -1;
- }
-
- if (strcmp(data->pkgid, PKG_SIZE_INFO_TOTAL) == 0)
- ret = pkgmgr_client_usr_get_total_package_size_info(pc,
- __total_pkg_size_info_recv_cb, NULL,
- target_uid);
- else
- ret = pkgmgr_client_usr_get_package_size_info(pc,
- data->pkgid, __pkg_size_info_recv_cb, NULL,
- target_uid);
-
- if (ret < 0) {
- data->result = PKGMGR_INSTALLER_ERR_FATAL_ERROR;
- pkgmgr_client_free(pc);
- return ret;
- }
-
- printf("pkg[%s] ret: %d\n", data->pkgid, ret);
-
- g_main_loop_run(main_loop);
- pkgmgr_client_free(pc);
- return data->result;
-}
-
-static dispatch_func __process_request_func_ptr[] = {
- [INSTALL_REQ] = __install_req_dispatcher,
- [UNINSTALL_REQ] = __uninstall_req_dispatcher,
- [REINSTALL_REQ] = __reinstall_req_dispatcher,
- [MOUNT_INSTALL_REQ] = __mount_install_req_dispatcher,
- [GETSIZE_REQ] = __getsize_req_dispatcher,
- [CLEAR_REQ] = __clear_req_dispatcher,
- [CLEAR_ALL_REQ] = __clear_all_req_dispatcher,
- [MOVE_REQ] = __move_req_dispatcher,
- [ACTIVATE_REQ] = __activate_req_dispatcher,
- [DEACTIVATE_REQ] = __deactivate_req_dispatcher,
- [APPPATH_REQ] = __apppath_req_dispatcher,
- [CHECKAPP_REQ] = __checkapp_req_dispatcher,
- [KILLAPP_REQ] = __killapp_req_dispatcher,
- [LIST_REQ] = __list_req_dispatcher,
- [SHOW_REQ] = __show_req_dispatcher,
- [CREATE_DELTA] = __create_delta_dispatcher,
- [GET_PKG_SIZE_INFO_REQ] = __get_pkg_size_info_req_dispatcher,
-};
-
-static int __process_request(pm_tool_args *data, uid_t target_uid)
-{
- int ret;
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
- g_type_init();
-#endif
- size_t req_size =
- sizeof(__process_request_func_ptr) / sizeof(dispatch_func);
-
- if (data->request >= req_size || data->request == 0) {
- printf("Wrong Request\n");
- return -1;
- }
- ret = __process_request_func_ptr[data->request](data, target_uid);
-
- return ret;
-}
-
-static void __parse_multiple_pkgs(pm_tool_args *data, int argc, char **argv)
-{
- while ((optind <= argc) && (*argv[optind - 1] != '-')) {
- data->pkgs = g_list_append(data->pkgs,
- strdup(argv[optind - 1]));
- optind++;
- }
- optind--;
-}
-
-int main(int argc, char *argv[])
-{
- optind = 1;
- int opt_idx = 0;
- int c = -1;
- int ret = -1;
- char *errstr = NULL;
- long starttime;
- long endtime;
- struct timeval tv;
- bool is_root_cmd = false;
- pm_tool_args data = { 0 };
- GList *list;
- /* Supported options */
- /* Note: 'G' is reserved */
- const char *short_options = "iurwmcgxCkaADL:lsd:p:t:n:T:e:M:X:Y:Z:qhGS";
- const struct option long_options[] = {
- {"install", 0, NULL, 'i'},
- {"uninstall", 0, NULL, 'u'},
- {"reinstall", 0, NULL, 'r'},
- {"mount-install", 0, NULL, 'w'},
- {"move", 0, NULL, 'm'},
- {"clear", 0, NULL, 'c'},
- {"clear-all", 0, NULL, OPTVAL_CLEAR_ALL},
- {"getsize", 0, NULL, 'g'},
- {"activate", 0, NULL, 'A'},
- {"deactivate", 0, NULL, 'D'},
- {"activate with Label", 1, NULL, 'L'},
- {"check", 0, NULL, 'C'},
- {"kill", 0, NULL, 'k'},
- {"app-path", 0, NULL, 'a'},
- {"list", 0, NULL, 'l'},
- {"show", 0, NULL, 's'},
- {"descriptor", 1, NULL, 'd'},
- {"package-path", 1, NULL, 'p'},
- {"old_pkg", 1, NULL, 'X'},
- {"new_pkg", 1, NULL, 'Y'},
- {"delta_pkg", 1, NULL, 'Z'},
- {"package-type", 1, NULL, 't'},
- {"package-name", 1, NULL, 'n'},
- {"move-type", 1, NULL, 'T'},
- {"getsize-type", 1, NULL, 'T'},
- {"tep-path", 1, NULL, 'e'},
- {"tep-move", 1, NULL, 'M'},
- {"global", 0, NULL, OPTVAL_GLOBAL},
- {"quiet", 0, NULL, 'q'},
- {"help", 0, NULL, 'h'},
- {"debug-mode", 0, NULL, 'G'},
- {"getsizeinfo", 0, NULL, 'x'},
- {"uid", 1, NULL, OPTVAL_UID},
- {"skip-optimization", 0, NULL, 'S'},
- {0, 0, 0, 0} /* sentinel */
- };
-
- if (argc == 1)
- __print_usage();
-
- gettimeofday(&tv, NULL);
- starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
-
- data.request = -1;
- memset(data.des_path, '\0', PATH_MAX);
- memset(data.pkg_path, '\0', PATH_MAX);
- memset(data.pkgid, '\0', PKG_NAME_STRING_LEN_MAX);
- memset(data.pkg_old, '\0', PATH_MAX);
- memset(data.pkg_new, '\0', PATH_MAX);
- memset(data.delta_pkg, '\0', PATH_MAX);
- memset(data.pkg_type, '\0', PKG_TYPE_STRING_LEN_MAX);
- memset(data.label, '\0', PKG_TYPE_STRING_LEN_MAX);
- memset(data.tep_path, '\0', PATH_MAX);
-
- data.tep_move = 0;
- data.global = 0; /* By default pkg_cmd will manage for the current user */
- data.result = 0;
- data.type = -1;
- data.uid = -1;
- data.pkgs = NULL;
- data.start_count = 0;
- data.end_count = 0;
-
- while (1) {
- c = getopt_long(argc, argv, short_options, long_options,
- &opt_idx);
- if (c == -1)
- break; /* Parse end */
- switch (c) {
- case OPTVAL_GLOBAL: /* global mode */
- data.global = 1;
- break;
-
- case 'i': /* install */
- data.request = INSTALL_REQ;
- break;
-
- case 'u': /* uninstall */
- data.request = UNINSTALL_REQ;
- break;
-
- case 'r': /* reinstall */
- data.request = REINSTALL_REQ;
- break;
-
- case 'w': /* mount install */
- data.request = MOUNT_INSTALL_REQ;
- break;
-
- case 'c': /* clear */
- data.request = CLEAR_REQ;
- break;
-
- case OPTVAL_CLEAR_ALL: /* clear all */
- data.request = CLEAR_ALL_REQ;
- break;
-
- case 'g': /* get pkg size */
- 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;
-
- case 'A': /* activate */
- data.request = ACTIVATE_REQ;
- break;
-
- case 'D': /* deactivate */
- data.request = DEACTIVATE_REQ;
- break;
-
- case 'L': /* activate with Label */
- data.request = ACTIVATE_REQ;
- if (optarg)
- snprintf(data.label, sizeof(data.label),
- "%s", optarg);
- break;
-
- case 'a': /* app installation path */
- data.request = APPPATH_REQ;
- break;
-
- case 'k': /* Terminate applications of a package */
- data.request = KILLAPP_REQ;
- break;
-
- case 'C': /* Check running status of applications of a package */
- data.request = CHECKAPP_REQ;
- break;
-
- case 'l': /* list */
- data.request = LIST_REQ;
- break;
-
- case 's': /* show */
- data.request = SHOW_REQ;
- break;
-
- case 'p': /* package path */
- if (optarg)
- snprintf(data.pkg_path, sizeof(data.pkg_path),
- "%s", optarg);
- __parse_multiple_pkgs(&data, argc, argv);
- ret = __convert_to_absolute_path(&data);
- if (ret == -1)
- printf("conversion of relative path to absolute path failed\n");
- printf("path is ");
- if (g_list_length(data.pkgs)) {
- for (list = data.pkgs; list;
- list = list->next) {
- printf("%s ", (char *)list->data);
- }
- printf("\n");
- } else {
- printf("%s\n", data.pkg_path);
- }
- break;
-
- case 'X': /* old_tpk */
- data.request = CREATE_DELTA;
- is_root_cmd = true;
- if (optarg)
- strncpy(data.pkg_old, optarg, PATH_MAX - 1);
-
- data.resolved_path_pkg_old = realpath(data.pkg_old, NULL);
- if (data.resolved_path_pkg_old == NULL) {
- printf("failed to set realpath\n");
- __free_data(&data);
- return -1;
- }
- printf("pkg_old abs path is %s\n", data.resolved_path_pkg_old);
- break;
-
- case 'Y': /* new_tpk */
- if (optarg)
- strncpy(data.pkg_new, optarg, PATH_MAX - 1);
-
- data.resolved_path_pkg_new = realpath(data.pkg_new, NULL);
- if (data.resolved_path_pkg_new == NULL) {
- printf("failed to set realpath\n");
- __free_data(&data);
- return -1;
- }
- printf("pkg_new abs path is %s\n", data.resolved_path_pkg_new);
- break;
-
- case 'Z': /* delta_tpk */
- if (optarg)
- strncpy(data.delta_pkg, optarg, PATH_MAX - 1);
-
- printf("delta_pkg is %s\n", data.delta_pkg);
-
- data.resolved_path_delta_pkg = realpath(data.delta_pkg, NULL);
- if (data.resolved_path_delta_pkg == NULL) {
- printf("failed to set realpath\n");
- __free_data(&data);
- return -1;
- }
- printf("delta_pkg abs path is %s\n", data.resolved_path_delta_pkg);
- break;
- case 'd': /* descriptor path */
- if (optarg)
- snprintf(data.des_path, sizeof(data.des_path),
- "%s", optarg);
- break;
-
- case 'n': /* package name */
- if (optarg)
- snprintf(data.pkgid, sizeof(data.pkgid),
- "%s", optarg);
-
- __parse_multiple_pkgs(&data, argc, argv);
- break;
-
- case 'e': /* tep name */
- if (optarg)
- strncpy(data.tep_path, optarg,
- PATH_MAX - 1);
- ret = __convert_to_absolute_tep_path(&data);
- if (ret == -1) {
- printf("conversion of relative tep path to absolute path failed\n");
- __free_data(&data);
- return -1;
- }
- printf("TEP path is %s\n", data.tep_path);
- break;
-
- case 'M': /*tep move*/
- if (optarg)
- data.tep_move = (atoi(optarg) == 1) ? true : false;
- break;
-
- case 't': /* package type */
- if (optarg)
- snprintf(data.pkg_type, sizeof(data.pkg_type),
- "%s", optarg);
- break;
-
- case 'T': /* move type */
- if (optarg)
- data.type = atoi(optarg);
- break;
-
- case 'h': /* help */
- __free_data(&data);
- __print_usage();
- break;
-
- case 'q': /* quiet mode is removed */
- break;
-
- case 'G': /* debug mode */
- data.debug_mode = true;
- break;
-
- case 'S': /* skip optimization */
- data.skip_optimization = true;
- break;
-
- /* Otherwise */
- case '?': /* Not an option */
- __free_data(&data);
- __print_usage();
- break;
-
- case ':': /* */
- break;
-
- case OPTVAL_UID: /* specify target user id */
- if (optarg)
- data.uid = atoi(optarg);
- break;
-
- default:
- break;
-
- }
- }
-
- uid_t uid = getuid();
- if (is_root_cmd && uid != OWNER_ROOT) {
- printf("This cmd is allowed for only root user\n");
- __free_data(&data);
- return -1;
- }
-
- if (uid == OWNER_ROOT)
- uid = DEFAULT_USER;
-
- if (data.global == 1)
- uid = GLOBAL_USER;
-
- ret = __process_request(&data, uid);
- if ((ret < 0) && (data.result == 0)) {
- printf("Undefined error(%d)", ret);
- data.result = PKGMGR_INSTALLER_ERRCODE_UNDEFINED_ERROR;
- }
-
- if (ret != 0) {
- __error_no_to_string(data.result, &errstr);
- printf("processing result : %s [%d] failed\n", errstr, data.result);
- }
-
- gettimeofday(&tv, NULL);
- endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
- printf("spend time for pkgcmd is [%d]ms\n", (int)(endtime - starttime));
- __free_data(&data);
-
- return data.result;
-}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <pkgmgr-info.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include <sys/types.h>
-#include <fcntl.h>
-
-/* For multi-user support */
-#include <tzplatform_config.h>
-
-#include <dlog.h>
-#include <package-manager.h>
-#include <pkgmgr_installer.h>
-#include <storage-internal.h>
-
-#undef LOG_TAG
-#ifndef LOG_TAG
-#define LOG_TAG "PKGMGR_GETSIZE"
-#endif /* LOG_TAG */
-
-#define MAX_PKG_BUF_LEN 1024
-#define BLOCK_SIZE 4096 /*in bytes*/
-#define MAX_PATH_LENGTH 512
-#define MAX_LONGLONG_LENGTH 32
-#define MAX_SIZE_INFO_SIZE 128
-
-#define OWNER_ROOT 0
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-
-typedef enum {
- STORAGE_TYPE_INTERNAL_GLOBAL_PATH,
- STORAGE_TYPE_INTERNAL_USER_PATH,
- STORAGE_TYPE_EXTERNAL_USER_PATH,
- STORAGE_TYPE_MAX = 255,
-} STORAGE_TYPE;
-
-static uid_t caller_uid;
-static uid_t target_uid;
-
-long long __stat_size(struct stat *s)
-{
- long long blksize = s->st_blksize;
- long long size = (long long)s->st_blocks * 512;
-
- if (blksize)
- size = (size + blksize - 1) & (~(blksize - 1));
-
- return size;
-}
-
-static int __get_sdcard_path(char **sdpath)
-{
- static int ret = STORAGE_ERROR_NONE;
- static char sdcard_path[MAX_PATH_LENGTH];
- int storage_id;
- char *tmp_path;
-
- if (sdpath == NULL)
- return -1;
-
- if (ret == STORAGE_ERROR_NO_DEVICE)
- return -1;
-
- if (sdcard_path[0] == '\0') {
- ret = storage_get_primary_sdcard(&storage_id, &tmp_path);
- if (ret != STORAGE_ERROR_NONE || tmp_path == NULL)
- return -1;
- snprintf(sdcard_path, MAX_PATH_LENGTH, "%s", tmp_path);
- free(tmp_path);
- }
-
- *sdpath = strdup(sdcard_path);
- return 0;
-}
-
-static char *__get_external_tep_path_by_handle(pkgmgrinfo_pkginfo_h handle)
-{
- int ret;
- char *result_path;
- char *sdpath = NULL;
-
- ret = pkgmgrinfo_pkginfo_get_tep_name(handle, &result_path);
- if (ret != PMINFO_R_OK)
- return NULL;
-
- ret = __get_sdcard_path(&sdpath);
- if (ret < 0)
- return NULL;
-
- if (strstr(result_path, sdpath) == NULL) {
- free(sdpath);
- return NULL;
- }
-
- free(sdpath);
-
- return strdup(result_path);
-}
-
-static char *__get_external_image_path_by_handle(pkgmgrinfo_pkginfo_h handle)
-{
- int ret;
- char *result_path;
-
- ret = pkgmgrinfo_pkginfo_get_external_image_path(handle, &result_path);
- if (ret != PMINFO_R_OK)
- return NULL;
-
- return strdup(result_path);
-}
-
-static long long __calculate_directory_size(int dfd, bool include_itself)
-{
- long long size = 0;
- struct stat st;
- int subfd;
- int ret;
- DIR *dir;
- struct dirent *dent = NULL;
- const char *file_info;
- char buf[1024] = {0, };
-
- if (include_itself) {
- ret = fstat(dfd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, file_info: ., errno: %d (%s)", errno,
- strerror_r(errno, buf, sizeof(buf)));
- return -1;
- }
- size += __stat_size(&st);
- }
-
- /* fd passed to fdopendir is used internally by the implementation,
- * and should not otherwise be used by the application.
- * So we need to pass duplicated fd to fdopendir.
- */
- dfd = dup(dfd);
- if (dfd == -1) {
- LOGE("failed to duplicate fd, errno: %d (%s)", errno,
- strerror_r(errno, buf, sizeof(buf)));
- return -1;
- }
- dir = fdopendir(dfd);
- if (dir == NULL) {
- LOGE("fdopendir() failed, errno: %d (%s)", errno,
- strerror_r(errno, buf, sizeof(buf)));
- return -1;
- }
-
- while ((dent = readdir(dir)) != NULL) {
- file_info = dent->d_name;
- if (file_info[0] == '.') {
- if (file_info[1] == '\0')
- continue;
- if ((file_info[1] == '.') && (file_info[2] == '\0'))
- continue;
- }
-
- if (dent->d_type == DT_DIR) {
- subfd = openat(dfd, file_info, O_RDONLY | O_DIRECTORY);
- if (subfd < 0) {
- LOGE("openat() failed, file_info:%s, errno: %d(%s)",
- file_info, errno, strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
-
- LOGD("traverse file_info: %s", file_info);
- size += __calculate_directory_size(subfd, true);
- close(subfd);
- } else {
- ret = fstatat(dfd, file_info, &st, AT_SYMLINK_NOFOLLOW);
- if (ret < 0) {
- LOGE("fstatat() failed, file_info:%s, errno: %d(%s)",
- file_info, errno, strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
- size += __stat_size(&st);
- }
- }
-
- closedir(dir);
- return size;
-
-error:
- closedir(dir);
- return -1;
-}
-
-static int __calculate_tep_dir_size(int dfd)
-{
- long long size = 0;
- struct stat st;
- int ret;
- DIR *dir;
- struct dirent *dent = NULL;
- const char *file_info;
- char buf[1024] = {0, };
-
- ret = fstat(dfd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, file_info: ., errno: %d (%s)", errno,
- strerror_r(errno, buf, sizeof(buf)));
- return -1;
- }
- size += __stat_size(&st);
-
- dir = fdopendir(dfd);
- if (dir == NULL) {
- LOGE("fdopendir() failed, errno: %d (%s)", errno,
- strerror_r(errno, buf, sizeof(buf)));
- return -1;
- }
-
- while ((dent = readdir(dir)) != NULL) {
- file_info = dent->d_name;
- if (file_info[0] == '.') {
- if (file_info[1] == '\0')
- continue;
- if ((file_info[1] == '.') && (file_info[2] == '\0'))
- continue;
- }
-
- if (strncmp(file_info, "mount", strlen("mount")) == 0)
- continue;
-
- ret = fstatat(dfd, file_info, &st, AT_SYMLINK_NOFOLLOW);
- if (ret < 0) {
- LOGE("fstatat() failed, file_info:%s, errno: %d(%s)",
- file_info, errno, strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
- size += __stat_size(&st);
- }
-
- closedir(dir);
- return size;
-
-error:
- closedir(dir);
- return -1;
-}
-
-static int __calculate_shared_dir_size(int dfd, const char *app_root_dir,
- long long *data_size, long long *app_size,
- long long *cache_size)
-{
- int fd = -1;
- int subfd = -1;
- long long size = 0;
- struct stat st;
- int ret;
- char buf[1024] = {0, };
-
- LOGD("traverse path: %s/shared", app_root_dir);
-
- fd = openat(dfd, "shared", O_RDONLY | O_DIRECTORY);
- if (fd < 0) {
- LOGE("openat() failed, path: %s/shared, errno: %d (%s)",
- app_root_dir, errno, strerror_r(errno, buf, sizeof(buf)));
- return -1;
- }
-
- ret = fstat(fd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, path: %s/shared, errno: %d (%s)",
- app_root_dir, errno, strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
- *app_size += __stat_size(&st); /* shared directory */
- LOGD("app_size: %lld", *app_size);
-
- LOGD("traverse path: %s/shared/data", app_root_dir);
-
- subfd = openat(fd, "data", O_RDONLY | O_DIRECTORY);
- if (subfd >= 0) {
- ret = fstat(subfd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, errno: %d (%s)", errno,
- strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
- *app_size += __stat_size(&st); /* shared/data directory */
- size = __calculate_directory_size(subfd, false);
- if (size < 0) {
- LOGE("Calculating shared/data directory failed.");
- goto error;
- }
- *data_size += size;
- LOGD("data_size: %lld", *data_size);
- close(subfd);
- } else if (subfd < 0 && errno != ENOENT) {
- LOGE("openat() failed, file_info: data, errno: %d (%s)",
- errno, strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
-
- LOGD("traverse path: %s/shared/trusted", app_root_dir);
-
- subfd = openat(fd, "trusted", O_RDONLY | O_DIRECTORY);
- if (subfd >= 0) {
- ret = fstat(subfd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, errno: %d (%s)", errno,
- strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
- *app_size += __stat_size(&st); /* shared/trusted directory */
- size = __calculate_directory_size(subfd, false);
- if (size < 0) {
- LOGE("Calculating shared/trusted directory failed.");
- goto error;
- }
- *data_size += size;
- LOGD("data_size: %lld", *data_size);
- close(subfd);
- } else if (subfd < 0 && errno != ENOENT) {
- LOGD("openat() failed, file_info: trusted, errno: %d (%s)",
- errno, strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
-
- LOGD("traverse path: %s/shared/res", app_root_dir);
-
- subfd = openat(fd, "res", O_RDONLY | O_DIRECTORY);
- if (subfd >= 0) {
- size = __calculate_directory_size(subfd, true);
- if (size < 0) {
- LOGE("Calculating shared/res directory failed.");
- goto error;
- }
- *app_size += size;
- LOGD("app_size: %lld", *app_size);
- close(subfd);
- } else if (subfd < 0 && errno != ENOENT) {
- LOGE("openat() failed, file_info: res, errno: %d (%s)",
- errno, strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
-
- LOGD("traverse path: %s/shared/cache", app_root_dir);
-
- subfd = openat(fd, "cache", O_RDONLY | O_DIRECTORY);
- if (subfd >= 0) {
- ret = fstat(subfd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, errno: %d (%s)", errno,
- strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
- *app_size += __stat_size(&st); /* shared/cache directory */
- size = __calculate_directory_size(subfd, false);
- if (size < 0) {
- LOGE("Calculating shared/cache directory failed.");
- goto error;
- }
- *cache_size += size;
- LOGD("cache_size: %lld", *cache_size);
- close(subfd);
- } else if (subfd < 0 && errno != ENOENT) {
- LOGE("openat() failed, file_info: data, errno: %d (%s)",
- errno, strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
-
- close(fd);
- return 0;
-
-error:
- if (fd != -1)
- close(fd);
- if (subfd != -1)
- close(subfd);
-
- return -1;
-}
-
-static int __calculate_pkg_size_info(STORAGE_TYPE type,
- const char *pkgid, const char *ext_image_path,
- const char *ext_tep_path, long long *data_size,
- long long *cache_size, long long *app_size)
-{
- char app_root_dir[MAX_PATH_LENGTH] = {0, };
- char buf[1024] = {0, };
- char *sdpath = NULL;
- DIR *dir;
- int dfd;
- int subfd = -1;
- struct stat st;
- int ret;
- struct dirent *dent = NULL;
- long long size = 0;
-
- if (type == STORAGE_TYPE_INTERNAL_GLOBAL_PATH) {
- snprintf(app_root_dir, sizeof(app_root_dir), "%s",
- tzplatform_mkpath(TZ_SYS_RW_APP, pkgid));
- if (access(app_root_dir, F_OK) != 0) {
- snprintf(app_root_dir, sizeof(app_root_dir), "%s",
- tzplatform_mkpath(
- TZ_SYS_RO_APP, pkgid));
- }
- } else if (type == STORAGE_TYPE_INTERNAL_USER_PATH) {
- tzplatform_set_user(target_uid);
- snprintf(app_root_dir, sizeof(app_root_dir), "%s",
- tzplatform_mkpath(TZ_USER_APP, pkgid));
- tzplatform_reset_user();
- } else if (type == STORAGE_TYPE_EXTERNAL_USER_PATH) {
- tzplatform_set_user(target_uid);
- ret = __get_sdcard_path(&sdpath);
- if (ret != 0 || sdpath == NULL)
- return -1;
- snprintf(app_root_dir, MAX_PATH_LENGTH, "%s/%s%s",
- sdpath, "apps",
- tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid));
- free(sdpath);
- tzplatform_reset_user();
- if (ext_image_path) {
- subfd = open(ext_image_path, O_RDONLY);
- if (subfd < 0) {
- LOGE("open() failed, path: %s, errno: %d (%s)",
- ext_image_path, errno,
- strerror_r(errno, buf, sizeof(buf)));
- return -1;
- } else {
- ret = fstat(subfd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, path: %s, "
- "errno: %d (%s)",
- ext_image_path, errno,
- strerror_r(errno, buf,
- sizeof(buf)));
- close(subfd);
- return -1;
- }
- /* external image file */
- *app_size += __stat_size(&st);
- LOGD("app_size: %lld", *app_size);
- close(subfd);
- subfd = -1;
- }
- }
- if (ext_tep_path) {
- subfd = open(ext_tep_path, O_RDONLY);
- if (subfd < 0) {
- LOGE("open() failed, path: %s, errno: %d (%s)",
- ext_tep_path, errno,
- strerror_r(errno, buf, sizeof(buf)));
- return -1;
- } else {
- ret = fstat(subfd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, path: %s, "
- "errno: %d (%s)",
- ext_tep_path, errno,
- strerror_r(errno, buf,
- sizeof(buf)));
- close(subfd);
- return -1;
- }
- /* external tep file */
- *app_size += __stat_size(&st);
- LOGD("app_size: %lld", *app_size);
- close(subfd);
- subfd = -1;
- }
- }
- } else {
- LOGE("Invalid STORAGE_TYPE");
- return -1;
- }
-
- dir = opendir(app_root_dir);
- if (dir == NULL) {
- if (errno == ENOENT) {
- LOGD("no entry, path(%s)", app_root_dir);
- return 0;
- }
-
- LOGE("opendir() failed, path: %s, errno: %d (%s)",
- app_root_dir, errno, strerror_r(errno, buf, sizeof(buf)));
-
- return -1;
- }
-
- dfd = dirfd(dir);
- ret = fstat(dfd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, path: %s, errno: %d (%s)", app_root_dir,
- errno, strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
- *app_size += __stat_size(&st);
- while ((dent = readdir(dir)) != NULL) {
- const char *name = dent->d_name;
- if (name[0] == '.') {
- if (name[1] == '\0') continue;
- if ((name[1] == '.') && (name[2] == '\0'))
- continue;
- }
-
- if (dent->d_type != DT_DIR)
- continue;
-
- if (strncmp(name, ".pkg", strlen(".pkg")) == 0 ||
- strncmp(name, ".mmc", strlen(".mmc")) == 0)
- continue;
-
- subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
- if (subfd < 0) {
- if (errno != ENOENT) {
- LOGE("openat() failed, errno: %d (%s)",
- errno, strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
- continue;
- }
- if (strncmp(name, "data", strlen("data")) == 0) {
- LOGD("traverse path: %s/%s", app_root_dir, name);
- ret = fstat(subfd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, errno: %d (%s)", errno,
- strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
- *app_size += __stat_size(&st); /* data directory */
- size = __calculate_directory_size(subfd, false);
- if (size < 0) {
- LOGE("Calculating data directory failed.");
- goto error;
- }
- if (type != STORAGE_TYPE_INTERNAL_GLOBAL_PATH) {
- *data_size += size;
- LOGD("data_size: %lld", *data_size);
- }
- } else if (strncmp(name, "cache", strlen("cache")) == 0) {
- LOGD("traverse path: %s/%s", app_root_dir, name);
- ret = fstat(subfd, &st);
- if (ret < 0) {
- LOGE("fstat() failed, errno: %d (%s)", errno,
- strerror_r(errno, buf, sizeof(buf)));
- goto error;
- }
- *app_size += __stat_size(&st); /* cache directory */
- size = __calculate_directory_size(subfd, false);
- if (size < 0) {
- LOGE("Calculating cache directory failed.");
- goto error;
- }
- if (type != STORAGE_TYPE_INTERNAL_GLOBAL_PATH) {
- *cache_size += size;
- LOGD("cache_size: %lld", *cache_size);
- }
- } else if (strncmp(name, "shared", strlen("shared")) == 0) {
- ret = __calculate_shared_dir_size(dfd, app_root_dir,
- data_size, app_size, cache_size);
- if (ret < 0) {
- LOGE("Calculating shared directory failed.");
- goto error;
- }
- LOGD("app_size: %lld", *app_size);
- } else if (strncmp(name, "tep", strlen("tep")) == 0) {
- LOGD("traverse path: %s/%s", app_root_dir, name);
- size = __calculate_tep_dir_size(subfd);
- if (size < 0) {
- LOGE("Calculating tep directory failed.");
- goto error;
- }
- *app_size += size;
- LOGD("app_size: %lld", *app_size);
- } else {
- LOGD("traverse path: %s/%s", app_root_dir, name);
- size = __calculate_directory_size(subfd, true);
- if (size < 0) {
- LOGE("Calculating %s directory failed.", name);
- goto error;
- }
- *app_size += size;
- LOGD("app_size: %lld", *app_size);
- }
- close(subfd);
- }
- closedir(dir);
- return 0;
-
-error:
- if (dir)
- closedir(dir);
- if (subfd != -1)
- close(subfd);
-
- return -1;
-}
-
-static char *__get_pkg_size_info_str(const pkg_size_info_t* pkg_size_info)
-{
- char *size_info_str;
-
- size_info_str = (char *)malloc(MAX_SIZE_INFO_SIZE);
- if (size_info_str == NULL) {
- LOGE("Out of memory.");
- return NULL;
- }
-
- snprintf(size_info_str, MAX_SIZE_INFO_SIZE, "%lld",
- pkg_size_info->data_size);
- strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
- snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
- "%lld", pkg_size_info->cache_size);
- strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
- snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
- "%lld", pkg_size_info->app_size);
- strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
- snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
- "%lld", pkg_size_info->ext_data_size);
- strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
- snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
- "%lld", pkg_size_info->ext_cache_size);
- strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
- snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
- "%lld", pkg_size_info->ext_app_size);
- strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
-
- LOGD("size_info_str: %s", size_info_str);
-
- return size_info_str;
-}
-
-static int __get_pkg_size_info(const char *pkgid, const char *ext_image_path,
- const char *ext_tep_path, pkg_size_info_t *pkg_size_info)
-{
- int ret;
-
- ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL_GLOBAL_PATH,
- pkgid, ext_image_path, ext_tep_path, &pkg_size_info->data_size,
- &pkg_size_info->cache_size, &pkg_size_info->app_size);
- if (ret < 0) {
- LOGE("failed to calculate interal(global) size " \
- "for pkgid(%s)", pkgid);
- } else {
- LOGD("size_info(upto global), (%lld %lld %lld)",
- pkg_size_info->data_size,
- pkg_size_info->cache_size, pkg_size_info->app_size);
- }
-
- ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL_USER_PATH,
- pkgid, ext_image_path, ext_tep_path, &pkg_size_info->data_size,
- &pkg_size_info->cache_size, &pkg_size_info->app_size);
- if (ret < 0) {
- LOGE("failed to calculate interal(user) size " \
- "for pkgid(%s)", pkgid);
- } else {
- LOGD("size_info(upto user), (%lld %lld %lld)",
- pkg_size_info->data_size,
- pkg_size_info->cache_size, pkg_size_info->app_size);
- }
-
- ret = __calculate_pkg_size_info(STORAGE_TYPE_EXTERNAL_USER_PATH,
- pkgid, ext_image_path, ext_tep_path,
- &pkg_size_info->ext_data_size, &pkg_size_info->ext_cache_size,
- &pkg_size_info->ext_app_size);
- if (ret < 0) {
- LOGE("failed to calculate external(user) size " \
- "for pkgid(%s)", pkgid);
- } else {
- LOGD("size_info(external, upto user), (%lld %lld %lld)",
- pkg_size_info->ext_data_size,
- pkg_size_info->ext_cache_size,
- pkg_size_info->ext_app_size);
- }
-
- return ret;
-}
-
-static int __get_total_pkg_size_info_cb(const pkgmgrinfo_pkginfo_h handle,
- void *user_data)
-{
- int ret;
- char *pkgid;
- char *ext_image_path;
- char *ext_tep_path;
- pkg_size_info_t temp_pkg_size_info = {0,};
- pkg_size_info_t *pkg_size_info = (void *)user_data;
-
- ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (ret != PMINFO_R_OK) {
- LOGE("pkgmgrinfo_pkginfo_get_pkgid() failed");
- return -1;
- }
-
- ext_image_path = __get_external_image_path_by_handle(handle);
- ext_tep_path = __get_external_tep_path_by_handle(handle);
- ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path,
- &temp_pkg_size_info);
- if (ret < 0)
- LOGW("failed to get size of some path");
- /* even if it's an error, store all the valid result */
- if (ext_image_path)
- free(ext_image_path);
- if (ext_tep_path)
- free(ext_tep_path);
-
- pkg_size_info->app_size += temp_pkg_size_info.app_size;
- pkg_size_info->data_size += temp_pkg_size_info.data_size;
- pkg_size_info->cache_size += temp_pkg_size_info.cache_size;
- pkg_size_info->ext_app_size += temp_pkg_size_info.ext_app_size;
- pkg_size_info->ext_data_size += temp_pkg_size_info.ext_data_size;
- pkg_size_info->ext_cache_size += temp_pkg_size_info.ext_cache_size;
-
- return 0;
-}
-
-static int __write_size_info_fifo(char *req_key, long long size)
-{
- int fd;
- char buf[MAX_LONGLONG_LENGTH];
- char fifo_path[PATH_MAX];
- int ret = 0;
-
- if (req_key == NULL)
- return -1;
-
- snprintf(fifo_path, sizeof(fifo_path), "/tmp/pkgmgr/%s", req_key);
- LOGD("fifo path = (%s), size = (%lld)", fifo_path, size);
-
- fd = open(fifo_path, O_WRONLY);
- if (fd < 0) {
- LOGE("failed to open, errno(%d)", errno);
- return -1;
- }
-
- snprintf(buf, MAX_LONGLONG_LENGTH, "%lld", size);
- ret = write(fd, buf, strlen(buf));
- if (ret < 0) {
- LOGE("failed to write, ret(%d), errno(%d)", ret, errno);
- close(fd);
- return -1;
- }
-
- close(fd);
-
- return 0;
-}
-
-static int __send_result_to_signal(pkgmgr_installer *pi, const char *req_key,
- const char *pkgid, pkg_size_info_t *info)
-{
- int ret;
- char *info_str;
-
- info_str = __get_pkg_size_info_str(info);
- if (info_str == NULL)
- return -1;
-
- ret = pkgmgr_installer_send_signal(pi,
- PKGMGR_INSTALLER_GET_SIZE_KEY_STR,
- pkgid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, info_str);
- if (ret) {
- free(info_str);
- return ret;
- }
-
- ret = pkgmgr_installer_send_signal_for_uid(pi, target_uid,
- PKGMGR_INSTALLER_GET_SIZE_KEY_STR,
- pkgid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, info_str);
- free(info_str);
-
- return ret;
-}
-
-int main(int argc, char *argv[])
-{
- int ret;
- int get_type;
- char *pkgid;
- char *req_key;
- long long size = 0;
- pkgmgr_installer *pi;
- pkg_size_info_t info = {0, };
- int fifo_exist = 0;
- char *ext_image_path = NULL;
- char *ext_tep_path = NULL;
- pkgmgrinfo_pkginfo_h handle;
-
- /* argv has bellowed meaning */
- /* argv[1] = pkgid */
- /* argv[2] = get type */
- /* argv[3] = caller uid */
- /* argv[5] = req_key */
- /* argv[7] = target uid */
- /* argv[8] = sync flag */
-
- if (argv[1] == NULL) {
- LOGE("pkgid is NULL");
- return -1;
- }
-
- pkgid = argv[1];
- get_type = atoi(argv[2]);
- caller_uid = atoi(argv[3]);
- req_key = argv[5];
-
- if (argv[8] && !strcmp("--sync", argv[8]))
- fifo_exist = 1;
-
- pi = pkgmgr_installer_new();
- if (pi == NULL) {
- LOGE("failed to create installer");
- if (fifo_exist) {
- if (__write_size_info_fifo(req_key, -1) < 0)
- LOGE("failed to write to fifo");
- }
- return -1;
- }
- pkgmgr_installer_receive_request(pi, argc, argv);
- pkgmgr_installer_set_request_type(pi, PKGMGR_REQ_GETSIZE);
- target_uid = pkgmgr_installer_get_uid(pi);
-
- LOGD("start get size : [pkgid=%s, request type=%d, target_uid=%d, "
- "caller_uid=%d, fifo_exist=%d]",
- pkgid, get_type, target_uid, caller_uid, fifo_exist);
-
- if (get_type == PM_GET_TOTAL_SIZE ||
- get_type == PM_GET_DATA_SIZE ||
- get_type == PM_GET_PKG_SIZE_INFO) {
- ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
- if (ret == PMINFO_R_OK) {
- ext_image_path =
- __get_external_image_path_by_handle(handle);
- ext_tep_path =
- __get_external_tep_path_by_handle(handle);
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- }
- }
-
- switch (get_type) {
- case PM_GET_TOTAL_SIZE:
- /* send result to file */
- ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path,
- &info);
- if (ret < 0)
- LOGW("failed to get size of some path");
- size = info.app_size + info.data_size + info.cache_size;
- break;
- case PM_GET_DATA_SIZE:
- /* send result to file */
- ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path,
- &info);
- if (ret < 0)
- LOGW("failed to get size of some path");
- size = info.data_size + info.cache_size;
- break;
- case PM_GET_ALL_PKGS:
- /* send result to file */
- ret = pkgmgrinfo_pkginfo_get_usr_list_full(
- __get_total_pkg_size_info_cb,
- PMINFO_PKGINFO_GET_BASICINFO, &info, target_uid);
- if (ret < 0)
- LOGE("failed to get all packages");
- else
- size = info.app_size + info.data_size + info.cache_size;
- break;
- case PM_GET_PKG_SIZE_INFO:
- /* send result to signal */
- ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path,
- &info);
- if (ret < 0)
- LOGW("failed to get size of some path");
- size = info.app_size + info.data_size + info.cache_size;
- /* always send a result */
- ret = __send_result_to_signal(pi, req_key,
- pkgid, &info);
- break;
- case PM_GET_TOTAL_PKG_SIZE_INFO:
- /* send result to signal */
- ret = pkgmgrinfo_pkginfo_get_usr_list_full(
- __get_total_pkg_size_info_cb,
- PMINFO_PKGINFO_GET_BASICINFO, &info, target_uid);
- if (ret < 0)
- LOGE("failed to get all packages");
- else
- size = info.app_size + info.data_size + info.cache_size;
- /* always send a result */
- ret = __send_result_to_signal(pi, req_key,
- PKG_SIZE_INFO_TOTAL, &info);
- break;
- default:
- ret = -1;
- LOGE("unsupported or depreated type");
- break;
- }
-
- if (fifo_exist) {
- if (__write_size_info_fifo(req_key, size) < 0)
- LOGE("failed to write to fifo");
- }
-
- if (ext_image_path)
- free(ext_image_path);
- if (ext_tep_path)
- free(ext_tep_path);
-
- LOGD("get size result = %d", ret);
- pkgmgr_installer_free(pi);
-
- return ret;
-}
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <pkgmgr-info.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+
+/* For multi-user support */
+#include <tzplatform_config.h>
+
+#include <dlog.h>
+#include <package-manager.h>
+#include <pkgmgr_installer.h>
+#include <storage-internal.h>
+
+#undef LOG_TAG
+#ifndef LOG_TAG
+#define LOG_TAG "PKGMGR_GETSIZE"
+#endif /* LOG_TAG */
+
+#define MAX_PKG_BUF_LEN 1024
+#define BLOCK_SIZE 4096 /*in bytes*/
+#define MAX_PATH_LENGTH 512
+#define MAX_LONGLONG_LENGTH 32
+#define MAX_SIZE_INFO_SIZE 128
+
+#define OWNER_ROOT 0
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+
+typedef enum {
+ STORAGE_TYPE_INTERNAL_GLOBAL_PATH,
+ STORAGE_TYPE_INTERNAL_USER_PATH,
+ STORAGE_TYPE_EXTERNAL_USER_PATH,
+ STORAGE_TYPE_MAX = 255,
+} STORAGE_TYPE;
+
+static uid_t caller_uid;
+static uid_t target_uid;
+
+long long __stat_size(struct stat *s)
+{
+ long long blksize = s->st_blksize;
+ long long size = (long long)s->st_blocks * 512;
+
+ if (blksize)
+ size = (size + blksize - 1) & (~(blksize - 1));
+
+ return size;
+}
+
+static int __get_sdcard_path(char **sdpath)
+{
+ static int ret = STORAGE_ERROR_NONE;
+ static char sdcard_path[MAX_PATH_LENGTH];
+ int storage_id;
+ char *tmp_path;
+
+ if (sdpath == NULL)
+ return -1;
+
+ if (ret == STORAGE_ERROR_NO_DEVICE)
+ return -1;
+
+ if (sdcard_path[0] == '\0') {
+ ret = storage_get_primary_sdcard(&storage_id, &tmp_path);
+ if (ret != STORAGE_ERROR_NONE || tmp_path == NULL)
+ return -1;
+ snprintf(sdcard_path, MAX_PATH_LENGTH, "%s", tmp_path);
+ free(tmp_path);
+ }
+
+ *sdpath = strdup(sdcard_path);
+ return 0;
+}
+
+static char *__get_external_tep_path_by_handle(pkgmgrinfo_pkginfo_h handle)
+{
+ int ret;
+ char *result_path;
+ char *sdpath = NULL;
+
+ ret = pkgmgrinfo_pkginfo_get_tep_name(handle, &result_path);
+ if (ret != PMINFO_R_OK)
+ return NULL;
+
+ ret = __get_sdcard_path(&sdpath);
+ if (ret < 0)
+ return NULL;
+
+ if (strstr(result_path, sdpath) == NULL) {
+ free(sdpath);
+ return NULL;
+ }
+
+ free(sdpath);
+
+ return strdup(result_path);
+}
+
+static char *__get_external_image_path_by_handle(pkgmgrinfo_pkginfo_h handle)
+{
+ int ret;
+ char *result_path;
+
+ ret = pkgmgrinfo_pkginfo_get_external_image_path(handle, &result_path);
+ if (ret != PMINFO_R_OK)
+ return NULL;
+
+ return strdup(result_path);
+}
+
+static long long __calculate_directory_size(int dfd, bool include_itself)
+{
+ long long size = 0;
+ struct stat st;
+ int subfd;
+ int ret;
+ DIR *dir;
+ struct dirent *dent = NULL;
+ const char *file_info;
+ char buf[1024] = {0, };
+
+ if (include_itself) {
+ ret = fstat(dfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, file_info: ., errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ }
+ size += __stat_size(&st);
+ }
+
+ /* fd passed to fdopendir is used internally by the implementation,
+ * and should not otherwise be used by the application.
+ * So we need to pass duplicated fd to fdopendir.
+ */
+ dfd = dup(dfd);
+ if (dfd == -1) {
+ LOGE("failed to duplicate fd, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ }
+ dir = fdopendir(dfd);
+ if (dir == NULL) {
+ LOGE("fdopendir() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ }
+
+ while ((dent = readdir(dir)) != NULL) {
+ file_info = dent->d_name;
+ if (file_info[0] == '.') {
+ if (file_info[1] == '\0')
+ continue;
+ if ((file_info[1] == '.') && (file_info[2] == '\0'))
+ continue;
+ }
+
+ if (dent->d_type == DT_DIR) {
+ subfd = openat(dfd, file_info, O_RDONLY | O_DIRECTORY);
+ if (subfd < 0) {
+ LOGE("openat() failed, file_info:%s, errno: %d(%s)",
+ file_info, errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+
+ LOGD("traverse file_info: %s", file_info);
+ size += __calculate_directory_size(subfd, true);
+ close(subfd);
+ } else {
+ ret = fstatat(dfd, file_info, &st, AT_SYMLINK_NOFOLLOW);
+ if (ret < 0) {
+ LOGE("fstatat() failed, file_info:%s, errno: %d(%s)",
+ file_info, errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ size += __stat_size(&st);
+ }
+ }
+
+ closedir(dir);
+ return size;
+
+error:
+ closedir(dir);
+ return -1;
+}
+
+static int __calculate_tep_dir_size(int dfd)
+{
+ long long size = 0;
+ struct stat st;
+ int ret;
+ DIR *dir;
+ struct dirent *dent = NULL;
+ const char *file_info;
+ char buf[1024] = {0, };
+
+ ret = fstat(dfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, file_info: ., errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ }
+ size += __stat_size(&st);
+
+ dir = fdopendir(dfd);
+ if (dir == NULL) {
+ LOGE("fdopendir() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ }
+
+ while ((dent = readdir(dir)) != NULL) {
+ file_info = dent->d_name;
+ if (file_info[0] == '.') {
+ if (file_info[1] == '\0')
+ continue;
+ if ((file_info[1] == '.') && (file_info[2] == '\0'))
+ continue;
+ }
+
+ if (strncmp(file_info, "mount", strlen("mount")) == 0)
+ continue;
+
+ ret = fstatat(dfd, file_info, &st, AT_SYMLINK_NOFOLLOW);
+ if (ret < 0) {
+ LOGE("fstatat() failed, file_info:%s, errno: %d(%s)",
+ file_info, errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ size += __stat_size(&st);
+ }
+
+ closedir(dir);
+ return size;
+
+error:
+ closedir(dir);
+ return -1;
+}
+
+static int __calculate_shared_dir_size(int dfd, const char *app_root_dir,
+ long long *data_size, long long *app_size,
+ long long *cache_size)
+{
+ int fd = -1;
+ int subfd = -1;
+ long long size = 0;
+ struct stat st;
+ int ret;
+ char buf[1024] = {0, };
+
+ LOGD("traverse path: %s/shared", app_root_dir);
+
+ fd = openat(dfd, "shared", O_RDONLY | O_DIRECTORY);
+ if (fd < 0) {
+ LOGE("openat() failed, path: %s/shared, errno: %d (%s)",
+ app_root_dir, errno, strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ }
+
+ ret = fstat(fd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, path: %s/shared, errno: %d (%s)",
+ app_root_dir, errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* shared directory */
+ LOGD("app_size: %lld", *app_size);
+
+ LOGD("traverse path: %s/shared/data", app_root_dir);
+
+ subfd = openat(fd, "data", O_RDONLY | O_DIRECTORY);
+ if (subfd >= 0) {
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* shared/data directory */
+ size = __calculate_directory_size(subfd, false);
+ if (size < 0) {
+ LOGE("Calculating shared/data directory failed.");
+ goto error;
+ }
+ *data_size += size;
+ LOGD("data_size: %lld", *data_size);
+ close(subfd);
+ } else if (subfd < 0 && errno != ENOENT) {
+ LOGE("openat() failed, file_info: data, errno: %d (%s)",
+ errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+
+ LOGD("traverse path: %s/shared/trusted", app_root_dir);
+
+ subfd = openat(fd, "trusted", O_RDONLY | O_DIRECTORY);
+ if (subfd >= 0) {
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* shared/trusted directory */
+ size = __calculate_directory_size(subfd, false);
+ if (size < 0) {
+ LOGE("Calculating shared/trusted directory failed.");
+ goto error;
+ }
+ *data_size += size;
+ LOGD("data_size: %lld", *data_size);
+ close(subfd);
+ } else if (subfd < 0 && errno != ENOENT) {
+ LOGD("openat() failed, file_info: trusted, errno: %d (%s)",
+ errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+
+ LOGD("traverse path: %s/shared/res", app_root_dir);
+
+ subfd = openat(fd, "res", O_RDONLY | O_DIRECTORY);
+ if (subfd >= 0) {
+ size = __calculate_directory_size(subfd, true);
+ if (size < 0) {
+ LOGE("Calculating shared/res directory failed.");
+ goto error;
+ }
+ *app_size += size;
+ LOGD("app_size: %lld", *app_size);
+ close(subfd);
+ } else if (subfd < 0 && errno != ENOENT) {
+ LOGE("openat() failed, file_info: res, errno: %d (%s)",
+ errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+
+ LOGD("traverse path: %s/shared/cache", app_root_dir);
+
+ subfd = openat(fd, "cache", O_RDONLY | O_DIRECTORY);
+ if (subfd >= 0) {
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* shared/cache directory */
+ size = __calculate_directory_size(subfd, false);
+ if (size < 0) {
+ LOGE("Calculating shared/cache directory failed.");
+ goto error;
+ }
+ *cache_size += size;
+ LOGD("cache_size: %lld", *cache_size);
+ close(subfd);
+ } else if (subfd < 0 && errno != ENOENT) {
+ LOGE("openat() failed, file_info: data, errno: %d (%s)",
+ errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+
+ close(fd);
+ return 0;
+
+error:
+ if (fd != -1)
+ close(fd);
+ if (subfd != -1)
+ close(subfd);
+
+ return -1;
+}
+
+static int __calculate_pkg_size_info(STORAGE_TYPE type,
+ const char *pkgid, const char *ext_image_path,
+ const char *ext_tep_path, long long *data_size,
+ long long *cache_size, long long *app_size)
+{
+ char app_root_dir[MAX_PATH_LENGTH] = {0, };
+ char buf[1024] = {0, };
+ char *sdpath = NULL;
+ DIR *dir;
+ int dfd;
+ int subfd = -1;
+ struct stat st;
+ int ret;
+ struct dirent *dent = NULL;
+ long long size = 0;
+
+ if (type == STORAGE_TYPE_INTERNAL_GLOBAL_PATH) {
+ snprintf(app_root_dir, sizeof(app_root_dir), "%s",
+ tzplatform_mkpath(TZ_SYS_RW_APP, pkgid));
+ if (access(app_root_dir, F_OK) != 0) {
+ snprintf(app_root_dir, sizeof(app_root_dir), "%s",
+ tzplatform_mkpath(
+ TZ_SYS_RO_APP, pkgid));
+ }
+ } else if (type == STORAGE_TYPE_INTERNAL_USER_PATH) {
+ tzplatform_set_user(target_uid);
+ snprintf(app_root_dir, sizeof(app_root_dir), "%s",
+ tzplatform_mkpath(TZ_USER_APP, pkgid));
+ tzplatform_reset_user();
+ } else if (type == STORAGE_TYPE_EXTERNAL_USER_PATH) {
+ tzplatform_set_user(target_uid);
+ ret = __get_sdcard_path(&sdpath);
+ if (ret != 0 || sdpath == NULL)
+ return -1;
+ snprintf(app_root_dir, MAX_PATH_LENGTH, "%s/%s%s",
+ sdpath, "apps",
+ tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid));
+ free(sdpath);
+ tzplatform_reset_user();
+ if (ext_image_path) {
+ subfd = open(ext_image_path, O_RDONLY);
+ if (subfd < 0) {
+ LOGE("open() failed, path: %s, errno: %d (%s)",
+ ext_image_path, errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ } else {
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, path: %s, "
+ "errno: %d (%s)",
+ ext_image_path, errno,
+ strerror_r(errno, buf,
+ sizeof(buf)));
+ close(subfd);
+ return -1;
+ }
+ /* external image file */
+ *app_size += __stat_size(&st);
+ LOGD("app_size: %lld", *app_size);
+ close(subfd);
+ subfd = -1;
+ }
+ }
+ if (ext_tep_path) {
+ subfd = open(ext_tep_path, O_RDONLY);
+ if (subfd < 0) {
+ LOGE("open() failed, path: %s, errno: %d (%s)",
+ ext_tep_path, errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ } else {
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, path: %s, "
+ "errno: %d (%s)",
+ ext_tep_path, errno,
+ strerror_r(errno, buf,
+ sizeof(buf)));
+ close(subfd);
+ return -1;
+ }
+ /* external tep file */
+ *app_size += __stat_size(&st);
+ LOGD("app_size: %lld", *app_size);
+ close(subfd);
+ subfd = -1;
+ }
+ }
+ } else {
+ LOGE("Invalid STORAGE_TYPE");
+ return -1;
+ }
+
+ dir = opendir(app_root_dir);
+ if (dir == NULL) {
+ if (errno == ENOENT) {
+ LOGD("no entry, path(%s)", app_root_dir);
+ return 0;
+ }
+
+ LOGE("opendir() failed, path: %s, errno: %d (%s)",
+ app_root_dir, errno, strerror_r(errno, buf, sizeof(buf)));
+
+ return -1;
+ }
+
+ dfd = dirfd(dir);
+ ret = fstat(dfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, path: %s, errno: %d (%s)", app_root_dir,
+ errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st);
+ while ((dent = readdir(dir)) != NULL) {
+ const char *name = dent->d_name;
+ if (name[0] == '.') {
+ if (name[1] == '\0') continue;
+ if ((name[1] == '.') && (name[2] == '\0'))
+ continue;
+ }
+
+ if (dent->d_type != DT_DIR)
+ continue;
+
+ if (strncmp(name, ".pkg", strlen(".pkg")) == 0 ||
+ strncmp(name, ".mmc", strlen(".mmc")) == 0)
+ continue;
+
+ subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
+ if (subfd < 0) {
+ if (errno != ENOENT) {
+ LOGE("openat() failed, errno: %d (%s)",
+ errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ continue;
+ }
+ if (strncmp(name, "data", strlen("data")) == 0) {
+ LOGD("traverse path: %s/%s", app_root_dir, name);
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* data directory */
+ size = __calculate_directory_size(subfd, false);
+ if (size < 0) {
+ LOGE("Calculating data directory failed.");
+ goto error;
+ }
+ if (type != STORAGE_TYPE_INTERNAL_GLOBAL_PATH) {
+ *data_size += size;
+ LOGD("data_size: %lld", *data_size);
+ }
+ } else if (strncmp(name, "cache", strlen("cache")) == 0) {
+ LOGD("traverse path: %s/%s", app_root_dir, name);
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* cache directory */
+ size = __calculate_directory_size(subfd, false);
+ if (size < 0) {
+ LOGE("Calculating cache directory failed.");
+ goto error;
+ }
+ if (type != STORAGE_TYPE_INTERNAL_GLOBAL_PATH) {
+ *cache_size += size;
+ LOGD("cache_size: %lld", *cache_size);
+ }
+ } else if (strncmp(name, "shared", strlen("shared")) == 0) {
+ ret = __calculate_shared_dir_size(dfd, app_root_dir,
+ data_size, app_size, cache_size);
+ if (ret < 0) {
+ LOGE("Calculating shared directory failed.");
+ goto error;
+ }
+ LOGD("app_size: %lld", *app_size);
+ } else if (strncmp(name, "tep", strlen("tep")) == 0) {
+ LOGD("traverse path: %s/%s", app_root_dir, name);
+ size = __calculate_tep_dir_size(subfd);
+ if (size < 0) {
+ LOGE("Calculating tep directory failed.");
+ goto error;
+ }
+ *app_size += size;
+ LOGD("app_size: %lld", *app_size);
+ } else {
+ LOGD("traverse path: %s/%s", app_root_dir, name);
+ size = __calculate_directory_size(subfd, true);
+ if (size < 0) {
+ LOGE("Calculating %s directory failed.", name);
+ goto error;
+ }
+ *app_size += size;
+ LOGD("app_size: %lld", *app_size);
+ }
+ close(subfd);
+ }
+ closedir(dir);
+ return 0;
+
+error:
+ if (dir)
+ closedir(dir);
+ if (subfd != -1)
+ close(subfd);
+
+ return -1;
+}
+
+static char *__get_pkg_size_info_str(const pkg_size_info_t* pkg_size_info)
+{
+ char *size_info_str;
+
+ size_info_str = (char *)malloc(MAX_SIZE_INFO_SIZE);
+ if (size_info_str == NULL) {
+ LOGE("Out of memory.");
+ return NULL;
+ }
+
+ snprintf(size_info_str, MAX_SIZE_INFO_SIZE, "%lld",
+ pkg_size_info->data_size);
+ strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
+ snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
+ "%lld", pkg_size_info->cache_size);
+ strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
+ snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
+ "%lld", pkg_size_info->app_size);
+ strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
+ snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
+ "%lld", pkg_size_info->ext_data_size);
+ strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
+ snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
+ "%lld", pkg_size_info->ext_cache_size);
+ strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
+ snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH,
+ "%lld", pkg_size_info->ext_app_size);
+ strncat(size_info_str, ":", MAX_SIZE_INFO_SIZE - strlen(size_info_str) - 1);
+
+ LOGD("size_info_str: %s", size_info_str);
+
+ return size_info_str;
+}
+
+static int __get_pkg_size_info(const char *pkgid, const char *ext_image_path,
+ const char *ext_tep_path, pkg_size_info_t *pkg_size_info)
+{
+ int ret;
+
+ ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL_GLOBAL_PATH,
+ pkgid, ext_image_path, ext_tep_path, &pkg_size_info->data_size,
+ &pkg_size_info->cache_size, &pkg_size_info->app_size);
+ if (ret < 0) {
+ LOGE("failed to calculate interal(global) size " \
+ "for pkgid(%s)", pkgid);
+ } else {
+ LOGD("size_info(upto global), (%lld %lld %lld)",
+ pkg_size_info->data_size,
+ pkg_size_info->cache_size, pkg_size_info->app_size);
+ }
+
+ ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL_USER_PATH,
+ pkgid, ext_image_path, ext_tep_path, &pkg_size_info->data_size,
+ &pkg_size_info->cache_size, &pkg_size_info->app_size);
+ if (ret < 0) {
+ LOGE("failed to calculate interal(user) size " \
+ "for pkgid(%s)", pkgid);
+ } else {
+ LOGD("size_info(upto user), (%lld %lld %lld)",
+ pkg_size_info->data_size,
+ pkg_size_info->cache_size, pkg_size_info->app_size);
+ }
+
+ ret = __calculate_pkg_size_info(STORAGE_TYPE_EXTERNAL_USER_PATH,
+ pkgid, ext_image_path, ext_tep_path,
+ &pkg_size_info->ext_data_size, &pkg_size_info->ext_cache_size,
+ &pkg_size_info->ext_app_size);
+ if (ret < 0) {
+ LOGE("failed to calculate external(user) size " \
+ "for pkgid(%s)", pkgid);
+ } else {
+ LOGD("size_info(external, upto user), (%lld %lld %lld)",
+ pkg_size_info->ext_data_size,
+ pkg_size_info->ext_cache_size,
+ pkg_size_info->ext_app_size);
+ }
+
+ return ret;
+}
+
+static int __get_total_pkg_size_info_cb(const pkgmgrinfo_pkginfo_h handle,
+ void *user_data)
+{
+ int ret;
+ char *pkgid;
+ char *ext_image_path;
+ char *ext_tep_path;
+ pkg_size_info_t temp_pkg_size_info = {0,};
+ pkg_size_info_t *pkg_size_info = (void *)user_data;
+
+ ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+ if (ret != PMINFO_R_OK) {
+ LOGE("pkgmgrinfo_pkginfo_get_pkgid() failed");
+ return -1;
+ }
+
+ ext_image_path = __get_external_image_path_by_handle(handle);
+ ext_tep_path = __get_external_tep_path_by_handle(handle);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path,
+ &temp_pkg_size_info);
+ if (ret < 0)
+ LOGW("failed to get size of some path");
+ /* even if it's an error, store all the valid result */
+ if (ext_image_path)
+ free(ext_image_path);
+ if (ext_tep_path)
+ free(ext_tep_path);
+
+ pkg_size_info->app_size += temp_pkg_size_info.app_size;
+ pkg_size_info->data_size += temp_pkg_size_info.data_size;
+ pkg_size_info->cache_size += temp_pkg_size_info.cache_size;
+ pkg_size_info->ext_app_size += temp_pkg_size_info.ext_app_size;
+ pkg_size_info->ext_data_size += temp_pkg_size_info.ext_data_size;
+ pkg_size_info->ext_cache_size += temp_pkg_size_info.ext_cache_size;
+
+ return 0;
+}
+
+static int __write_size_info_fifo(char *req_key, long long size)
+{
+ int fd;
+ char buf[MAX_LONGLONG_LENGTH];
+ char fifo_path[PATH_MAX];
+ int ret = 0;
+
+ if (req_key == NULL)
+ return -1;
+
+ snprintf(fifo_path, sizeof(fifo_path), "/tmp/pkgmgr/%s", req_key);
+ LOGD("fifo path = (%s), size = (%lld)", fifo_path, size);
+
+ fd = open(fifo_path, O_WRONLY);
+ if (fd < 0) {
+ LOGE("failed to open, errno(%d)", errno);
+ return -1;
+ }
+
+ snprintf(buf, MAX_LONGLONG_LENGTH, "%lld", size);
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ LOGE("failed to write, ret(%d), errno(%d)", ret, errno);
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+static int __send_result_to_signal(pkgmgr_installer *pi, const char *req_key,
+ const char *pkgid, pkg_size_info_t *info)
+{
+ int ret;
+ char *info_str;
+
+ info_str = __get_pkg_size_info_str(info);
+ if (info_str == NULL)
+ return -1;
+
+ ret = pkgmgr_installer_send_signal(pi,
+ PKGMGR_INSTALLER_GET_SIZE_KEY_STR,
+ pkgid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, info_str);
+ if (ret) {
+ free(info_str);
+ return ret;
+ }
+
+ ret = pkgmgr_installer_send_signal_for_uid(pi, target_uid,
+ PKGMGR_INSTALLER_GET_SIZE_KEY_STR,
+ pkgid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, info_str);
+ free(info_str);
+
+ return ret;
+}
+
+int main(int argc, char *argv[])
+{
+ int ret;
+ int get_type;
+ char *pkgid;
+ char *req_key;
+ long long size = 0;
+ pkgmgr_installer *pi;
+ pkg_size_info_t info = {0, };
+ int fifo_exist = 0;
+ char *ext_image_path = NULL;
+ char *ext_tep_path = NULL;
+ pkgmgrinfo_pkginfo_h handle;
+
+ /* argv has bellowed meaning */
+ /* argv[1] = pkgid */
+ /* argv[2] = get type */
+ /* argv[3] = caller uid */
+ /* argv[5] = req_key */
+ /* argv[7] = target uid */
+ /* argv[8] = sync flag */
+
+ if (argv[1] == NULL) {
+ LOGE("pkgid is NULL");
+ return -1;
+ }
+
+ pkgid = argv[1];
+ get_type = atoi(argv[2]);
+ caller_uid = atoi(argv[3]);
+ req_key = argv[5];
+
+ if (argv[8] && !strcmp("--sync", argv[8]))
+ fifo_exist = 1;
+
+ pi = pkgmgr_installer_new();
+ if (pi == NULL) {
+ LOGE("failed to create installer");
+ if (fifo_exist) {
+ if (__write_size_info_fifo(req_key, -1) < 0)
+ LOGE("failed to write to fifo");
+ }
+ return -1;
+ }
+ pkgmgr_installer_receive_request(pi, argc, argv);
+ pkgmgr_installer_set_request_type(pi, PKGMGR_REQ_GETSIZE);
+ target_uid = pkgmgr_installer_get_uid(pi);
+
+ LOGD("start get size : [pkgid=%s, request type=%d, target_uid=%d, "
+ "caller_uid=%d, fifo_exist=%d]",
+ pkgid, get_type, target_uid, caller_uid, fifo_exist);
+
+ if (get_type == PM_GET_TOTAL_SIZE ||
+ get_type == PM_GET_DATA_SIZE ||
+ get_type == PM_GET_PKG_SIZE_INFO) {
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret == PMINFO_R_OK) {
+ ext_image_path =
+ __get_external_image_path_by_handle(handle);
+ ext_tep_path =
+ __get_external_tep_path_by_handle(handle);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ }
+ }
+
+ switch (get_type) {
+ case PM_GET_TOTAL_SIZE:
+ /* send result to file */
+ ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path,
+ &info);
+ if (ret < 0)
+ LOGW("failed to get size of some path");
+ size = info.app_size + info.data_size + info.cache_size;
+ break;
+ case PM_GET_DATA_SIZE:
+ /* send result to file */
+ ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path,
+ &info);
+ if (ret < 0)
+ LOGW("failed to get size of some path");
+ size = info.data_size + info.cache_size;
+ break;
+ case PM_GET_ALL_PKGS:
+ /* send result to file */
+ ret = pkgmgrinfo_pkginfo_get_usr_list_full(
+ __get_total_pkg_size_info_cb,
+ PMINFO_PKGINFO_GET_BASICINFO, &info, target_uid);
+ if (ret < 0)
+ LOGE("failed to get all packages");
+ else
+ size = info.app_size + info.data_size + info.cache_size;
+ break;
+ case PM_GET_PKG_SIZE_INFO:
+ /* send result to signal */
+ ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path,
+ &info);
+ if (ret < 0)
+ LOGW("failed to get size of some path");
+ size = info.app_size + info.data_size + info.cache_size;
+ /* always send a result */
+ ret = __send_result_to_signal(pi, req_key,
+ pkgid, &info);
+ break;
+ case PM_GET_TOTAL_PKG_SIZE_INFO:
+ /* send result to signal */
+ ret = pkgmgrinfo_pkginfo_get_usr_list_full(
+ __get_total_pkg_size_info_cb,
+ PMINFO_PKGINFO_GET_BASICINFO, &info, target_uid);
+ if (ret < 0)
+ LOGE("failed to get all packages");
+ else
+ size = info.app_size + info.data_size + info.cache_size;
+ /* always send a result */
+ ret = __send_result_to_signal(pi, req_key,
+ PKG_SIZE_INFO_TOTAL, &info);
+ break;
+ default:
+ ret = -1;
+ LOGE("unsupported or depreated type");
+ break;
+ }
+
+ if (fifo_exist) {
+ if (__write_size_info_fifo(req_key, size) < 0)
+ LOGE("failed to write to fifo");
+ }
+
+ if (ext_image_path)
+ free(ext_image_path);
+ if (ext_tep_path)
+ free(ext_tep_path);
+
+ LOGD("get size result = %d", ret);
+ pkgmgr_installer_free(pi);
+
+ return ret;
+}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/time.h>
-
-#include <pkgmgr_parser.h>
-#include <pkgmgr-info.h>
-
-#include <package-manager.h>
-#include <package-manager-types.h>
-#include <pkgmgr_installer.h>
-
-#define OWNER_ROOT 0
-
-static void __print_usage();
-static int __get_pkg_info(char *pkgid, uid_t uid);
-static int __get_app_info(char *appid);
-static int __get_app_list(char *pkgid, uid_t uid);
-static int __get_app_category_list(char *appid);
-static int __get_app_metadata_list(char *appid);
-static int __get_app_control_list(char *appid);
-static int __get_pkg_list(uid_t uid);
-static int __get_installed_app_list(uid_t uid);
-static int __add_app_filter(uid_t uid);
-static int __add_pkg_filter(uid_t uid);
-static int __set_certinfo_in_db(char *pkgid, uid_t uid);
-static int __get_certinfo_from_db(char *pkgid, uid_t uid);
-static int __del_certinfo_from_db(char *pkgid);
-static int __get_integer_input_data(void);
-char *__get_string_input_data(void);
-static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data);
-static int __app_category_list_cb(const char *category_name, void *user_data);
-static int __app_control_list_cb(const char *operation, const char *uri, const char *mime, void *user_data);
-static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data);
-int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data);
-
-static void __get_pkgmgrinfo_pkginfo(const pkgmgrinfo_pkginfo_h handle, void *user_data)
-{
- int ret = -1;
- char *type = NULL;
- char *version = NULL;
- char *author_name = NULL;
- char *author_email = NULL;
- char *author_href = NULL;
- char *root_path = NULL;
- char *mainappid = NULL;
- pkgmgrinfo_install_location location = 0;
- char *icon = NULL;
- char *label = NULL;
- char *desc = NULL;
- bool removable = 0;
- bool preload = 0;
- bool readonly = 0;
- bool update = 0;
- bool system = 0;
- int installed_time = -1;
-
- ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
- if (ret < 0)
- printf("Failed to get pkg type\n");
- if (type)
- printf("Type: %s\n", type);
-
- ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
- if (ret < 0)
- printf("Failed to get version\n");
- if (version)
- printf("Version: %s\n", version);
-
- ret = pkgmgrinfo_pkginfo_get_install_location(handle, &location);
- if (ret < 0)
- printf("Failed to get install location\n");
- printf("Install Location: %d\n", location);
-
- ret = pkgmgrinfo_pkginfo_get_icon(handle, &icon);
- if (ret < 0)
- printf("Failed to get icon\n");
- if (icon)
- printf("Icon: %s\n", icon);
-
- ret = pkgmgrinfo_pkginfo_get_label(handle, &label);
- if (ret < 0)
- printf("Failed to get label\n");
- if (label)
- printf("Label: %s\n", label);
-
- ret = pkgmgrinfo_pkginfo_get_description(handle, &desc);
- if (ret < 0)
- printf("Failed to get description\n");
- if (desc)
- printf("Description: %s\n", desc);
-
- ret = pkgmgrinfo_pkginfo_get_author_name(handle, &author_name);
- if (ret < 0)
- printf("Failed to get author name\n");
- if (author_name)
- printf("Author Name: %s\n", author_name);
-
- ret = pkgmgrinfo_pkginfo_get_author_email(handle, &author_email);
- if (ret < 0)
- printf("Failed to get author email\n");
- if (author_email)
- printf("Author Email: %s\n", author_email);
-
- ret = pkgmgrinfo_pkginfo_get_author_href(handle, &author_href);
- if (ret < 0)
- printf("Failed to get author href\n");
- if (author_href)
- printf("Author Href: %s\n", author_href);
-
- ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path);
- if (ret < 0)
- printf("Failed to get root_path\n");
- if (root_path)
- printf("root_path : %s\n", root_path);
-
- ret = pkgmgrinfo_pkginfo_get_mainappid(handle, &mainappid);
- if (ret < 0)
- printf("Failed to get mainappid\n");
- if (mainappid)
- printf("mainappid : %s\n", mainappid);
-
- ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time);
- if (ret < 0)
- printf("Failed to get install time\n");
- printf("Install time: %d\n", installed_time);
-
- ret = pkgmgrinfo_pkginfo_is_removable(handle, &removable);
- if (ret < 0)
- printf("Failed to get removable\n");
- else
- printf("Removable: %d\n", removable);
-
- ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
- if (ret < 0)
- printf("Failed to get preload\n");
- else
- printf("Preload: %d\n", preload);
-
- ret = pkgmgrinfo_pkginfo_is_readonly(handle, &readonly);
- if (ret < 0)
- printf("Failed to get readonly\n");
- else
- printf("Readonly: %d\n", readonly);
-
- ret = pkgmgrinfo_pkginfo_is_update(handle, &update);
- if (ret < 0)
- printf("Failed to get update\n");
- else
- printf("update: %d\n", update);
-
- ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
- if (ret < 0)
- printf("Failed to get system\n");
- else
- printf("system: %d\n", system);
-}
-
-int __get_app_id(const pkgmgrinfo_appinfo_h handle, void *user_data)
-{
- char *appid = NULL;
- char *apptype = NULL;
- int ret = -1;
-
- ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
- if (ret < 0)
- printf("Failed to get appid\n");
-
- ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
- if (ret < 0)
- printf("Failed to get package\n");
- printf("apptype [%s]\t appid [%s]\n", apptype, appid);
-
- return 0;
-}
-
-static int __get_integer_input_data(void)
-{
- char input_str[32] = { 0, };
- int data = 0;
-
- if (fgets(input_str, sizeof(input_str), stdin) == NULL) {
- printf("fgets() failed....\n");
- return -1;
- }
-
- if (sscanf(input_str, "%4d", &data) != 1) {
- printf("Input only integer option....\n");
- return -1;
- }
-
- return data;
-}
-
-
-char *__get_string_input_data(void)
-{
- char *data = (char *)malloc(1024);
- if (data == NULL) {
- printf("Malloc Failed\n");
- return NULL;
- }
-
- if (fgets(data, 1024, stdin) == NULL) {
- printf("Buffer overflow!!! try again\n");
- exit(-1);
- }
- data[strlen(data) - 1] = '\0';
-
- return data;
-}
-
-static void __print_usage()
-{
- printf("For Getting package|App Info\n");
- printf("\tpkginfo --[pkg|app] <pkgid|appid>\n\n");
- printf("For Getting list of installed packages\n");
- printf("\tpkginfo --listpkg \n\n");
- printf("For Getting list of installed applications\n");
- printf("\tpkginfo --listapp \n\n");
- printf("For Getting app list for a particular package\n");
- printf("\tpkginfo --list <pkgid>\n\n");
- printf("For Getting app category list for a particular application\n");
- printf("\tpkginfo --category <appid>\n\n");
- printf("For Getting app metadata list for a particular application\n");
- printf("\tpkginfo --metadata <appid>\n\n");
- printf("For Getting app control list for a particular application\n");
- printf("\tpkginfo --appcontrol <appid>\n\n");
- printf("To insert|remove manifest info in DB\n");
- printf("\tpkginfo --[imd|rmd] <manifest file name>\n\n");
- printf("To set manifest validation\n");
- printf("\tpkginfo --check <manifest file name>\n\n");
- printf("To set cert info in DB [root only]\n");
- printf("\tpkginfo --setcert <pkgid>\n\n");
- printf("To get cert info from DB [root only]\n");
- printf("\tpkginfo --getcert <pkgid>\n\n");
- printf("To compare pkg cert info from DB\n");
- printf("\tpkginfo --cmp-pkgcert <lhs_pkgid> <rhs_pkgid>\n\n");
- printf("To compare app cert info from DB\n");
- printf("\tpkginfo --cmp-appcert <lhs_appid> <rhs_appid>\n\n");
- printf("To delete all cert info from DB [root only]\n");
- printf("\tpkginfo --delcert <pkgid>\n\n");
- printf("To add application filter values [Multiple values can be added]\n");
- printf("\tpkginfo --app-flt\n\n");
- printf("To add package filter values [Multiple values can be added]\n");
- printf("\tpkginfo --pkg-flt\n\n");
- printf("To add metadata filter values\n");
- printf("\tpkginfo --metadata-flt\n\n");
-}
-
-static void __print_arg_filter_usage()
-{
- printf("=========================================\n");
- printf("pkginfo --arg-flt key value\n");
- printf("ex : pkginfo --arg-flt 6 webapp\n");
- printf("key list is bellowed\n");
- printf("2 --> filter by app ID\n");
- printf("3 --> filter by app component\n");
- printf("4 --> filter by app exec\n");
- printf("5 --> filter by app icon\n");
- printf("6 --> filter by app type\n");
- printf("7 --> filter by app operation\n");
- printf("8 --> filter by app uri\n");
- printf("9 --> filter by app mime\n");
- printf("10 --> filter by app category\n");
- printf("11 --> filter by app nodisplay [0|1]\n");
- printf("12 --> filter by app multiple [0|1]\n");
- printf("13 --> filter by app onboot [0|1]\n");
- printf("14 --> filter by app autorestart [0|1]\n");
- printf("15 --> filter by app taskmanage [0|1]\n");
- printf("16 --> filter by app hwacceleration\n");
- printf("17 --> filter by app screenreader\n");
- printf("=========================================\n");
-}
-
-static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
-{
- char *appid = NULL;
-
- pkgmgrinfo_appinfo_get_appid(handle, &appid);
- printf("appid : %s\n", appid);
-
- return 0;
-}
-
-static int __add_metadata_filter()
-{
- int ret = 0;
- pkgmgrinfo_appinfo_metadata_filter_h handle;
- char *key = NULL;
- char *value = NULL;
-
- ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
- if (ret != PMINFO_R_OK) {
- printf("pkgmgrinfo_appinfo_metadata_filter_create() failed\n");
- return ret;
- }
-
- printf("enter metadata - key\n");
- key = __get_string_input_data();
- printf("enter metadata - value\n");
- value = __get_string_input_data();
-
- printf("filter condition : key=[%s], value=[%s]\n", key, value);
-
- ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, key, value);
- if (ret != PMINFO_R_OK) {
- printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n");
- goto err;
- }
-
- ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, __app_list_cb, NULL);
- if (ret != PMINFO_R_OK) {
- printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n");
- goto err;
- }
-
-err:
- pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
- if (key) {
- free(key);
- key = NULL;
- }
- if (value) {
- free(value);
- value = NULL;
- }
- return ret;
-}
-
-static int __add_app_filter(uid_t uid)
-{
- int ret = 0;
- int choice = -1;
- char *value = NULL;
- int val = -1;
- int count = 0;
- pkgmgrinfo_appinfo_filter_h handle;
-
- ret = pkgmgrinfo_appinfo_filter_create(&handle);
- if (ret > 0) {
- printf("appinfo filter handle create failed\n");
- return -1;
- }
-
- while (choice != 0 && choice != 1) {
- printf("Enter Choice\n");
- printf("0 --> Finalize filter and get count of apps\n");
- printf("1 --> Finalize filter and get list of apps\n");
- printf("2 --> filter by app ID\n");
- printf("3 --> filter by app component\n");
- printf("4 --> filter by app exec\n");
- printf("5 --> filter by app icon\n");
- printf("6 --> filter by app type\n");
- printf("7 --> filter by app operation\n");
- printf("8 --> filter by app uri\n");
- printf("9 --> filter by app mime\n");
- printf("10 --> filter by app category\n");
- printf("11 --> filter by app nodisplay [0|1]\n");
- printf("12 --> filter by app multiple [0|1]\n");
- printf("13 --> filter by app onboot [0|1]\n");
- printf("14 --> filter by app autorestart [0|1]\n");
- printf("15 --> filter by app taskmanage [0|1]\n");
- printf("16 --> filter by app hwacceleration\n");
- printf("17 --> filter by app screenreader\n");
- printf("18 --> filter by app ui-gadget [0|1]\n");
- printf("19 --> filter by app support disable [0|1]\n");
- printf("20 --> filter by app installed storage\n");
- choice = __get_integer_input_data();
- switch (choice) {
- case 0:
- ret = pkgmgrinfo_appinfo_filter_count(handle, &count);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_count() failed\n");
- ret = -1;
- goto err;
- }
- printf("App count = %d\n", count);
- break;
- case 1:
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_func, NULL, uid);
- else
- ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, app_func, NULL);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 2:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_ID, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 3:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_COMPONENT, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 4:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_EXEC, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 5:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_ICON, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 6:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_TYPE, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 7:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_OPERATION, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 8:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_URI, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 9:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_MIME, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 10:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_CATEGORY, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 11:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
- PMINFO_APPINFO_PROP_APP_NODISPLAY, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 12:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
- PMINFO_APPINFO_PROP_APP_MULTIPLE, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 13:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
- PMINFO_APPINFO_PROP_APP_ONBOOT, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 14:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
- PMINFO_APPINFO_PROP_APP_AUTORESTART, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 15:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
- PMINFO_APPINFO_PROP_APP_TASKMANAGE, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 16:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_HWACCELERATION, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 17:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_SCREENREADER, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 18:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
- PMINFO_APPINFO_PROP_APP_UI_GADGET, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 19:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
- PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 20:
- value = __get_string_input_data();
- ret = pkgmgrinfo_appinfo_filter_add_string(handle,
- PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- break;
-
- default:
- printf("Invalid filter property\n");
- ret = -1;
- goto err;
- }
- }
- ret = 0;
-err:
- pkgmgrinfo_appinfo_filter_destroy(handle);
- if (value) {
- free(value);
- value = NULL;
- }
- return ret;
-}
-
-static int __add_pkg_filter(uid_t uid)
-{
- int ret = 0;
- int choice = -1;
- char *value = NULL;
- int val = -1;
- int count = 0;
- pkgmgrinfo_pkginfo_filter_h handle;
-
- ret = pkgmgrinfo_pkginfo_filter_create(&handle);
- if (ret > 0) {
- printf("pkginfo filter handle create failed\n");
- return -1;
- }
-
- while (choice != 0 && choice != 1) {
- printf("Enter Choice\n");
- printf("0 --> Finalize filter and get count of packages\n");
- printf("1 --> Finalize filter and get list of packages\n");
- printf("2 --> filter by package ID\n");
- printf("3 --> filter by package version\n");
- printf("4 --> filter by package type\n");
- printf("5 --> filter by package install location\n");
- printf("6 --> filter by author name\n");
- printf("7 --> filter by author email\n");
- printf("8 --> filter by author href\n");
- printf("9 --> filter by package removable [0|1]\n");
- printf("10 --> filter by package readonly [0|1]\n");
- printf("11 --> filter by package preload [0|1]\n");
- printf("12 --> filter by package update [0|1]\n");
- printf("13 --> filter by package appsetting [0|1]\n");
- printf("14 --> filter by package installed storage[installed_internal | installed_external]\n");
- printf("15 --> filter by package privilege\n");
- printf("16 --> filter by package support disable [0|1]\n");
- choice = __get_integer_input_data();
- switch (choice) {
- case 0:
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_pkginfo_usr_filter_count(handle, &count, uid);
- else
- ret = pkgmgrinfo_pkginfo_filter_count(handle, &count);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_count() failed\n");
- ret = -1;
- goto err;
- }
- printf("Package count = %d\n", count);
- break;
- case 1:
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, __pkg_list_cb, NULL, uid);
- else
- ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkg_list_cb, NULL);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_(usr)_filter_foreach_pkginfo() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 2:
- value = __get_string_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_ID, value);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 3:
- value = __get_string_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_VERSION, value);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 4:
- value = __get_string_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_TYPE, value);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 5:
- value = __get_string_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION, value);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 6:
- value = __get_string_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME, value);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 7:
- value = __get_string_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL, value);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 8:
- value = __get_string_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF, value);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 9:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, val);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 10:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_READONLY, val);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 11:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, val);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 12:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_UPDATE, val);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 13:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, val);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 14:
- value = __get_string_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, value);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 15:
- value = __get_string_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE,
- value);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 16:
- val = __get_integer_input_data();
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, val);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- default:
- printf("Invalid filter property\n");
- ret = -1;
- goto err;
- }
- }
- ret = 0;
-err:
- pkgmgrinfo_pkginfo_filter_destroy(handle);
- if (value) {
- free(value);
- value = NULL;
- }
- return ret;
-}
-
-static int __add_arg_filter(char *key, char *value, uid_t uid)
-{
- int ret = 0;
- int choice = -1;
- int val = -1;
- pkgmgrinfo_appinfo_filter_h handle;
- ret = pkgmgrinfo_appinfo_filter_create(&handle);
- if (ret > 0) {
- printf("appinfo filter handle create failed\n");
- return -1;
- }
- choice = atoi(key);
-
- switch (choice) {
- case 2:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_ID, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 3:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_COMPONENT, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 4:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_EXEC, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 5:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_ICON, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 6:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_TYPE, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 7:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_OPERATION, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 8:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_URI, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 9:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_MIME, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 10:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 11:
- val = atoi(value);
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 12:
- val = atoi(value);
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_MULTIPLE, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 13:
- val = atoi(value);
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_ONBOOT, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 14:
- val = atoi(value);
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_AUTORESTART, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 15:
- val = atoi(value);
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_TASKMANAGE, val);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 16:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_HWACCELERATION, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
- case 17:
- ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_SCREENREADER, value);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
- ret = -1;
- goto err;
- }
- break;
-
- default:
- __print_arg_filter_usage();
- goto err;
- }
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, __get_app_id, NULL, uid);
- else
- ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __get_app_id, NULL);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n");
- ret = -1;
- goto err;
- }
-
-err:
- pkgmgrinfo_appinfo_filter_destroy(handle);
- return ret;
-}
-static int __del_certinfo_from_db(char *pkgid)
-{
- int ret = 0;
- if (pkgid == NULL) {
- printf("pkgid is NULL\n");
- return -1;
- }
- ret = pkgmgr_installer_delete_certinfo(pkgid);
- if (ret < 0) {
- printf("pkgmgr_installer_delete_certinfo failed\n");
- return -1;
- }
- return 0;
-}
-
-static int __get_certinfo_from_db(char *pkgid, uid_t uid)
-{
- if (pkgid == NULL) {
- printf("pkgid is NULL\n");
- return -1;
- }
- int ret = 0;
- int choice = -1;
- int i = 0;
- const char *value = NULL;
- pkgmgrinfo_certinfo_h handle = NULL;
-
- ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_create_certinfo failed\n");
- return -1;
- }
-
- ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle, uid);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_load_certinfo failed\n");
- pkgmgrinfo_pkginfo_destroy_certinfo(handle);
- return -1;
- }
-
- while (choice != 10) {
- printf("Enter the choice to get\n");
- printf("0 --> to get all cert values\n");
- printf("1 --> author root certificate\n");
- printf("2 --> author intermediate certificate\n");
- printf("3 --> author signer certificate\n");
- printf("4 --> distributor root certificate\n");
- printf("5 --> distributor intermediate certificate\n");
- printf("6 --> distributor signer certificate\n");
- printf("7 --> distributor2 root certificate\n");
- printf("8 --> distributor2 intermediate certificate\n");
- printf("9 --> distributor2 signer certificate\n");
- printf("10 --> exit\n");
- choice = __get_integer_input_data();
- switch (choice) {
- case 0:
- for (i = 0; i < 9; i++) {
- pkgmgrinfo_pkginfo_get_cert_value(handle, i, &value);
- if (value)
- printf("cert type[%d] value = %s\n", i, value);
- }
- break;
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- ret = pkgmgrinfo_pkginfo_get_cert_value(handle, choice - 1, &value);
- if (value)
- printf("cert type[%d] value = %s\n", choice - 1, value);
- if (ret < 0)
- ret = -1;
- break;
- case 10:
- ret = pkgmgrinfo_pkginfo_destroy_certinfo(handle);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_destroy_certinfo failed\n");
- ret = -1;
- }
- break;
- default:
- printf("Invalid choice entered\n");
- ret = -1;
- break;
- }
- }
-
- return ret;
-}
-
-static int __compare_pkg_certinfo_from_db(char *lhs_pkgid, char *rhs_pkgid, uid_t uid)
-{
- if (lhs_pkgid == NULL || rhs_pkgid == NULL) {
- printf("pkgid is NULL\n");
- return -1;
- }
-
- int ret = 0;
- pkgmgrinfo_cert_compare_result_type_e result;
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_pkgid, rhs_pkgid, uid, &result);
- else
- ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lhs_pkgid, rhs_pkgid, &result);
- if (ret != PMINFO_R_OK)
- return -1;
-
- printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n");
- printf("pkgid =[%s] and [%s] compare result = [%d] \n", lhs_pkgid, rhs_pkgid, result);
- return 0;
-}
-
-static int __compare_app_certinfo_from_db(char *lhs_appid, char *rhs_appid, uid_t uid)
-{
- if (lhs_appid == NULL || rhs_appid == NULL) {
- printf("appid is NULL\n");
- return -1;
- }
-
- int ret = 0;
- pkgmgrinfo_cert_compare_result_type_e result;
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(lhs_appid, rhs_appid, uid, &result);
- else
- ret = pkgmgrinfo_pkginfo_compare_app_cert_info(lhs_appid, rhs_appid, &result);
- if (ret != PMINFO_R_OK)
- return -1;
-
- printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n");
- printf("appid =[%s] and [%s] compare result = [%d] \n", lhs_appid, rhs_appid, result);
- return 0;
-}
-
-static int __set_certinfo_in_db(char *pkgid, uid_t uid)
-{
- if (pkgid == NULL) {
- printf("pkgid is NULL\n");
- return -1;
- }
- int ret = 0;
- int choice = -1;
- char *value = NULL;
- pkgmgr_instcertinfo_h handle = NULL;
-
- ret = pkgmgr_installer_create_certinfo_set_handle(&handle);
- if (ret < 0) {
- printf("pkgmgr_installer_create_certinfo_set_handle failed\n");
- return -1;
- }
-
- while (choice != 0) {
- printf("Enter the choice you want to set\n");
- printf("0 --> to set data in DB\n");
- printf("1 --> author root certificate\n");
- printf("2 --> author intermediate certificate\n");
- printf("3 --> author signer certificate\n");
- printf("4 --> distributor root certificate\n");
- printf("5 --> distributor intermediate certificate\n");
- printf("6 --> distributor signer certificate\n");
- printf("7 --> distributor2 root certificate\n");
- printf("8 --> distributor2 intermediate certificate\n");
- printf("9 --> distributor2 signer certificate\n");
- choice = __get_integer_input_data();
- switch (choice) {
- case 0:
- ret = pkgmgr_installer_delete_certinfo(pkgid);
- if (ret < 0) {
- printf("pkgmgr_installer_delete_certinfo failed\n");
- pkgmgr_installer_destroy_certinfo_set_handle(handle);
- return -1;
- }
- ret = pkgmgr_installer_save_certinfo(pkgid, handle, uid);
- if (ret < 0) {
- printf("pkgmgr_installer_save_certinfo failed\n");
- pkgmgr_installer_destroy_certinfo_set_handle(handle);
- return -1;
- }
- ret = pkgmgr_installer_destroy_certinfo_set_handle(handle);
- if (ret < 0) {
- printf("pkgmgr_installer_destroy_certinfo_set_handle failed\n");
- return -1;
- }
- return 0;
- case 1:
- printf("Enter Author Root Certificate Value: \n");
- value = __get_string_input_data();
- ret = pkgmgr_installer_set_cert_value(handle, 0, value);
- if (ret < 0) {
- printf("pkgmgr_installer_set_cert_value failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 2:
- printf("Enter Author Intermediate Certificate Value: \n");
- value = __get_string_input_data();
- ret = pkgmgr_installer_set_cert_value(handle, 1, value);
- if (ret < 0) {
- printf("pkgmgr_installer_set_cert_value failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 3:
- printf("Enter Author Signer Certificate Value: \n");
- value = __get_string_input_data();
- ret = pkgmgr_installer_set_cert_value(handle, 2, value);
- if (ret < 0) {
- printf("pkgmgr_installer_set_cert_value failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 4:
- printf("Enter Distributor Root Certificate Value: \n");
- value = __get_string_input_data();
- ret = pkgmgr_installer_set_cert_value(handle, 3, value);
- if (ret < 0) {
- printf("pkgmgr_installer_set_cert_value failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 5:
- printf("Enter Distributor Intermediate Certificate Value: \n");
- value = __get_string_input_data();
- ret = pkgmgr_installer_set_cert_value(handle, 4, value);
- if (ret < 0) {
- printf("pkgmgr_installer_set_cert_value failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 6:
- printf("Enter Distributor Signer Certificate Value: \n");
- value = __get_string_input_data();
- ret = pkgmgr_installer_set_cert_value(handle, 5, value);
- if (ret < 0) {
- printf("pkgmgr_installer_set_cert_value failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 7:
- printf("Enter Distributor2 Root Certificate Value: \n");
- value = __get_string_input_data();
- ret = pkgmgr_installer_set_cert_value(handle, 6, value);
- if (ret < 0) {
- printf("pkgmgr_installer_set_cert_value failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 8:
- printf("Enter Distributor2 Intermediate Certificate Value: \n");
- value = __get_string_input_data();
- ret = pkgmgr_installer_set_cert_value(handle, 7, value);
- if (ret < 0) {
- printf("pkgmgr_installer_set_cert_value failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- case 9:
- printf("Enter Distributor2 Signer Certificate Value: \n");
- value = __get_string_input_data();
- ret = pkgmgr_installer_set_cert_value(handle, 8, value);
- if (ret < 0) {
- printf("pkgmgr_installer_set_cert_value failed\n");
- ret = -1;
- goto err;
- }
- free(value);
- value = NULL;
- break;
- default:
- printf("Invalid Number Entered\n");
- break;
- }
- }
-err:
- if (value) {
- free(value);
- value = NULL;
- }
- pkgmgr_installer_destroy_certinfo_set_handle(handle);
- return ret;
-}
-
-int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data)
-{
- int ret = -1;
- char *appid;
- char *data = NULL;
- char *exec = NULL;
- char *icon = NULL;
- char *label = NULL;
- char *apptype = NULL;
- char *package = NULL;
- bool nodisplay = 0;
- bool multiple = 0;
- bool taskmanage = 0;
- bool onboot = 0;
- bool autorestart = 0;
- pkgmgrinfo_app_component component = 0;
- pkgmgrinfo_app_hwacceleration hwacceleration;
- pkgmgrinfo_app_screenreader screenreader;
-
- if (user_data)
- data = (char *)user_data;
-
- ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
- if (ret < 0)
- printf("Failed to get appid\n");
- if (appid)
- printf("Appid: %s\n", appid);
-
- ret = pkgmgrinfo_appinfo_get_pkgid(handle, &package);
- if (ret < 0)
- printf("Failed to get package\n");
- if (package)
- printf("Package: %s\n", package);
-
- ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
- if (ret < 0)
- printf("Failed to get exec\n");
- if (exec)
- printf("Exec: %s\n", exec);
-
- ret = pkgmgrinfo_appinfo_get_icon(handle, &icon);
- if (ret < 0)
- printf("Failed to get icon\n");
- if (icon)
- printf("Icon: %s\n", icon);
-
- ret = pkgmgrinfo_appinfo_get_label(handle, &label);
- if (ret < 0)
- printf("Failed to get label\n");
- if (label)
- printf("Label: %s\n", label);
-
- ret = pkgmgrinfo_appinfo_get_component(handle, &component);
- if (ret < 0)
- printf("Failed to get component\n");
-
- ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
- if (ret < 0)
- printf("Failed to get apptype\n");
- if (apptype)
- printf("Apptype: %s\n", apptype);
-
- if (component == PMINFO_UI_APP || component == PMINFO_WIDGET_APP ||
- component == PMINFO_WATCH_APP) {
- printf("component: %s\n", component == PMINFO_UI_APP ?
- "uiapp" : component == PMINFO_WIDGET_APP ?
- "widgetapp" : "watchapp");
- ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
- if (ret < 0)
- printf("Failed to get multiple\n");
- else
- printf("Multiple: %d\n", multiple);
-
- ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &nodisplay);
- if (ret < 0)
- printf("Failed to get nodisplay\n");
- else
- printf("Nodisplay: %d \n", nodisplay);
-
- ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage);
- if (ret < 0)
- printf("Failed to get taskmanage\n");
- else
- printf("Taskmanage: %d\n", taskmanage);
-
- ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacceleration);
- if (ret < 0)
- printf("Failed to get hwacceleration\n");
- else
- printf("hw-acceleration: %d\n", hwacceleration);
-
- ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader);
- if (ret < 0)
- printf("Failed to get screenreader\n");
- else
- printf("screenreader: %d\n", screenreader);
- }
-
- if (component == PMINFO_SVC_APP) {
- printf("component: svcapp\n");
- ret = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
- if (ret < 0)
- printf("Failed to get onboot\n");
- else
- printf("Onboot: %d\n", onboot);
-
- ret = pkgmgrinfo_appinfo_is_autorestart(handle, &autorestart);
- if (ret < 0)
- printf("Failed to get autorestart\n");
- else
- printf("Autorestart: %d \n", autorestart);
- }
-
- if (data)
- printf("user_data : %s\n\n", data);
-
- return 0;
-}
-
-
-static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
-{
- int ret = -1;
- int installed_time = -1;
- char *test_data = "test data";
- char *pkgid;
- char *pkg_type;
- char *pkg_version;
- bool preload = 0;
-
- pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle;
- ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (ret < 0)
- printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n");
-
- ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type);
- if (ret < 0)
- printf("pkgmgrinfo_pkginfo_get_type() failed\n");
-
- ret = pkgmgrinfo_pkginfo_get_version(handle, &pkg_version);
- if (ret < 0)
- printf("pkgmgrinfo_pkginfo_get_version() failed\n");
-
- ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
- if (ret < 0)
- printf("pkgmgrinfo_pkginfo_is_preload() failed\n");
-
- ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time);
- if (ret < 0)
- printf("pkgmgrinfo_pkginfo_get_installed_time() failed\n");
-
- printf("---------------------------------------\n");
- printf("pkg_type [%s]\tpkgid [%s]\tversion [%s]\tpreload [%d]\tinstalled_time [%d]\n", pkg_type,
- pkgid, pkg_version, preload, installed_time);
-
- if (uid_info->uid != GLOBAL_USER) {
- printf("**List of Ui-Apps**\n");
- ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_UI_APP, app_func, (void *)test_data, uid_info->uid);
- if (ret < 0)
- printf("pkgmgr_get_info_app() failed\n");
-
- printf("**List of Svc-Apps**\n");
- ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data, uid_info->uid);
- if (ret < 0)
- printf("pkgmgr_get_info_app() failed\n");
-
- printf("**List of Widget-Apps**\n");
- ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_WIDGET_APP, app_func, (void *)test_data, uid_info->uid);
- if (ret < 0)
- printf("pkgmgr_get_info_app() failed\n");
-
- printf("**List of Watch-Apps**\n");
- ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_WATCH_APP, app_func, (void *)test_data, uid_info->uid);
- if (ret < 0)
- printf("pkgmgr_get_info_app() failed\n");
- } else {
- printf("**List of Ui-Apps**\n");
- ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, app_func, (void *)test_data);
- if (ret < 0)
- printf("pkgmgr_get_info_app() failed\n");
-
- printf("**List of Svc-Apps**\n");
- ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data);
- if (ret < 0)
- printf("pkgmgr_get_info_app() failed\n");
-
- printf("**List of Widget-Apps**\n");
- ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_WIDGET_APP, app_func, (void *)test_data);
- if (ret < 0)
- printf("pkgmgr_get_info_app() failed\n");
-
- printf("**List of Watch-Apps**\n");
- ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_WATCH_APP, app_func, (void *)test_data);
- if (ret < 0)
- printf("pkgmgr_get_info_app() failed\n");
- }
- printf("---------------------------------------\n");
-
- return 0;
-}
-
-static int __get_pkg_list(uid_t uid)
-{
- int ret = -1;
-
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, NULL, uid);
- else
- ret = pkgmgrinfo_pkginfo_get_list(__pkg_list_cb, NULL);
- if (ret < 0) {
- printf("pkgmgrinfo_pkginfo_get_list() failed\n");
- return -1;
- }
-
- return 0;
-}
-
-static int __get_installed_app_list(uid_t uid)
-{
- int ret = -1;
-
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_appinfo_get_usr_installed_list(app_func, uid, NULL);
- else
- ret = pkgmgrinfo_appinfo_get_installed_list(app_func, NULL);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_get_installed_list() failed\n");
- return -1;
- }
-
- return 0;
-}
-
-
-static int __app_category_list_cb(const char *category_name, void *user_data)
-{
- if (category_name)
- printf("Category: %s\n", category_name);
- return 0;
-}
-
-static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data)
-{
- if (metadata_name && metadata_value) {
- printf("Name: %s\n", metadata_name);
- printf("Value: %s\n", metadata_value);
- printf("\n");
- }
- return 0;
-}
-
-static int __app_control_list_cb(const char *operation, const char *uri, const char *mime, void *user_data)
-{
- printf("-------------------------------------------------------\n");
- printf("Operation: %s\n", operation);
- printf("Uri: %s\n", uri);
- printf("Mime: %s\n", mime);
- printf("-------------------------------------------------------\n\n");
- return 0;
-}
-
-
-static int __get_app_category_list(char *appid)
-{
- int ret = -1;
- pkgmgrinfo_appinfo_h handle;
-
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
- if (ret < 0) {
- printf("Failed to get handle\n");
- return -1;
- }
-
- ret = pkgmgrinfo_appinfo_foreach_category(handle, __app_category_list_cb, NULL);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_foreach_category() failed\n");
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
- return -1;
- }
-
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
- return 0;
-}
-
-static int __get_app_metadata_list(char *appid)
-{
- int ret = -1;
- pkgmgrinfo_appinfo_h handle;
-
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
- if (ret < 0) {
- printf("Failed to get handle\n");
- return -1;
- }
-
- ret = pkgmgrinfo_appinfo_foreach_metadata(handle, __app_metadata_list_cb, NULL);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_foreach_metadata() failed\n");
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
- return -1;
- }
-
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
- return 0;
-}
-
-static int __get_app_control_list(char *appid)
-{
- int ret = -1;
- pkgmgrinfo_appinfo_h handle;
-
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
- if (ret < 0) {
- printf("Failed to get handle\n");
- return -1;
- }
-
- ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, __app_control_list_cb, NULL);
- if (ret < 0) {
- printf("pkgmgrinfo_appinfo_foreach_appcontrol() failed\n");
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
- return -1;
- }
-
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
- return 0;
-}
-
-static int __get_app_list(char *pkgid, uid_t uid)
-{
- int ret = -1;
- char *test_data = "test data";
- pkgmgrinfo_pkginfo_h handle;
-
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
- else
- ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
- if (ret < 0) {
- printf("Failed to get handle\n");
- return -1;
- }
-
- if (uid != GLOBAL_USER) {
- printf("List of Ui-Apps\n\n");
- ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_UI_APP, app_func, (void *)test_data, uid);
- if (ret < 0)
- printf("pkgmgrinfo_appinfo_get_list() failed\n");
-
- printf("List of Svc-Apps\n\n");
- ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data, uid);
- if (ret < 0)
- printf("pkgmgrinfo_appinfo_get_list() failed\n");
-
- printf("List of Widget-Apps\n\n");
- ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_WIDGET_APP, app_func, (void *)test_data, uid);
- if (ret < 0)
- printf("pkgmgrinfo_appinfo_get_list() failed\n");
-
- printf("List of Watch-Apps\n\n");
- ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_WATCH_APP, app_func, (void *)test_data, uid);
- if (ret < 0)
- printf("pkgmgrinfo_appinfo_get_list() failed\n");
- } else {
- printf("List of Ui-Apps\n\n");
- ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, app_func, (void *)test_data);
- if (ret < 0)
- printf("pkgmgrinfo_appinfo_get_list() failed\n");
-
- printf("List of Svc-Apps\n\n");
- ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data);
- if (ret < 0)
- printf("pkgmgrinfo_appinfo_get_list() failed\n");
-
- printf("List of Widget-Apps\n\n");
- ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_WIDGET_APP, app_func, (void *)test_data);
- if (ret < 0)
- printf("pkgmgrinfo_appinfo_get_list() failed\n");
-
- printf("List of Watch-Apps\n\n");
- ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_WATCH_APP, app_func, (void *)test_data);
- if (ret < 0)
- printf("pkgmgrinfo_appinfo_get_list() failed\n");
- }
-
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-
- return 0;
-}
-
-static int __get_pkg_info(char *pkgid, uid_t uid)
-{
- int ret = -1;
- pkgmgrinfo_pkginfo_h handle;
-
- printf("Get Pkg Info Called [%s]\n", pkgid);
- if (uid != GLOBAL_USER)
- ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
- else
- ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
- if (ret < 0) {
- printf("Failed to get handle\n");
- return -1;
- }
-
- __get_pkgmgrinfo_pkginfo(handle, NULL);
-
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-
- return 0;
-}
-
-static int __get_app_info(char *appid)
-{
- int ret = -1;
- int support_mode = 0;
- char *exec = NULL;
- char *app_id = NULL;
- char *apptype = NULL;
- char *icon = NULL;
- char *label = NULL;
- char *package = NULL;
- bool nodisplay = 0;
- bool multiple = 0;
- bool taskmanage = 0;
- bool onboot = 0;
- bool autorestart = 0;
- bool enabled = 0;
- bool preload = 0;
- pkgmgrinfo_appinfo_h handle;
- pkgmgrinfo_app_component component = 0;
- pkgmgrinfo_app_hwacceleration hwacceleration;
- pkgmgrinfo_app_screenreader screenreader;
-
- printf("Get App Info Called [%s]\n", appid);
-
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
- if (ret < 0) {
- printf("Failed to get handle\n");
- return -1;
- }
-
- ret = pkgmgrinfo_appinfo_get_pkgid(handle, &package);
- if (ret < 0)
- printf("Failed to get package\n");
-
- ret = pkgmgrinfo_appinfo_get_appid(handle, &app_id);
- if (ret < 0)
- printf("Failed to get exec\n");
-
- ret = pkgmgrinfo_appinfo_get_label(handle, &label);
- if (ret < 0)
- printf("Failed to get label\n");
-
- ret = pkgmgrinfo_appinfo_get_icon(handle, &icon);
- if (ret < 0)
- printf("Failed to get icon\n");
-
- ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
- if (ret < 0)
- printf("Failed to get exec\n");
-
- ret = pkgmgrinfo_appinfo_get_component(handle, &component);
- if (ret < 0)
- printf("Failed to get component\n");
-
- ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
- if (ret < 0)
- printf("Failed to get apptype\n");
-
- ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &nodisplay);
- if (ret < 0)
- printf("Failed to get nodisplay\n");
-
- ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
- if (ret < 0)
- printf("Failed to get multiple\n");
-
- ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage);
- if (ret < 0)
- printf("Failed to get taskmanage\n");
-
- ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacceleration);
- if (ret < 0)
- printf("Failed to get hwacceleration\n");
-
- ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader);
- if (ret < 0)
- printf("Failed to get screenreader\n");
-
- ret = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
- if (ret < 0)
- printf("Failed to get onboot\n");
-
- ret = pkgmgrinfo_appinfo_is_autorestart(handle, &autorestart);
- if (ret < 0)
- printf("Failed to get autorestart\n");
-
- ret = pkgmgrinfo_appinfo_is_enabled(handle, &enabled);
- if (ret < 0)
- printf("Failed to get enabled\n");
-
- ret = pkgmgrinfo_appinfo_is_preload(handle, &preload);
- if (ret < 0)
- printf("Failed to get preload\n");
-
- ret = pkgmgrinfo_appinfo_get_support_mode(handle, &support_mode);
- if (ret < 0)
- printf("Failed to get support_mode\n");
-
- if (app_id)
- printf("Appid: %s\n", app_id);
-
- if (package)
- printf("Package: %s\n", package);
-
- if (exec)
- printf("Exec: %s\n", exec);
-
- if (apptype)
- printf("Apptype: %s\n", apptype);
-
- if (component == PMINFO_UI_APP || component == PMINFO_WIDGET_APP ||
- component == PMINFO_WATCH_APP ||
- component == PMINFO_COMPONENT_BASED_APP) {
- printf("component: %s\n", component == PMINFO_UI_APP ?
- "uiapp" : component == PMINFO_WIDGET_APP ?
- "widgetapp" : component == PMINFO_WATCH_APP ?
- "watchapp" : "componentbasedapp");
- if (icon)
- printf("Icon: %s\n", icon);
- if (label)
- printf("Label: %s\n", label);
- printf("Nodisplay: %d\n", nodisplay);
- printf("Multiple: %d\n", multiple);
- printf("Taskmanage: %d\n", taskmanage);
- printf("Hw-Acceleration: %d\n", hwacceleration);
- printf("Screenreader: %d\n", screenreader);
- } else if (component == PMINFO_SVC_APP) {
- printf("component: svcapp\n");
-
- if (icon)
- printf("Icon: %s\n", icon);
- if (label)
- printf("Label: %s\n", label);
-
- printf("Autorestart: %d\n", autorestart);
- printf("Onboot: %d\n", onboot);
- } else {
- printf("Invalid Component Type\n");
- }
-
- printf("Enabled: %d\n", enabled);
- printf("Preload: %d\n", preload);
- printf("Support_mode: %d\n", support_mode);
-
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
- return 0;
-}
-
-static int __check_manifest_validation(char *manifest)
-{
- int ret = 0;
-
- if (manifest == NULL) {
- printf("Manifest file is NULL\n");
- return -1;
- }
-
- ret = pkgmgr_parser_check_manifest_validation(manifest);
- if (ret < 0) {
- printf("check manifest validation failed\n");
- return -1;
- }
-
- return 0;
-}
-
-static int _is_authorized(uid_t uid)
-{
- if ((uid_t) OWNER_ROOT == uid) {
- return 1;
- } else {
- printf("Error! This cmd is allowed for only root user!\n\n");
- return 0;
- }
-}
-
-int main(int argc, char *argv[])
-{
- int ret = 0;
- long starttime;
- long endtime;
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
- starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
-
- if (argc < 2) {
- __print_usage();
- ret = -1;
- goto end;
- }
-
- /* TODO : refactor all with getopt system funtion */
- /* a group for the authorized user */
- if (strcmp(argv[1], "--setcert") == 0) {
- if (argc != 3 || !_is_authorized(getuid())) {
- __print_usage();
- ret = -1;
- goto end;
- }
- ret = __set_certinfo_in_db(argv[2], 0);
- if (ret == -1) {
- printf("set certinfo in db failed\n");
- goto end;
- }
- } else if (strcmp(argv[1], "--getcert") == 0) {
- if (argc != 3 || !_is_authorized(getuid())) {
- __print_usage();
- ret = -1;
- goto end;
- }
- ret = __get_certinfo_from_db(argv[2], 0);
- if (ret == -1) {
- printf("get certinfo from db failed\n");
- goto end;
- }
- } else if (strcmp(argv[1], "--delcert") == 0) {
- if (argc != 3 || !_is_authorized(getuid())) {
- __print_usage();
- ret = -1;
- goto end;
- }
- ret = __del_certinfo_from_db(argv[2]);
- if (ret == -1) {
- printf("del certinfo from db failed\n");
- goto end;
- }
- }
-
- if (argc == 2) {
- if (strcmp(argv[1], "--listpkg") == 0) {
- ret = __get_pkg_list(getuid());
- if (ret == -1) {
- printf("get pkg list failed\n");
- goto end;
- } else {
- goto end;
- }
- } else if (strcmp(argv[1], "--app-flt") == 0) {
- ret = __add_app_filter(getuid());
- if (ret == -1) {
- printf("Adding app filter failed\n");
- goto end;
- } else {
- goto end;
- }
- } else if (strcmp(argv[1], "--pkg-flt") == 0) {
- ret = __add_pkg_filter(getuid());
- if (ret == -1) {
- printf("Adding pkg filter failed\n");
- goto end;
- } else {
- goto end;
- }
- } else if (strcmp(argv[1], "--metadata-flt") == 0) {
- ret = __add_metadata_filter();
- if (ret == -1) {
- printf("Adding pkg filter failed\n");
- goto end;
- } else {
- goto end;
- }
- } else if (strcmp(argv[1], "--listapp") == 0) {
- ret = __get_installed_app_list(getuid());
- if (ret == -1) {
- printf("get installed app list failed\n");
- goto end;
- } else {
- goto end;
- }
- } else {
- __print_usage();
- ret = -1;
- goto end;
- }
- } else if (argc == 3) {
- if (strcmp(argv[1], "--pkg") == 0) {
- ret = __get_pkg_info(argv[2], getuid());
- if (ret == -1) {
- printf("get pkg info failed\n");
- goto end;
- }
- } else if (strcmp(argv[1], "--app") == 0) {
- ret = __get_app_info(argv[2]);
- if (ret == -1) {
- printf("get app info failed\n");
- goto end;
- }
- } else if (strcmp(argv[1], "--list") == 0) {
- ret = __get_app_list(argv[2], getuid());
- if (ret == -1) {
- printf("get app list failed\n");
- goto end;
- }
- } else if (strcmp(argv[1], "--imd") == 0) {
- printf("Not supported!\n");
- goto end;
- } else if (strcmp(argv[1], "--fota") == 0) {
- printf("Not supported!\n");
- goto end;
- } else if (strcmp(argv[1], "--rmd") == 0) {
- printf("Not supported!\n");
- goto end;
- } else if (strcmp(argv[1], "--check") == 0) {
- ret = __check_manifest_validation(argv[2]);
- if (ret == -1) {
- printf("check manifest failed\n");
- goto end;
- }
- } else if (strcmp(argv[1], "--category") == 0) {
- ret = __get_app_category_list(argv[2]);
- if (ret == -1) {
- printf("get app category list failed\n");
- goto end;
- }
- } else if (strcmp(argv[1], "--metadata") == 0) {
- ret = __get_app_metadata_list(argv[2]);
- if (ret == -1) {
- printf("get app metadata list failed\n");
- goto end;
- }
- } else if (strcmp(argv[1], "--appcontrol") == 0) {
- ret = __get_app_control_list(argv[2]);
- if (ret == -1) {
- printf("get app control list failed\n");
- goto end;
- }
- } else {
- __print_usage();
- ret = -1;
- goto end;
- }
- } else if (argc == 4) {
- if (strcmp(argv[1], "--cmp-pkgcert") == 0) {
- ret = __compare_pkg_certinfo_from_db(argv[2], argv[3], getuid());
- if (ret == -1) {
- printf("compare certinfo from db failed\n");
- goto end;
- }
- goto end;
- } else if (strcmp(argv[1], "--cmp-appcert") == 0) {
- ret = __compare_app_certinfo_from_db(argv[2], argv[3], getuid());
- if (ret == -1) {
- printf("compare certinfo from db failed\n");
- goto end;
- }
- goto end;
- } else if (strcmp(argv[1], "--arg-flt") == 0) {
- ret = __add_arg_filter(argv[2], argv[3], getuid());
- if (ret == -1) {
- printf("compare certinfo from db failed\n");
- goto end;
- }
- goto end;
- } else {
- __print_usage();
- ret = -1;
- goto end;
- }
- } else {
- __print_usage();
- ret = -1;
- }
-
-end:
- gettimeofday(&tv, NULL);
- endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
-
- printf("spend time for pkginfo is [%d]ms\n", (int)(endtime - starttime));
-
- return ret;
-}
+++ /dev/null
-
-/*
- * pkgmgr-tool
- *
- * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <getopt.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <dlfcn.h>
-#include <sys/types.h>
-#include <glib.h>
-#include <glib-object.h>
-#include <glib/gstdio.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <sys/time.h>
-#include "aul_rsc_mgr.h"
-
-#define RSC_TOOL_VERSION "0.1"
-#define BUF_SIZE 1024
-
-static void __print_usage();
-
-struct rsc_tool_args_t {
- char res_path[PATH_MAX];
- int dpi;
- int bpp;
- char dpi_range[BUF_SIZE];
- char width_range[BUF_SIZE];
- char screen_large[BUF_SIZE];
- char platform_version[BUF_SIZE];
- GHashTable *valid_file_list;
-};
-
-typedef struct rsc_tool_args_t rsc_tool_args;
-
-static int __convert_to_abs_path(rsc_tool_args *data)
-{
- char tmp[BUF_SIZE];
- char abs[BUF_SIZE] = {'\0'};
- char cwd[BUF_SIZE] = {'\0'};
- char *buf = NULL;
- int ret = -1;
-
- if (data->res_path[0] == '\0') {
- printf("invalid path\n");
- return -1;
- }
-
- ret = snprintf(tmp, sizeof(tmp), "%s", data->res_path);
- if (ret < 0 || ret > sizeof(tmp)) {
- printf("snprintf fail\n");
- return -1;
- }
-
- buf = getcwd(cwd, BUF_SIZE - 1);
- if (buf == NULL) {
- printf("failed to get cwd\n");
- return -1;
- }
-
- ret = chdir(tmp);
- if (ret < 0) {
- printf("failed to change dir[%s]\n", tmp);
- return -1;
- }
-
- buf = getcwd(abs, BUF_SIZE - 1);
- if (buf == NULL) {
- printf("failed to get cwd\n");
- return -1;
- }
-
- memset(data->res_path, '\0', BUF_SIZE);
- snprintf(data->res_path, sizeof(data->res_path), "%s/", abs);
- ret = chdir(cwd);
- if (ret < 0) {
- printf("failed to change dir[%s]\n", tmp);
- return -1;
- }
-
- return 0;
-}
-
-static void __print_usage()
-{
- printf("\nResource Slicing Tool Version: %s\n\n", RSC_TOOL_VERSION);
- printf("-p, --path set resource path\n");
- printf("-d, --screen-dpi set screen dpi value\n");
-
- printf("Usage: rscslice [options] \n");
- printf("rsc-slice -p [res path] \n");
- printf("rsc-slice -p [res_path] -d [dpi value] \n");
-
- printf("Example:\n");
- printf("rsc-slice -p /home/userid/workspace/testapp/res/ \n");
- printf("rsc-slice -p /home/userid/workspace/testapp/res/ -d 300 \n");
-
- exit(0);
-}
-
-static void __del_file(GHashTable *valid_file_list, char *path)
-{
- struct dirent **items;
- struct stat fstat;
- char abs_path[1024] = {0, };
- char cwd[1024] = {0, };
- char *tmp = NULL;
- int nitems, i;
- int ret;
-
- if (chdir(path) < 0) {
- printf("failed to chdir[%s]\n", path);
- return;
- }
-
- tmp = getcwd(cwd, 1024 - 1);
- nitems = scandir("./", &items, NULL, alphasort);
-
- for (i = 0; i < nitems; i++) {
- if (items[i]->d_name[0] == '.')
- continue;
-
- ret = snprintf(abs_path, 1024 - 1, "%s/%s", cwd, items[i]->d_name);
- if (ret < 0 || ret > 1024 -1 ) {
- printf("snprintf fail\n");
- return;
- }
- if (g_lstat(abs_path, &fstat) != 0) {
- printf("failed to get info[%s]\n", abs_path);
- return;
- }
- if ((fstat.st_mode & S_IFDIR) == S_IFDIR) {
- __del_file(valid_file_list, abs_path);
- } else {
- tmp = g_hash_table_lookup(valid_file_list, abs_path);
- if (tmp == NULL) {
- printf("deleting [%s]\n", abs_path);
- ret = remove(abs_path);
- if (ret == -1) {
- printf("failed to remove [%s][%d]\n",
- abs_path, errno);
- }
- }
- }
- }
-}
-
-static int __process_slice(rsc_tool_args *data)
-{
- int ret = -1;
- bundle *b = NULL;
- char dpi_value[1024] = {0, };
-
- if (data->res_path[0] == '\0')
- return -1;
-
- b = bundle_create();
- if (data->dpi != 0) {
- snprintf(dpi_value, 1024 - 1, "%d", data->dpi);
- bundle_add_str(b, "screen-dpi", dpi_value);
- }
-
- /* other attributes will be added here*/
-
- ret = aul_resource_manager_init_slice(data->res_path, b);
- if (ret < 0) {
- printf("failed to init rsc manager\n");
- goto catch;
- }
-
- ret = aul_resource_manager_get_path_list(&data->valid_file_list);
- if (ret < 0) {
- printf("failed to init rsc manager\n");
- goto catch;
- }
-
- /* remove useless resources and empty directories */
- __del_file(data->valid_file_list, data->res_path);
-
-
-catch:
- if (aul_resource_manager_release() < 0)
- printf("failed to release resource manager\n");
-
- bundle_free(b);
- return ret;
-}
-
-int main(int argc, char *argv[])
-{
- optind = 1;
- int opt_idx = 0;
- int c = -1;
- int ret = 0;
- long starttime;
- long endtime;
- int i = 0;
- struct timeval tv;
- const char *short_options = "p:d:";
- const struct option long_options[] = {
- {"path", 1, NULL, 'p'},
- {"screen-dpi", 1, NULL, 'd'},
- {0, 0, 0, 0} /* sentinel */
- };
- rsc_tool_args data = { 0 };
-
- if (argc == 1)
- __print_usage();
-
- gettimeofday(&tv, NULL);
- starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
-
- /* initialization of global structure */
- data.dpi = 0;
- data.bpp = 0;
- memset(data.dpi_range, '\0', BUF_SIZE);
- memset(data.width_range, '\0', BUF_SIZE);
- memset(data.screen_large, '\0', BUF_SIZE);
- memset(data.platform_version, '\0', BUF_SIZE);
-
- while (1) {
- i++;
- c = getopt_long(argc, argv, short_options, long_options, &opt_idx);
- if (c == -1)
- break; /* Parse end */
- switch (c) {
- case 'p': /* resource path */
- if (optarg)
- strncpy(data.res_path, optarg, PATH_MAX - 1);
-
- ret = __convert_to_abs_path(&data);
- if (ret == -1) {
- printf("conversion of relative path to absolute path failed\n");
- return -1;
- }
- printf("path is [%s]\n", data.res_path);
- break;
-
- case 'd': /* set dpi */
- if (optarg)
- data.dpi = atoi(optarg);
-
- if (data.dpi == 0) {
- printf("failed to get dpi value\n");
- return -1;
- }
- printf("dpi value is [%d]\n", data.dpi);
- break;
-
- default:
- break;
-
- }
- }
-
- ret = __process_slice(&data);
-
- gettimeofday(&tv, NULL);
- endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
- printf("spend time for rsc-slice is [%d]ms\n", (int)(endtime - starttime));
-
- return 0;
-}
+++ /dev/null
-/*
- * pkg-fota
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <iniparser.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/time.h>
-#include <libxml/xmlreader.h>
-#include <sqlite3.h>
-
-#include <package-manager-types.h>
-#include <package-manager.h>
-#include <pkgmgr_parser.h>
-#include <pkgmgr-info.h>
-#include "pkg_upgrade.h"
-
-#include <tzplatform_config.h>
-
-#define USR_MANIFEST_DIRECTORY tzplatform_getenv(TZ_SYS_RO_PACKAGES)
-
-#define PKGMGR_FOTA_PATH tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
- "pkgmgr/fota")
-#define PKGID_LIST_FROM_DB_FILE tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
- "pkgmgr/fota/pkgid_list_from_db.txt")
-#define PKGID_LIST_FROM_XML_FILE \
- tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
- "pkgmgr/fota/pkgid_list_from_xml.txt")
-#define PRELOAD_RW_PKG_LIST \
- tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
- "pkgmgr/fota/.all_preload_rw_list")
-#define DBPATH tzplatform_mkpath(TZ_SYS_DB, "/.pkgmgr_parser.db")
-#define OPT_ZIP_FILE "/usr/system/RestoreDir/opt.zip"
-#define ALL_PRELOAD_RW_PKG_LIST "/opt/usr/share/.all_preload_rw_list"
-
-struct pkginfo {
- char *pkgid;
- char *version;
- char *type;
-};
-
-static char *unzip_path[BUF_SIZE] = {
- "opt/usr/globalapps",
- "opt/etc/skel/apps_rw",
- NULL
-};
-
-static void __free_pkginfo(gpointer data)
-{
- struct pkginfo *info = (struct pkginfo *)data;
- free(info->pkgid);
- free(info->version);
- free(info->type);
- free(info);
-}
-
-float __get_elapsed_time()
-{
- static long start_time = 0;
- long endtime = 0;
- struct timeval tv;
-
- if (start_time == 0) {
- gettimeofday(&tv, NULL);
- start_time = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
- }
-
- gettimeofday(&tv, NULL);
- endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
-
- return (endtime - start_time)/1000.0;
-}
-
-#define _LOG(fmt, arg...) do { \
- int fd = 0; \
- FILE *file = NULL; \
- file = fopen(FOTA_RESULT_FILE, "a"); \
- if (file == NULL) break; \
- fprintf(file, "[PKG_FOTA][%5d][%10.3fs] "fmt"", getpid(), \
- __get_elapsed_time(), ##arg); \
- fflush(file); \
- fd = fileno(file); \
- fsync(fd); \
- fclose(file); \
- fprintf(stderr, "[PKG_FOTA][%5d][%10.3fs] "fmt"", getpid(), \
- __get_elapsed_time(), ##arg); \
-} while (0)
-
-int remove_directory(const char *path)
-{
- DIR *dir;
- struct dirent *entry;
- size_t path_len = strlen(path);
- int ret = 0;
- int iterate_ret;
- char buf[BUF_SIZE] = {0};
- size_t len;
- struct stat statbuf;
-
- dir = opendir(path);
- if (!dir)
- return -1;
-
- while (!ret && (entry = readdir(dir))) {
- iterate_ret = -1;
-
- if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
- continue;
-
- len = path_len + strlen(entry->d_name) + 2;
- snprintf(buf, len, "%s/%s", path, entry->d_name);
-
- if (!stat(buf, &statbuf)) {
- if (S_ISDIR(statbuf.st_mode))
- iterate_ret = remove_directory(buf);
- else
- iterate_ret = unlink(buf);
- }
- ret = iterate_ret;
- }
-
- closedir(dir);
- if (!ret)
- ret = rmdir(path);
-
- return ret;
-}
-
-static void __iter_cb(gpointer key, gpointer value, gpointer user_data)
-{
-
- FILE *file;
- char *pkgid;
- char *version;
- char *type;
- char pkg_info[BUF_SIZE];
- pkgmgrinfo_pkginfo_h info;
-
- if (user_data == NULL || key == NULL)
- return;
-
- file = user_data;
- pkgid = key;
-
- if (pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &info)) {
- _LOGE("failed to get pkginfo of %s\n", pkgid);
- return;
- }
-
- if (pkgmgrinfo_pkginfo_get_version(info, &version)) {
- pkgmgrinfo_pkginfo_destroy_pkginfo(info);
- return;
- }
-
- if (pkgmgrinfo_pkginfo_get_type(info, &type)) {
- pkgmgrinfo_pkginfo_destroy_pkginfo(info);
- return;
- }
-
- snprintf(pkg_info, BUF_SIZE,
- "package=\"%s\"\tversion=\"%s\"\ttype=\"%s\":\n",
- pkgid, version, type);
- fwrite(pkg_info, 1, strlen(pkg_info), file);
- pkgmgrinfo_pkginfo_destroy_pkginfo(info);
-}
-
-static void __make_preload_rw_list(GHashTable *preload_rw_table)
-{
- if (preload_rw_table == NULL) {
- _LOG("preload_rw_table is null\n");
- return;
- }
- FILE *file = NULL;
-
- char buf[BUF_SIZE];
- char tmp_path[BUF_SIZE];
- snprintf(tmp_path, BUF_SIZE, "%s.tmp", ALL_PRELOAD_RW_PKG_LIST);
-
- if (rename(ALL_PRELOAD_RW_PKG_LIST, tmp_path)) {
- if (errno != ENOENT)
- _LOG("can not backup preload rw pkg list: %d", errno);
- }
-
- file = fopen(ALL_PRELOAD_RW_PKG_LIST, "w");
- if (file == NULL) {
- _LOG("can not open [%s]: %s\n", ALL_PRELOAD_RW_PKG_LIST,
- strerror_r(errno, buf, sizeof(buf)));
- return;
- }
- g_hash_table_foreach(preload_rw_table, __iter_cb, file);
- fsync(fileno(file));
- fclose(file);
- if (remove(tmp_path))
- _LOG("cannot remove backup file(%s): %d", tmp_path, errno);
-}
-
-static int __is_dir(const char *dirname)
-{
- struct stat stFileInfo;
-
- retvm_if(dirname == NULL, -1, "dirname == NULL\n");
- retvm_if(stat(dirname, &stFileInfo) < 0, -1,
- "stFileInfo is not enough\n");
-
- if (S_ISDIR(stFileInfo.st_mode))
- return 0;
- return -1;
-}
-
-static int __xsystem(const char *argv[])
-{
- int status = 0;
- pid_t pid;
- pid = fork();
- switch (pid) {
- case -1:
- perror("fork failed");
- return -1;
- case 0:
- /* child */
- execvp(argv[0], (char *const *)argv);
- _exit(-1);
- default:
- /* parent */
- break;
- }
- if (waitpid(pid, &status, 0) == -1) {
- perror("waitpid failed");
- return -1;
- }
- if (WIFSIGNALED(status)) {
- perror("signal");
- return -1;
- }
- if (!WIFEXITED(status)) {
- /* shouldn't happen */
- perror("should not happen");
- return -1;
- }
- return WEXITSTATUS(status);
-}
-
-static int __check_pkgmgr_fota_dir()
-{
- int ret = 0;
-
- if (__is_dir(PKGMGR_FOTA_PATH) < 0) {
- const char *mkdir_argv[] = { "/bin/mkdir",
- "-p", PKGMGR_FOTA_PATH, NULL };
- ret = __xsystem(mkdir_argv);
- retvm_if(ret != 0, -1, "mkdir_argv error [%d]\n", ret);
- }
-
- return 0;
-}
-
-static int __remove_pkgid_list()
-{
- int ret = 0;
-
- if (access(FOTA_RESULT_FILE, R_OK) == 0) {
- ret = remove(FOTA_RESULT_FILE);
- err_if(ret < 0, "remove[%s] failed", FOTA_RESULT_FILE);
- }
-
- if (access(PKGID_LIST_FROM_DB_FILE, R_OK) == 0) {
- ret = remove(PKGID_LIST_FROM_DB_FILE);
- err_if(ret < 0, "remove[%s] failed", PKGID_LIST_FROM_DB_FILE);
- }
-
- if (access(PKGID_LIST_FROM_XML_FILE, R_OK) == 0) {
- ret = remove(PKGID_LIST_FROM_XML_FILE);
- err_if(ret < 0, "remove[%s] failed", PKGID_LIST_FROM_XML_FILE);
- }
-
- return 0;
-}
-
-static int __make_pkgid_list(const char *file_path, char *pkgid,
- char *version, char *type, bool is_update)
-{
- FILE *fp;
-
- if (NULL == pkgid)
- return 0;
-
- fp = fopen(file_path, "a+");
- if (NULL == fp)
- return -1;
-
- fprintf(fp, "%s\"%s\" %s\"%s\" %s\"%s\" %s\"%s\":\n",
- TOKEN_PKGID_STR, pkgid,
- TOKEN_VERSION_STR, version,
- TOKEN_TYPE_STR, type,
- TOKEN_UPDATE_STR, (is_update) ? "true" : "false");
-
- fclose(fp);
-
- return 0;
-}
-
-static int __insert_preload_rw_table(GHashTable *preload_rw_table,
- const char *pkgid, const char *version, const char *type)
-{
- struct pkginfo *info;
- char *package;
-
- info = calloc(1, sizeof(struct pkginfo));
- if (info == NULL) {
- _LOGE("out of memory");
- return -1;
- }
-
- info->pkgid = strdup(pkgid);
- if (info->pkgid == NULL) {
- _LOGE("out of memory");
- __free_pkginfo((struct pkginfo *)info);
- return -1;
- }
-
- info->version = strdup(version);
- if (info->version == NULL) {
- _LOGE("out of memory");
- __free_pkginfo((struct pkginfo *)info);
- return -1;
- }
-
- info->type = strdup(type);
- if (info->type == NULL) {
- _LOGE("out of memory");
- __free_pkginfo((struct pkginfo *)info);
- return -1;
- }
-
- package = strdup(pkgid);
- if (package == NULL) {
- _LOGE("out of memory");
- __free_pkginfo((struct pkginfo *)info);
- return -1;
- }
-
- g_hash_table_insert(preload_rw_table, package, info);
- return 0;
-}
-
-static int __delete_preload_rw_table(GHashTable *preload_rw_table,
- const char *pkgid)
-{
- gboolean removed;
- removed = g_hash_table_remove(preload_rw_table, pkgid);
- return removed ? 0 : -1;
-}
-
-static int __pkgid_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
-{
- int ret = -1;
- char *pkgid = NULL;
- char *version = NULL;
- char *type = NULL;
- bool is_update = false;
-
- ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- err_if(ret < 0, "pkgmgrinfo_pkginfo_get_pkgid failed");
-
- ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
- err_if(ret < 0, "pkgmgrinfo_pkginfo_get_version failed");
-
- ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
- err_if(ret < 0, "pkgmgrinfo_pkginfo_get_type failed");
-
- ret = pkgmgrinfo_pkginfo_is_update(handle, &is_update);
- err_if(ret < 0, "pkgmgrinfo_pkginfo_is_update failed");
-
- ret = __make_pkgid_list((char *)user_data, pkgid,
- version, type, is_update);
- return ret;
-}
-
-static int __preload_rw_pkgid_list_cb(const pkgmgrinfo_pkginfo_h handle,
- void *user_data)
-{
- int ret;
- char *pkgid;
- char *version;
- char *type;
- GHashTable *preload_rw_table = (GHashTable *)user_data;
-
- ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (ret < 0) {
- _LOGE("pkgmgrinfo_pkginfo_get_pkgid failed\n");
- return -1;
- }
-
- ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
- if (ret < 0) {
- _LOGE("pkgmgrinfo_pkginfo_get_version failed\n");
- return -1;
- }
-
- ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
- if (ret < 0) {
- _LOGE("pkgmgrinfo_pkginfo_get_type failed\n");
- return -1;
- }
-
- ret = __insert_preload_rw_table(preload_rw_table, pkgid, version, type);
- if (ret < 0) {
- _LOGE("__insert_preload_rw_table failed\n");
- return -1;
- }
-
- return 0;
-}
-
-static void __str_trim(char *input)
-{
- char *trim_str = input;
-
- if (input == NULL)
- return;
-
- while (*input != 0) {
- if (!isspace(*input)) {
- *trim_str = *input;
- trim_str++;
- }
- input++;
- }
-
- *trim_str = 0;
- return;
-}
-
-static char *__getvalue(const char *pBuf, const char *pKey, int depth)
-{
- const char *p = NULL;
- const char *pStart = NULL;
- const char *pEnd = NULL;
-
- p = strstr(pBuf, pKey);
- if (p == NULL)
- return NULL;
-
- pStart = p + strlen(pKey) + depth;
- pEnd = strchr(pStart, SEPERATOR_END);
- if (pEnd == NULL) {
- pEnd = strchr(pStart, SEPERATOR_MID);
- if (pEnd == NULL)
- return NULL;
- }
-
- size_t len = pEnd - pStart;
- if (len <= 0)
- return NULL;
-
- char *pRes = (char *)malloc(len + 1);
- if (pRes == NULL) {
- _LOG("malloc failed.\n");
- return NULL;
- }
- strncpy(pRes, pStart, len);
- pRes[len] = 0;
-
- return pRes;
-}
-
-static int __compare_pkgid(char *file_path, char *fota_pkgid,
- char *fota_version, bool *is_updated)
-{
- retvm_if(file_path == NULL, -1, "file_path is null.\n");
- retvm_if(fota_pkgid == NULL, -1, "fota_pkgid is null.\n");
- retvm_if(fota_version == NULL, -1, "fota_version is null.\n");
-
- int ret = PKG_IS_NOT_EXIST;
- FILE *fp = NULL;
- char buf[BUF_SIZE] = {0};
- char *pkgid = NULL;
- char *version = NULL;
- char *update = NULL;
- int compare = PMINFO_VERSION_SAME;
-
- fp = fopen(file_path, "r");
- retvm_if(fp == NULL, -1, "Fail get : %s\n", file_path);
-
- while (fgets(buf, BUF_SIZE, fp) != NULL) {
- __str_trim(buf);
-
- pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
- if (pkgid == NULL) {
- _LOG("pkgid is null\n");
- continue;
- }
-
- version = __getvalue(buf, TOKEN_VERSION_STR, 1);
- if (version == NULL) {
- FREE_AND_NULL(pkgid);
- _LOG("compare_data is null\n");
- continue;
- }
-
- update = __getvalue(buf, TOKEN_UPDATE_STR, 1);
- if (update == NULL) {
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- _LOG("compare_data is null\n");
- continue;
- }
- if (!strncmp(update, "true", strlen("true")))
- *is_updated = true;
- else
- *is_updated = false;
-
- if (strcmp(pkgid, fota_pkgid) == 0) {
- ret = pkgmgrinfo_compare_package_version(version,
- fota_version, &compare);
- if (compare == PMINFO_VERSION_NEW) {
- _LOG("pkgid = %s, db version = %s, new package"
- " version = %s\n", pkgid, version,
- fota_version);
- _LOG("pkg is updated, need to upgrade\n");
-
- ret = PKG_IS_UPDATED;
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- FREE_AND_NULL(update);
- break;
- } else if (compare == PMINFO_VERSION_OLD) {
- ret = PKG_IS_OLD;
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- FREE_AND_NULL(update);
- break;
- }
-
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- FREE_AND_NULL(update);
- ret = PKG_IS_SAME;
- break;
- }
-
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- FREE_AND_NULL(update);
- memset(buf, 0x00, BUF_SIZE);
- }
-
- if (fp != NULL)
- fclose(fp);
-
- return ret;
-}
-
-static bool __check_deleted_pkg(GHashTable *preload_rw_table,
- const char *fota_pkgid)
-{
- if (g_hash_table_contains(preload_rw_table, fota_pkgid))
- return true;
- return false;
-}
-
-char *__manifest_to_package(const char *manifest)
-{
- char *package;
-
- if (manifest == NULL)
- return NULL;
-
- package = strdup(manifest);
- if (package == NULL)
- return NULL;
-
- if (!strstr(package, ".xml")) {
- _LOG("%s is not a manifest file \n", manifest);
- free(package);
- return NULL;
- }
-
- return package;
-}
-
-static void __send_args_to_backend(const char *pkgid, const char *pkgtype,
- int operation)
-{
- int ret = 0;
-
- long starttime;
- long endtime;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
- char *query;
- char backend_cmd[BUF_SIZE];
- const char *new_pkgtype;
- const char tpk_pkgtype[] = "tpk";
-
- const char *preload_rw[] = { backend_cmd, "-y", pkgid,
- "--preload-rw", NULL };
- const char *install_ro[] = { backend_cmd, "-y", pkgid,
- "--preload", "--partial-rw", NULL };
- const char *uninstall_ro[] = { backend_cmd, "-d", pkgid,
- "--preload", "--force-remove",
- "--partial-rw", NULL };
- const char *uninstall_ro_keeprwdata[] = { backend_cmd, "-d", pkgid,
- "--preload", "--force-remove",
- "--keep-rwdata", NULL };
- const char *uninstall_ro_update[] = { backend_cmd, "-d",
- pkgid, "--keep-rwdata", NULL };
- const char *db_cmd[] = {"/usr/bin/sqlite3",
- NULL, NULL, NULL};
-
- if (operation == PKG_NEED_NOTHING)
- return;
-
- if (!strcmp(pkgtype, "rpm"))
- new_pkgtype = tpk_pkgtype;
- else
- new_pkgtype = pkgtype;
-
- snprintf(backend_cmd, sizeof(backend_cmd), "/usr/bin/%s-backend",
- new_pkgtype);
-
- switch (operation) {
- case PKG_NEED_INSTALL:
- case PKG_NEED_ROUPDATE:
- ret = __xsystem(install_ro);
- break;
- case PKG_NEED_UNINSTALL:
- ret = __xsystem(uninstall_ro);
- break;
- case PKG_NEED_UPDATE_TO_RW:
- query = sqlite3_mprintf(
- "UPDATE package_info SET " \
- "package_preload='false', " \
- "package_system='false' "\
- "WHERE package=%Q", pkgid);
- db_cmd[1] = strdup(DBPATH);
- db_cmd[2] = query;
- ret = __xsystem(db_cmd);
- FREE_AND_NULL(db_cmd[1]);
- sqlite3_free(query);
- break;
- case PKG_NEED_RWUNINSTALL:
- case PKG_NEED_UPDATE_TO_RO:
- ret = __xsystem(uninstall_ro_update);
- break;
- case PKG_NEED_RO_DBREMOVE:
- query = sqlite3_mprintf(
- "PRAGMA foreign_keys=on; " \
- "DELETE FROM package_info " \
- "WHERE package=%Q", pkgid);
- db_cmd[1] = strdup(DBPATH);
- db_cmd[2] = query;
- ret = __xsystem(db_cmd);
- FREE_AND_NULL(db_cmd[1]);
- sqlite3_free(query);
- break;
- case PKG_NEED_PRELOADRW_INSTALL:
- ret = __xsystem(preload_rw);
- break;
- case PKG_NEED_RO_UNINSTALL_KEEPRWDATA:
- ret = __xsystem(uninstall_ro_keeprwdata);
- break;
- }
-
- gettimeofday(&tv, NULL);
- endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
-
- _LOG("result[%ld ms, %d] \t Pkgid[%s] \n",
- (endtime - starttime), ret, pkgid);
-}
-
-int __child_element(xmlTextReaderPtr reader, int depth)
-{
- int ret = xmlTextReaderRead(reader);
- int cur = xmlTextReaderDepth(reader);
- while (ret == 1) {
- switch (xmlTextReaderNodeType(reader)) {
- case XML_READER_TYPE_ELEMENT:
- if (cur == depth + 1)
- return 1;
- break;
- case XML_READER_TYPE_TEXT:
- /*text is handled by each function separately*/
- if (cur == depth + 1)
- return 0;
- break;
- case XML_READER_TYPE_END_ELEMENT:
- if (cur == depth)
- return 0;
- break;
- default:
- if (cur <= depth)
- return 0;
- break;
- }
-
- ret = xmlTextReaderRead(reader);
- cur = xmlTextReaderDepth(reader);
- }
- return ret;
-}
-
-char *__find_info_from_xml(const char *manifest, const char *find_info)
-{
- retvm_if(manifest == NULL, NULL, "manifest is null.\n");
- retvm_if(find_info == NULL, NULL, "find_info is null.\n");
-
- const xmlChar *node;
- xmlTextReaderPtr reader;
- char *info_val = NULL;
- xmlChar *tmp = NULL;
-
- reader = xmlReaderForFile(manifest, NULL, 0);
-
- if (reader) {
- if (__child_element(reader, -1)) {
- node = xmlTextReaderConstName(reader);
- if (!node) {
- printf("xmlTextReaderConstName value is NULL\n");
- goto end;
- }
-
- if (!strcmp(ASCII(node), "manifest")) {
- tmp = xmlTextReaderGetAttribute(reader,
- XMLCHAR(find_info));
- if (tmp) {
- FREE_AND_STRDUP(ASCII(tmp), info_val);
- if (info_val == NULL)
- printf("Malloc Failed\n");
- FREE_AND_NULL(tmp);
- }
- } else {
- printf("Manifest Node is not found\n");
- }
- }
- } else {
- printf("xmlReaderForFile value is NULL\n");
- }
-
-end:
- if (reader)
- xmlFreeTextReader(reader);
-
- return info_val;
-}
-
-static int __find_preload_pkgid_from_xml(const char *file_path,
- const char *xml_directory)
-{
- retvm_if(file_path == NULL, -1, "file_path is NULL.\n");
- retvm_if(xml_directory == NULL, -1, "xml_directory is NULL.\n");
-
- int ret = 0;
- char buf[BUF_SIZE] = {0};
- DIR *dir;
- struct dirent *entry = NULL;
-
- dir = opendir(xml_directory);
- if (!dir) {
- if (strerror_r(errno, buf, sizeof(buf)) == 0)
- _LOG("Failed to access the [%s] because %s\n",
- xml_directory, buf);
- return -1;
- }
-
- while ((entry = readdir(dir)) != NULL) {
- char *manifest = NULL;
- char *pkgid = NULL;
- char *version = NULL;
- char *type = NULL;
-
- if (entry->d_name[0] == '.') continue;
-
- manifest = __manifest_to_package(entry->d_name);
- if (!manifest) {
- _LOG("Failed to convert file to xml[%s]\n",
- entry->d_name);
- continue;
- }
-
- snprintf(buf, sizeof(buf), "%s/%s", xml_directory, manifest);
-
- /*Get the package name from manifest file*/
- pkgid = __find_info_from_xml(buf, "package");
- if (pkgid == NULL) {
- FREE_AND_NULL(manifest);
- continue;
- }
-
- version = __find_info_from_xml(buf, "version");
- if (version == NULL)
- version = strdup("0.0.1");
-
- type = __find_info_from_xml(buf, "type");
- if (type == NULL)
- type = strdup("tpk");
-
- ret = __make_pkgid_list((char *)file_path, pkgid,
- version, type, false);
- if (ret < 0)
- _LOG("Make file Fail : %s => %s, %s\n",
- buf, pkgid, version);
-
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- FREE_AND_NULL(manifest);
- FREE_AND_NULL(type);
- }
-
- closedir(dir);
-
- return 0;
-}
-
-static int __find_preload_pkgid_from_db(const char *file_path)
-{
- retvm_if(file_path == NULL, -1, "file_path is NULL.\n");
-
- int ret = 0;
- pkgmgrinfo_pkginfo_filter_h handle = NULL;
-
- ret = pkgmgrinfo_pkginfo_filter_create(&handle);
- retvm_if(ret != PMINFO_R_OK, -1,
- "pkginfo filter handle create failed\n");
-
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, 1);
- tryvm_if(ret < 0, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
- "(PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD) failed\n");
-
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM, 1);
- tryvm_if(ret < 0, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
- "(PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM) failed\n");
-
- ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle,
- __pkgid_list_cb, (void *)file_path);
- err_if(ret < 0,
- "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() failed\n");
-
-catch:
- pkgmgrinfo_pkginfo_filter_destroy(handle);
- return ret;
-}
-
-static int __find_preload_rw_pkgid_from_db(GHashTable *preload_rw_table)
-{
- int ret;
- pkgmgrinfo_pkginfo_filter_h handle;
-
- ret = pkgmgrinfo_pkginfo_filter_create(&handle);
- retvm_if(ret != PMINFO_R_OK, -1,
- "pkginfo filter handle create failed\n");
-
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, 1);
- tryvm_if(ret != PMINFO_R_OK, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
- "(PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD) failed\n");
-
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, 1);
- tryvm_if(ret != PMINFO_R_OK, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
- "(PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE) failed\n");
-
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_READONLY, 0);
- tryvm_if(ret != PMINFO_R_OK, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
- "(PMINFO_PKGINFO_PROP_PACKAGE_READONLY) failed\n");
-
- ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
- PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM, 0);
- tryvm_if(ret != PMINFO_R_OK, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
- "(PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM) failed\n");
-
- ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle,
- __preload_rw_pkgid_list_cb, (void *)preload_rw_table);
- err_if(ret != PMINFO_R_OK,
- "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() failed\n");
-
- ret = 0;
-catch:
- pkgmgrinfo_pkginfo_filter_destroy(handle);
- return ret;
-}
-
-static int __find_matched_pkgid_from_list(const char *source_file,
- const char *target_file)
-{
- retvm_if(source_file == NULL, -1, "source_file is NULL.\n");
- retvm_if(target_file == NULL, -1, "target_file is NULL.\n");
-
- FILE *fp = NULL;
- char buf[BUF_SIZE] = {0};
- char *pkgid = NULL;
- char *version = NULL;
- char *pkgtype = NULL;
-
- int same_pkg_cnt = 0;
- int update_pkg_cnt = 0;
- int insert_pkg_cnt = 0;
- int total_pkg_cnt = 0;
-
- int compare_result = 0;
- int operation;
-
- bool db_update;
-
- fp = fopen(source_file, "r");
- retvm_if(fp == NULL, -1, "Fail get : %s\n", source_file);
-
- _LOG("Searching...... inserted or Updated package \n");
-
- while (fgets(buf, BUF_SIZE, fp) != NULL) {
- __str_trim(buf);
-
- pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
- if (pkgid == NULL)
- continue;
-
- version = __getvalue(buf, TOKEN_VERSION_STR, 1);
- if (version == NULL) {
- free(pkgid);
- continue;
- }
- pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1);
- if (pkgtype == NULL) {
- free(version);
- free(pkgid);
- continue;
- }
-
- operation = PKG_NEED_NOTHING;
- compare_result = __compare_pkgid((char *)target_file, pkgid,
- version, &db_update);
- if (compare_result == PKG_IS_NOT_EXIST) {
- _LOG("pkgid[%s] is installed, Start install\n", pkgid);
- operation = PKG_NEED_INSTALL;
- insert_pkg_cnt++;
- } else if (compare_result == PKG_IS_SAME) {
- if (db_update) {
- operation = PKG_NEED_RWUNINSTALL;
- update_pkg_cnt++;
- } else {
- operation = PKG_NEED_NOTHING;
- same_pkg_cnt++;
- }
- } else if (compare_result == PKG_IS_UPDATED) {
- if (db_update) {
- operation = PKG_NEED_UPDATE_TO_RO;
- } else {
- operation = PKG_NEED_ROUPDATE;
- }
- update_pkg_cnt++;
- }
-
- total_pkg_cnt++;
- __send_args_to_backend(pkgid, pkgtype, operation);
-
- memset(buf, 0x00, BUF_SIZE);
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- FREE_AND_NULL(pkgtype);
- }
-
- _LOG("-------------------------------------------------------\n");
- _LOG("[Total pkg=%d, same pkg=%d, updated pkg=%d, "
- "inserted package=%d]\n",
- total_pkg_cnt, same_pkg_cnt, update_pkg_cnt, insert_pkg_cnt);
- _LOG("-------------------------------------------------------\n");
-
- if (fp != NULL)
- fclose(fp);
-
- return 0;
-}
-
-static bool __find_pkgid_from_rw_list(const char *pkgid)
-{
- if (pkgid == NULL)
- return false;
-
- bool ret = false;
- FILE *fp = NULL;
- char buf[BUF_SIZE] = {0};
- char *preload_rw_pkgid = NULL;
-
- fp = fopen(PRELOAD_RW_PKG_LIST, "r");
- retvm_if(fp == NULL, -1, "Failed to open : %s\n", PRELOAD_RW_PKG_LIST);
-
- while (fgets(buf, BUF_SIZE, fp) != NULL) {
- __str_trim(buf);
-
- preload_rw_pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
- if (preload_rw_pkgid == NULL) {
- _LOG("Failed to get pkgidstring[%s]\n", buf);
- continue;
- }
-
- if (strcmp(pkgid, preload_rw_pkgid) == 0) {
- _LOG("pkgid[%s] is converted to preload rw pkg\n", pkgid);
- FREE_AND_NULL(preload_rw_pkgid);
- ret = true;
- break;
- }
- FREE_AND_NULL(preload_rw_pkgid);
- }
-
- fclose(fp);
- return ret;
-}
-
-static int __unzip_file_only_to_path(char *dest_path, char *unzip_to)
-{
- const char *unzip_argv[] = { "/usr/bin/unzip", "-joXqq",
- OPT_ZIP_FILE, dest_path, "-d", unzip_to, NULL };
- int ret = __xsystem(unzip_argv);
-
- return ret;
-}
-
-static int __unzip_files(char *dest_path)
-{
- const char *unzip_argv[] = { "/usr/bin/unzip", "-oXqq",
- OPT_ZIP_FILE, dest_path, "-d", "/", NULL };
- int ret = __xsystem(unzip_argv);
-
- return ret;
-}
-
-static int __install_preload_rw(const char *pkgid, const char *version,
- const char *pkgtype, GHashTable *preload_rw_table)
-{
- if (pkgid == NULL || version == NULL || pkgtype == NULL)
- return -1;
-
- int index;
- int ret;
- char buf[BUF_SIZE] = {0};
-
- /* copy modified manifest */
- snprintf(buf, BUF_SIZE, "%s/%s.xml",
- (tzplatform_getenv(TZ_SYS_RW_PACKAGES) + 1), pkgid);
- ret = __unzip_files(buf);
- if (ret != 0) {
- _LOG("Failed to unzip file from backup[%s]\n", buf);
- return ret;
- }
-
- /* copy stored signature */
- snprintf(buf, BUF_SIZE, "%s/signatures/%s.txt",
- (tzplatform_getenv(TZ_SYS_SHARE) + 1), pkgid);
- ret = __unzip_files(buf);
- if (ret != 0) {
- _LOG("Failed to unzip file from backup[%s]\n", buf);
- return ret;
- }
-
- /* copy RO and RW components */
- for (index = 0; index < BUF_SIZE; index++) {
- if (unzip_path[index] == NULL)
- break;
-
- snprintf(buf, BUF_SIZE, "%s/%s/*", unzip_path[index], pkgid);
- ret = __unzip_files(buf);
- if (ret != 0) {
- _LOG("Failed to unzip file from backup[%s]\n", buf);
- return ret;
- }
- }
-
- ret = __insert_preload_rw_table(preload_rw_table, pkgid, version,
- pkgtype);
- retvm_if(ret < 0, -1, "__insert_preload_rw_table fail\n");
-
- __send_args_to_backend(pkgid, pkgtype, PKG_NEED_PRELOADRW_INSTALL);
- return ret;
-}
-
-static void __convert_preload_to_rw(const char *pkgid, const char *version,
- const char *pkgtype, GHashTable *preload_rw_table)
-{
- if (pkgid == NULL || version == NULL || pkgtype == NULL)
- return;
- char buf[BUF_SIZE] = {0};
- int ret;
-
- snprintf(buf, BUF_SIZE, "%s/skel/apps_rw/%s",
- tzplatform_getenv(TZ_SYS_ETC), pkgid);
-
- __send_args_to_backend(pkgid, pkgtype, PKG_NEED_RO_UNINSTALL_KEEPRWDATA);
- ret = remove_directory(buf);
- if (ret != 0)
- _LOG("Failed to remove directory[%s]\n", buf);
-
- ret = __install_preload_rw(pkgid, version, pkgtype, preload_rw_table);
- if (ret != 0) {
- _LOG("Failed install preload rw pkg[%s]\n", pkgid);
- return;
- }
-}
-
-static int __find_deleted_pkgid_from_list(const char *source_file,
- const char *target_file, GHashTable *preload_rw_table)
-{
- retvm_if(source_file == NULL, -1, "source_file is NULL.\n");
- retvm_if(target_file == NULL, -1, "target_file is NULL.\n");
-
- FILE *fp = NULL;
- char buf[BUF_SIZE] = {0};
- char *pkgid;
- char *version;
- char *pkgtype = NULL;
- char *update = NULL;
- bool is_preload_rw_pkg;
- bool xml_update;
- int deleted_pkg_cnt = 0;
- int modified_pkg_cnt = 0;
- int total_pkg_cnt = 0;
- int compare_result = 0;
-
- fp = fopen(source_file, "r");
- retvm_if(fp == NULL, -1, "Fail get : %s\n", source_file);
-
- _LOG("Searching...... deleted package \n");
-
- while (fgets(buf, BUF_SIZE, fp) != NULL) {
- __str_trim(buf);
-
- pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
- version = __getvalue(buf, TOKEN_VERSION_STR, 1);
- pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1);
- if (pkgid == NULL || version == NULL || pkgtype == NULL) {
- _LOG("Failed to get pkg info from string[%s]\n", buf);
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- FREE_AND_NULL(pkgtype);
- continue;
- }
-
- compare_result = __compare_pkgid((char *)target_file, pkgid,
- version, &xml_update);
- if (compare_result == PKG_IS_NOT_EXIST) {
- update = __getvalue(buf, TOKEN_UPDATE_STR, 1);
- if (update == NULL) {
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- FREE_AND_NULL(pkgtype);
- continue;
- }
-
- is_preload_rw_pkg = __find_pkgid_from_rw_list(pkgid);
-
- if (!strncmp(update, "false", strlen("false"))) {
- if (is_preload_rw_pkg) {
- __convert_preload_to_rw(pkgid, version,
- pkgtype,
- preload_rw_table);
- modified_pkg_cnt++;
- } else {
- __send_args_to_backend(pkgid, pkgtype,
- PKG_NEED_UNINSTALL);
- deleted_pkg_cnt++;
- }
- } else {
- __send_args_to_backend(pkgid, pkgtype,
- PKG_NEED_UPDATE_TO_RW);
- modified_pkg_cnt++;
- if (is_preload_rw_pkg) {
- __send_args_to_backend(pkgid, pkgtype,
- PKG_NEED_RWUNINSTALL);
- __install_preload_rw(pkgid, version,
- pkgtype,
- preload_rw_table);
- }
- }
- }
- total_pkg_cnt++;
-
- memset(buf, 0x00, BUF_SIZE);
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- FREE_AND_NULL(pkgtype);
- FREE_AND_NULL(update);
- }
-
- _LOG("-------------------------------------------------------\n");
- _LOG("[Total pkg=%d, deleted package=%d, modified package=%d]\n",
- total_pkg_cnt, deleted_pkg_cnt, modified_pkg_cnt);
- _LOG("-------------------------------------------------------\n");
-
- if (fp != NULL)
- fclose(fp);
-
- return 0;
-
-}
-
-static int __get_pkgid_list_from_db_and_xml()
-{
- _LOG("=======================================================\n");
- _LOG("RO preload package fota\n");
- _LOG("=======================================================\n");
-
- int ret = 0;
- char updated_preload_rw_list[BUF_SIZE];
-
- /*get pkg info on pkgmgr db, it means old version */
- ret = __find_preload_pkgid_from_db(PKGID_LIST_FROM_DB_FILE);
- retvm_if(ret < 0, -1, "__find_preload_pkgid_from_db fail.\n");
-
- _LOG("Make pkgid list from db success!! \n");
-
- /*get pkg info on xml, it means new version */
- ret = __find_preload_pkgid_from_xml(PKGID_LIST_FROM_XML_FILE,
- USR_MANIFEST_DIRECTORY);
- retvm_if(ret < 0, -1, "__find_preload_pkgid_from_xml fail.\n");
-
- _LOG("Make pkgid list from xml success!! \n");
-
-
- /*get preload rw pkg info on xml from opt.zip, it means new version */
- snprintf(updated_preload_rw_list, sizeof(updated_preload_rw_list), "%s",
- ALL_PRELOAD_RW_PKG_LIST);
- ret = __unzip_file_only_to_path(updated_preload_rw_list + 1,
- (char *)PKGMGR_FOTA_PATH);
- if (ret != 0) {
- _LOG("Failed to unzip file from backup[%s]\n",
- updated_preload_rw_list);
- return ret;
- }
-
- _LOG("Make rw pkgid list from xml success!! \n");
-
- return 0;
-}
-
-static int __process_ro_fota(GHashTable *preload_rw_table)
-{
- int ret;
- long starttime;
- long endtime;
- struct timeval tv;
-
- xmlInitParser();
-
- gettimeofday(&tv, NULL);
- starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
-
- /* find deleted pkgid */
- ret = __find_deleted_pkgid_from_list(PKGID_LIST_FROM_DB_FILE,
- PKGID_LIST_FROM_XML_FILE, preload_rw_table);
- err_if(ret < 0, "__find_deleted_pkgid_from_list fail.\n");
-
- /* find updated, inserted pkgid */
- ret = __find_matched_pkgid_from_list(PKGID_LIST_FROM_XML_FILE,
- PKGID_LIST_FROM_DB_FILE);
- err_if(ret < 0, "__find_matched_pkgid_from_list fail.\n");
-
- gettimeofday(&tv, NULL);
- endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
-
- _LOG("=======================================================\n");
- _LOG("End RO process[time : %ld ms]\n", endtime - starttime);
- _LOG("=======================================================\n");
-
- xmlCleanupParser();
-
- return 0;
-}
-
-static int __process_rw_fota(GHashTable *preload_rw_table)
-{
- FILE *fp = NULL;
- char buf[BUF_SIZE] = {0};
- int ret = -1;
- char *pkgid = NULL;
- char *list_version = NULL;
- char *db_stored_version = NULL;
- char *pkgtype = NULL;
- char *version = NULL;
- pkgmgrinfo_pkginfo_h handle = NULL;
- int compare = PMINFO_VERSION_SAME;
- long total_time = 0;
-
- long starttime;
- long endtime;
- struct timeval tv;
- bool is_deleted_pkg;
-
- _LOG("=======================================================\n");
- _LOG("RW preload package fota\n");
- _LOG("=======================================================\n");
-
- fp = fopen(PRELOAD_RW_PKG_LIST, "r");
- retvm_if(fp == NULL, -1, "Fail get : %s\n", PRELOAD_RW_PKG_LIST);
-
- while (fgets(buf, BUF_SIZE, fp) != NULL) {
- __str_trim(buf);
-
- gettimeofday(&tv, NULL);
- starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
-
- pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
- if (pkgid == NULL)
- continue;
-
- ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
- if (ret == PMINFO_R_OK) {
- list_version = __getvalue(buf, TOKEN_VERSION_STR, 1);
- if (list_version == NULL) {
- FREE_AND_NULL(pkgid);
- continue;
- }
- ret = pkgmgrinfo_pkginfo_get_version(handle, &db_stored_version);
- ret = pkgmgrinfo_compare_package_version(db_stored_version,
- list_version, &compare);
- if (ret != PMINFO_R_OK) {
- _LOG("can not compare pkg version[%s]\n", pkgid);
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- handle = NULL;
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(list_version);
- continue;
- }
-
- if (compare != PMINFO_VERSION_NEW) {
- /* package version is not update on FOTA. */
- _LOG("pkgid[%s] is not updated\n", pkgid);
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- handle = NULL;
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(list_version);
- continue;
- }
-
- _LOG("pkgid[%s] is updated, need to upgrade "
- "from version [%s] to [%s]\n",
- pkgid, db_stored_version, list_version);
- } else {
- is_deleted_pkg = __check_deleted_pkg(preload_rw_table, pkgid);
- if (is_deleted_pkg) {
- _LOG("pkgid[%s] is deleted pkg\n", pkgid);
- __delete_preload_rw_table(preload_rw_table,
- pkgid);
- FREE_AND_NULL(pkgid);
- continue;
- }
- _LOG("pkgid[%s] is new\n", pkgid);
- }
-
- version = __getvalue(buf, TOKEN_VERSION_STR, 1);
- pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1);
- __install_preload_rw(pkgid, version, pkgtype, preload_rw_table);
-
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(pkgtype);
- FREE_AND_NULL(version);
-
- if (handle)
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-
- gettimeofday(&tv, NULL);
- endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
- total_time += (int)(endtime - starttime);
- _LOG("finish request [time : %d ms]\n",
- (int)(endtime - starttime));
- }
- fclose(fp);
-
- return 0;
-}
-
-static int __check_tmp_all_preload_rw_pkg_list()
-{
- char buf[BUF_SIZE];
- char tmp_path[BUF_SIZE];
- snprintf(tmp_path, BUF_SIZE, "%s.tmp", ALL_PRELOAD_RW_PKG_LIST);
- if (access(tmp_path, F_OK) == 0) {
- if (rename(tmp_path, ALL_PRELOAD_RW_PKG_LIST)) {
- _LOG("rename tmp all preload rw pkg list fail : %s\n",
- strerror_r(errno, buf, sizeof(buf)));
- return -1;
- }
- }
- return 0;
-}
-
-static int __fill_preload_rw_table(GHashTable *preload_rw_table)
-{
- FILE *fp;
- char buf[BUF_SIZE];
- char *pkgid;
- char *version;
- char *type;
-
- fp = fopen(ALL_PRELOAD_RW_PKG_LIST, "r");
- retvm_if(fp == NULL, -1, "Fail get : %s\n", ALL_PRELOAD_RW_PKG_LIST);
-
- while (fgets(buf, BUF_SIZE, fp) != NULL) {
- __str_trim(buf);
-
- pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
- if (pkgid == NULL) {
- _LOG("pkgid is null\n");
- continue;
- }
-
- version = __getvalue(buf, TOKEN_VERSION_STR, 1);
- if (version == NULL) {
- _LOG("version is null\n");
- version = strdup("");
- if (version == NULL) {
- _LOGE("out of memory\n");
- FREE_AND_NULL(pkgid);
- continue;
- }
- }
-
- type = __getvalue(buf, TOKEN_TYPE_STR, 1);
- if (type == NULL) {
- _LOG("type is null\n");
- type = strdup("");
- if (type == NULL) {
- _LOGE("out of memory\n");
- FREE_AND_NULL(version);
- FREE_AND_NULL(pkgid);
- continue;
- }
- }
-
- __insert_preload_rw_table(preload_rw_table, pkgid, version,
- type);
- FREE_AND_NULL(pkgid);
- FREE_AND_NULL(version);
- FREE_AND_NULL(type);
- }
- fclose(fp);
-
- return 0;
-}
-
-int main(int argc, char *argv[])
-{
- GHashTable *preload_rw_table;
- int ret = 0;
-
- /* check pkgmgr-fota dir, if it is not, then exit */
- ret = __check_pkgmgr_fota_dir();
- retvm_if(ret < 0, -1, "__check_pkgmgr_fota_dir is failed.\n");
-
- /* clean pkgid list file */
- ret = __remove_pkgid_list();
- err_if(ret < 0, "remove[%s] failed\n", FOTA_RESULT_FILE);
-
- /* get pkgid from orginal pkgmgr db */
- ret = __get_pkgid_list_from_db_and_xml();
- retvm_if(ret < 0, -1, "__get_pkgid_list_from_db_and_xml is failed.\n");
-
- //__get_pkginfo_from_opt();
-
- ret = __check_tmp_all_preload_rw_pkg_list();
- retvm_if(ret < 0, -1,
- "__check_tmp_all_preload_rw_pkg_list is failed.\n");
-
- preload_rw_table = g_hash_table_new_full(
- g_str_hash, g_str_equal, free, __free_pkginfo);
- if (__fill_preload_rw_table(preload_rw_table) < 0) {
- ret = __find_preload_rw_pkgid_from_db(preload_rw_table);
- retvm_if(ret < 0, -1, "__find_preload_rw_pkgid_from_db is failed\n");
- }
-
- if (argc == 1) {
- ret = __process_ro_fota(preload_rw_table);
- if (ret < 0) {
- g_hash_table_destroy(preload_rw_table);
- _LOGE("__process_ro_fota is failed.\n");
- return EXIT_FAILURE;
- }
- ret = __process_rw_fota(preload_rw_table);
- if (ret < 0) {
- g_hash_table_destroy(preload_rw_table);
- _LOGE("__process_rw_fota is failed.\n");
- return EXIT_FAILURE;
- }
- } else {
- if (strcmp(argv[1], "-rof") == 0) {
- ret = __process_ro_fota(preload_rw_table);
- if (ret < 0) {
- g_hash_table_destroy(preload_rw_table);
- _LOGE("__process_ro_fota is failed.\n");
- return EXIT_FAILURE;
- }
- } else if (strcmp(argv[1], "-rwf") == 0) {
- ret = __process_rw_fota(preload_rw_table);
- if (ret < 0) {
- g_hash_table_destroy(preload_rw_table);
- _LOGE("__process_rw_fota is failed.\n");
- return EXIT_FAILURE;
- }
- } else {
- fprintf(stderr, "not supported operand\n");
- }
- }
- __make_preload_rw_list(preload_rw_table);
- g_hash_table_destroy(preload_rw_table);
- return EXIT_SUCCESS;
-}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef PKG_FOTA_H_
-#define PKG_FOTA_H_
-
-
-#define TOKEN_TYPE_STR "type="
-#define TOKEN_PKGID_STR "package="
-#define TOKEN_VERSION_STR "version="
-#define TOKEN_OPERATION_STR "op="
-#define TOKEN_REMOVE_STR "removable="
-#define TOKEN_UPDATE_STR "update="
-
-#define SEPERATOR_END '"'
-#define SEPERATOR_MID ':'
-
-
-#define ASCII(s) (const char *)s
-#define XMLCHAR(s) (const xmlChar *)s
-
-#define BUF_SIZE 1024
-#define DIRECTORY_PERMISSION_755 0755
-#define FOTA_RESULT_FILE tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
- "pkgmgr/fota/result.txt")
-
-#ifndef FREE_AND_NULL
-#define FREE_AND_NULL(ptr) do { \
- if (ptr) { \
- free((void *)ptr); \
- ptr = NULL; \
- } \
-} while (0)
-#endif
-
-#ifndef FREE_AND_STRDUP
-#define FREE_AND_STRDUP(from, to) do { \
- if (to) free((void *)to); \
- if (from) to = strdup(from); \
-} while (0)
-#endif
-
-#define _LOGE(fmt, arg...) do { \
- int fd = 0;\
- FILE* file = NULL;\
- file = fopen(FOTA_RESULT_FILE, "a");\
- if (file == NULL) break;\
- fprintf(file, "[PKG_FOTA][%5d][err] "fmt"", getpid(), ##arg); \
- fflush(file);\
- fd = fileno(file);\
- fsync(fd);\
- fclose(file);\
- fprintf(stderr, "[PKG_FOTA][%5d][err] "fmt"", getpid(), ##arg); \
-} while (0)
-
-#define retvm_if(expr, val, fmt, arg...) do { \
- if (expr) { \
- _LOGE("(%s)"fmt, #expr, ##arg); \
- return (val); \
- } \
-} while (0)
-
-#define err_if(expr, fmt, arg...) do { \
- if (expr) { \
- _LOGE("(%s)"fmt, #expr, ##arg); \
- } \
-} while (0)
-
-#define tryvm_if(expr, val, fmt, arg...) do { \
- if (expr) { \
- _LOGE("(%s)"fmt, #expr, ##arg); \
- val; \
- goto catch; \
- } \
-} while (0)
-
-typedef enum {
- PKG_IS_NOT_EXIST = 0,
- PKG_IS_SAME,
- PKG_IS_UPDATED,
- PKG_IS_INSERTED,
- PKG_IS_OLD
-} COMPARE_RESULT;
-
-typedef enum {
- PKG_NEED_NOTHING = 0,
- PKG_NEED_INSTALL,
- PKG_NEED_UNINSTALL,
- PKG_NEED_ROUPDATE,
- PKG_NEED_UPDATE_TO_RW,
- PKG_NEED_RWUNINSTALL,
- PKG_NEED_UPDATE_TO_RO,
- PKG_NEED_RO_DBREMOVE,
- PKG_NEED_RO_UNINSTALL_KEEPRWDATA,
- PKG_NEED_PRELOADRW_INSTALL
-} UPGRADE_OPRATION;
-
-enum rpm_request_type {
- INSTALL_REQ,
- UNINSTALL_REQ,
- UPGRADE_REQ
-};
-
-#endif /* PKG_FOTA_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef PKG_FOTA_H_
+#define PKG_FOTA_H_
+
+
+#define TOKEN_TYPE_STR "type="
+#define TOKEN_PKGID_STR "package="
+#define TOKEN_VERSION_STR "version="
+#define TOKEN_OPERATION_STR "op="
+#define TOKEN_REMOVE_STR "removable="
+#define TOKEN_UPDATE_STR "update="
+
+#define SEPERATOR_END '"'
+#define SEPERATOR_MID ':'
+
+
+#define ASCII(s) (const char *)s
+#define XMLCHAR(s) (const xmlChar *)s
+
+#define BUF_SIZE 1024
+#define DIRECTORY_PERMISSION_755 0755
+#define FOTA_RESULT_FILE tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
+ "pkgmgr/fota/result.txt")
+
+#ifndef FREE_AND_NULL
+#define FREE_AND_NULL(ptr) do { \
+ if (ptr) { \
+ free((void *)ptr); \
+ ptr = NULL; \
+ } \
+} while (0)
+#endif
+
+#ifndef FREE_AND_STRDUP
+#define FREE_AND_STRDUP(from, to) do { \
+ if (to) free((void *)to); \
+ if (from) to = strdup(from); \
+} while (0)
+#endif
+
+#define _LOGE(fmt, arg...) do { \
+ int fd = 0;\
+ FILE* file = NULL;\
+ file = fopen(FOTA_RESULT_FILE, "a");\
+ if (file == NULL) break;\
+ fprintf(file, "[PKG_FOTA][%5d][err] "fmt"", getpid(), ##arg); \
+ fflush(file);\
+ fd = fileno(file);\
+ fsync(fd);\
+ fclose(file);\
+ fprintf(stderr, "[PKG_FOTA][%5d][err] "fmt"", getpid(), ##arg); \
+} while (0)
+
+#define retvm_if(expr, val, fmt, arg...) do { \
+ if (expr) { \
+ _LOGE("(%s)"fmt, #expr, ##arg); \
+ return (val); \
+ } \
+} while (0)
+
+#define err_if(expr, fmt, arg...) do { \
+ if (expr) { \
+ _LOGE("(%s)"fmt, #expr, ##arg); \
+ } \
+} while (0)
+
+#define tryvm_if(expr, val, fmt, arg...) do { \
+ if (expr) { \
+ _LOGE("(%s)"fmt, #expr, ##arg); \
+ val; \
+ goto catch; \
+ } \
+} while (0)
+
+typedef enum {
+ PKG_IS_NOT_EXIST = 0,
+ PKG_IS_SAME,
+ PKG_IS_UPDATED,
+ PKG_IS_INSERTED,
+ PKG_IS_OLD
+} COMPARE_RESULT;
+
+typedef enum {
+ PKG_NEED_NOTHING = 0,
+ PKG_NEED_INSTALL,
+ PKG_NEED_UNINSTALL,
+ PKG_NEED_ROUPDATE,
+ PKG_NEED_UPDATE_TO_RW,
+ PKG_NEED_RWUNINSTALL,
+ PKG_NEED_UPDATE_TO_RO,
+ PKG_NEED_RO_DBREMOVE,
+ PKG_NEED_RO_UNINSTALL_KEEPRWDATA,
+ PKG_NEED_PRELOADRW_INSTALL
+} UPGRADE_OPRATION;
+
+enum rpm_request_type {
+ INSTALL_REQ,
+ UNINSTALL_REQ,
+ UPGRADE_REQ
+};
+
+#endif /* PKG_FOTA_H_ */
--- /dev/null
+/*
+ * pkg-fota
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <iniparser.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <libxml/xmlreader.h>
+#include <sqlite3.h>
+
+#include <package-manager-types.h>
+#include <package-manager.h>
+#include <pkgmgr_parser.h>
+#include <pkgmgr-info.h>
+#include "include/pkg_upgrade.h"
+
+#include <tzplatform_config.h>
+
+#define USR_MANIFEST_DIRECTORY tzplatform_getenv(TZ_SYS_RO_PACKAGES)
+
+#define PKGMGR_FOTA_PATH tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
+ "pkgmgr/fota")
+#define PKGID_LIST_FROM_DB_FILE tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
+ "pkgmgr/fota/pkgid_list_from_db.txt")
+#define PKGID_LIST_FROM_XML_FILE \
+ tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
+ "pkgmgr/fota/pkgid_list_from_xml.txt")
+#define PRELOAD_RW_PKG_LIST \
+ tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
+ "pkgmgr/fota/.all_preload_rw_list")
+#define DBPATH tzplatform_mkpath(TZ_SYS_DB, "/.pkgmgr_parser.db")
+#define OPT_ZIP_FILE "/usr/system/RestoreDir/opt.zip"
+#define ALL_PRELOAD_RW_PKG_LIST "/opt/usr/share/.all_preload_rw_list"
+
+struct pkginfo {
+ char *pkgid;
+ char *version;
+ char *type;
+};
+
+static char *unzip_path[BUF_SIZE] = {
+ "opt/usr/globalapps",
+ "opt/etc/skel/apps_rw",
+ NULL
+};
+
+static void __free_pkginfo(gpointer data)
+{
+ struct pkginfo *info = (struct pkginfo *)data;
+ free(info->pkgid);
+ free(info->version);
+ free(info->type);
+ free(info);
+}
+
+float __get_elapsed_time()
+{
+ static long start_time = 0;
+ long endtime = 0;
+ struct timeval tv;
+
+ if (start_time == 0) {
+ gettimeofday(&tv, NULL);
+ start_time = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+ }
+
+ gettimeofday(&tv, NULL);
+ endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+
+ return (endtime - start_time)/1000.0;
+}
+
+#define _LOG(fmt, arg...) do { \
+ int fd = 0; \
+ FILE *file = NULL; \
+ file = fopen(FOTA_RESULT_FILE, "a"); \
+ if (file == NULL) break; \
+ fprintf(file, "[PKG_FOTA][%5d][%10.3fs] "fmt"", getpid(), \
+ __get_elapsed_time(), ##arg); \
+ fflush(file); \
+ fd = fileno(file); \
+ fsync(fd); \
+ fclose(file); \
+ fprintf(stderr, "[PKG_FOTA][%5d][%10.3fs] "fmt"", getpid(), \
+ __get_elapsed_time(), ##arg); \
+} while (0)
+
+int remove_directory(const char *path)
+{
+ DIR *dir;
+ struct dirent *entry;
+ size_t path_len = strlen(path);
+ int ret = 0;
+ int iterate_ret;
+ char buf[BUF_SIZE] = {0};
+ size_t len;
+ struct stat statbuf;
+
+ dir = opendir(path);
+ if (!dir)
+ return -1;
+
+ while (!ret && (entry = readdir(dir))) {
+ iterate_ret = -1;
+
+ if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
+ continue;
+
+ len = path_len + strlen(entry->d_name) + 2;
+ snprintf(buf, len, "%s/%s", path, entry->d_name);
+
+ if (!stat(buf, &statbuf)) {
+ if (S_ISDIR(statbuf.st_mode))
+ iterate_ret = remove_directory(buf);
+ else
+ iterate_ret = unlink(buf);
+ }
+ ret = iterate_ret;
+ }
+
+ closedir(dir);
+ if (!ret)
+ ret = rmdir(path);
+
+ return ret;
+}
+
+static void __iter_cb(gpointer key, gpointer value, gpointer user_data)
+{
+
+ FILE *file;
+ char *pkgid;
+ char *version;
+ char *type;
+ char pkg_info[BUF_SIZE];
+ pkgmgrinfo_pkginfo_h info;
+
+ if (user_data == NULL || key == NULL)
+ return;
+
+ file = user_data;
+ pkgid = key;
+
+ if (pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &info)) {
+ _LOGE("failed to get pkginfo of %s\n", pkgid);
+ return;
+ }
+
+ if (pkgmgrinfo_pkginfo_get_version(info, &version)) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(info);
+ return;
+ }
+
+ if (pkgmgrinfo_pkginfo_get_type(info, &type)) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(info);
+ return;
+ }
+
+ snprintf(pkg_info, BUF_SIZE,
+ "package=\"%s\"\tversion=\"%s\"\ttype=\"%s\":\n",
+ pkgid, version, type);
+ fwrite(pkg_info, 1, strlen(pkg_info), file);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(info);
+}
+
+static void __make_preload_rw_list(GHashTable *preload_rw_table)
+{
+ if (preload_rw_table == NULL) {
+ _LOG("preload_rw_table is null\n");
+ return;
+ }
+ FILE *file = NULL;
+
+ char buf[BUF_SIZE];
+ char tmp_path[BUF_SIZE];
+ snprintf(tmp_path, BUF_SIZE, "%s.tmp", ALL_PRELOAD_RW_PKG_LIST);
+
+ if (rename(ALL_PRELOAD_RW_PKG_LIST, tmp_path)) {
+ if (errno != ENOENT)
+ _LOG("can not backup preload rw pkg list: %d", errno);
+ }
+
+ file = fopen(ALL_PRELOAD_RW_PKG_LIST, "w");
+ if (file == NULL) {
+ _LOG("can not open [%s]: %s\n", ALL_PRELOAD_RW_PKG_LIST,
+ strerror_r(errno, buf, sizeof(buf)));
+ return;
+ }
+ g_hash_table_foreach(preload_rw_table, __iter_cb, file);
+ fsync(fileno(file));
+ fclose(file);
+ if (remove(tmp_path))
+ _LOG("cannot remove backup file(%s): %d", tmp_path, errno);
+}
+
+static int __is_dir(const char *dirname)
+{
+ struct stat stFileInfo;
+
+ retvm_if(dirname == NULL, -1, "dirname == NULL\n");
+ retvm_if(stat(dirname, &stFileInfo) < 0, -1,
+ "stFileInfo is not enough\n");
+
+ if (S_ISDIR(stFileInfo.st_mode))
+ return 0;
+ return -1;
+}
+
+static int __xsystem(const char *argv[])
+{
+ int status = 0;
+ pid_t pid;
+ pid = fork();
+ switch (pid) {
+ case -1:
+ perror("fork failed");
+ return -1;
+ case 0:
+ /* child */
+ execvp(argv[0], (char *const *)argv);
+ _exit(-1);
+ default:
+ /* parent */
+ break;
+ }
+ if (waitpid(pid, &status, 0) == -1) {
+ perror("waitpid failed");
+ return -1;
+ }
+ if (WIFSIGNALED(status)) {
+ perror("signal");
+ return -1;
+ }
+ if (!WIFEXITED(status)) {
+ /* shouldn't happen */
+ perror("should not happen");
+ return -1;
+ }
+ return WEXITSTATUS(status);
+}
+
+static int __check_pkgmgr_fota_dir()
+{
+ int ret = 0;
+
+ if (__is_dir(PKGMGR_FOTA_PATH) < 0) {
+ const char *mkdir_argv[] = { "/bin/mkdir",
+ "-p", PKGMGR_FOTA_PATH, NULL };
+ ret = __xsystem(mkdir_argv);
+ retvm_if(ret != 0, -1, "mkdir_argv error [%d]\n", ret);
+ }
+
+ return 0;
+}
+
+static int __remove_pkgid_list()
+{
+ int ret = 0;
+
+ if (access(FOTA_RESULT_FILE, R_OK) == 0) {
+ ret = remove(FOTA_RESULT_FILE);
+ err_if(ret < 0, "remove[%s] failed", FOTA_RESULT_FILE);
+ }
+
+ if (access(PKGID_LIST_FROM_DB_FILE, R_OK) == 0) {
+ ret = remove(PKGID_LIST_FROM_DB_FILE);
+ err_if(ret < 0, "remove[%s] failed", PKGID_LIST_FROM_DB_FILE);
+ }
+
+ if (access(PKGID_LIST_FROM_XML_FILE, R_OK) == 0) {
+ ret = remove(PKGID_LIST_FROM_XML_FILE);
+ err_if(ret < 0, "remove[%s] failed", PKGID_LIST_FROM_XML_FILE);
+ }
+
+ return 0;
+}
+
+static int __make_pkgid_list(const char *file_path, char *pkgid,
+ char *version, char *type, bool is_update)
+{
+ FILE *fp;
+
+ if (NULL == pkgid)
+ return 0;
+
+ fp = fopen(file_path, "a+");
+ if (NULL == fp)
+ return -1;
+
+ fprintf(fp, "%s\"%s\" %s\"%s\" %s\"%s\" %s\"%s\":\n",
+ TOKEN_PKGID_STR, pkgid,
+ TOKEN_VERSION_STR, version,
+ TOKEN_TYPE_STR, type,
+ TOKEN_UPDATE_STR, (is_update) ? "true" : "false");
+
+ fclose(fp);
+
+ return 0;
+}
+
+static int __insert_preload_rw_table(GHashTable *preload_rw_table,
+ const char *pkgid, const char *version, const char *type)
+{
+ struct pkginfo *info;
+ char *package;
+
+ info = calloc(1, sizeof(struct pkginfo));
+ if (info == NULL) {
+ _LOGE("out of memory");
+ return -1;
+ }
+
+ info->pkgid = strdup(pkgid);
+ if (info->pkgid == NULL) {
+ _LOGE("out of memory");
+ __free_pkginfo((struct pkginfo *)info);
+ return -1;
+ }
+
+ info->version = strdup(version);
+ if (info->version == NULL) {
+ _LOGE("out of memory");
+ __free_pkginfo((struct pkginfo *)info);
+ return -1;
+ }
+
+ info->type = strdup(type);
+ if (info->type == NULL) {
+ _LOGE("out of memory");
+ __free_pkginfo((struct pkginfo *)info);
+ return -1;
+ }
+
+ package = strdup(pkgid);
+ if (package == NULL) {
+ _LOGE("out of memory");
+ __free_pkginfo((struct pkginfo *)info);
+ return -1;
+ }
+
+ g_hash_table_insert(preload_rw_table, package, info);
+ return 0;
+}
+
+static int __delete_preload_rw_table(GHashTable *preload_rw_table,
+ const char *pkgid)
+{
+ gboolean removed;
+ removed = g_hash_table_remove(preload_rw_table, pkgid);
+ return removed ? 0 : -1;
+}
+
+static int __pkgid_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+ int ret = -1;
+ char *pkgid = NULL;
+ char *version = NULL;
+ char *type = NULL;
+ bool is_update = false;
+
+ ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+ err_if(ret < 0, "pkgmgrinfo_pkginfo_get_pkgid failed");
+
+ ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
+ err_if(ret < 0, "pkgmgrinfo_pkginfo_get_version failed");
+
+ ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
+ err_if(ret < 0, "pkgmgrinfo_pkginfo_get_type failed");
+
+ ret = pkgmgrinfo_pkginfo_is_update(handle, &is_update);
+ err_if(ret < 0, "pkgmgrinfo_pkginfo_is_update failed");
+
+ ret = __make_pkgid_list((char *)user_data, pkgid,
+ version, type, is_update);
+ return ret;
+}
+
+static int __preload_rw_pkgid_list_cb(const pkgmgrinfo_pkginfo_h handle,
+ void *user_data)
+{
+ int ret;
+ char *pkgid;
+ char *version;
+ char *type;
+ GHashTable *preload_rw_table = (GHashTable *)user_data;
+
+ ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+ if (ret < 0) {
+ _LOGE("pkgmgrinfo_pkginfo_get_pkgid failed\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
+ if (ret < 0) {
+ _LOGE("pkgmgrinfo_pkginfo_get_version failed\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
+ if (ret < 0) {
+ _LOGE("pkgmgrinfo_pkginfo_get_type failed\n");
+ return -1;
+ }
+
+ ret = __insert_preload_rw_table(preload_rw_table, pkgid, version, type);
+ if (ret < 0) {
+ _LOGE("__insert_preload_rw_table failed\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static void __str_trim(char *input)
+{
+ char *trim_str = input;
+
+ if (input == NULL)
+ return;
+
+ while (*input != 0) {
+ if (!isspace(*input)) {
+ *trim_str = *input;
+ trim_str++;
+ }
+ input++;
+ }
+
+ *trim_str = 0;
+ return;
+}
+
+static char *__getvalue(const char *pBuf, const char *pKey, int depth)
+{
+ const char *p = NULL;
+ const char *pStart = NULL;
+ const char *pEnd = NULL;
+
+ p = strstr(pBuf, pKey);
+ if (p == NULL)
+ return NULL;
+
+ pStart = p + strlen(pKey) + depth;
+ pEnd = strchr(pStart, SEPERATOR_END);
+ if (pEnd == NULL) {
+ pEnd = strchr(pStart, SEPERATOR_MID);
+ if (pEnd == NULL)
+ return NULL;
+ }
+
+ size_t len = pEnd - pStart;
+ if (len <= 0)
+ return NULL;
+
+ char *pRes = (char *)malloc(len + 1);
+ if (pRes == NULL) {
+ _LOG("malloc failed.\n");
+ return NULL;
+ }
+ strncpy(pRes, pStart, len);
+ pRes[len] = 0;
+
+ return pRes;
+}
+
+static int __compare_pkgid(char *file_path, char *fota_pkgid,
+ char *fota_version, bool *is_updated)
+{
+ retvm_if(file_path == NULL, -1, "file_path is null.\n");
+ retvm_if(fota_pkgid == NULL, -1, "fota_pkgid is null.\n");
+ retvm_if(fota_version == NULL, -1, "fota_version is null.\n");
+
+ int ret = PKG_IS_NOT_EXIST;
+ FILE *fp = NULL;
+ char buf[BUF_SIZE] = {0};
+ char *pkgid = NULL;
+ char *version = NULL;
+ char *update = NULL;
+ int compare = PMINFO_VERSION_SAME;
+
+ fp = fopen(file_path, "r");
+ retvm_if(fp == NULL, -1, "Fail get : %s\n", file_path);
+
+ while (fgets(buf, BUF_SIZE, fp) != NULL) {
+ __str_trim(buf);
+
+ pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
+ if (pkgid == NULL) {
+ _LOG("pkgid is null\n");
+ continue;
+ }
+
+ version = __getvalue(buf, TOKEN_VERSION_STR, 1);
+ if (version == NULL) {
+ FREE_AND_NULL(pkgid);
+ _LOG("compare_data is null\n");
+ continue;
+ }
+
+ update = __getvalue(buf, TOKEN_UPDATE_STR, 1);
+ if (update == NULL) {
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ _LOG("compare_data is null\n");
+ continue;
+ }
+ if (!strncmp(update, "true", strlen("true")))
+ *is_updated = true;
+ else
+ *is_updated = false;
+
+ if (strcmp(pkgid, fota_pkgid) == 0) {
+ ret = pkgmgrinfo_compare_package_version(version,
+ fota_version, &compare);
+ if (compare == PMINFO_VERSION_NEW) {
+ _LOG("pkgid = %s, db version = %s, new package"
+ " version = %s\n", pkgid, version,
+ fota_version);
+ _LOG("pkg is updated, need to upgrade\n");
+
+ ret = PKG_IS_UPDATED;
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(update);
+ break;
+ } else if (compare == PMINFO_VERSION_OLD) {
+ ret = PKG_IS_OLD;
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(update);
+ break;
+ }
+
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(update);
+ ret = PKG_IS_SAME;
+ break;
+ }
+
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(update);
+ memset(buf, 0x00, BUF_SIZE);
+ }
+
+ if (fp != NULL)
+ fclose(fp);
+
+ return ret;
+}
+
+static bool __check_deleted_pkg(GHashTable *preload_rw_table,
+ const char *fota_pkgid)
+{
+ if (g_hash_table_contains(preload_rw_table, fota_pkgid))
+ return true;
+ return false;
+}
+
+char *__manifest_to_package(const char *manifest)
+{
+ char *package;
+
+ if (manifest == NULL)
+ return NULL;
+
+ package = strdup(manifest);
+ if (package == NULL)
+ return NULL;
+
+ if (!strstr(package, ".xml")) {
+ _LOG("%s is not a manifest file \n", manifest);
+ free(package);
+ return NULL;
+ }
+
+ return package;
+}
+
+static void __send_args_to_backend(const char *pkgid, const char *pkgtype,
+ int operation)
+{
+ int ret = 0;
+
+ long starttime;
+ long endtime;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+ char *query;
+ char backend_cmd[BUF_SIZE];
+ const char *new_pkgtype;
+ const char tpk_pkgtype[] = "tpk";
+
+ const char *preload_rw[] = { backend_cmd, "-y", pkgid,
+ "--preload-rw", NULL };
+ const char *install_ro[] = { backend_cmd, "-y", pkgid,
+ "--preload", "--partial-rw", NULL };
+ const char *uninstall_ro[] = { backend_cmd, "-d", pkgid,
+ "--preload", "--force-remove",
+ "--partial-rw", NULL };
+ const char *uninstall_ro_keeprwdata[] = { backend_cmd, "-d", pkgid,
+ "--preload", "--force-remove",
+ "--keep-rwdata", NULL };
+ const char *uninstall_ro_update[] = { backend_cmd, "-d",
+ pkgid, "--keep-rwdata", NULL };
+ const char *db_cmd[] = {"/usr/bin/sqlite3",
+ NULL, NULL, NULL};
+
+ if (operation == PKG_NEED_NOTHING)
+ return;
+
+ if (!strcmp(pkgtype, "rpm"))
+ new_pkgtype = tpk_pkgtype;
+ else
+ new_pkgtype = pkgtype;
+
+ snprintf(backend_cmd, sizeof(backend_cmd), "/usr/bin/%s-backend",
+ new_pkgtype);
+
+ switch (operation) {
+ case PKG_NEED_INSTALL:
+ case PKG_NEED_ROUPDATE:
+ ret = __xsystem(install_ro);
+ break;
+ case PKG_NEED_UNINSTALL:
+ ret = __xsystem(uninstall_ro);
+ break;
+ case PKG_NEED_UPDATE_TO_RW:
+ query = sqlite3_mprintf(
+ "UPDATE package_info SET " \
+ "package_preload='false', " \
+ "package_system='false' "\
+ "WHERE package=%Q", pkgid);
+ db_cmd[1] = strdup(DBPATH);
+ db_cmd[2] = query;
+ ret = __xsystem(db_cmd);
+ FREE_AND_NULL(db_cmd[1]);
+ sqlite3_free(query);
+ break;
+ case PKG_NEED_RWUNINSTALL:
+ case PKG_NEED_UPDATE_TO_RO:
+ ret = __xsystem(uninstall_ro_update);
+ break;
+ case PKG_NEED_RO_DBREMOVE:
+ query = sqlite3_mprintf(
+ "PRAGMA foreign_keys=on; " \
+ "DELETE FROM package_info " \
+ "WHERE package=%Q", pkgid);
+ db_cmd[1] = strdup(DBPATH);
+ db_cmd[2] = query;
+ ret = __xsystem(db_cmd);
+ FREE_AND_NULL(db_cmd[1]);
+ sqlite3_free(query);
+ break;
+ case PKG_NEED_PRELOADRW_INSTALL:
+ ret = __xsystem(preload_rw);
+ break;
+ case PKG_NEED_RO_UNINSTALL_KEEPRWDATA:
+ ret = __xsystem(uninstall_ro_keeprwdata);
+ break;
+ }
+
+ gettimeofday(&tv, NULL);
+ endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+
+ _LOG("result[%ld ms, %d] \t Pkgid[%s] \n",
+ (endtime - starttime), ret, pkgid);
+}
+
+int __child_element(xmlTextReaderPtr reader, int depth)
+{
+ int ret = xmlTextReaderRead(reader);
+ int cur = xmlTextReaderDepth(reader);
+ while (ret == 1) {
+ switch (xmlTextReaderNodeType(reader)) {
+ case XML_READER_TYPE_ELEMENT:
+ if (cur == depth + 1)
+ return 1;
+ break;
+ case XML_READER_TYPE_TEXT:
+ /*text is handled by each function separately*/
+ if (cur == depth + 1)
+ return 0;
+ break;
+ case XML_READER_TYPE_END_ELEMENT:
+ if (cur == depth)
+ return 0;
+ break;
+ default:
+ if (cur <= depth)
+ return 0;
+ break;
+ }
+
+ ret = xmlTextReaderRead(reader);
+ cur = xmlTextReaderDepth(reader);
+ }
+ return ret;
+}
+
+char *__find_info_from_xml(const char *manifest, const char *find_info)
+{
+ retvm_if(manifest == NULL, NULL, "manifest is null.\n");
+ retvm_if(find_info == NULL, NULL, "find_info is null.\n");
+
+ const xmlChar *node;
+ xmlTextReaderPtr reader;
+ char *info_val = NULL;
+ xmlChar *tmp = NULL;
+
+ reader = xmlReaderForFile(manifest, NULL, 0);
+
+ if (reader) {
+ if (__child_element(reader, -1)) {
+ node = xmlTextReaderConstName(reader);
+ if (!node) {
+ printf("xmlTextReaderConstName value is NULL\n");
+ goto end;
+ }
+
+ if (!strcmp(ASCII(node), "manifest")) {
+ tmp = xmlTextReaderGetAttribute(reader,
+ XMLCHAR(find_info));
+ if (tmp) {
+ FREE_AND_STRDUP(ASCII(tmp), info_val);
+ if (info_val == NULL)
+ printf("Malloc Failed\n");
+ FREE_AND_NULL(tmp);
+ }
+ } else {
+ printf("Manifest Node is not found\n");
+ }
+ }
+ } else {
+ printf("xmlReaderForFile value is NULL\n");
+ }
+
+end:
+ if (reader)
+ xmlFreeTextReader(reader);
+
+ return info_val;
+}
+
+static int __find_preload_pkgid_from_xml(const char *file_path,
+ const char *xml_directory)
+{
+ retvm_if(file_path == NULL, -1, "file_path is NULL.\n");
+ retvm_if(xml_directory == NULL, -1, "xml_directory is NULL.\n");
+
+ int ret = 0;
+ char buf[BUF_SIZE] = {0};
+ DIR *dir;
+ struct dirent *entry = NULL;
+
+ dir = opendir(xml_directory);
+ if (!dir) {
+ if (strerror_r(errno, buf, sizeof(buf)) == 0)
+ _LOG("Failed to access the [%s] because %s\n",
+ xml_directory, buf);
+ return -1;
+ }
+
+ while ((entry = readdir(dir)) != NULL) {
+ char *manifest = NULL;
+ char *pkgid = NULL;
+ char *version = NULL;
+ char *type = NULL;
+
+ if (entry->d_name[0] == '.') continue;
+
+ manifest = __manifest_to_package(entry->d_name);
+ if (!manifest) {
+ _LOG("Failed to convert file to xml[%s]\n",
+ entry->d_name);
+ continue;
+ }
+
+ snprintf(buf, sizeof(buf), "%s/%s", xml_directory, manifest);
+
+ /*Get the package name from manifest file*/
+ pkgid = __find_info_from_xml(buf, "package");
+ if (pkgid == NULL) {
+ FREE_AND_NULL(manifest);
+ continue;
+ }
+
+ version = __find_info_from_xml(buf, "version");
+ if (version == NULL)
+ version = strdup("0.0.1");
+
+ type = __find_info_from_xml(buf, "type");
+ if (type == NULL)
+ type = strdup("tpk");
+
+ ret = __make_pkgid_list((char *)file_path, pkgid,
+ version, type, false);
+ if (ret < 0)
+ _LOG("Make file Fail : %s => %s, %s\n",
+ buf, pkgid, version);
+
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(manifest);
+ FREE_AND_NULL(type);
+ }
+
+ closedir(dir);
+
+ return 0;
+}
+
+static int __find_preload_pkgid_from_db(const char *file_path)
+{
+ retvm_if(file_path == NULL, -1, "file_path is NULL.\n");
+
+ int ret = 0;
+ pkgmgrinfo_pkginfo_filter_h handle = NULL;
+
+ ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+ retvm_if(ret != PMINFO_R_OK, -1,
+ "pkginfo filter handle create failed\n");
+
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, 1);
+ tryvm_if(ret < 0, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
+ "(PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD) failed\n");
+
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM, 1);
+ tryvm_if(ret < 0, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
+ "(PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM) failed\n");
+
+ ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle,
+ __pkgid_list_cb, (void *)file_path);
+ err_if(ret < 0,
+ "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() failed\n");
+
+catch:
+ pkgmgrinfo_pkginfo_filter_destroy(handle);
+ return ret;
+}
+
+static int __find_preload_rw_pkgid_from_db(GHashTable *preload_rw_table)
+{
+ int ret;
+ pkgmgrinfo_pkginfo_filter_h handle;
+
+ ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+ retvm_if(ret != PMINFO_R_OK, -1,
+ "pkginfo filter handle create failed\n");
+
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, 1);
+ tryvm_if(ret != PMINFO_R_OK, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
+ "(PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD) failed\n");
+
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, 1);
+ tryvm_if(ret != PMINFO_R_OK, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
+ "(PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE) failed\n");
+
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_READONLY, 0);
+ tryvm_if(ret != PMINFO_R_OK, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
+ "(PMINFO_PKGINFO_PROP_PACKAGE_READONLY) failed\n");
+
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM, 0);
+ tryvm_if(ret != PMINFO_R_OK, ret = -1, "pkgmgrinfo_pkginfo_filter_add_bool"
+ "(PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM) failed\n");
+
+ ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle,
+ __preload_rw_pkgid_list_cb, (void *)preload_rw_table);
+ err_if(ret != PMINFO_R_OK,
+ "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() failed\n");
+
+ ret = 0;
+catch:
+ pkgmgrinfo_pkginfo_filter_destroy(handle);
+ return ret;
+}
+
+static int __find_matched_pkgid_from_list(const char *source_file,
+ const char *target_file)
+{
+ retvm_if(source_file == NULL, -1, "source_file is NULL.\n");
+ retvm_if(target_file == NULL, -1, "target_file is NULL.\n");
+
+ FILE *fp = NULL;
+ char buf[BUF_SIZE] = {0};
+ char *pkgid = NULL;
+ char *version = NULL;
+ char *pkgtype = NULL;
+
+ int same_pkg_cnt = 0;
+ int update_pkg_cnt = 0;
+ int insert_pkg_cnt = 0;
+ int total_pkg_cnt = 0;
+
+ int compare_result = 0;
+ int operation;
+
+ bool db_update;
+
+ fp = fopen(source_file, "r");
+ retvm_if(fp == NULL, -1, "Fail get : %s\n", source_file);
+
+ _LOG("Searching...... inserted or Updated package \n");
+
+ while (fgets(buf, BUF_SIZE, fp) != NULL) {
+ __str_trim(buf);
+
+ pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
+ if (pkgid == NULL)
+ continue;
+
+ version = __getvalue(buf, TOKEN_VERSION_STR, 1);
+ if (version == NULL) {
+ free(pkgid);
+ continue;
+ }
+ pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1);
+ if (pkgtype == NULL) {
+ free(version);
+ free(pkgid);
+ continue;
+ }
+
+ operation = PKG_NEED_NOTHING;
+ compare_result = __compare_pkgid((char *)target_file, pkgid,
+ version, &db_update);
+ if (compare_result == PKG_IS_NOT_EXIST) {
+ _LOG("pkgid[%s] is installed, Start install\n", pkgid);
+ operation = PKG_NEED_INSTALL;
+ insert_pkg_cnt++;
+ } else if (compare_result == PKG_IS_SAME) {
+ if (db_update) {
+ operation = PKG_NEED_RWUNINSTALL;
+ update_pkg_cnt++;
+ } else {
+ operation = PKG_NEED_NOTHING;
+ same_pkg_cnt++;
+ }
+ } else if (compare_result == PKG_IS_UPDATED) {
+ if (db_update) {
+ operation = PKG_NEED_UPDATE_TO_RO;
+ } else {
+ operation = PKG_NEED_ROUPDATE;
+ }
+ update_pkg_cnt++;
+ }
+
+ total_pkg_cnt++;
+ __send_args_to_backend(pkgid, pkgtype, operation);
+
+ memset(buf, 0x00, BUF_SIZE);
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(pkgtype);
+ }
+
+ _LOG("-------------------------------------------------------\n");
+ _LOG("[Total pkg=%d, same pkg=%d, updated pkg=%d, "
+ "inserted package=%d]\n",
+ total_pkg_cnt, same_pkg_cnt, update_pkg_cnt, insert_pkg_cnt);
+ _LOG("-------------------------------------------------------\n");
+
+ if (fp != NULL)
+ fclose(fp);
+
+ return 0;
+}
+
+static bool __find_pkgid_from_rw_list(const char *pkgid)
+{
+ if (pkgid == NULL)
+ return false;
+
+ bool ret = false;
+ FILE *fp = NULL;
+ char buf[BUF_SIZE] = {0};
+ char *preload_rw_pkgid = NULL;
+
+ fp = fopen(PRELOAD_RW_PKG_LIST, "r");
+ retvm_if(fp == NULL, -1, "Failed to open : %s\n", PRELOAD_RW_PKG_LIST);
+
+ while (fgets(buf, BUF_SIZE, fp) != NULL) {
+ __str_trim(buf);
+
+ preload_rw_pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
+ if (preload_rw_pkgid == NULL) {
+ _LOG("Failed to get pkgidstring[%s]\n", buf);
+ continue;
+ }
+
+ if (strcmp(pkgid, preload_rw_pkgid) == 0) {
+ _LOG("pkgid[%s] is converted to preload rw pkg\n", pkgid);
+ FREE_AND_NULL(preload_rw_pkgid);
+ ret = true;
+ break;
+ }
+ FREE_AND_NULL(preload_rw_pkgid);
+ }
+
+ fclose(fp);
+ return ret;
+}
+
+static int __unzip_file_only_to_path(char *dest_path, char *unzip_to)
+{
+ const char *unzip_argv[] = { "/usr/bin/unzip", "-joXqq",
+ OPT_ZIP_FILE, dest_path, "-d", unzip_to, NULL };
+ int ret = __xsystem(unzip_argv);
+
+ return ret;
+}
+
+static int __unzip_files(char *dest_path)
+{
+ const char *unzip_argv[] = { "/usr/bin/unzip", "-oXqq",
+ OPT_ZIP_FILE, dest_path, "-d", "/", NULL };
+ int ret = __xsystem(unzip_argv);
+
+ return ret;
+}
+
+static int __install_preload_rw(const char *pkgid, const char *version,
+ const char *pkgtype, GHashTable *preload_rw_table)
+{
+ if (pkgid == NULL || version == NULL || pkgtype == NULL)
+ return -1;
+
+ int index;
+ int ret;
+ char buf[BUF_SIZE] = {0};
+
+ /* copy modified manifest */
+ snprintf(buf, BUF_SIZE, "%s/%s.xml",
+ (tzplatform_getenv(TZ_SYS_RW_PACKAGES) + 1), pkgid);
+ ret = __unzip_files(buf);
+ if (ret != 0) {
+ _LOG("Failed to unzip file from backup[%s]\n", buf);
+ return ret;
+ }
+
+ /* copy stored signature */
+ snprintf(buf, BUF_SIZE, "%s/signatures/%s.txt",
+ (tzplatform_getenv(TZ_SYS_SHARE) + 1), pkgid);
+ ret = __unzip_files(buf);
+ if (ret != 0) {
+ _LOG("Failed to unzip file from backup[%s]\n", buf);
+ return ret;
+ }
+
+ /* copy RO and RW components */
+ for (index = 0; index < BUF_SIZE; index++) {
+ if (unzip_path[index] == NULL)
+ break;
+
+ snprintf(buf, BUF_SIZE, "%s/%s/*", unzip_path[index], pkgid);
+ ret = __unzip_files(buf);
+ if (ret != 0) {
+ _LOG("Failed to unzip file from backup[%s]\n", buf);
+ return ret;
+ }
+ }
+
+ ret = __insert_preload_rw_table(preload_rw_table, pkgid, version,
+ pkgtype);
+ retvm_if(ret < 0, -1, "__insert_preload_rw_table fail\n");
+
+ __send_args_to_backend(pkgid, pkgtype, PKG_NEED_PRELOADRW_INSTALL);
+ return ret;
+}
+
+static void __convert_preload_to_rw(const char *pkgid, const char *version,
+ const char *pkgtype, GHashTable *preload_rw_table)
+{
+ if (pkgid == NULL || version == NULL || pkgtype == NULL)
+ return;
+ char buf[BUF_SIZE] = {0};
+ int ret;
+
+ snprintf(buf, BUF_SIZE, "%s/skel/apps_rw/%s",
+ tzplatform_getenv(TZ_SYS_ETC), pkgid);
+
+ __send_args_to_backend(pkgid, pkgtype, PKG_NEED_RO_UNINSTALL_KEEPRWDATA);
+ ret = remove_directory(buf);
+ if (ret != 0)
+ _LOG("Failed to remove directory[%s]\n", buf);
+
+ ret = __install_preload_rw(pkgid, version, pkgtype, preload_rw_table);
+ if (ret != 0) {
+ _LOG("Failed install preload rw pkg[%s]\n", pkgid);
+ return;
+ }
+}
+
+static int __find_deleted_pkgid_from_list(const char *source_file,
+ const char *target_file, GHashTable *preload_rw_table)
+{
+ retvm_if(source_file == NULL, -1, "source_file is NULL.\n");
+ retvm_if(target_file == NULL, -1, "target_file is NULL.\n");
+
+ FILE *fp = NULL;
+ char buf[BUF_SIZE] = {0};
+ char *pkgid;
+ char *version;
+ char *pkgtype = NULL;
+ char *update = NULL;
+ bool is_preload_rw_pkg;
+ bool xml_update;
+ int deleted_pkg_cnt = 0;
+ int modified_pkg_cnt = 0;
+ int total_pkg_cnt = 0;
+ int compare_result = 0;
+
+ fp = fopen(source_file, "r");
+ retvm_if(fp == NULL, -1, "Fail get : %s\n", source_file);
+
+ _LOG("Searching...... deleted package \n");
+
+ while (fgets(buf, BUF_SIZE, fp) != NULL) {
+ __str_trim(buf);
+
+ pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
+ version = __getvalue(buf, TOKEN_VERSION_STR, 1);
+ pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1);
+ if (pkgid == NULL || version == NULL || pkgtype == NULL) {
+ _LOG("Failed to get pkg info from string[%s]\n", buf);
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(pkgtype);
+ continue;
+ }
+
+ compare_result = __compare_pkgid((char *)target_file, pkgid,
+ version, &xml_update);
+ if (compare_result == PKG_IS_NOT_EXIST) {
+ update = __getvalue(buf, TOKEN_UPDATE_STR, 1);
+ if (update == NULL) {
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(pkgtype);
+ continue;
+ }
+
+ is_preload_rw_pkg = __find_pkgid_from_rw_list(pkgid);
+
+ if (!strncmp(update, "false", strlen("false"))) {
+ if (is_preload_rw_pkg) {
+ __convert_preload_to_rw(pkgid, version,
+ pkgtype,
+ preload_rw_table);
+ modified_pkg_cnt++;
+ } else {
+ __send_args_to_backend(pkgid, pkgtype,
+ PKG_NEED_UNINSTALL);
+ deleted_pkg_cnt++;
+ }
+ } else {
+ __send_args_to_backend(pkgid, pkgtype,
+ PKG_NEED_UPDATE_TO_RW);
+ modified_pkg_cnt++;
+ if (is_preload_rw_pkg) {
+ __send_args_to_backend(pkgid, pkgtype,
+ PKG_NEED_RWUNINSTALL);
+ __install_preload_rw(pkgid, version,
+ pkgtype,
+ preload_rw_table);
+ }
+ }
+ }
+ total_pkg_cnt++;
+
+ memset(buf, 0x00, BUF_SIZE);
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(pkgtype);
+ FREE_AND_NULL(update);
+ }
+
+ _LOG("-------------------------------------------------------\n");
+ _LOG("[Total pkg=%d, deleted package=%d, modified package=%d]\n",
+ total_pkg_cnt, deleted_pkg_cnt, modified_pkg_cnt);
+ _LOG("-------------------------------------------------------\n");
+
+ if (fp != NULL)
+ fclose(fp);
+
+ return 0;
+
+}
+
+static int __get_pkgid_list_from_db_and_xml()
+{
+ _LOG("=======================================================\n");
+ _LOG("RO preload package fota\n");
+ _LOG("=======================================================\n");
+
+ int ret = 0;
+ char updated_preload_rw_list[BUF_SIZE];
+
+ /*get pkg info on pkgmgr db, it means old version */
+ ret = __find_preload_pkgid_from_db(PKGID_LIST_FROM_DB_FILE);
+ retvm_if(ret < 0, -1, "__find_preload_pkgid_from_db fail.\n");
+
+ _LOG("Make pkgid list from db success!! \n");
+
+ /*get pkg info on xml, it means new version */
+ ret = __find_preload_pkgid_from_xml(PKGID_LIST_FROM_XML_FILE,
+ USR_MANIFEST_DIRECTORY);
+ retvm_if(ret < 0, -1, "__find_preload_pkgid_from_xml fail.\n");
+
+ _LOG("Make pkgid list from xml success!! \n");
+
+
+ /*get preload rw pkg info on xml from opt.zip, it means new version */
+ snprintf(updated_preload_rw_list, sizeof(updated_preload_rw_list), "%s",
+ ALL_PRELOAD_RW_PKG_LIST);
+ ret = __unzip_file_only_to_path(updated_preload_rw_list + 1,
+ (char *)PKGMGR_FOTA_PATH);
+ if (ret != 0) {
+ _LOG("Failed to unzip file from backup[%s]\n",
+ updated_preload_rw_list);
+ return ret;
+ }
+
+ _LOG("Make rw pkgid list from xml success!! \n");
+
+ return 0;
+}
+
+static int __process_ro_fota(GHashTable *preload_rw_table)
+{
+ int ret;
+ long starttime;
+ long endtime;
+ struct timeval tv;
+
+ xmlInitParser();
+
+ gettimeofday(&tv, NULL);
+ starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+
+ /* find deleted pkgid */
+ ret = __find_deleted_pkgid_from_list(PKGID_LIST_FROM_DB_FILE,
+ PKGID_LIST_FROM_XML_FILE, preload_rw_table);
+ err_if(ret < 0, "__find_deleted_pkgid_from_list fail.\n");
+
+ /* find updated, inserted pkgid */
+ ret = __find_matched_pkgid_from_list(PKGID_LIST_FROM_XML_FILE,
+ PKGID_LIST_FROM_DB_FILE);
+ err_if(ret < 0, "__find_matched_pkgid_from_list fail.\n");
+
+ gettimeofday(&tv, NULL);
+ endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+
+ _LOG("=======================================================\n");
+ _LOG("End RO process[time : %ld ms]\n", endtime - starttime);
+ _LOG("=======================================================\n");
+
+ xmlCleanupParser();
+
+ return 0;
+}
+
+static int __process_rw_fota(GHashTable *preload_rw_table)
+{
+ FILE *fp = NULL;
+ char buf[BUF_SIZE] = {0};
+ int ret = -1;
+ char *pkgid = NULL;
+ char *list_version = NULL;
+ char *db_stored_version = NULL;
+ char *pkgtype = NULL;
+ char *version = NULL;
+ pkgmgrinfo_pkginfo_h handle = NULL;
+ int compare = PMINFO_VERSION_SAME;
+ long total_time = 0;
+
+ long starttime;
+ long endtime;
+ struct timeval tv;
+ bool is_deleted_pkg;
+
+ _LOG("=======================================================\n");
+ _LOG("RW preload package fota\n");
+ _LOG("=======================================================\n");
+
+ fp = fopen(PRELOAD_RW_PKG_LIST, "r");
+ retvm_if(fp == NULL, -1, "Fail get : %s\n", PRELOAD_RW_PKG_LIST);
+
+ while (fgets(buf, BUF_SIZE, fp) != NULL) {
+ __str_trim(buf);
+
+ gettimeofday(&tv, NULL);
+ starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+
+ pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
+ if (pkgid == NULL)
+ continue;
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret == PMINFO_R_OK) {
+ list_version = __getvalue(buf, TOKEN_VERSION_STR, 1);
+ if (list_version == NULL) {
+ FREE_AND_NULL(pkgid);
+ continue;
+ }
+ ret = pkgmgrinfo_pkginfo_get_version(handle, &db_stored_version);
+ ret = pkgmgrinfo_compare_package_version(db_stored_version,
+ list_version, &compare);
+ if (ret != PMINFO_R_OK) {
+ _LOG("can not compare pkg version[%s]\n", pkgid);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ handle = NULL;
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(list_version);
+ continue;
+ }
+
+ if (compare != PMINFO_VERSION_NEW) {
+ /* package version is not update on FOTA. */
+ _LOG("pkgid[%s] is not updated\n", pkgid);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ handle = NULL;
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(list_version);
+ continue;
+ }
+
+ _LOG("pkgid[%s] is updated, need to upgrade "
+ "from version [%s] to [%s]\n",
+ pkgid, db_stored_version, list_version);
+ } else {
+ is_deleted_pkg = __check_deleted_pkg(preload_rw_table, pkgid);
+ if (is_deleted_pkg) {
+ _LOG("pkgid[%s] is deleted pkg\n", pkgid);
+ __delete_preload_rw_table(preload_rw_table,
+ pkgid);
+ FREE_AND_NULL(pkgid);
+ continue;
+ }
+ _LOG("pkgid[%s] is new\n", pkgid);
+ }
+
+ version = __getvalue(buf, TOKEN_VERSION_STR, 1);
+ pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1);
+ __install_preload_rw(pkgid, version, pkgtype, preload_rw_table);
+
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(pkgtype);
+ FREE_AND_NULL(version);
+
+ if (handle)
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+ gettimeofday(&tv, NULL);
+ endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+ total_time += (int)(endtime - starttime);
+ _LOG("finish request [time : %d ms]\n",
+ (int)(endtime - starttime));
+ }
+ fclose(fp);
+
+ return 0;
+}
+
+static int __check_tmp_all_preload_rw_pkg_list()
+{
+ char buf[BUF_SIZE];
+ char tmp_path[BUF_SIZE];
+ snprintf(tmp_path, BUF_SIZE, "%s.tmp", ALL_PRELOAD_RW_PKG_LIST);
+ if (access(tmp_path, F_OK) == 0) {
+ if (rename(tmp_path, ALL_PRELOAD_RW_PKG_LIST)) {
+ _LOG("rename tmp all preload rw pkg list fail : %s\n",
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int __fill_preload_rw_table(GHashTable *preload_rw_table)
+{
+ FILE *fp;
+ char buf[BUF_SIZE];
+ char *pkgid;
+ char *version;
+ char *type;
+
+ fp = fopen(ALL_PRELOAD_RW_PKG_LIST, "r");
+ retvm_if(fp == NULL, -1, "Fail get : %s\n", ALL_PRELOAD_RW_PKG_LIST);
+
+ while (fgets(buf, BUF_SIZE, fp) != NULL) {
+ __str_trim(buf);
+
+ pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
+ if (pkgid == NULL) {
+ _LOG("pkgid is null\n");
+ continue;
+ }
+
+ version = __getvalue(buf, TOKEN_VERSION_STR, 1);
+ if (version == NULL) {
+ _LOG("version is null\n");
+ version = strdup("");
+ if (version == NULL) {
+ _LOGE("out of memory\n");
+ FREE_AND_NULL(pkgid);
+ continue;
+ }
+ }
+
+ type = __getvalue(buf, TOKEN_TYPE_STR, 1);
+ if (type == NULL) {
+ _LOG("type is null\n");
+ type = strdup("");
+ if (type == NULL) {
+ _LOGE("out of memory\n");
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(pkgid);
+ continue;
+ }
+ }
+
+ __insert_preload_rw_table(preload_rw_table, pkgid, version,
+ type);
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(type);
+ }
+ fclose(fp);
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ GHashTable *preload_rw_table;
+ int ret = 0;
+
+ /* check pkgmgr-fota dir, if it is not, then exit */
+ ret = __check_pkgmgr_fota_dir();
+ retvm_if(ret < 0, -1, "__check_pkgmgr_fota_dir is failed.\n");
+
+ /* clean pkgid list file */
+ ret = __remove_pkgid_list();
+ err_if(ret < 0, "remove[%s] failed\n", FOTA_RESULT_FILE);
+
+ /* get pkgid from orginal pkgmgr db */
+ ret = __get_pkgid_list_from_db_and_xml();
+ retvm_if(ret < 0, -1, "__get_pkgid_list_from_db_and_xml is failed.\n");
+
+ //__get_pkginfo_from_opt();
+
+ ret = __check_tmp_all_preload_rw_pkg_list();
+ retvm_if(ret < 0, -1,
+ "__check_tmp_all_preload_rw_pkg_list is failed.\n");
+
+ preload_rw_table = g_hash_table_new_full(
+ g_str_hash, g_str_equal, free, __free_pkginfo);
+ if (__fill_preload_rw_table(preload_rw_table) < 0) {
+ ret = __find_preload_rw_pkgid_from_db(preload_rw_table);
+ retvm_if(ret < 0, -1, "__find_preload_rw_pkgid_from_db is failed\n");
+ }
+
+ if (argc == 1) {
+ ret = __process_ro_fota(preload_rw_table);
+ if (ret < 0) {
+ g_hash_table_destroy(preload_rw_table);
+ _LOGE("__process_ro_fota is failed.\n");
+ return EXIT_FAILURE;
+ }
+ ret = __process_rw_fota(preload_rw_table);
+ if (ret < 0) {
+ g_hash_table_destroy(preload_rw_table);
+ _LOGE("__process_rw_fota is failed.\n");
+ return EXIT_FAILURE;
+ }
+ } else {
+ if (strcmp(argv[1], "-rof") == 0) {
+ ret = __process_ro_fota(preload_rw_table);
+ if (ret < 0) {
+ g_hash_table_destroy(preload_rw_table);
+ _LOGE("__process_ro_fota is failed.\n");
+ return EXIT_FAILURE;
+ }
+ } else if (strcmp(argv[1], "-rwf") == 0) {
+ ret = __process_rw_fota(preload_rw_table);
+ if (ret < 0) {
+ g_hash_table_destroy(preload_rw_table);
+ _LOGE("__process_rw_fota is failed.\n");
+ return EXIT_FAILURE;
+ }
+ } else {
+ fprintf(stderr, "not supported operand\n");
+ }
+ }
+ __make_preload_rw_list(preload_rw_table);
+ g_hash_table_destroy(preload_rw_table);
+ return EXIT_SUCCESS;
+}
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Vivek Kumar <vivek.kumar2@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <dirent.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include "delta.h"
+
+static GList *__list_directory(const char *dir_name, const char *tpk_path, GList *list);
+static int __compare_files(char *path1, char *path2);
+static void __print_to_file(char *msg);
+static void __free_g_list(GList *list);
+
+static void __free_g_list(GList *list)
+{
+ GList *iter = NULL;
+
+ for (iter = list; iter != NULL; iter = iter->next) {
+ if (iter->data)
+ free(iter->data);
+ }
+ g_list_free(list);
+
+ return;
+}
+
+static GList *__list_directory(const char *dir_name, const char *tpk_path, GList *list)
+{
+ DIR *dir = NULL;
+ struct dirent *file_info = NULL;
+ char path[PATH_MAX] = {0, };
+ char rel_path_old_tpk_file[PATH_MAX] = {0, };
+ char *file_path = NULL;
+ char buf[BUF_SIZE] = {0};
+ const char *d_name = NULL;
+ int path_length;
+
+ dir = opendir(dir_name);
+ if (!dir) {
+ if (strerror_r(errno, buf, sizeof(buf)) == 0)
+ printf("Cannot open directory '%s': %s\n", dir_name, buf);
+ exit(EXIT_FAILURE);
+ }
+
+ while ((file_info = readdir(dir)) != NULL) {
+ d_name = file_info->d_name;
+ if (!(file_info->d_type & DT_DIR)) {
+ snprintf(rel_path_old_tpk_file, PATH_MAX, "%s/%s", dir_name, d_name);
+ strncpy(path, rel_path_old_tpk_file + strlen(tpk_path),
+ strlen(rel_path_old_tpk_file));
+ file_path = strndup(path, sizeof(path));
+ list = g_list_append(list, file_path);
+ memset(path, 0, PATH_MAX);
+ memset(rel_path_old_tpk_file, 0, PATH_MAX);
+ }
+
+ if (file_info->d_type & DT_DIR) {
+ if (strcmp(d_name, "..") != 0 && strcmp(d_name, ".") != 0) {
+ path_length = snprintf(path, PATH_MAX, "%s/%s", dir_name, d_name);
+ if (path_length >= PATH_MAX) {
+ printf("Path length has got too long.\n");
+ exit(EXIT_FAILURE);
+ }
+ list = __list_directory(path, tpk_path, list);
+ memset(path, 0, PATH_MAX);
+ }
+ }
+ }
+
+ if (closedir(dir)) {
+ if (strerror_r(errno, buf, sizeof(buf)) == 0)
+ printf("Could not close '%s': %s\n", dir_name, buf);
+ exit(EXIT_FAILURE);
+ }
+
+ return list;
+}
+
+static char *__create_md5Hash(char *file_name)
+{
+ FILE *inFile = fopen(file_name, "rb");
+ unsigned char data[1024] = {0, };
+ int bytes = 0;
+
+ GChecksum *checksum = NULL;
+ char *checksum_val = NULL;
+ char *return_val = NULL;
+
+ if (inFile == NULL) {
+ printf("%s can't be opened.\n", file_name);
+ return 0;
+ }
+
+ checksum = g_checksum_new(G_CHECKSUM_MD5);
+ if (checksum == NULL) {
+ printf("failed to create a new GChecksum\n");
+ fclose(inFile);
+ return 0;
+ }
+
+ while ((bytes = fread(data, 1, 1024, inFile)) != 0)
+ g_checksum_update(checksum, (const guchar *)data, bytes);
+
+ checksum_val = (char *)g_checksum_get_string(checksum);
+ if (checksum_val)
+ return_val = strdup(checksum_val);
+
+ g_checksum_free(checksum);
+ fclose(inFile);
+
+ return return_val;
+}
+
+static int __compare_files(char *old_file, char *new_file)
+{
+ char *md5_old_file = NULL;
+ char *md5_new_file = NULL;
+
+ md5_old_file = __create_md5Hash(old_file);
+ if (md5_old_file == NULL) {
+ printf("md5checksum failed for %s.\n", old_file);
+ exit(EXIT_FAILURE);
+ }
+
+ md5_new_file = __create_md5Hash(new_file);
+ if (md5_new_file == NULL) {
+ printf("md5checksum failed for %s.\n", new_file);
+ exit(EXIT_FAILURE);
+ }
+
+ if (strcmp(md5_old_file, md5_new_file) == 0) {
+ free(md5_old_file);
+ free(md5_new_file);
+ return 0;
+ } else {
+ free(md5_old_file);
+ free(md5_new_file);
+ return 1;
+ }
+}
+
+static void __print_to_file(char *msg)
+{
+ FILE *fp;
+
+ fp = fopen(DIFF_FILE, "a");
+
+ if (fp == NULL) {
+ printf("Cannot open %s for writing ", DIFF_FILE);
+ exit(1);
+ }
+
+ fprintf(fp, "%s \n", msg);
+ memset(msg, 0, MAX_MESSAGE_LEN);
+ fclose(fp);
+}
+
+void __create_diff_file(char *old_tpk_path, char *new_tpk_path)
+{
+ char rel_path_old_tpk_file[PATH_MAX] = {0, };
+ char rel_path_new_tpk_file[PATH_MAX] = {0, };
+ GList *list_dir_old_tpk = NULL;
+ GList *list_dir_new_tpk = NULL;
+ GList *iterator_old_tpk = NULL;
+ GList *iterator_new_tpk = NULL;
+ GList *next_iterator_old_tpk = NULL;
+ GList *next_iterator_new_tpk = NULL;
+ int ret = -1;
+ char message[MAX_MESSAGE_LEN];
+
+ list_dir_old_tpk = __list_directory(old_tpk_path, old_tpk_path, list_dir_old_tpk);
+ if (list_dir_old_tpk == NULL) {
+ printf("Could Not read %s\n", old_tpk_path);
+ return;
+ }
+
+ list_dir_new_tpk = __list_directory(new_tpk_path, new_tpk_path, list_dir_new_tpk);
+ if (list_dir_new_tpk == NULL) {
+ printf("Could Not read %s\n", new_tpk_path);
+ __free_g_list(list_dir_old_tpk);
+ return;
+ }
+
+ iterator_old_tpk = list_dir_old_tpk;
+ iterator_new_tpk = list_dir_new_tpk;
+
+ while (iterator_old_tpk != NULL) {
+ next_iterator_old_tpk = iterator_old_tpk->next;
+
+ iterator_new_tpk = list_dir_new_tpk;
+ while (iterator_new_tpk != NULL) {
+ next_iterator_new_tpk = iterator_new_tpk->next;
+
+ if (strcmp((char *)iterator_old_tpk->data,
+ (char *)iterator_new_tpk->data) == 0) {
+ snprintf(rel_path_old_tpk_file, PATH_MAX, "%s%s", old_tpk_path,
+ (char *)iterator_old_tpk->data);
+ snprintf(rel_path_new_tpk_file, PATH_MAX, "%s%s", new_tpk_path,
+ (char *)iterator_new_tpk->data);
+ ret = 0;
+ if (rel_path_new_tpk_file[strlen(rel_path_new_tpk_file) - 1]
+ != '/') {
+ ret = __compare_files(rel_path_old_tpk_file,
+ rel_path_new_tpk_file);
+ if (ret == 1) {
+ ret = snprintf(message, MAX_MESSAGE_LEN,
+ "Files %s and %s differ",
+ rel_path_old_tpk_file,
+ rel_path_new_tpk_file);
+ if (ret < 0 || ret > MAX_MESSAGE_LEN)
+ printf("snprintf fail\n");
+ __print_to_file(message);
+ } else {
+ ret = snprintf(message, MAX_MESSAGE_LEN,
+ "Files %s and %s are the same",
+ rel_path_old_tpk_file,
+ rel_path_new_tpk_file);
+ if (ret < 0 || ret > MAX_MESSAGE_LEN)
+ printf("snprintf fail\n");
+ __print_to_file(message);
+ }
+ }
+ list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk,
+ iterator_new_tpk);
+ list_dir_old_tpk = g_list_delete_link(list_dir_old_tpk,
+ iterator_old_tpk);
+ iterator_new_tpk = next_iterator_new_tpk;
+ iterator_old_tpk = next_iterator_old_tpk;
+ break;
+ }
+ iterator_new_tpk = next_iterator_new_tpk;
+ }
+ iterator_old_tpk = next_iterator_old_tpk;
+ }
+
+ /* find if new file or new directory */
+ iterator_old_tpk = list_dir_old_tpk;
+ while (iterator_old_tpk != NULL) {
+ iterator_new_tpk = iterator_old_tpk->next;
+ while (iterator_new_tpk != NULL) {
+ next_iterator_new_tpk = iterator_new_tpk->next;
+ if (strstr(iterator_new_tpk->data, iterator_old_tpk->data) != NULL)
+ list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk,
+ iterator_new_tpk);
+ iterator_new_tpk = next_iterator_new_tpk;
+ }
+ iterator_old_tpk = iterator_old_tpk->next;
+ }
+
+ iterator_old_tpk = list_dir_new_tpk;
+ while (iterator_old_tpk != NULL) {
+ iterator_new_tpk = iterator_old_tpk->next;
+ while (iterator_new_tpk != NULL) {
+ next_iterator_new_tpk = iterator_new_tpk->next;
+ if (strstr(iterator_new_tpk->data, iterator_old_tpk->data) != NULL)
+ list_dir_new_tpk = g_list_delete_link(list_dir_new_tpk,
+ iterator_new_tpk);
+ iterator_new_tpk = next_iterator_new_tpk;
+ }
+ iterator_old_tpk = iterator_old_tpk->next;
+ }
+
+ iterator_old_tpk = list_dir_old_tpk;
+ while (iterator_old_tpk != NULL) {
+ snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", old_tpk_path,
+ (char *)iterator_old_tpk->data);
+ __print_to_file(message);
+ iterator_old_tpk = iterator_old_tpk->next;
+ }
+
+ iterator_new_tpk = list_dir_new_tpk;
+ while (iterator_new_tpk != NULL) {
+ snprintf(message, MAX_MESSAGE_LEN, "Only in %s%s", new_tpk_path,
+ (char *)iterator_new_tpk->data);
+ __print_to_file(message);
+ iterator_new_tpk = iterator_new_tpk->next;
+ }
+
+ /* to free GSList */
+ __free_g_list(list_dir_old_tpk);
+ __free_g_list(list_dir_new_tpk);
+}
+
+int __xsystem(const char *argv[])
+{
+ char buf[BUF_SIZE] = {0};
+ int status = 0;
+ pid_t pid;
+
+ pid = fork();
+
+ switch (pid) {
+ case -1:
+ perror("fork failed");
+ return -1;
+ case 0:
+ /* child */
+ if (execvp(argv[0], (char *const *)argv) < 0) {
+ if (strerror_r(errno, buf, sizeof(buf)) == 0)
+ fprintf(stderr, "execvp failed %d....%s\n", errno, buf);
+ }
+ _exit(-1);
+ default:
+ /* parent */
+ break;
+ }
+
+ if (waitpid(pid, &status, 0) == -1) {
+ perror("waitpid failed");
+ return -1;
+ }
+
+ if (WIFSIGNALED(status)) {
+ perror("signal");
+ return -1;
+ }
+
+ if (!WIFEXITED(status)) {
+ /* shouldn't happen */
+ perror("should not happen");
+ return -1;
+ }
+
+ return WEXITSTATUS(status);
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Vivek Kumar <vivek.kumar2@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef DELTA_H_
+#define DELTA_H_
+
+#define DIFF_FILE "/opt/usr/temp_delta/difffile.txt"
+#define TEMP_DELTA_REPO "/opt/usr/temp_delta/"
+#define UNZIPFILE "_FILES"
+#define MAX_MESSAGE_LEN 1024
+#define BUF_SIZE 1024
+
+void __create_diff_file(char *old_tpk_path, char *new_tpk_path);
+int __xsystem(const char *argv[]);
+
+#endif /* DELTA_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <getopt.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <pkgmgr-info.h>
+#include <pkgmgr_installer_error.h>
+/* For multi-user support */
+#include <tzplatform_config.h>
+
+#include <package-manager.h>
+#include <package-manager-types.h>
+#include "delta.h"
+
+#define PKG_TOOL_VERSION "0.1"
+#define APP_INSTALLATION_PATH_RW tzplatform_getenv(TZ_USER_APP)
+#define MAX_QUERY_LEN 4096
+
+#define OWNER_ROOT 0
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+#define DEFAULT_USER tzplatform_getuid(TZ_SYS_DEFAULT_USER)
+
+#define OPTVAL_GLOBAL 1000
+#define OPTVAL_CLEAR_ALL 1001
+#define OPTVAL_UID 1002
+
+static int __is_app_installed(char *pkgid, uid_t uid);
+static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type,
+ const char *pkgid, const char *key, const char *val,
+ const void *pmsg, void *data);
+
+enum pm_tool_request_e {
+ INSTALL_REQ = 1,
+ UNINSTALL_REQ,
+ REINSTALL_REQ,
+ MOUNT_INSTALL_REQ,
+ GETSIZE_REQ,
+ CLEAR_REQ,
+ CLEAR_ALL_REQ,
+ MOVE_REQ,
+ ACTIVATE_REQ,
+ DEACTIVATE_REQ,
+ APPPATH_REQ,
+ CHECKAPP_REQ,
+ KILLAPP_REQ,
+ LIST_REQ,
+ SHOW_REQ,
+ CREATE_DELTA,
+ GET_PKG_SIZE_INFO_REQ
+};
+typedef enum pm_tool_request_e req_type;
+
+struct pm_tool_args_t {
+ req_type request;
+ char pkg_path[PATH_MAX];
+ char pkg_type[PKG_TYPE_STRING_LEN_MAX];
+ char pkgid[PKG_NAME_STRING_LEN_MAX];
+ char des_path[PATH_MAX];
+ char pkg_old[PATH_MAX];
+ char pkg_new[PATH_MAX];
+ char delta_pkg[PATH_MAX];
+ char *resolved_path_pkg_old;
+ char *resolved_path_pkg_new;
+ char *resolved_path_delta_pkg;
+ char label[PKG_NAME_STRING_LEN_MAX];
+ char tep_path[PATH_MAX];
+ GList *pkgs;
+ int start_count;
+ int end_count;
+
+ bool tep_move;
+ int global;
+ int type;
+ int result;
+ int uid;
+ bool debug_mode;
+ bool skip_optimization;
+};
+typedef struct pm_tool_args_t pm_tool_args;
+
+typedef int (*dispatch_func)(pm_tool_args *data, uid_t target_uid);
+
+static GMainLoop *main_loop = NULL;
+
+static void __free_data(pm_tool_args *data)
+{
+ if (data->resolved_path_pkg_old)
+ free(data->resolved_path_pkg_old);
+ if (data->resolved_path_pkg_new)
+ free(data->resolved_path_pkg_new);
+ if (data->resolved_path_delta_pkg)
+ free(data->resolved_path_delta_pkg);
+ if (data->pkgs)
+ g_list_free_full(data->pkgs, free);
+}
+
+static void __error_no_to_string(int errnumber, char **errstr)
+{
+ if (errstr == NULL)
+ return;
+ switch (errnumber) {
+ case PKGMGR_INSTALLER_ERRCODE_GLOBALSYMLINK_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_GLOBALSYMLINK_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_GRANT_PERMISSION_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_GRANT_PERMISSION_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_IMAGE_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_IMAGE_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_UNZIP_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_UNZIP_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_SECURITY_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_SECURITY_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_REGISTER_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_REGISTER_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_PRIVILEGE_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_PRIVILEGE_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_PARSE_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_PARSE_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_RECOVERY_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_RECOVERY_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_DELTA_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_DELTA_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_APP_DIR_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_APP_DIR_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_CONFIG_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_CONFIG_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_SIGNATURE_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_SIGNATURE_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_SIGNATURE_INVALID:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_SIGNATURE_INVALID_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_CERT_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_CERT_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_MATCH:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_MATCH_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_FOUND:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_FOUND_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_ICON_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_ICON_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_ICON_NOT_FOUND:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_ICON_NOT_FOUND_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_MANIFEST_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_MANIFEST_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_MANIFEST_NOT_FOUND:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_MANIFEST_NOT_FOUND_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_OPERATION_NOT_ALLOWED:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_OPERATION_NOT_ALLOWED_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_OUT_OF_SPACE:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_OUT_OF_SPACE_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_INVALID_VALUE:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_INVALID_VALUE_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_ERROR:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_ERROR_STR;
+ break;
+ case PKGMGR_INSTALLER_ERRCODE_OK:
+ *errstr = PKGMGR_INSTALLER_ERRCODE_OK_STR;
+ break;
+ default:
+ *errstr = "Undefined Error";
+ break;
+ }
+}
+
+static uid_t __get_current_user_id(void)
+{
+ uid_t uid = getuid();
+
+ if (uid == OWNER_ROOT)
+ uid = DEFAULT_USER;
+
+ return uid;
+}
+
+static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type,
+ const char *pkgid, const char *key, const char *val,
+ const void *pmsg, void *priv_data)
+{
+ int ret_val;
+ char delims[] = ":";
+ char *ret_result = NULL;
+ pm_tool_args *data = (pm_tool_args *)priv_data;
+
+ if (strncmp(key, "error", strlen("error")) == 0) {
+ ret_val = atoi(val);
+ data->result = ret_val;
+
+ ret_result = strstr((char *)val, delims);
+ if (ret_result)
+ printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d] error message: %s\n",
+ req_id, pkg_type, pkgid, key, ret_val, ret_result);
+ else
+ printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d]\n",
+ req_id, pkg_type, pkgid, key, ret_val);
+ } else
+ printf("__return_cb req_id[%d] pkg_type[%s] "
+ "pkgid[%s] key[%s] val[%s]\n",
+ req_id, pkg_type, pkgid, key, val);
+
+ if (strncmp(key, "start", strlen("start")) == 0)
+ data->start_count++;
+
+ if (strncmp(key, "end", strlen("end")) == 0) {
+ data->end_count++;
+ if ((strncmp(val, "fail", strlen("fail")) == 0) && data->result == 0)
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ if (data->start_count == data->end_count)
+ g_main_loop_quit(main_loop);
+ }
+
+ return 0;
+}
+
+static int __app_return_cb(uid_t target_uid, int req_id, const char *pkg_type,
+ const char *pkgid, const char *appid, const char *key, const char *val,
+ const void *pmsg, void *priv_data)
+{
+ int ret_val;
+ pm_tool_args *data = (pm_tool_args *)priv_data;
+
+ if (strncmp(key, "error", strlen("error")) == 0) {
+ ret_val = atoi(val);
+ data->result = ret_val;
+ }
+
+ printf("__app_return_cb req_id[%d] pkg_type[%s] pkgid[%s] appid[%s] " \
+ "key[%s] val[%s]\n",
+ req_id, pkg_type, pkgid, appid, key, val);
+
+ if (strncmp(key, "end", strlen("end")) == 0) {
+ if ((strncmp(val, "fail", strlen("fail")) == 0) && data->result == 0)
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ g_main_loop_quit(main_loop);
+ }
+
+ return 0;
+}
+
+static int __convert_to_absolute_path(pm_tool_args *data)
+{
+ char abs[PATH_MAX] = {'\0'};
+ char *temp;
+ char *ptr = NULL;
+ int ret;
+ GList *list;
+
+ ptr = realpath(data->pkg_path, abs);
+ if (ptr == NULL) {
+ printf("realpath fail: %d\n", errno);
+ return -1;
+ }
+ ret = snprintf(data->pkg_path, PATH_MAX - 1, "%s", abs);
+ if (ret < 0 || ret > PATH_MAX - 1) {
+ printf("snprintf fail\n");
+ return -1;
+ }
+
+ for (list = data->pkgs; list; list = list->next) {
+ ptr = realpath(list->data, abs);
+ if (ptr == NULL) {
+ printf("realpath fail: %d\n", errno);
+ return -1;
+ }
+ temp = list->data;
+ list->data = strdup(abs);
+ if (list->data == NULL) {
+ printf("out of memory\n");
+ return -1;
+ }
+ free(temp);
+ }
+
+ return 0;
+}
+
+static int __convert_to_absolute_tep_path(pm_tool_args *data)
+{
+ char abs[PATH_MAX] = {'\0'};
+ char temp[PATH_MAX] = {'\0'};
+ char *ptr = NULL;
+ int ret;
+ if (data->tep_path[0] == '\0') {
+ printf("path is NULL\n");
+ return -1;
+ }
+ ret = snprintf(temp, PATH_MAX - 1, "%s", data->tep_path);
+ if (ret < 0 || ret > PATH_MAX - 1) {
+ printf("snprintf fail\n");
+ return -1;
+ }
+ if (strchr(data->tep_path, '/') == NULL) {
+ if (getcwd(abs, PATH_MAX - 1) == NULL || abs[0] == '\0') {
+ printf("getcwd() failed\n");
+ return -1;
+ }
+ memset(data->tep_path, '\0', PATH_MAX);
+ ret = snprintf(data->tep_path, PATH_MAX - 1, "%s/%s", abs, temp);
+ if (ret < 0 || ret > PATH_MAX - 1) {
+ printf("snprintf fail\n");
+ return -1;
+ }
+ return 0;
+ }
+ if (strncmp(data->tep_path, "./", 2) == 0) {
+ ptr = temp;
+ if (getcwd(abs, PATH_MAX - 1) == NULL || abs[0] == '\0') {
+ printf("getcwd() failed\n");
+ return -1;
+ }
+ ptr = ptr + 2;
+ memset(data->tep_path, '\0', PATH_MAX);
+ ret = snprintf(data->tep_path, PATH_MAX - 1, "%s/%s", abs, ptr);
+ if (ret < 0 || ret > PATH_MAX - 1) {
+ printf("snprintf fail\n");
+ return -1;
+ }
+ return 0;
+ }
+ return 0;
+}
+
+static int __is_app_installed(char *pkgid, uid_t uid)
+{
+ pkgmgrinfo_pkginfo_h handle;
+ int ret;
+
+ ret = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, uid, &handle);
+ if (ret < 0) {
+ printf("package is not in pkgmgr_info DB\n");
+ return -1;
+ } else {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ }
+
+ return 0;
+}
+
+static void __print_usage()
+{
+ printf("\nPackage Manager Tool Version: %s\n", PKG_TOOL_VERSION);
+
+ printf("\n");
+ printf("-i, --install install the package\n");
+ printf("-u, --uninstall uninstall the package\n");
+ printf("-r, --reinstall reinstall the package\n");
+ printf("-w, --mount-install mount install the package\n");
+ printf("-c, --clear clear user data\n");
+ printf(" --clear-all clear user data for all packages or packages type\n");
+ printf("-m, --move move package\n");
+ printf("-g, --getsize get size of given package\n");
+ printf("-T, --getsize-type get type [0: total size / 1: data size]\n");
+ printf("-l, --list display list of installed packages available for the current user\n");
+ printf(" i.e. user's specific apps and global apps\n");
+ printf("-s, --show show detail package info\n");
+ printf("-a, --app-path show app installation path\n");
+ printf("-C, --check check if applications belonging to a package are running or not\n");
+ printf("-k, --kill terminate applications belonging to a package\n");
+ printf("-d, --descriptor provide descriptor path\n");
+ printf("-p, --package-path provide package path\n");
+ printf("-n, --package-name provide package name\n");
+ printf("-t, --package-type provide package type\n");
+ printf("-T, --move-type provide move type [0: move to internal / 1: move to external / 2: move to extended]\n");
+ printf(" --global Global Mode [Warning: user should be privilegied to use this mode]\n");
+ printf(" --uid Specify target user's id. This only affect app activation/deactivation.\n");
+ printf("-e, --tep-path provide TEP package path\n");
+ printf("-M, --tep-move decide move/copy of TEP package [0: copy TEP package / 1: move TEP package]\n");
+ printf("-G, --debug-mode install the package with debug mode for sdk\n");
+ printf("-D, --deactivate disable package or app\n");
+ printf("-A, --activate enable package or app\n");
+ printf("-S, --skip-optimization install the package with skip optimization for sdk\n");
+ printf("-h, --help print this help\n");
+
+ printf("\n");
+ printf("Usage: pkgcmd [options]\n");
+ printf("pkgcmd -i -t <pkg type> (-d <descriptor path>) -p <pkg path> (--global)\n");
+ printf("pkgcmd -u -n <pkgid> (--global)\n");
+ printf("pkgcmd -r -t <pkg type> -n <pkgid> (--global)\n");
+ printf("pkgcmd -w -t <pkg type> (-d <descriptor path>) -p <pkg path> (--global)\n");
+ printf("pkgcmd -l (-t <pkg type>)\n");
+ printf("pkgcmd -s -t <pkg type> -p <pkg path>\n");
+ printf("pkgcmd -s -t <pkg type> -n <pkg name>\n");
+ printf("pkgcmd -m -t <pkg type> -T <move type> -n <pkg name>\n");
+ printf("pkgcmd -g -T <getsize type> -n <pkgid>\n");
+ printf("pkgcmd -C -n <pkgid>\n");
+ printf("pkgcmd -k -n <pkgid>\n");
+ printf("pkgcmd --clear-all (-t <pkg type>)\n");
+ printf("pkgcmd -X <old_pkg> -Y <new_pkg> -Z <delta_pkg>\n");
+ printf("pkgcmd -D -t <pkg type> -n <pkgid> (--global) (--uid <uid>)\n");
+
+ printf("\n");
+ printf("Example:\n");
+ printf("pkgcmd -u -n org.example.hello\n");
+ printf("pkgcmd -i -t tpk -p /tmp/org.example.hello-1.0.0-arm.tpk\n");
+ printf("pkgcmd -r -t tpk -n org.example.hello\n");
+ printf("pkgcmd -w -t tpk -p /tmp/org.example.hello-1.0.0-arm.tpk\n");
+ printf("pkgcmd -c -t tpk -n org.example.hello\n");
+ printf("pkgcmd --clear-all -t wgt\n");
+ printf("pkgcmd -m -t tpk -T 1 -n org.example.hello\n");
+ printf("pkgcmd -C -n org.example.hello\n");
+ printf("pkgcmd -k -n org.example.hello\n");
+ printf("pkgcmd -a\n");
+ printf("pkgcmd -a -t tpk -n org.example.hello\n");
+ printf("pkgcmd -l\n");
+ printf("pkgcmd -l -t tpk\n");
+ printf("pkgcmd -g -T 0 -n org.example.hello\n");
+ printf("pkgcmd -D -t tpk -n org.example.hellopkg\n");
+ printf("pkgcmd -D -t app -n org.example.helloapp --global\n");
+
+ printf("\n");
+ exit(0);
+}
+
+static int __pkgmgr_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+ int ret = -1;
+ char *pkgid = NULL;
+ char *pkg_type = NULL;
+ char *pkg_version = NULL;
+ char *pkg_label = NULL;
+ bool for_all_users = 0;
+ pkgmgrinfo_installed_storage storage;
+
+ ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+ if (ret == -1) {
+ printf("Failed to get pkgmgrinfo_pkginfo_get_pkgid\n");
+ return ret;
+ }
+ ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type);
+ if (ret == -1) {
+ printf("Failed to get pkgmgrinfo_pkginfo_get_type\n");
+ return ret;
+ }
+ ret = pkgmgrinfo_pkginfo_get_version(handle, &pkg_version);
+ if (ret == -1) {
+ printf("Failed to get pkgmgrinfo_pkginfo_get_version\n");
+ return ret;
+ }
+ ret = pkgmgrinfo_pkginfo_get_label(handle, &pkg_label);
+ if (ret == -1)
+ pkg_label = "(null)";
+
+ ret = pkgmgrinfo_pkginfo_is_for_all_users(handle, &for_all_users);
+ if (ret == -1) {
+ printf("Failed to get pkgmgrinfo_pkginfo_is_for_all_users\n");
+ return ret;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_installed_storage(handle, &storage);
+ if (ret == -1) {
+ printf("Failed to get pkgmgrinfo_pkginfo_get_installed_storage\n");
+ return ret;
+ }
+
+ printf("%s\tpkg_type [%s]\tpkgid [%s]\tname [%s]\tversion [%s]\tstorage [%s]\n",
+ for_all_users ? "system apps" : "user apps ", pkg_type, pkgid, pkg_label, pkg_version,
+ (storage == PMINFO_EXTERNAL_STORAGE) ? "external" : "internal");
+ return ret;
+}
+
+static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+ int ret = -1;
+ char *pkgid;
+ pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle;
+
+ ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+ if (ret < 0)
+ printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n");
+
+ ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE,
+ (pkgmgr_client *)user_data, NULL, pkgid, uid_info->uid, NULL, NULL, NULL);
+ if (ret < 0) {
+ printf("pkgmgr_client_request_service Failed\n");
+ return -1;
+ }
+
+ printf("pkg[%s] size = %d\n", pkgid, ret);
+
+ 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 __pkgmgr_list_clear_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+ int ret = -1;
+ char *pkgid = NULL;
+ char *pkg_type = NULL;
+ pm_tool_args *data = (pm_tool_args *)user_data;
+
+ ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+ if (ret == -1) {
+ printf("Failed to get pkgmgrinfo_pkginfo_get_pkgid\n");
+ return ret;
+ }
+ ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type);
+ if (ret == -1) {
+ printf("Failed to get pkgmgrinfo_pkginfo_get_type\n");
+ return ret;
+ }
+
+ pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle;
+ uid_t uid = uid_info->uid;
+
+ pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST);
+ if (pc == NULL) {
+ printf("PkgMgr Client Creation Failed\n");
+ return -1;
+ }
+ ret = pkgmgr_client_usr_clear_user_data(pc, pkg_type, pkgid, PM_QUIET,
+ uid);
+ if (ret >= 0)
+ ret = data->result;
+ pkgmgr_client_free(pc);
+
+ return ret;
+}
+
+static void __invalid_arg_handler(pm_tool_args *data)
+{
+ printf("Please provide the arguments.\n");
+ printf("use -h option to see usage\n");
+ data->result = PKGMGR_INSTALLER_ERRCODE_INVALID_VALUE;
+}
+
+static int __install_single_pkg(pkgmgr_client *pc, pm_tool_args *data,
+ uid_t target_uid)
+{
+ int ret;
+
+ if (data->des_path[0] == '\0')
+ ret = pkgmgr_client_usr_install(pc,
+ data->pkg_type[0] != '\0' ? data->pkg_type : NULL,
+ NULL, data->pkg_path, NULL, PM_QUIET,
+ __return_cb, data, target_uid);
+ else
+ ret = pkgmgr_client_usr_install(pc,
+ data->pkg_type[0] != '\0' ? data->pkg_type : NULL,
+ data->des_path, data->pkg_path,
+ NULL, PM_QUIET, __return_cb, data, target_uid);
+
+ return ret;
+}
+
+static int __install_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data,
+ uid_t target_uid)
+{
+ int ret;
+ const char **pkgs;
+ int n_pkgs;
+ GList *l;
+ int i;
+
+ n_pkgs = g_list_length(data->pkgs);
+
+ pkgs = malloc(sizeof(char *) * n_pkgs);
+ for (l = data->pkgs, i = 0; l; l = l->next, i++)
+ pkgs[i] = (char *)l->data;
+
+ ret = pkgmgr_client_usr_install_packages(pc, pkgs, n_pkgs, __return_cb,
+ data, target_uid);
+
+ free(pkgs);
+
+ return ret;
+}
+
+static int __install_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ pkgmgr_client *pc;
+ GList *list;
+ char *pkg;
+
+ if (data->pkg_path[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+ 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 = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ return -1;
+ }
+
+ if (data->debug_mode)
+ pkgmgr_client_set_debug_mode(pc, true);
+
+ if (data->skip_optimization)
+ pkgmgr_client_set_skip_optimization(pc, true);
+
+ if (data->tep_path[0] != '\0')
+ pkgmgr_client_set_tep_path(pc, data->tep_path, data->tep_move);
+
+ if (g_list_length(data->pkgs) > 1)
+ ret = __install_multiple_pkgs(pc, data, target_uid);
+ else
+ ret = __install_single_pkg(pc, data, target_uid);
+
+ if (ret < 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ if (access(data->pkg_path, F_OK) != 0)
+ data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
+ for (list = data->pkgs; list; list = list->next) {
+ pkg = (char *)list->data;
+ if (access(pkg, F_OK) != 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
+ break;
+ }
+ }
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+ g_main_loop_run(main_loop);
+ pkgmgr_client_free(pc);
+ return data->result;
+}
+
+static int __uninstall_single_pkg(pkgmgr_client *pc, pm_tool_args *data,
+ uid_t target_uid)
+{
+ return pkgmgr_client_usr_uninstall(pc, data->pkg_type, data->pkgid,
+ PM_QUIET, __return_cb, data, target_uid);
+}
+
+static int __uninstall_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data,
+ uid_t target_uid)
+{
+ int ret;
+ const char **pkgs;
+ int n_pkgs;
+ GList *l;
+ int i;
+
+ n_pkgs = g_list_length(data->pkgs);
+
+ pkgs = malloc(sizeof(char *) * n_pkgs);
+ for (l = data->pkgs, i = 0; l; l = l->next, i++)
+ pkgs[i] = (char *)l->data;
+
+ ret = pkgmgr_client_usr_uninstall_packages(pc, pkgs, n_pkgs,
+ __return_cb, data, target_uid);
+
+ free(pkgs);
+
+ return ret;
+}
+
+static int __uninstall_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ pkgmgr_client *pc;
+
+ if (data->pkgid[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+ 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 = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ return -1;
+ }
+
+ ret = __is_app_installed(data->pkgid, target_uid);
+ if (ret == -1) {
+ printf("package is not installed\n");
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+
+ if (g_list_length(data->pkgs) > 1)
+ ret = __uninstall_multiple_pkgs(pc, data, target_uid);
+ else
+ ret = __uninstall_single_pkg(pc, data, target_uid);
+
+ if (ret < 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ if (access(data->pkg_path, F_OK) != 0)
+ data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+ g_main_loop_run(main_loop);
+ pkgmgr_client_free(pc);
+ return data->result;
+}
+
+static int __reinstall_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ pkgmgr_client *pc;
+
+ if (data->pkgid[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+ 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 = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ return -1;
+ }
+
+ if (data->debug_mode)
+ pkgmgr_client_set_debug_mode(pc, true);
+
+ if (data->skip_optimization)
+ pkgmgr_client_set_skip_optimization(pc, true);
+
+ ret = pkgmgr_client_usr_reinstall(pc, NULL,
+ data->pkgid, NULL, PM_QUIET, __return_cb, data, target_uid);
+ if (ret < 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ if (access(data->pkg_path, F_OK) != 0)
+ data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+ g_main_loop_run(main_loop);
+ pkgmgr_client_free(pc);
+ return data->result;
+}
+
+static int __mount_install_single_pkg(pkgmgr_client *pc, pm_tool_args *data,
+ uid_t target_uid)
+{
+ int ret;
+
+ if (data->des_path[0] == '\0')
+ ret = pkgmgr_client_usr_mount_install(pc,
+ data->pkg_type[0] != '\0' ? data->pkg_type : NULL,
+ NULL, data->pkg_path, NULL, PM_QUIET,
+ __return_cb, data, target_uid);
+ else
+ ret = pkgmgr_client_usr_mount_install(pc,
+ data->pkg_type[0] != '\0' ? data->pkg_type : NULL,
+ data->des_path, data->pkg_path,
+ NULL, PM_QUIET, __return_cb, data, target_uid);
+
+ return ret;
+}
+
+static int __mount_install_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data,
+ uid_t target_uid)
+{
+ int ret;
+ const char **pkgs;
+ int n_pkgs;
+ GList *l;
+ int i;
+
+ n_pkgs = g_list_length(data->pkgs);
+
+ pkgs = malloc(sizeof(char *) * n_pkgs);
+ for (l = data->pkgs, i = 0; l; l = l->next, i++)
+ pkgs[i] = (char *)l->data;
+
+ ret = pkgmgr_client_usr_mount_install_packages(pc, pkgs, n_pkgs,
+ __return_cb, data, target_uid);
+
+ free(pkgs);
+
+ return ret;
+}
+
+static int __mount_install_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ pkgmgr_client *pc;
+ GList *list;
+ char *pkg;
+
+ if (data->pkg_path[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+ 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 = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ return -1;
+ }
+
+ if (data->debug_mode)
+ pkgmgr_client_set_debug_mode(pc, true);
+
+ if (data->skip_optimization)
+ pkgmgr_client_set_skip_optimization(pc, true);
+
+ if (data->tep_path[0] != '\0')
+ pkgmgr_client_set_tep_path(pc, data->tep_path, data->tep_move);
+
+ if (g_list_length(data->pkgs) > 1)
+ ret = __mount_install_multiple_pkgs(pc, data, target_uid);
+ else
+ ret = __mount_install_single_pkg(pc, data, target_uid);
+
+ if (ret < 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ if (access(data->pkg_path, F_OK) != 0)
+ data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
+ for (list = data->pkgs; list; list = list->next) {
+ pkg = (char *)list->data;
+ if (access(pkg, F_OK) != 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND;
+ break;
+ }
+ }
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+ g_main_loop_run(main_loop);
+ pkgmgr_client_free(pc);
+ return data->result;
+}
+
+static int __getsize_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ pkgmgr_client *pc;
+
+ if (data->pkgid[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+
+ pc = pkgmgr_client_new(PC_REQUEST);
+ if (pc == NULL) {
+ printf("PkgMgr Client Creation Failed\n");
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ return -1;
+ }
+
+ if (data->type == 9) {
+ ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb,
+ (void *)(pc), target_uid);
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+ ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, data->type,
+ pc, NULL, data->pkgid, target_uid, NULL, NULL, NULL);
+ if (ret < 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+
+ printf("pkg[%s] size = %d\n", data->pkgid, ret);
+ pkgmgr_client_free(pc);
+ return data->result;
+}
+
+static int __clear_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ pkgmgr_client *pc;
+
+ if (data->pkg_type[0] == '\0' || data->pkgid[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+
+ pc = pkgmgr_client_new(PC_REQUEST);
+ if (pc == NULL) {
+ printf("PkgMgr Client Creation Failed\n");
+ return -1;
+ }
+ ret = __is_app_installed(data->pkgid, target_uid);
+ if (ret == -1) {
+ printf("package is not installed\n");
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+ ret = pkgmgr_client_usr_clear_user_data(pc, data->pkg_type,
+ data->pkgid, PM_QUIET, target_uid);
+ if (ret < 0) {
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+ pkgmgr_client_free(pc);
+ return data->result;
+}
+
+static int __clear_all_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+
+ if (data->pkg_type[0] == '\0') {
+ ret = pkgmgrinfo_pkginfo_get_usr_list(__pkgmgr_list_clear_cb,
+ data, target_uid);
+ if (ret == -1)
+ printf("no packages found\n");
+ return ret;
+ }
+ pkgmgrinfo_pkginfo_filter_h handle;
+
+ ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+ if (ret == -1) {
+ printf("Failed to get package filter handle\n");
+ return ret;
+ }
+
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data->pkg_type);
+ if (ret == -1) {
+ printf("Failed to add package type filter\n");
+ pkgmgrinfo_pkginfo_filter_destroy(handle);
+ return ret;
+ }
+
+ ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle,
+ __pkgmgr_list_clear_cb, data, target_uid);
+ if (ret != PMINFO_R_OK)
+ printf("no package filter list\n");
+
+ pkgmgrinfo_pkginfo_filter_destroy(handle);
+ return ret;
+}
+
+static int __move_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ pkgmgr_client *pc;
+
+ if (data->pkg_type[0] == '\0' || data->pkgid[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+ if (data->type < 0 || data->type > 2) {
+ printf("Invalid move type...See usage\n");
+ return -1;
+ }
+
+ main_loop = g_main_loop_new(NULL, FALSE);
+ pc = pkgmgr_client_new(PC_REQUEST);
+ if (pc == NULL) {
+ printf("PkgMgr Client Creation Failed\n");
+ return -1;
+ }
+ ret = __is_app_installed(data->pkgid, target_uid);
+ if (ret == -1) {
+ printf("package is not installed\n");
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+ ret = pkgmgr_client_usr_request_service(PM_REQUEST_MOVE, data->type, pc,
+ data->pkg_type, data->pkgid, target_uid, NULL, __return_cb, data);
+
+ if (ret < 0) {
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+
+ g_main_loop_run(main_loop);
+ pkgmgr_client_free(pc);
+ return data->result;
+}
+
+static int __activate_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ pkgmgrinfo_appinfo_h appinfo_h;
+ pkgmgr_client *pc;
+ pkgmgr_client *listen_pc = NULL;
+
+ if (data->pkg_type[0] == '\0' || data->pkgid[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+
+ main_loop = g_main_loop_new(NULL, FALSE);
+ pc = pkgmgr_client_new(PC_REQUEST);
+ if (pc == NULL) {
+ printf("PkgMgr Client Creation Failed\n");
+ return -1;
+ }
+
+ if (strlen(data->label) != 0) {
+ printf("requested label = %s\n", data->label);
+
+ ret = pkgmgr_client_usr_set_app_label(pc, data->pkgid,
+ data->label, target_uid);
+ if (ret < 0) {
+ printf("set_app_label is failed\n");
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+
+ printf("set_app_label is done\n");
+ }
+
+ if (strcmp(data->pkg_type, "app") == 0) {
+ if (data->global && data->uid != -1) {
+ if (data->uid != __get_current_user_id()) {
+ printf("Invalid uid : %d\n", data->uid);
+ pkgmgr_client_free(pc);
+ return -1;
+ }
+ target_uid = data->uid;
+ }
+ ret = pkgmgrinfo_appinfo_get_usr_disabled_appinfo(data->pkgid,
+ target_uid, &appinfo_h);
+ if (ret != PMINFO_R_OK) {
+ printf("Failed to get appinfo[%s]\n", data->pkgid);
+ pkgmgr_client_free(pc);
+ return -1;
+ }
+
+ if (data->global) {
+ if (data->uid != -1)
+ /* enable global app for this user only */
+ ret = pkgmgr_client_activate_global_app_for_uid(pc,
+ data->pkgid, __app_return_cb, data,
+ __get_current_user_id());
+ else
+ /* enable global app for all user */
+ ret = pkgmgr_client_usr_activate_app(pc, data->pkgid,
+ __app_return_cb, data, GLOBAL_USER);
+ } else {
+ /* enable local app */
+ ret = pkgmgr_client_usr_activate_app(pc, data->pkgid,
+ __app_return_cb, data, target_uid);
+ }
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
+ } else {
+ listen_pc = pkgmgr_client_new(PC_LISTENING);
+ if (listen_pc == NULL) {
+ printf("PkgMgr Client Creation Failed\n");
+ pkgmgr_client_free(pc);
+ return -1;
+ }
+ ret = pkgmgr_client_listen_status(listen_pc, __return_cb, data);
+ if (ret < 0) {
+ printf("Failed to set callback[%d]\n", ret);
+ pkgmgr_client_free(pc);
+ pkgmgr_client_free(listen_pc);
+ return ret;
+ }
+ ret = pkgmgr_client_usr_activate(pc, data->pkg_type, data->pkgid,
+ target_uid);
+ }
+ if (ret < 0) {
+ pkgmgr_client_free(pc);
+ if (listen_pc)
+ pkgmgr_client_free(listen_pc);
+ return ret;
+ }
+
+ g_main_loop_run(main_loop);
+
+ pkgmgr_client_free(pc);
+ if (listen_pc)
+ pkgmgr_client_free(listen_pc);
+ return data->result;
+}
+
+static int __deactivate_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ pkgmgrinfo_appinfo_h appinfo_h;
+ pkgmgr_client *pc;
+ pkgmgr_client *listen_pc = NULL;
+
+ if (data->pkg_type[0] == '\0' || data->pkgid[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+
+ main_loop = g_main_loop_new(NULL, FALSE);
+ pc = pkgmgr_client_new(PC_REQUEST);
+ if (pc == NULL) {
+ printf("PkgMgr Client Creation Failed\n");
+ return -1;
+ }
+
+ if (strcmp(data->pkg_type, "app") == 0) {
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(data->pkgid,
+ target_uid, &appinfo_h);
+ if (ret != PMINFO_R_OK) {
+ printf("Failed to get appinfo[%s]\n", data->pkgid);
+ pkgmgr_client_free(pc);
+ return -1;
+ }
+
+ if (data->global) {
+ if (data->uid != -1 && data->uid != getuid()) {
+ printf("Invalid uid : %d\n", data->uid);
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
+ pkgmgr_client_free(pc);
+ return -1;
+ }
+ if (data->uid != -1)
+ /* disable global app for this user only */
+ ret = pkgmgr_client_deactivate_global_app_for_uid(pc,
+ data->pkgid, __app_return_cb, NULL,
+ __get_current_user_id());
+ else
+ /* disable global app for all user */
+ ret = pkgmgr_client_usr_deactivate_app(pc, data->pkgid,
+ __app_return_cb, NULL, GLOBAL_USER);
+ } else {
+ /* disable local app */
+ ret = pkgmgr_client_usr_deactivate_app(pc, data->pkgid,
+ __app_return_cb, NULL, target_uid);
+ }
+
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
+ } else {
+ listen_pc = pkgmgr_client_new(PC_LISTENING);
+ if (listen_pc == NULL) {
+ printf("PkgMgr Client Creation Failed\n");
+ pkgmgr_client_free(pc);
+ return -1;
+ }
+ ret = pkgmgr_client_listen_status(listen_pc, __return_cb, data);
+ if (ret < 0) {
+ printf("Failed to set callback[%d]\n", ret);
+ pkgmgr_client_free(pc);
+ pkgmgr_client_free(listen_pc);
+ return ret;
+ }
+ ret = pkgmgr_client_usr_deactivate(pc, data->pkg_type, data->pkgid,
+ target_uid);
+ }
+ if (ret < 0) {
+ pkgmgr_client_free(pc);
+ if (listen_pc)
+ pkgmgr_client_free(listen_pc);
+ return ret;
+ }
+
+ g_main_loop_run(main_loop);
+
+ pkgmgr_client_free(pc);
+ if (listen_pc)
+ pkgmgr_client_free(listen_pc);
+ return data->result;
+}
+
+static int __apppath_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ char buf[1024];
+
+ if (data->pkg_type[0] == '\0' && data->pkgid[0] == '\0') {
+ printf("Tizen Application Installation Path: %s\n",
+ APP_INSTALLATION_PATH_RW);
+ return 0;
+ }
+ if ((data->pkg_type[0] == '\0') || (data->pkgid[0] == '\0')) {
+ printf("Use -h option to see usage\n");
+ return -1;
+ }
+ if (strncmp(data->pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
+ snprintf(buf, 1023, "%s/%s/res/wgt",
+ APP_INSTALLATION_PATH_RW, data->pkgid);
+ printf("Tizen Application Installation Path: %s\n", buf);
+ return 0;
+ } else if (strncmp(data->pkg_type, "tpk", PKG_TYPE_STRING_LEN_MAX - 1) == 0) {
+ snprintf(buf, 1023, "%s/%s", APP_INSTALLATION_PATH_RW, data->pkgid);
+ printf("Tizen Application Installation Path: %s\n", buf);
+ return 0;
+ } else {
+ printf("Invalid package type.\n");
+ printf("use -h option to see usage\n");
+ return -1;
+ }
+}
+
+static int __checkapp_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ int pid = -1;
+ pkgmgr_client *pc;
+
+ if (data->pkgid[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+
+ pc = pkgmgr_client_new(PC_REQUEST);
+ if (pc == NULL) {
+ printf("PkgMgr Client Creation Failed\n");
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ return -1;
+ }
+
+ if (data->request == KILLAPP_REQ) {
+ ret = pkgmgr_client_usr_request_service(PM_REQUEST_KILL_APP, 0, pc,
+ NULL, data->pkgid, target_uid, NULL, NULL, &pid);
+ if (ret < 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+ if (pid)
+ printf("Pkgid: %s is Terminated\n", data->pkgid);
+ else
+ printf("Pkgid: %s is already Terminated\n", data->pkgid);
+ } else if (data->request == CHECKAPP_REQ) {
+ ret = pkgmgr_client_usr_request_service(PM_REQUEST_CHECK_APP, 0, pc,
+ NULL, data->pkgid, target_uid, NULL, NULL, &pid);
+ if (ret < 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+
+ if (pid)
+ printf("Pkgid: %s is Running\n", data->pkgid);
+ else
+ printf("Pkgid: %s is Not Running\n", data->pkgid);
+ }
+ pkgmgr_client_free(pc);
+ return data->result;
+}
+
+static int __killapp_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ int pid = -1;
+ pkgmgr_client *pc;
+
+ if (data->pkgid[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+
+ pc = pkgmgr_client_new(PC_REQUEST);
+ if (pc == NULL) {
+ printf("PkgMgr Client Creation Failed\n");
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ return -1;
+ }
+
+ if (data->request == KILLAPP_REQ) {
+ ret = pkgmgr_client_usr_request_service(PM_REQUEST_KILL_APP, 0, pc,
+ NULL, data->pkgid, target_uid, NULL, NULL, &pid);
+ if (ret < 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+ if (pid)
+ printf("Pkgid: %s is Terminated\n", data->pkgid);
+ else
+ printf("Pkgid: %s is already Terminated\n", data->pkgid);
+ } else if (data->request == CHECKAPP_REQ) {
+ ret = pkgmgr_client_usr_request_service(PM_REQUEST_CHECK_APP, 0, pc,
+ NULL, data->pkgid, target_uid, NULL, NULL, &pid);
+ if (ret < 0) {
+ data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+
+ if (pid)
+ printf("Pkgid: %s is Running\n", data->pkgid);
+ else
+ printf("Pkgid: %s is Not Running\n", data->pkgid);
+ }
+ pkgmgr_client_free(pc);
+ return data->result;
+}
+
+static int __list_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+
+ if (data->pkg_type[0] == '\0') {
+ ret = pkgmgrinfo_pkginfo_get_usr_list(__pkgmgr_list_cb,
+ NULL, target_uid);
+ if (ret == -1)
+ printf("no packages found\n");
+ return ret;
+ }
+ pkgmgrinfo_pkginfo_filter_h handle;
+
+ ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+ if (ret == -1) {
+ printf("Failed to get package filter handle\n");
+ return ret;
+ }
+
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data->pkg_type);
+ if (ret == -1) {
+ printf("Failed to add package type filter\n");
+ pkgmgrinfo_pkginfo_filter_destroy(handle);
+ return ret;
+ }
+
+ ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle,
+ __pkgmgr_list_cb, NULL, target_uid);
+ if (ret != PMINFO_R_OK)
+ printf("no package filter list\n");
+
+ pkgmgrinfo_pkginfo_filter_destroy(handle);
+ return ret;
+}
+
+/* unsupported */
+static int __show_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ return -1;
+}
+
+static int __create_delta_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ char pkg_old[PATH_MAX];
+ char pkg_new[PATH_MAX];
+
+ printf("CREATE_DELTA\n");
+ if (data->pkg_old[0] == '\0' || data->pkg_new[0] == '\0') {
+ printf("tpk pkg missing\n");
+ return -1;
+ }
+ if (data->delta_pkg[0] == '\0') {
+ data->resolved_path_delta_pkg = strdup("/tmp/delta_pkg");
+ printf("output file will be /tmp/delta_pkg.delta\n");
+ }
+ const char *unzip_argv[] = {"sh",
+ "/etc/package-manager/pkgmgr-unzip-pkg.sh", "-a",
+ data->resolved_path_pkg_old, "-b", data->resolved_path_pkg_new, "-p",
+ data->resolved_path_delta_pkg, NULL};
+ ret = __xsystem(unzip_argv);
+ if (ret != 0) {
+ printf("unzip is fail .\n");
+ return ret;
+ }
+ printf("unzip is success .\n");
+ char *ptr_old_pkg = NULL;
+ ptr_old_pkg = strrchr(data->resolved_path_pkg_old, '/');
+
+ if (!ptr_old_pkg) {
+ printf("not able to extract package name.\n");
+ return ret;
+ }
+ ptr_old_pkg++;
+ char *ptr_new_pkg = NULL;
+ ptr_new_pkg = strrchr(data->resolved_path_pkg_new, '/');
+
+ if (!ptr_new_pkg) {
+ printf("not able to extract package name.\n");
+ return ret;
+ }
+ ptr_new_pkg++;
+
+ snprintf(pkg_old, PATH_MAX, "%s%s%s", TEMP_DELTA_REPO,
+ ptr_old_pkg, UNZIPFILE);
+ snprintf(pkg_new, PATH_MAX, "%s%s%s", TEMP_DELTA_REPO,
+ ptr_new_pkg, UNZIPFILE);
+ __create_diff_file(pkg_old, pkg_new);
+
+ const char *delta_argv[] = {"sh",
+ "/etc/package-manager/pkgmgr-create-delta.sh", "-a",
+ data->resolved_path_pkg_old, "-b", data->resolved_path_pkg_new, "-p",
+ data->resolved_path_delta_pkg, NULL};
+ ret = __xsystem(delta_argv);
+ if (ret != 0) {
+ printf("create delta script fail .\n");
+ return ret;
+ }
+ printf("create delta script success .\n");
+ return ret;
+}
+
+static int __get_pkg_size_info_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+ pkgmgr_client *pc;
+
+ if (data->pkgid[0] == '\0') {
+ __invalid_arg_handler(data);
+ return -1;
+ }
+
+ 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 = PKGMGR_INSTALLER_ERR_FATAL_ERROR;
+ return -1;
+ }
+
+ if (strcmp(data->pkgid, PKG_SIZE_INFO_TOTAL) == 0)
+ ret = pkgmgr_client_usr_get_total_package_size_info(pc,
+ __total_pkg_size_info_recv_cb, NULL,
+ target_uid);
+ else
+ ret = pkgmgr_client_usr_get_package_size_info(pc,
+ data->pkgid, __pkg_size_info_recv_cb, NULL,
+ target_uid);
+
+ if (ret < 0) {
+ data->result = PKGMGR_INSTALLER_ERR_FATAL_ERROR;
+ pkgmgr_client_free(pc);
+ return ret;
+ }
+
+ printf("pkg[%s] ret: %d\n", data->pkgid, ret);
+
+ g_main_loop_run(main_loop);
+ pkgmgr_client_free(pc);
+ return data->result;
+}
+
+static dispatch_func __process_request_func_ptr[] = {
+ [INSTALL_REQ] = __install_req_dispatcher,
+ [UNINSTALL_REQ] = __uninstall_req_dispatcher,
+ [REINSTALL_REQ] = __reinstall_req_dispatcher,
+ [MOUNT_INSTALL_REQ] = __mount_install_req_dispatcher,
+ [GETSIZE_REQ] = __getsize_req_dispatcher,
+ [CLEAR_REQ] = __clear_req_dispatcher,
+ [CLEAR_ALL_REQ] = __clear_all_req_dispatcher,
+ [MOVE_REQ] = __move_req_dispatcher,
+ [ACTIVATE_REQ] = __activate_req_dispatcher,
+ [DEACTIVATE_REQ] = __deactivate_req_dispatcher,
+ [APPPATH_REQ] = __apppath_req_dispatcher,
+ [CHECKAPP_REQ] = __checkapp_req_dispatcher,
+ [KILLAPP_REQ] = __killapp_req_dispatcher,
+ [LIST_REQ] = __list_req_dispatcher,
+ [SHOW_REQ] = __show_req_dispatcher,
+ [CREATE_DELTA] = __create_delta_dispatcher,
+ [GET_PKG_SIZE_INFO_REQ] = __get_pkg_size_info_req_dispatcher,
+};
+
+static int __process_request(pm_tool_args *data, uid_t target_uid)
+{
+ int ret;
+
+#if !GLIB_CHECK_VERSION(2, 35, 0)
+ g_type_init();
+#endif
+ size_t req_size =
+ sizeof(__process_request_func_ptr) / sizeof(dispatch_func);
+
+ if (data->request >= req_size || data->request == 0) {
+ printf("Wrong Request\n");
+ return -1;
+ }
+ ret = __process_request_func_ptr[data->request](data, target_uid);
+
+ return ret;
+}
+
+static void __parse_multiple_pkgs(pm_tool_args *data, int argc, char **argv)
+{
+ while ((optind <= argc) && (*argv[optind - 1] != '-')) {
+ data->pkgs = g_list_append(data->pkgs,
+ strdup(argv[optind - 1]));
+ optind++;
+ }
+ optind--;
+}
+
+int main(int argc, char *argv[])
+{
+ optind = 1;
+ int opt_idx = 0;
+ int c = -1;
+ int ret = -1;
+ char *errstr = NULL;
+ long starttime;
+ long endtime;
+ struct timeval tv;
+ bool is_root_cmd = false;
+ pm_tool_args data = { 0 };
+ GList *list;
+ /* Supported options */
+ /* Note: 'G' is reserved */
+ const char *short_options = "iurwmcgxCkaADL:lsd:p:t:n:T:e:M:X:Y:Z:qhGS";
+ const struct option long_options[] = {
+ {"install", 0, NULL, 'i'},
+ {"uninstall", 0, NULL, 'u'},
+ {"reinstall", 0, NULL, 'r'},
+ {"mount-install", 0, NULL, 'w'},
+ {"move", 0, NULL, 'm'},
+ {"clear", 0, NULL, 'c'},
+ {"clear-all", 0, NULL, OPTVAL_CLEAR_ALL},
+ {"getsize", 0, NULL, 'g'},
+ {"activate", 0, NULL, 'A'},
+ {"deactivate", 0, NULL, 'D'},
+ {"activate with Label", 1, NULL, 'L'},
+ {"check", 0, NULL, 'C'},
+ {"kill", 0, NULL, 'k'},
+ {"app-path", 0, NULL, 'a'},
+ {"list", 0, NULL, 'l'},
+ {"show", 0, NULL, 's'},
+ {"descriptor", 1, NULL, 'd'},
+ {"package-path", 1, NULL, 'p'},
+ {"old_pkg", 1, NULL, 'X'},
+ {"new_pkg", 1, NULL, 'Y'},
+ {"delta_pkg", 1, NULL, 'Z'},
+ {"package-type", 1, NULL, 't'},
+ {"package-name", 1, NULL, 'n'},
+ {"move-type", 1, NULL, 'T'},
+ {"getsize-type", 1, NULL, 'T'},
+ {"tep-path", 1, NULL, 'e'},
+ {"tep-move", 1, NULL, 'M'},
+ {"global", 0, NULL, OPTVAL_GLOBAL},
+ {"quiet", 0, NULL, 'q'},
+ {"help", 0, NULL, 'h'},
+ {"debug-mode", 0, NULL, 'G'},
+ {"getsizeinfo", 0, NULL, 'x'},
+ {"uid", 1, NULL, OPTVAL_UID},
+ {"skip-optimization", 0, NULL, 'S'},
+ {0, 0, 0, 0} /* sentinel */
+ };
+
+ if (argc == 1)
+ __print_usage();
+
+ gettimeofday(&tv, NULL);
+ starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+
+ data.request = -1;
+ memset(data.des_path, '\0', PATH_MAX);
+ memset(data.pkg_path, '\0', PATH_MAX);
+ memset(data.pkgid, '\0', PKG_NAME_STRING_LEN_MAX);
+ memset(data.pkg_old, '\0', PATH_MAX);
+ memset(data.pkg_new, '\0', PATH_MAX);
+ memset(data.delta_pkg, '\0', PATH_MAX);
+ memset(data.pkg_type, '\0', PKG_TYPE_STRING_LEN_MAX);
+ memset(data.label, '\0', PKG_TYPE_STRING_LEN_MAX);
+ memset(data.tep_path, '\0', PATH_MAX);
+
+ data.tep_move = 0;
+ data.global = 0; /* By default pkg_cmd will manage for the current user */
+ data.result = 0;
+ data.type = -1;
+ data.uid = -1;
+ data.pkgs = NULL;
+ data.start_count = 0;
+ data.end_count = 0;
+
+ while (1) {
+ c = getopt_long(argc, argv, short_options, long_options,
+ &opt_idx);
+ if (c == -1)
+ break; /* Parse end */
+ switch (c) {
+ case OPTVAL_GLOBAL: /* global mode */
+ data.global = 1;
+ break;
+
+ case 'i': /* install */
+ data.request = INSTALL_REQ;
+ break;
+
+ case 'u': /* uninstall */
+ data.request = UNINSTALL_REQ;
+ break;
+
+ case 'r': /* reinstall */
+ data.request = REINSTALL_REQ;
+ break;
+
+ case 'w': /* mount install */
+ data.request = MOUNT_INSTALL_REQ;
+ break;
+
+ case 'c': /* clear */
+ data.request = CLEAR_REQ;
+ break;
+
+ case OPTVAL_CLEAR_ALL: /* clear all */
+ data.request = CLEAR_ALL_REQ;
+ break;
+
+ case 'g': /* get pkg size */
+ 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;
+
+ case 'A': /* activate */
+ data.request = ACTIVATE_REQ;
+ break;
+
+ case 'D': /* deactivate */
+ data.request = DEACTIVATE_REQ;
+ break;
+
+ case 'L': /* activate with Label */
+ data.request = ACTIVATE_REQ;
+ if (optarg)
+ snprintf(data.label, sizeof(data.label),
+ "%s", optarg);
+ break;
+
+ case 'a': /* app installation path */
+ data.request = APPPATH_REQ;
+ break;
+
+ case 'k': /* Terminate applications of a package */
+ data.request = KILLAPP_REQ;
+ break;
+
+ case 'C': /* Check running status of applications of a package */
+ data.request = CHECKAPP_REQ;
+ break;
+
+ case 'l': /* list */
+ data.request = LIST_REQ;
+ break;
+
+ case 's': /* show */
+ data.request = SHOW_REQ;
+ break;
+
+ case 'p': /* package path */
+ if (optarg)
+ snprintf(data.pkg_path, sizeof(data.pkg_path),
+ "%s", optarg);
+ __parse_multiple_pkgs(&data, argc, argv);
+ ret = __convert_to_absolute_path(&data);
+ if (ret == -1)
+ printf("conversion of relative path to absolute path failed\n");
+ printf("path is ");
+ if (g_list_length(data.pkgs)) {
+ for (list = data.pkgs; list;
+ list = list->next) {
+ printf("%s ", (char *)list->data);
+ }
+ printf("\n");
+ } else {
+ printf("%s\n", data.pkg_path);
+ }
+ break;
+
+ case 'X': /* old_tpk */
+ data.request = CREATE_DELTA;
+ is_root_cmd = true;
+ if (optarg)
+ strncpy(data.pkg_old, optarg, PATH_MAX - 1);
+
+ data.resolved_path_pkg_old = realpath(data.pkg_old, NULL);
+ if (data.resolved_path_pkg_old == NULL) {
+ printf("failed to set realpath\n");
+ __free_data(&data);
+ return -1;
+ }
+ printf("pkg_old abs path is %s\n", data.resolved_path_pkg_old);
+ break;
+
+ case 'Y': /* new_tpk */
+ if (optarg)
+ strncpy(data.pkg_new, optarg, PATH_MAX - 1);
+
+ data.resolved_path_pkg_new = realpath(data.pkg_new, NULL);
+ if (data.resolved_path_pkg_new == NULL) {
+ printf("failed to set realpath\n");
+ __free_data(&data);
+ return -1;
+ }
+ printf("pkg_new abs path is %s\n", data.resolved_path_pkg_new);
+ break;
+
+ case 'Z': /* delta_tpk */
+ if (optarg)
+ strncpy(data.delta_pkg, optarg, PATH_MAX - 1);
+
+ printf("delta_pkg is %s\n", data.delta_pkg);
+
+ data.resolved_path_delta_pkg = realpath(data.delta_pkg, NULL);
+ if (data.resolved_path_delta_pkg == NULL) {
+ printf("failed to set realpath\n");
+ __free_data(&data);
+ return -1;
+ }
+ printf("delta_pkg abs path is %s\n", data.resolved_path_delta_pkg);
+ break;
+ case 'd': /* descriptor path */
+ if (optarg)
+ snprintf(data.des_path, sizeof(data.des_path),
+ "%s", optarg);
+ break;
+
+ case 'n': /* package name */
+ if (optarg)
+ snprintf(data.pkgid, sizeof(data.pkgid),
+ "%s", optarg);
+
+ __parse_multiple_pkgs(&data, argc, argv);
+ break;
+
+ case 'e': /* tep name */
+ if (optarg)
+ strncpy(data.tep_path, optarg,
+ PATH_MAX - 1);
+ ret = __convert_to_absolute_tep_path(&data);
+ if (ret == -1) {
+ printf("conversion of relative tep path to absolute path failed\n");
+ __free_data(&data);
+ return -1;
+ }
+ printf("TEP path is %s\n", data.tep_path);
+ break;
+
+ case 'M': /*tep move*/
+ if (optarg)
+ data.tep_move = (atoi(optarg) == 1) ? true : false;
+ break;
+
+ case 't': /* package type */
+ if (optarg)
+ snprintf(data.pkg_type, sizeof(data.pkg_type),
+ "%s", optarg);
+ break;
+
+ case 'T': /* move type */
+ if (optarg)
+ data.type = atoi(optarg);
+ break;
+
+ case 'h': /* help */
+ __free_data(&data);
+ __print_usage();
+ break;
+
+ case 'q': /* quiet mode is removed */
+ break;
+
+ case 'G': /* debug mode */
+ data.debug_mode = true;
+ break;
+
+ case 'S': /* skip optimization */
+ data.skip_optimization = true;
+ break;
+
+ /* Otherwise */
+ case '?': /* Not an option */
+ __free_data(&data);
+ __print_usage();
+ break;
+
+ case ':': /* */
+ break;
+
+ case OPTVAL_UID: /* specify target user id */
+ if (optarg)
+ data.uid = atoi(optarg);
+ break;
+
+ default:
+ break;
+
+ }
+ }
+
+ uid_t uid = getuid();
+ if (is_root_cmd && uid != OWNER_ROOT) {
+ printf("This cmd is allowed for only root user\n");
+ __free_data(&data);
+ return -1;
+ }
+
+ if (uid == OWNER_ROOT)
+ uid = DEFAULT_USER;
+
+ if (data.global == 1)
+ uid = GLOBAL_USER;
+
+ ret = __process_request(&data, uid);
+ if ((ret < 0) && (data.result == 0)) {
+ printf("Undefined error(%d)", ret);
+ data.result = PKGMGR_INSTALLER_ERRCODE_UNDEFINED_ERROR;
+ }
+
+ if (ret != 0) {
+ __error_no_to_string(data.result, &errstr);
+ printf("processing result : %s [%d] failed\n", errstr, data.result);
+ }
+
+ gettimeofday(&tv, NULL);
+ endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+ printf("spend time for pkgcmd is [%d]ms\n", (int)(endtime - starttime));
+ __free_data(&data);
+
+ return data.result;
+}
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <pkgmgr_parser.h>
+#include <pkgmgr-info.h>
+
+#include <package-manager.h>
+#include <package-manager-types.h>
+#include <pkgmgr_installer.h>
+
+#define OWNER_ROOT 0
+
+static void __print_usage();
+static int __get_pkg_info(char *pkgid, uid_t uid);
+static int __get_app_info(char *appid);
+static int __get_app_list(char *pkgid, uid_t uid);
+static int __get_app_category_list(char *appid);
+static int __get_app_metadata_list(char *appid);
+static int __get_app_control_list(char *appid);
+static int __get_pkg_list(uid_t uid);
+static int __get_installed_app_list(uid_t uid);
+static int __add_app_filter(uid_t uid);
+static int __add_pkg_filter(uid_t uid);
+static int __set_certinfo_in_db(char *pkgid, uid_t uid);
+static int __get_certinfo_from_db(char *pkgid, uid_t uid);
+static int __del_certinfo_from_db(char *pkgid);
+static int __get_integer_input_data(void);
+char *__get_string_input_data(void);
+static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data);
+static int __app_category_list_cb(const char *category_name, void *user_data);
+static int __app_control_list_cb(const char *operation, const char *uri, const char *mime, void *user_data);
+static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data);
+int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data);
+
+static void __get_pkgmgrinfo_pkginfo(const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+ int ret = -1;
+ char *type = NULL;
+ char *version = NULL;
+ char *author_name = NULL;
+ char *author_email = NULL;
+ char *author_href = NULL;
+ char *root_path = NULL;
+ char *mainappid = NULL;
+ pkgmgrinfo_install_location location = 0;
+ char *icon = NULL;
+ char *label = NULL;
+ char *desc = NULL;
+ bool removable = 0;
+ bool preload = 0;
+ bool readonly = 0;
+ bool update = 0;
+ bool system = 0;
+ int installed_time = -1;
+
+ ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
+ if (ret < 0)
+ printf("Failed to get pkg type\n");
+ if (type)
+ printf("Type: %s\n", type);
+
+ ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
+ if (ret < 0)
+ printf("Failed to get version\n");
+ if (version)
+ printf("Version: %s\n", version);
+
+ ret = pkgmgrinfo_pkginfo_get_install_location(handle, &location);
+ if (ret < 0)
+ printf("Failed to get install location\n");
+ printf("Install Location: %d\n", location);
+
+ ret = pkgmgrinfo_pkginfo_get_icon(handle, &icon);
+ if (ret < 0)
+ printf("Failed to get icon\n");
+ if (icon)
+ printf("Icon: %s\n", icon);
+
+ ret = pkgmgrinfo_pkginfo_get_label(handle, &label);
+ if (ret < 0)
+ printf("Failed to get label\n");
+ if (label)
+ printf("Label: %s\n", label);
+
+ ret = pkgmgrinfo_pkginfo_get_description(handle, &desc);
+ if (ret < 0)
+ printf("Failed to get description\n");
+ if (desc)
+ printf("Description: %s\n", desc);
+
+ ret = pkgmgrinfo_pkginfo_get_author_name(handle, &author_name);
+ if (ret < 0)
+ printf("Failed to get author name\n");
+ if (author_name)
+ printf("Author Name: %s\n", author_name);
+
+ ret = pkgmgrinfo_pkginfo_get_author_email(handle, &author_email);
+ if (ret < 0)
+ printf("Failed to get author email\n");
+ if (author_email)
+ printf("Author Email: %s\n", author_email);
+
+ ret = pkgmgrinfo_pkginfo_get_author_href(handle, &author_href);
+ if (ret < 0)
+ printf("Failed to get author href\n");
+ if (author_href)
+ printf("Author Href: %s\n", author_href);
+
+ ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path);
+ if (ret < 0)
+ printf("Failed to get root_path\n");
+ if (root_path)
+ printf("root_path : %s\n", root_path);
+
+ ret = pkgmgrinfo_pkginfo_get_mainappid(handle, &mainappid);
+ if (ret < 0)
+ printf("Failed to get mainappid\n");
+ if (mainappid)
+ printf("mainappid : %s\n", mainappid);
+
+ ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time);
+ if (ret < 0)
+ printf("Failed to get install time\n");
+ printf("Install time: %d\n", installed_time);
+
+ ret = pkgmgrinfo_pkginfo_is_removable(handle, &removable);
+ if (ret < 0)
+ printf("Failed to get removable\n");
+ else
+ printf("Removable: %d\n", removable);
+
+ ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
+ if (ret < 0)
+ printf("Failed to get preload\n");
+ else
+ printf("Preload: %d\n", preload);
+
+ ret = pkgmgrinfo_pkginfo_is_readonly(handle, &readonly);
+ if (ret < 0)
+ printf("Failed to get readonly\n");
+ else
+ printf("Readonly: %d\n", readonly);
+
+ ret = pkgmgrinfo_pkginfo_is_update(handle, &update);
+ if (ret < 0)
+ printf("Failed to get update\n");
+ else
+ printf("update: %d\n", update);
+
+ ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
+ if (ret < 0)
+ printf("Failed to get system\n");
+ else
+ printf("system: %d\n", system);
+}
+
+int __get_app_id(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+ char *appid = NULL;
+ char *apptype = NULL;
+ int ret = -1;
+
+ ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ if (ret < 0)
+ printf("Failed to get appid\n");
+
+ ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
+ if (ret < 0)
+ printf("Failed to get package\n");
+ printf("apptype [%s]\t appid [%s]\n", apptype, appid);
+
+ return 0;
+}
+
+static int __get_integer_input_data(void)
+{
+ char input_str[32] = { 0, };
+ int data = 0;
+
+ if (fgets(input_str, sizeof(input_str), stdin) == NULL) {
+ printf("fgets() failed....\n");
+ return -1;
+ }
+
+ if (sscanf(input_str, "%4d", &data) != 1) {
+ printf("Input only integer option....\n");
+ return -1;
+ }
+
+ return data;
+}
+
+
+char *__get_string_input_data(void)
+{
+ char *data = (char *)malloc(1024);
+ if (data == NULL) {
+ printf("Malloc Failed\n");
+ return NULL;
+ }
+
+ if (fgets(data, 1024, stdin) == NULL) {
+ printf("Buffer overflow!!! try again\n");
+ exit(-1);
+ }
+ data[strlen(data) - 1] = '\0';
+
+ return data;
+}
+
+static void __print_usage()
+{
+ printf("For Getting package|App Info\n");
+ printf("\tpkginfo --[pkg|app] <pkgid|appid>\n\n");
+ printf("For Getting list of installed packages\n");
+ printf("\tpkginfo --listpkg \n\n");
+ printf("For Getting list of installed applications\n");
+ printf("\tpkginfo --listapp \n\n");
+ printf("For Getting app list for a particular package\n");
+ printf("\tpkginfo --list <pkgid>\n\n");
+ printf("For Getting app category list for a particular application\n");
+ printf("\tpkginfo --category <appid>\n\n");
+ printf("For Getting app metadata list for a particular application\n");
+ printf("\tpkginfo --metadata <appid>\n\n");
+ printf("For Getting app control list for a particular application\n");
+ printf("\tpkginfo --appcontrol <appid>\n\n");
+ printf("To insert|remove manifest info in DB\n");
+ printf("\tpkginfo --[imd|rmd] <manifest file name>\n\n");
+ printf("To set manifest validation\n");
+ printf("\tpkginfo --check <manifest file name>\n\n");
+ printf("To set cert info in DB [root only]\n");
+ printf("\tpkginfo --setcert <pkgid>\n\n");
+ printf("To get cert info from DB [root only]\n");
+ printf("\tpkginfo --getcert <pkgid>\n\n");
+ printf("To compare pkg cert info from DB\n");
+ printf("\tpkginfo --cmp-pkgcert <lhs_pkgid> <rhs_pkgid>\n\n");
+ printf("To compare app cert info from DB\n");
+ printf("\tpkginfo --cmp-appcert <lhs_appid> <rhs_appid>\n\n");
+ printf("To delete all cert info from DB [root only]\n");
+ printf("\tpkginfo --delcert <pkgid>\n\n");
+ printf("To add application filter values [Multiple values can be added]\n");
+ printf("\tpkginfo --app-flt\n\n");
+ printf("To add package filter values [Multiple values can be added]\n");
+ printf("\tpkginfo --pkg-flt\n\n");
+ printf("To add metadata filter values\n");
+ printf("\tpkginfo --metadata-flt\n\n");
+}
+
+static void __print_arg_filter_usage()
+{
+ printf("=========================================\n");
+ printf("pkginfo --arg-flt key value\n");
+ printf("ex : pkginfo --arg-flt 6 webapp\n");
+ printf("key list is bellowed\n");
+ printf("2 --> filter by app ID\n");
+ printf("3 --> filter by app component\n");
+ printf("4 --> filter by app exec\n");
+ printf("5 --> filter by app icon\n");
+ printf("6 --> filter by app type\n");
+ printf("7 --> filter by app operation\n");
+ printf("8 --> filter by app uri\n");
+ printf("9 --> filter by app mime\n");
+ printf("10 --> filter by app category\n");
+ printf("11 --> filter by app nodisplay [0|1]\n");
+ printf("12 --> filter by app multiple [0|1]\n");
+ printf("13 --> filter by app onboot [0|1]\n");
+ printf("14 --> filter by app autorestart [0|1]\n");
+ printf("15 --> filter by app taskmanage [0|1]\n");
+ printf("16 --> filter by app hwacceleration\n");
+ printf("17 --> filter by app screenreader\n");
+ printf("=========================================\n");
+}
+
+static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+ char *appid = NULL;
+
+ pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ printf("appid : %s\n", appid);
+
+ return 0;
+}
+
+static int __add_metadata_filter()
+{
+ int ret = 0;
+ pkgmgrinfo_appinfo_metadata_filter_h handle;
+ char *key = NULL;
+ char *value = NULL;
+
+ ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
+ if (ret != PMINFO_R_OK) {
+ printf("pkgmgrinfo_appinfo_metadata_filter_create() failed\n");
+ return ret;
+ }
+
+ printf("enter metadata - key\n");
+ key = __get_string_input_data();
+ printf("enter metadata - value\n");
+ value = __get_string_input_data();
+
+ printf("filter condition : key=[%s], value=[%s]\n", key, value);
+
+ ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, key, value);
+ if (ret != PMINFO_R_OK) {
+ printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n");
+ goto err;
+ }
+
+ ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, __app_list_cb, NULL);
+ if (ret != PMINFO_R_OK) {
+ printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n");
+ goto err;
+ }
+
+err:
+ pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+ if (key) {
+ free(key);
+ key = NULL;
+ }
+ if (value) {
+ free(value);
+ value = NULL;
+ }
+ return ret;
+}
+
+static int __add_app_filter(uid_t uid)
+{
+ int ret = 0;
+ int choice = -1;
+ char *value = NULL;
+ int val = -1;
+ int count = 0;
+ pkgmgrinfo_appinfo_filter_h handle;
+
+ ret = pkgmgrinfo_appinfo_filter_create(&handle);
+ if (ret > 0) {
+ printf("appinfo filter handle create failed\n");
+ return -1;
+ }
+
+ while (choice != 0 && choice != 1) {
+ printf("Enter Choice\n");
+ printf("0 --> Finalize filter and get count of apps\n");
+ printf("1 --> Finalize filter and get list of apps\n");
+ printf("2 --> filter by app ID\n");
+ printf("3 --> filter by app component\n");
+ printf("4 --> filter by app exec\n");
+ printf("5 --> filter by app icon\n");
+ printf("6 --> filter by app type\n");
+ printf("7 --> filter by app operation\n");
+ printf("8 --> filter by app uri\n");
+ printf("9 --> filter by app mime\n");
+ printf("10 --> filter by app category\n");
+ printf("11 --> filter by app nodisplay [0|1]\n");
+ printf("12 --> filter by app multiple [0|1]\n");
+ printf("13 --> filter by app onboot [0|1]\n");
+ printf("14 --> filter by app autorestart [0|1]\n");
+ printf("15 --> filter by app taskmanage [0|1]\n");
+ printf("16 --> filter by app hwacceleration\n");
+ printf("17 --> filter by app screenreader\n");
+ printf("18 --> filter by app ui-gadget [0|1]\n");
+ printf("19 --> filter by app support disable [0|1]\n");
+ printf("20 --> filter by app installed storage\n");
+ choice = __get_integer_input_data();
+ switch (choice) {
+ case 0:
+ ret = pkgmgrinfo_appinfo_filter_count(handle, &count);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_count() failed\n");
+ ret = -1;
+ goto err;
+ }
+ printf("App count = %d\n", count);
+ break;
+ case 1:
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_func, NULL, uid);
+ else
+ ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, app_func, NULL);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 2:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_ID, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 3:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_COMPONENT, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 4:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_EXEC, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 5:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_ICON, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 6:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_TYPE, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 7:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_OPERATION, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 8:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_URI, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 9:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_MIME, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 10:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_CATEGORY, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 11:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
+ PMINFO_APPINFO_PROP_APP_NODISPLAY, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 12:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
+ PMINFO_APPINFO_PROP_APP_MULTIPLE, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 13:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
+ PMINFO_APPINFO_PROP_APP_ONBOOT, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 14:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
+ PMINFO_APPINFO_PROP_APP_AUTORESTART, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 15:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
+ PMINFO_APPINFO_PROP_APP_TASKMANAGE, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 16:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_HWACCELERATION, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 17:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_SCREENREADER, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 18:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
+ PMINFO_APPINFO_PROP_APP_UI_GADGET, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 19:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
+ PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 20:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+ PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+
+ default:
+ printf("Invalid filter property\n");
+ ret = -1;
+ goto err;
+ }
+ }
+ ret = 0;
+err:
+ pkgmgrinfo_appinfo_filter_destroy(handle);
+ if (value) {
+ free(value);
+ value = NULL;
+ }
+ return ret;
+}
+
+static int __add_pkg_filter(uid_t uid)
+{
+ int ret = 0;
+ int choice = -1;
+ char *value = NULL;
+ int val = -1;
+ int count = 0;
+ pkgmgrinfo_pkginfo_filter_h handle;
+
+ ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+ if (ret > 0) {
+ printf("pkginfo filter handle create failed\n");
+ return -1;
+ }
+
+ while (choice != 0 && choice != 1) {
+ printf("Enter Choice\n");
+ printf("0 --> Finalize filter and get count of packages\n");
+ printf("1 --> Finalize filter and get list of packages\n");
+ printf("2 --> filter by package ID\n");
+ printf("3 --> filter by package version\n");
+ printf("4 --> filter by package type\n");
+ printf("5 --> filter by package install location\n");
+ printf("6 --> filter by author name\n");
+ printf("7 --> filter by author email\n");
+ printf("8 --> filter by author href\n");
+ printf("9 --> filter by package removable [0|1]\n");
+ printf("10 --> filter by package readonly [0|1]\n");
+ printf("11 --> filter by package preload [0|1]\n");
+ printf("12 --> filter by package update [0|1]\n");
+ printf("13 --> filter by package appsetting [0|1]\n");
+ printf("14 --> filter by package installed storage[installed_internal | installed_external]\n");
+ printf("15 --> filter by package privilege\n");
+ printf("16 --> filter by package support disable [0|1]\n");
+ choice = __get_integer_input_data();
+ switch (choice) {
+ case 0:
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_pkginfo_usr_filter_count(handle, &count, uid);
+ else
+ ret = pkgmgrinfo_pkginfo_filter_count(handle, &count);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_count() failed\n");
+ ret = -1;
+ goto err;
+ }
+ printf("Package count = %d\n", count);
+ break;
+ case 1:
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, __pkg_list_cb, NULL, uid);
+ else
+ ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkg_list_cb, NULL);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_(usr)_filter_foreach_pkginfo() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 2:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_ID, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 3:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_VERSION, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 4:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_TYPE, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 5:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 6:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 7:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 8:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 9:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 10:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_READONLY, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 11:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 12:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_UPDATE, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 13:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 14:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 15:
+ value = __get_string_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE,
+ value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 16:
+ val = __get_integer_input_data();
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ default:
+ printf("Invalid filter property\n");
+ ret = -1;
+ goto err;
+ }
+ }
+ ret = 0;
+err:
+ pkgmgrinfo_pkginfo_filter_destroy(handle);
+ if (value) {
+ free(value);
+ value = NULL;
+ }
+ return ret;
+}
+
+static int __add_arg_filter(char *key, char *value, uid_t uid)
+{
+ int ret = 0;
+ int choice = -1;
+ int val = -1;
+ pkgmgrinfo_appinfo_filter_h handle;
+ ret = pkgmgrinfo_appinfo_filter_create(&handle);
+ if (ret > 0) {
+ printf("appinfo filter handle create failed\n");
+ return -1;
+ }
+ choice = atoi(key);
+
+ switch (choice) {
+ case 2:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_ID, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 3:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_COMPONENT, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 4:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_EXEC, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 5:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_ICON, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 6:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_TYPE, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 7:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_OPERATION, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 8:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_URI, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 9:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_MIME, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 10:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 11:
+ val = atoi(value);
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 12:
+ val = atoi(value);
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_MULTIPLE, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 13:
+ val = atoi(value);
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_ONBOOT, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 14:
+ val = atoi(value);
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_AUTORESTART, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 15:
+ val = atoi(value);
+ ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_TASKMANAGE, val);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 16:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_HWACCELERATION, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+ case 17:
+ ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_SCREENREADER, value);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
+ ret = -1;
+ goto err;
+ }
+ break;
+
+ default:
+ __print_arg_filter_usage();
+ goto err;
+ }
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, __get_app_id, NULL, uid);
+ else
+ ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __get_app_id, NULL);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n");
+ ret = -1;
+ goto err;
+ }
+
+err:
+ pkgmgrinfo_appinfo_filter_destroy(handle);
+ return ret;
+}
+static int __del_certinfo_from_db(char *pkgid)
+{
+ int ret = 0;
+ if (pkgid == NULL) {
+ printf("pkgid is NULL\n");
+ return -1;
+ }
+ ret = pkgmgr_installer_delete_certinfo(pkgid);
+ if (ret < 0) {
+ printf("pkgmgr_installer_delete_certinfo failed\n");
+ return -1;
+ }
+ return 0;
+}
+
+static int __get_certinfo_from_db(char *pkgid, uid_t uid)
+{
+ if (pkgid == NULL) {
+ printf("pkgid is NULL\n");
+ return -1;
+ }
+ int ret = 0;
+ int choice = -1;
+ int i = 0;
+ const char *value = NULL;
+ pkgmgrinfo_certinfo_h handle = NULL;
+
+ ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_create_certinfo failed\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle, uid);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_load_certinfo failed\n");
+ pkgmgrinfo_pkginfo_destroy_certinfo(handle);
+ return -1;
+ }
+
+ while (choice != 10) {
+ printf("Enter the choice to get\n");
+ printf("0 --> to get all cert values\n");
+ printf("1 --> author root certificate\n");
+ printf("2 --> author intermediate certificate\n");
+ printf("3 --> author signer certificate\n");
+ printf("4 --> distributor root certificate\n");
+ printf("5 --> distributor intermediate certificate\n");
+ printf("6 --> distributor signer certificate\n");
+ printf("7 --> distributor2 root certificate\n");
+ printf("8 --> distributor2 intermediate certificate\n");
+ printf("9 --> distributor2 signer certificate\n");
+ printf("10 --> exit\n");
+ choice = __get_integer_input_data();
+ switch (choice) {
+ case 0:
+ for (i = 0; i < 9; i++) {
+ pkgmgrinfo_pkginfo_get_cert_value(handle, i, &value);
+ if (value)
+ printf("cert type[%d] value = %s\n", i, value);
+ }
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ ret = pkgmgrinfo_pkginfo_get_cert_value(handle, choice - 1, &value);
+ if (value)
+ printf("cert type[%d] value = %s\n", choice - 1, value);
+ if (ret < 0)
+ ret = -1;
+ break;
+ case 10:
+ ret = pkgmgrinfo_pkginfo_destroy_certinfo(handle);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_destroy_certinfo failed\n");
+ ret = -1;
+ }
+ break;
+ default:
+ printf("Invalid choice entered\n");
+ ret = -1;
+ break;
+ }
+ }
+
+ return ret;
+}
+
+static int __compare_pkg_certinfo_from_db(char *lhs_pkgid, char *rhs_pkgid, uid_t uid)
+{
+ if (lhs_pkgid == NULL || rhs_pkgid == NULL) {
+ printf("pkgid is NULL\n");
+ return -1;
+ }
+
+ int ret = 0;
+ pkgmgrinfo_cert_compare_result_type_e result;
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_pkgid, rhs_pkgid, uid, &result);
+ else
+ ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lhs_pkgid, rhs_pkgid, &result);
+ if (ret != PMINFO_R_OK)
+ return -1;
+
+ printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n");
+ printf("pkgid =[%s] and [%s] compare result = [%d] \n", lhs_pkgid, rhs_pkgid, result);
+ return 0;
+}
+
+static int __compare_app_certinfo_from_db(char *lhs_appid, char *rhs_appid, uid_t uid)
+{
+ if (lhs_appid == NULL || rhs_appid == NULL) {
+ printf("appid is NULL\n");
+ return -1;
+ }
+
+ int ret = 0;
+ pkgmgrinfo_cert_compare_result_type_e result;
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(lhs_appid, rhs_appid, uid, &result);
+ else
+ ret = pkgmgrinfo_pkginfo_compare_app_cert_info(lhs_appid, rhs_appid, &result);
+ if (ret != PMINFO_R_OK)
+ return -1;
+
+ printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n");
+ printf("appid =[%s] and [%s] compare result = [%d] \n", lhs_appid, rhs_appid, result);
+ return 0;
+}
+
+static int __set_certinfo_in_db(char *pkgid, uid_t uid)
+{
+ if (pkgid == NULL) {
+ printf("pkgid is NULL\n");
+ return -1;
+ }
+ int ret = 0;
+ int choice = -1;
+ char *value = NULL;
+ pkgmgr_instcertinfo_h handle = NULL;
+
+ ret = pkgmgr_installer_create_certinfo_set_handle(&handle);
+ if (ret < 0) {
+ printf("pkgmgr_installer_create_certinfo_set_handle failed\n");
+ return -1;
+ }
+
+ while (choice != 0) {
+ printf("Enter the choice you want to set\n");
+ printf("0 --> to set data in DB\n");
+ printf("1 --> author root certificate\n");
+ printf("2 --> author intermediate certificate\n");
+ printf("3 --> author signer certificate\n");
+ printf("4 --> distributor root certificate\n");
+ printf("5 --> distributor intermediate certificate\n");
+ printf("6 --> distributor signer certificate\n");
+ printf("7 --> distributor2 root certificate\n");
+ printf("8 --> distributor2 intermediate certificate\n");
+ printf("9 --> distributor2 signer certificate\n");
+ choice = __get_integer_input_data();
+ switch (choice) {
+ case 0:
+ ret = pkgmgr_installer_delete_certinfo(pkgid);
+ if (ret < 0) {
+ printf("pkgmgr_installer_delete_certinfo failed\n");
+ pkgmgr_installer_destroy_certinfo_set_handle(handle);
+ return -1;
+ }
+ ret = pkgmgr_installer_save_certinfo(pkgid, handle, uid);
+ if (ret < 0) {
+ printf("pkgmgr_installer_save_certinfo failed\n");
+ pkgmgr_installer_destroy_certinfo_set_handle(handle);
+ return -1;
+ }
+ ret = pkgmgr_installer_destroy_certinfo_set_handle(handle);
+ if (ret < 0) {
+ printf("pkgmgr_installer_destroy_certinfo_set_handle failed\n");
+ return -1;
+ }
+ return 0;
+ case 1:
+ printf("Enter Author Root Certificate Value: \n");
+ value = __get_string_input_data();
+ ret = pkgmgr_installer_set_cert_value(handle, 0, value);
+ if (ret < 0) {
+ printf("pkgmgr_installer_set_cert_value failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 2:
+ printf("Enter Author Intermediate Certificate Value: \n");
+ value = __get_string_input_data();
+ ret = pkgmgr_installer_set_cert_value(handle, 1, value);
+ if (ret < 0) {
+ printf("pkgmgr_installer_set_cert_value failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 3:
+ printf("Enter Author Signer Certificate Value: \n");
+ value = __get_string_input_data();
+ ret = pkgmgr_installer_set_cert_value(handle, 2, value);
+ if (ret < 0) {
+ printf("pkgmgr_installer_set_cert_value failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 4:
+ printf("Enter Distributor Root Certificate Value: \n");
+ value = __get_string_input_data();
+ ret = pkgmgr_installer_set_cert_value(handle, 3, value);
+ if (ret < 0) {
+ printf("pkgmgr_installer_set_cert_value failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 5:
+ printf("Enter Distributor Intermediate Certificate Value: \n");
+ value = __get_string_input_data();
+ ret = pkgmgr_installer_set_cert_value(handle, 4, value);
+ if (ret < 0) {
+ printf("pkgmgr_installer_set_cert_value failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 6:
+ printf("Enter Distributor Signer Certificate Value: \n");
+ value = __get_string_input_data();
+ ret = pkgmgr_installer_set_cert_value(handle, 5, value);
+ if (ret < 0) {
+ printf("pkgmgr_installer_set_cert_value failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 7:
+ printf("Enter Distributor2 Root Certificate Value: \n");
+ value = __get_string_input_data();
+ ret = pkgmgr_installer_set_cert_value(handle, 6, value);
+ if (ret < 0) {
+ printf("pkgmgr_installer_set_cert_value failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 8:
+ printf("Enter Distributor2 Intermediate Certificate Value: \n");
+ value = __get_string_input_data();
+ ret = pkgmgr_installer_set_cert_value(handle, 7, value);
+ if (ret < 0) {
+ printf("pkgmgr_installer_set_cert_value failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ case 9:
+ printf("Enter Distributor2 Signer Certificate Value: \n");
+ value = __get_string_input_data();
+ ret = pkgmgr_installer_set_cert_value(handle, 8, value);
+ if (ret < 0) {
+ printf("pkgmgr_installer_set_cert_value failed\n");
+ ret = -1;
+ goto err;
+ }
+ free(value);
+ value = NULL;
+ break;
+ default:
+ printf("Invalid Number Entered\n");
+ break;
+ }
+ }
+err:
+ if (value) {
+ free(value);
+ value = NULL;
+ }
+ pkgmgr_installer_destroy_certinfo_set_handle(handle);
+ return ret;
+}
+
+int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+ int ret = -1;
+ char *appid;
+ char *data = NULL;
+ char *exec = NULL;
+ char *icon = NULL;
+ char *label = NULL;
+ char *apptype = NULL;
+ char *package = NULL;
+ bool nodisplay = 0;
+ bool multiple = 0;
+ bool taskmanage = 0;
+ bool onboot = 0;
+ bool autorestart = 0;
+ pkgmgrinfo_app_component component = 0;
+ pkgmgrinfo_app_hwacceleration hwacceleration;
+ pkgmgrinfo_app_screenreader screenreader;
+
+ if (user_data)
+ data = (char *)user_data;
+
+ ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ if (ret < 0)
+ printf("Failed to get appid\n");
+ if (appid)
+ printf("Appid: %s\n", appid);
+
+ ret = pkgmgrinfo_appinfo_get_pkgid(handle, &package);
+ if (ret < 0)
+ printf("Failed to get package\n");
+ if (package)
+ printf("Package: %s\n", package);
+
+ ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
+ if (ret < 0)
+ printf("Failed to get exec\n");
+ if (exec)
+ printf("Exec: %s\n", exec);
+
+ ret = pkgmgrinfo_appinfo_get_icon(handle, &icon);
+ if (ret < 0)
+ printf("Failed to get icon\n");
+ if (icon)
+ printf("Icon: %s\n", icon);
+
+ ret = pkgmgrinfo_appinfo_get_label(handle, &label);
+ if (ret < 0)
+ printf("Failed to get label\n");
+ if (label)
+ printf("Label: %s\n", label);
+
+ ret = pkgmgrinfo_appinfo_get_component(handle, &component);
+ if (ret < 0)
+ printf("Failed to get component\n");
+
+ ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
+ if (ret < 0)
+ printf("Failed to get apptype\n");
+ if (apptype)
+ printf("Apptype: %s\n", apptype);
+
+ if (component == PMINFO_UI_APP || component == PMINFO_WIDGET_APP ||
+ component == PMINFO_WATCH_APP) {
+ printf("component: %s\n", component == PMINFO_UI_APP ?
+ "uiapp" : component == PMINFO_WIDGET_APP ?
+ "widgetapp" : "watchapp");
+ ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
+ if (ret < 0)
+ printf("Failed to get multiple\n");
+ else
+ printf("Multiple: %d\n", multiple);
+
+ ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &nodisplay);
+ if (ret < 0)
+ printf("Failed to get nodisplay\n");
+ else
+ printf("Nodisplay: %d \n", nodisplay);
+
+ ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage);
+ if (ret < 0)
+ printf("Failed to get taskmanage\n");
+ else
+ printf("Taskmanage: %d\n", taskmanage);
+
+ ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacceleration);
+ if (ret < 0)
+ printf("Failed to get hwacceleration\n");
+ else
+ printf("hw-acceleration: %d\n", hwacceleration);
+
+ ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader);
+ if (ret < 0)
+ printf("Failed to get screenreader\n");
+ else
+ printf("screenreader: %d\n", screenreader);
+ }
+
+ if (component == PMINFO_SVC_APP) {
+ printf("component: svcapp\n");
+ ret = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
+ if (ret < 0)
+ printf("Failed to get onboot\n");
+ else
+ printf("Onboot: %d\n", onboot);
+
+ ret = pkgmgrinfo_appinfo_is_autorestart(handle, &autorestart);
+ if (ret < 0)
+ printf("Failed to get autorestart\n");
+ else
+ printf("Autorestart: %d \n", autorestart);
+ }
+
+ if (data)
+ printf("user_data : %s\n\n", data);
+
+ return 0;
+}
+
+
+static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+ int ret = -1;
+ int installed_time = -1;
+ char *test_data = "test data";
+ char *pkgid;
+ char *pkg_type;
+ char *pkg_version;
+ bool preload = 0;
+
+ pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle;
+ ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+ if (ret < 0)
+ printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n");
+
+ ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type);
+ if (ret < 0)
+ printf("pkgmgrinfo_pkginfo_get_type() failed\n");
+
+ ret = pkgmgrinfo_pkginfo_get_version(handle, &pkg_version);
+ if (ret < 0)
+ printf("pkgmgrinfo_pkginfo_get_version() failed\n");
+
+ ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
+ if (ret < 0)
+ printf("pkgmgrinfo_pkginfo_is_preload() failed\n");
+
+ ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time);
+ if (ret < 0)
+ printf("pkgmgrinfo_pkginfo_get_installed_time() failed\n");
+
+ printf("---------------------------------------\n");
+ printf("pkg_type [%s]\tpkgid [%s]\tversion [%s]\tpreload [%d]\tinstalled_time [%d]\n", pkg_type,
+ pkgid, pkg_version, preload, installed_time);
+
+ if (uid_info->uid != GLOBAL_USER) {
+ printf("**List of Ui-Apps**\n");
+ ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_UI_APP, app_func, (void *)test_data, uid_info->uid);
+ if (ret < 0)
+ printf("pkgmgr_get_info_app() failed\n");
+
+ printf("**List of Svc-Apps**\n");
+ ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data, uid_info->uid);
+ if (ret < 0)
+ printf("pkgmgr_get_info_app() failed\n");
+
+ printf("**List of Widget-Apps**\n");
+ ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_WIDGET_APP, app_func, (void *)test_data, uid_info->uid);
+ if (ret < 0)
+ printf("pkgmgr_get_info_app() failed\n");
+
+ printf("**List of Watch-Apps**\n");
+ ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_WATCH_APP, app_func, (void *)test_data, uid_info->uid);
+ if (ret < 0)
+ printf("pkgmgr_get_info_app() failed\n");
+ } else {
+ printf("**List of Ui-Apps**\n");
+ ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, app_func, (void *)test_data);
+ if (ret < 0)
+ printf("pkgmgr_get_info_app() failed\n");
+
+ printf("**List of Svc-Apps**\n");
+ ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data);
+ if (ret < 0)
+ printf("pkgmgr_get_info_app() failed\n");
+
+ printf("**List of Widget-Apps**\n");
+ ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_WIDGET_APP, app_func, (void *)test_data);
+ if (ret < 0)
+ printf("pkgmgr_get_info_app() failed\n");
+
+ printf("**List of Watch-Apps**\n");
+ ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_WATCH_APP, app_func, (void *)test_data);
+ if (ret < 0)
+ printf("pkgmgr_get_info_app() failed\n");
+ }
+ printf("---------------------------------------\n");
+
+ return 0;
+}
+
+static int __get_pkg_list(uid_t uid)
+{
+ int ret = -1;
+
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, NULL, uid);
+ else
+ ret = pkgmgrinfo_pkginfo_get_list(__pkg_list_cb, NULL);
+ if (ret < 0) {
+ printf("pkgmgrinfo_pkginfo_get_list() failed\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __get_installed_app_list(uid_t uid)
+{
+ int ret = -1;
+
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_appinfo_get_usr_installed_list(app_func, uid, NULL);
+ else
+ ret = pkgmgrinfo_appinfo_get_installed_list(app_func, NULL);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_get_installed_list() failed\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int __app_category_list_cb(const char *category_name, void *user_data)
+{
+ if (category_name)
+ printf("Category: %s\n", category_name);
+ return 0;
+}
+
+static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data)
+{
+ if (metadata_name && metadata_value) {
+ printf("Name: %s\n", metadata_name);
+ printf("Value: %s\n", metadata_value);
+ printf("\n");
+ }
+ return 0;
+}
+
+static int __app_control_list_cb(const char *operation, const char *uri, const char *mime, void *user_data)
+{
+ printf("-------------------------------------------------------\n");
+ printf("Operation: %s\n", operation);
+ printf("Uri: %s\n", uri);
+ printf("Mime: %s\n", mime);
+ printf("-------------------------------------------------------\n\n");
+ return 0;
+}
+
+
+static int __get_app_category_list(char *appid)
+{
+ int ret = -1;
+ pkgmgrinfo_appinfo_h handle;
+
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
+ if (ret < 0) {
+ printf("Failed to get handle\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_appinfo_foreach_category(handle, __app_category_list_cb, NULL);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_foreach_category() failed\n");
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+ return -1;
+ }
+
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
+ return 0;
+}
+
+static int __get_app_metadata_list(char *appid)
+{
+ int ret = -1;
+ pkgmgrinfo_appinfo_h handle;
+
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
+ if (ret < 0) {
+ printf("Failed to get handle\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_appinfo_foreach_metadata(handle, __app_metadata_list_cb, NULL);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_foreach_metadata() failed\n");
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+ return -1;
+ }
+
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
+ return 0;
+}
+
+static int __get_app_control_list(char *appid)
+{
+ int ret = -1;
+ pkgmgrinfo_appinfo_h handle;
+
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
+ if (ret < 0) {
+ printf("Failed to get handle\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, __app_control_list_cb, NULL);
+ if (ret < 0) {
+ printf("pkgmgrinfo_appinfo_foreach_appcontrol() failed\n");
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+ return -1;
+ }
+
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
+ return 0;
+}
+
+static int __get_app_list(char *pkgid, uid_t uid)
+{
+ int ret = -1;
+ char *test_data = "test data";
+ pkgmgrinfo_pkginfo_h handle;
+
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
+ else
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret < 0) {
+ printf("Failed to get handle\n");
+ return -1;
+ }
+
+ if (uid != GLOBAL_USER) {
+ printf("List of Ui-Apps\n\n");
+ ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_UI_APP, app_func, (void *)test_data, uid);
+ if (ret < 0)
+ printf("pkgmgrinfo_appinfo_get_list() failed\n");
+
+ printf("List of Svc-Apps\n\n");
+ ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data, uid);
+ if (ret < 0)
+ printf("pkgmgrinfo_appinfo_get_list() failed\n");
+
+ printf("List of Widget-Apps\n\n");
+ ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_WIDGET_APP, app_func, (void *)test_data, uid);
+ if (ret < 0)
+ printf("pkgmgrinfo_appinfo_get_list() failed\n");
+
+ printf("List of Watch-Apps\n\n");
+ ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_WATCH_APP, app_func, (void *)test_data, uid);
+ if (ret < 0)
+ printf("pkgmgrinfo_appinfo_get_list() failed\n");
+ } else {
+ printf("List of Ui-Apps\n\n");
+ ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, app_func, (void *)test_data);
+ if (ret < 0)
+ printf("pkgmgrinfo_appinfo_get_list() failed\n");
+
+ printf("List of Svc-Apps\n\n");
+ ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data);
+ if (ret < 0)
+ printf("pkgmgrinfo_appinfo_get_list() failed\n");
+
+ printf("List of Widget-Apps\n\n");
+ ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_WIDGET_APP, app_func, (void *)test_data);
+ if (ret < 0)
+ printf("pkgmgrinfo_appinfo_get_list() failed\n");
+
+ printf("List of Watch-Apps\n\n");
+ ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_WATCH_APP, app_func, (void *)test_data);
+ if (ret < 0)
+ printf("pkgmgrinfo_appinfo_get_list() failed\n");
+ }
+
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+ return 0;
+}
+
+static int __get_pkg_info(char *pkgid, uid_t uid)
+{
+ int ret = -1;
+ pkgmgrinfo_pkginfo_h handle;
+
+ printf("Get Pkg Info Called [%s]\n", pkgid);
+ if (uid != GLOBAL_USER)
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
+ else
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret < 0) {
+ printf("Failed to get handle\n");
+ return -1;
+ }
+
+ __get_pkgmgrinfo_pkginfo(handle, NULL);
+
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+ return 0;
+}
+
+static int __get_app_info(char *appid)
+{
+ int ret = -1;
+ int support_mode = 0;
+ char *exec = NULL;
+ char *app_id = NULL;
+ char *apptype = NULL;
+ char *icon = NULL;
+ char *label = NULL;
+ char *package = NULL;
+ bool nodisplay = 0;
+ bool multiple = 0;
+ bool taskmanage = 0;
+ bool onboot = 0;
+ bool autorestart = 0;
+ bool enabled = 0;
+ bool preload = 0;
+ pkgmgrinfo_appinfo_h handle;
+ pkgmgrinfo_app_component component = 0;
+ pkgmgrinfo_app_hwacceleration hwacceleration;
+ pkgmgrinfo_app_screenreader screenreader;
+
+ printf("Get App Info Called [%s]\n", appid);
+
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
+ if (ret < 0) {
+ printf("Failed to get handle\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_appinfo_get_pkgid(handle, &package);
+ if (ret < 0)
+ printf("Failed to get package\n");
+
+ ret = pkgmgrinfo_appinfo_get_appid(handle, &app_id);
+ if (ret < 0)
+ printf("Failed to get exec\n");
+
+ ret = pkgmgrinfo_appinfo_get_label(handle, &label);
+ if (ret < 0)
+ printf("Failed to get label\n");
+
+ ret = pkgmgrinfo_appinfo_get_icon(handle, &icon);
+ if (ret < 0)
+ printf("Failed to get icon\n");
+
+ ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
+ if (ret < 0)
+ printf("Failed to get exec\n");
+
+ ret = pkgmgrinfo_appinfo_get_component(handle, &component);
+ if (ret < 0)
+ printf("Failed to get component\n");
+
+ ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
+ if (ret < 0)
+ printf("Failed to get apptype\n");
+
+ ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &nodisplay);
+ if (ret < 0)
+ printf("Failed to get nodisplay\n");
+
+ ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
+ if (ret < 0)
+ printf("Failed to get multiple\n");
+
+ ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage);
+ if (ret < 0)
+ printf("Failed to get taskmanage\n");
+
+ ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacceleration);
+ if (ret < 0)
+ printf("Failed to get hwacceleration\n");
+
+ ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader);
+ if (ret < 0)
+ printf("Failed to get screenreader\n");
+
+ ret = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
+ if (ret < 0)
+ printf("Failed to get onboot\n");
+
+ ret = pkgmgrinfo_appinfo_is_autorestart(handle, &autorestart);
+ if (ret < 0)
+ printf("Failed to get autorestart\n");
+
+ ret = pkgmgrinfo_appinfo_is_enabled(handle, &enabled);
+ if (ret < 0)
+ printf("Failed to get enabled\n");
+
+ ret = pkgmgrinfo_appinfo_is_preload(handle, &preload);
+ if (ret < 0)
+ printf("Failed to get preload\n");
+
+ ret = pkgmgrinfo_appinfo_get_support_mode(handle, &support_mode);
+ if (ret < 0)
+ printf("Failed to get support_mode\n");
+
+ if (app_id)
+ printf("Appid: %s\n", app_id);
+
+ if (package)
+ printf("Package: %s\n", package);
+
+ if (exec)
+ printf("Exec: %s\n", exec);
+
+ if (apptype)
+ printf("Apptype: %s\n", apptype);
+
+ if (component == PMINFO_UI_APP || component == PMINFO_WIDGET_APP ||
+ component == PMINFO_WATCH_APP ||
+ component == PMINFO_COMPONENT_BASED_APP) {
+ printf("component: %s\n", component == PMINFO_UI_APP ?
+ "uiapp" : component == PMINFO_WIDGET_APP ?
+ "widgetapp" : component == PMINFO_WATCH_APP ?
+ "watchapp" : "componentbasedapp");
+ if (icon)
+ printf("Icon: %s\n", icon);
+ if (label)
+ printf("Label: %s\n", label);
+ printf("Nodisplay: %d\n", nodisplay);
+ printf("Multiple: %d\n", multiple);
+ printf("Taskmanage: %d\n", taskmanage);
+ printf("Hw-Acceleration: %d\n", hwacceleration);
+ printf("Screenreader: %d\n", screenreader);
+ } else if (component == PMINFO_SVC_APP) {
+ printf("component: svcapp\n");
+
+ if (icon)
+ printf("Icon: %s\n", icon);
+ if (label)
+ printf("Label: %s\n", label);
+
+ printf("Autorestart: %d\n", autorestart);
+ printf("Onboot: %d\n", onboot);
+ } else {
+ printf("Invalid Component Type\n");
+ }
+
+ printf("Enabled: %d\n", enabled);
+ printf("Preload: %d\n", preload);
+ printf("Support_mode: %d\n", support_mode);
+
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
+ return 0;
+}
+
+static int __check_manifest_validation(char *manifest)
+{
+ int ret = 0;
+
+ if (manifest == NULL) {
+ printf("Manifest file is NULL\n");
+ return -1;
+ }
+
+ ret = pkgmgr_parser_check_manifest_validation(manifest);
+ if (ret < 0) {
+ printf("check manifest validation failed\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int _is_authorized(uid_t uid)
+{
+ if ((uid_t) OWNER_ROOT == uid) {
+ return 1;
+ } else {
+ printf("Error! This cmd is allowed for only root user!\n\n");
+ return 0;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = 0;
+ long starttime;
+ long endtime;
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+
+ if (argc < 2) {
+ __print_usage();
+ ret = -1;
+ goto end;
+ }
+
+ /* TODO : refactor all with getopt system funtion */
+ /* a group for the authorized user */
+ if (strcmp(argv[1], "--setcert") == 0) {
+ if (argc != 3 || !_is_authorized(getuid())) {
+ __print_usage();
+ ret = -1;
+ goto end;
+ }
+ ret = __set_certinfo_in_db(argv[2], 0);
+ if (ret == -1) {
+ printf("set certinfo in db failed\n");
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--getcert") == 0) {
+ if (argc != 3 || !_is_authorized(getuid())) {
+ __print_usage();
+ ret = -1;
+ goto end;
+ }
+ ret = __get_certinfo_from_db(argv[2], 0);
+ if (ret == -1) {
+ printf("get certinfo from db failed\n");
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--delcert") == 0) {
+ if (argc != 3 || !_is_authorized(getuid())) {
+ __print_usage();
+ ret = -1;
+ goto end;
+ }
+ ret = __del_certinfo_from_db(argv[2]);
+ if (ret == -1) {
+ printf("del certinfo from db failed\n");
+ goto end;
+ }
+ }
+
+ if (argc == 2) {
+ if (strcmp(argv[1], "--listpkg") == 0) {
+ ret = __get_pkg_list(getuid());
+ if (ret == -1) {
+ printf("get pkg list failed\n");
+ goto end;
+ } else {
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--app-flt") == 0) {
+ ret = __add_app_filter(getuid());
+ if (ret == -1) {
+ printf("Adding app filter failed\n");
+ goto end;
+ } else {
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--pkg-flt") == 0) {
+ ret = __add_pkg_filter(getuid());
+ if (ret == -1) {
+ printf("Adding pkg filter failed\n");
+ goto end;
+ } else {
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--metadata-flt") == 0) {
+ ret = __add_metadata_filter();
+ if (ret == -1) {
+ printf("Adding pkg filter failed\n");
+ goto end;
+ } else {
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--listapp") == 0) {
+ ret = __get_installed_app_list(getuid());
+ if (ret == -1) {
+ printf("get installed app list failed\n");
+ goto end;
+ } else {
+ goto end;
+ }
+ } else {
+ __print_usage();
+ ret = -1;
+ goto end;
+ }
+ } else if (argc == 3) {
+ if (strcmp(argv[1], "--pkg") == 0) {
+ ret = __get_pkg_info(argv[2], getuid());
+ if (ret == -1) {
+ printf("get pkg info failed\n");
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--app") == 0) {
+ ret = __get_app_info(argv[2]);
+ if (ret == -1) {
+ printf("get app info failed\n");
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--list") == 0) {
+ ret = __get_app_list(argv[2], getuid());
+ if (ret == -1) {
+ printf("get app list failed\n");
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--imd") == 0) {
+ printf("Not supported!\n");
+ goto end;
+ } else if (strcmp(argv[1], "--fota") == 0) {
+ printf("Not supported!\n");
+ goto end;
+ } else if (strcmp(argv[1], "--rmd") == 0) {
+ printf("Not supported!\n");
+ goto end;
+ } else if (strcmp(argv[1], "--check") == 0) {
+ ret = __check_manifest_validation(argv[2]);
+ if (ret == -1) {
+ printf("check manifest failed\n");
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--category") == 0) {
+ ret = __get_app_category_list(argv[2]);
+ if (ret == -1) {
+ printf("get app category list failed\n");
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--metadata") == 0) {
+ ret = __get_app_metadata_list(argv[2]);
+ if (ret == -1) {
+ printf("get app metadata list failed\n");
+ goto end;
+ }
+ } else if (strcmp(argv[1], "--appcontrol") == 0) {
+ ret = __get_app_control_list(argv[2]);
+ if (ret == -1) {
+ printf("get app control list failed\n");
+ goto end;
+ }
+ } else {
+ __print_usage();
+ ret = -1;
+ goto end;
+ }
+ } else if (argc == 4) {
+ if (strcmp(argv[1], "--cmp-pkgcert") == 0) {
+ ret = __compare_pkg_certinfo_from_db(argv[2], argv[3], getuid());
+ if (ret == -1) {
+ printf("compare certinfo from db failed\n");
+ goto end;
+ }
+ goto end;
+ } else if (strcmp(argv[1], "--cmp-appcert") == 0) {
+ ret = __compare_app_certinfo_from_db(argv[2], argv[3], getuid());
+ if (ret == -1) {
+ printf("compare certinfo from db failed\n");
+ goto end;
+ }
+ goto end;
+ } else if (strcmp(argv[1], "--arg-flt") == 0) {
+ ret = __add_arg_filter(argv[2], argv[3], getuid());
+ if (ret == -1) {
+ printf("compare certinfo from db failed\n");
+ goto end;
+ }
+ goto end;
+ } else {
+ __print_usage();
+ ret = -1;
+ goto end;
+ }
+ } else {
+ __print_usage();
+ ret = -1;
+ }
+
+end:
+ gettimeofday(&tv, NULL);
+ endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+
+ printf("spend time for pkginfo is [%d]ms\n", (int)(endtime - starttime));
+
+ return ret;
+}
--- /dev/null
+
+/*
+ * pkgmgr-tool
+ *
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <getopt.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gstdio.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <sys/time.h>
+#include "aul_rsc_mgr.h"
+
+#define RSC_TOOL_VERSION "0.1"
+#define BUF_SIZE 1024
+
+static void __print_usage();
+
+struct rsc_tool_args_t {
+ char res_path[PATH_MAX];
+ int dpi;
+ int bpp;
+ char dpi_range[BUF_SIZE];
+ char width_range[BUF_SIZE];
+ char screen_large[BUF_SIZE];
+ char platform_version[BUF_SIZE];
+ GHashTable *valid_file_list;
+};
+
+typedef struct rsc_tool_args_t rsc_tool_args;
+
+static int __convert_to_abs_path(rsc_tool_args *data)
+{
+ char tmp[BUF_SIZE];
+ char abs[BUF_SIZE] = {'\0'};
+ char cwd[BUF_SIZE] = {'\0'};
+ char *buf = NULL;
+ int ret = -1;
+
+ if (data->res_path[0] == '\0') {
+ printf("invalid path\n");
+ return -1;
+ }
+
+ ret = snprintf(tmp, sizeof(tmp), "%s", data->res_path);
+ if (ret < 0 || ret > sizeof(tmp)) {
+ printf("snprintf fail\n");
+ return -1;
+ }
+
+ buf = getcwd(cwd, BUF_SIZE - 1);
+ if (buf == NULL) {
+ printf("failed to get cwd\n");
+ return -1;
+ }
+
+ ret = chdir(tmp);
+ if (ret < 0) {
+ printf("failed to change dir[%s]\n", tmp);
+ return -1;
+ }
+
+ buf = getcwd(abs, BUF_SIZE - 1);
+ if (buf == NULL) {
+ printf("failed to get cwd\n");
+ return -1;
+ }
+
+ memset(data->res_path, '\0', BUF_SIZE);
+ snprintf(data->res_path, sizeof(data->res_path), "%s/", abs);
+ ret = chdir(cwd);
+ if (ret < 0) {
+ printf("failed to change dir[%s]\n", tmp);
+ return -1;
+ }
+
+ return 0;
+}
+
+static void __print_usage()
+{
+ printf("\nResource Slicing Tool Version: %s\n\n", RSC_TOOL_VERSION);
+ printf("-p, --path set resource path\n");
+ printf("-d, --screen-dpi set screen dpi value\n");
+
+ printf("Usage: rscslice [options] \n");
+ printf("rsc-slice -p [res path] \n");
+ printf("rsc-slice -p [res_path] -d [dpi value] \n");
+
+ printf("Example:\n");
+ printf("rsc-slice -p /home/userid/workspace/testapp/res/ \n");
+ printf("rsc-slice -p /home/userid/workspace/testapp/res/ -d 300 \n");
+
+ exit(0);
+}
+
+static void __del_file(GHashTable *valid_file_list, char *path)
+{
+ struct dirent **items;
+ struct stat fstat;
+ char abs_path[1024] = {0, };
+ char cwd[1024] = {0, };
+ char *tmp = NULL;
+ int nitems, i;
+ int ret;
+
+ if (chdir(path) < 0) {
+ printf("failed to chdir[%s]\n", path);
+ return;
+ }
+
+ tmp = getcwd(cwd, 1024 - 1);
+ nitems = scandir("./", &items, NULL, alphasort);
+
+ for (i = 0; i < nitems; i++) {
+ if (items[i]->d_name[0] == '.')
+ continue;
+
+ ret = snprintf(abs_path, 1024 - 1, "%s/%s", cwd, items[i]->d_name);
+ if (ret < 0 || ret > 1024 -1 ) {
+ printf("snprintf fail\n");
+ return;
+ }
+ if (g_lstat(abs_path, &fstat) != 0) {
+ printf("failed to get info[%s]\n", abs_path);
+ return;
+ }
+ if ((fstat.st_mode & S_IFDIR) == S_IFDIR) {
+ __del_file(valid_file_list, abs_path);
+ } else {
+ tmp = g_hash_table_lookup(valid_file_list, abs_path);
+ if (tmp == NULL) {
+ printf("deleting [%s]\n", abs_path);
+ ret = remove(abs_path);
+ if (ret == -1) {
+ printf("failed to remove [%s][%d]\n",
+ abs_path, errno);
+ }
+ }
+ }
+ }
+}
+
+static int __process_slice(rsc_tool_args *data)
+{
+ int ret = -1;
+ bundle *b = NULL;
+ char dpi_value[1024] = {0, };
+
+ if (data->res_path[0] == '\0')
+ return -1;
+
+ b = bundle_create();
+ if (data->dpi != 0) {
+ snprintf(dpi_value, 1024 - 1, "%d", data->dpi);
+ bundle_add_str(b, "screen-dpi", dpi_value);
+ }
+
+ /* other attributes will be added here*/
+
+ ret = aul_resource_manager_init_slice(data->res_path, b);
+ if (ret < 0) {
+ printf("failed to init rsc manager\n");
+ goto catch;
+ }
+
+ ret = aul_resource_manager_get_path_list(&data->valid_file_list);
+ if (ret < 0) {
+ printf("failed to init rsc manager\n");
+ goto catch;
+ }
+
+ /* remove useless resources and empty directories */
+ __del_file(data->valid_file_list, data->res_path);
+
+
+catch:
+ if (aul_resource_manager_release() < 0)
+ printf("failed to release resource manager\n");
+
+ bundle_free(b);
+ return ret;
+}
+
+int main(int argc, char *argv[])
+{
+ optind = 1;
+ int opt_idx = 0;
+ int c = -1;
+ int ret = 0;
+ long starttime;
+ long endtime;
+ int i = 0;
+ struct timeval tv;
+ const char *short_options = "p:d:";
+ const struct option long_options[] = {
+ {"path", 1, NULL, 'p'},
+ {"screen-dpi", 1, NULL, 'd'},
+ {0, 0, 0, 0} /* sentinel */
+ };
+ rsc_tool_args data = { 0 };
+
+ if (argc == 1)
+ __print_usage();
+
+ gettimeofday(&tv, NULL);
+ starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+
+ /* initialization of global structure */
+ data.dpi = 0;
+ data.bpp = 0;
+ memset(data.dpi_range, '\0', BUF_SIZE);
+ memset(data.width_range, '\0', BUF_SIZE);
+ memset(data.screen_large, '\0', BUF_SIZE);
+ memset(data.platform_version, '\0', BUF_SIZE);
+
+ while (1) {
+ i++;
+ c = getopt_long(argc, argv, short_options, long_options, &opt_idx);
+ if (c == -1)
+ break; /* Parse end */
+ switch (c) {
+ case 'p': /* resource path */
+ if (optarg)
+ strncpy(data.res_path, optarg, PATH_MAX - 1);
+
+ ret = __convert_to_abs_path(&data);
+ if (ret == -1) {
+ printf("conversion of relative path to absolute path failed\n");
+ return -1;
+ }
+ printf("path is [%s]\n", data.res_path);
+ break;
+
+ case 'd': /* set dpi */
+ if (optarg)
+ data.dpi = atoi(optarg);
+
+ if (data.dpi == 0) {
+ printf("failed to get dpi value\n");
+ return -1;
+ }
+ printf("dpi value is [%d]\n", data.dpi);
+ break;
+
+ default:
+ break;
+
+ }
+ }
+
+ ret = __process_slice(&data);
+
+ gettimeofday(&tv, NULL);
+ endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+ printf("spend time for rsc-slice is [%d]ms\n", (int)(endtime - starttime));
+
+ return 0;
+}