Sync to the latest code 05/10405/3 accepted/tizen/20131014.080242 submit/tizen/20131014.075642
authorjunsuk77.oh <junsuk77.oh@samsung.com>
Tue, 1 Oct 2013 12:27:17 +0000 (21:27 +0900)
committerjunsuk77.oh <junsuk77.oh@samsung.com>
Wed, 2 Oct 2013 08:50:26 +0000 (17:50 +0900)
1. implement get size api to get package directory size
2. add upgrade listen type for listener
3. add wait time for sync api
4. implement rpm installer for corexml
5. add new api with callback to get a package size
6. kill pkgmgr server when dbus connection is fail

Change-Id: I9d9ffe8b50fc7ade8b1e20f6560b884f40d09b86
Signed-off-by: junsuk77.oh <junsuk77.oh@samsung.com>
19 files changed:
client/include/package-manager.h
client/include/pkgmgr-debug.h
client/src/pkgmgr.c
comm/SLP_package_manager_frontend_backend_PG.h
comm/comm_client.h
comm/comm_client_dbus.c
comm/comm_config.h
comm/comm_status_broadcast_server.h
comm/comm_status_broadcast_server_dbus.c
comm/pkgmgr_installer.c
comm/pkgmgr_installer.h
comm/pkgmgr_installer_config.h
server/src/pkgmgr-server.c
server/src/pm-queue.c
tool/CMakeLists.txt
tool/pkg_cmd.c
tool/pkg_fota.c [new file with mode: 0644]
tool/pkg_getsize.c
tool/pkg_info.c

index c96976b..0908fed 100755 (executable)
@@ -97,6 +97,17 @@ extern "C" {
 #define PKGMGR_INFO_STR_DATA_SIZE      "data_size"
 #define PKGMGR_INFO_STR_APP_SIZE       "app_size"
 #define PKGMGR_INFO_STR_INSTALLED_TIME "installed_time"
+
+/**
+ * @brief listening status type in pkgmgr.
+ */
+#define PKGMGR_CLIENT_STATUS_ALL                                               0x00
+#define PKGMGR_CLIENT_STATUS_INSTALL                                   0x01
+#define PKGMGR_CLIENT_STATUS_UNINSTALL                                 0x02
+#define PKGMGR_CLIENT_STATUS_UPGRADE                                   0x04
+#define PKGMGR_CLIENT_STATUS_MOVE                                              0x08
+#define PKGMGR_CLIENT_STATUS_CLEAR_DATA                                        0x10
+#define PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS                  0x20
 /** @} */
 
 /* 1 -100 : Package command errors */
@@ -258,12 +269,15 @@ typedef enum {
        PM_REQUEST_MOVE = 1,
        PM_REQUEST_GET_SIZE = 2,
        PM_REQUEST_KILL_APP = 3,
+       PM_REQUEST_CHECK_APP = 4,
        PM_REQUEST_MAX
 }pkgmgr_request_service_type;
 
 typedef enum {
        PM_GET_TOTAL_SIZE= 0,
        PM_GET_DATA_SIZE = 1,
+       PM_GET_ALL_PKGS = 2,
+       PM_GET_MAX
 }pkgmgr_getsize_type;
 
 /**
@@ -372,6 +386,26 @@ int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
                                const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode);
 
 /**
+ * @brief      This API moves installed package to SD card or vice versa.
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in]  pc      pkgmgr_client
+ * @param[in]  pkg_type                package type
+ * @param[in]  pkgid   application package id
+ * @param[in]  move_type               PM_MOVE_TO_INTERNAL or PM_MOVE_TO_SDCARD
+ * @param[in]  mode            installation mode  - PM_DEFAULT, PM_QUIET
+ * @param[in]  event_cb        user callback
+ * @param[in]  data            user data
+ * @retval     PKGMGR_R_OK     success
+ * @retval     PKGMGR_R_EINVAL invalid argument
+ * @retval     PKGMGR_R_ERROR  general error
+*/
+int pkgmgr_client_move_pkg(pkgmgr_client *pc, const char *pkg_type,
+                               const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode,
+                               pkgmgr_handler event_cb, void *data);
+
+/**
  * @brief      This API activates package.
  *
  * This API is for package-manager client application.\n
@@ -464,6 +498,19 @@ int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
                                const char *appid, pkgmgr_mode mode);
 
 /**
+ * @brief      This API set status type to listen for the pkgmgr's broadcasting
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in]  pc      pkgmgr_client
+ * @param[in]  status_type     status type to listen
+ * @return     request_id (>0) if success, error code(<0) if fail\n
+ * @retval     PKGMGR_R_OK     success
+ * @retval     PKGMGR_R_EINVAL invalid argument
+*/
+int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type);
+
+/**
  * @brief      This API request to listen the pkgmgr's broadcasting
  *
  * This API is for package-manager client application.\n
@@ -539,6 +586,23 @@ int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, int
                                        const char *custom_info, pkgmgr_handler event_cb, void *data);
 
 /**
+ * @brief      This API get package size
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in]  pc                              pkgmgr_client
+ * @param[in]  pkgid                   package id
+ * @param[in]  get_type                type for pkgmgr client request to get package size
+ * @param[in]  event_cb                user callback
+ * @param[in]  data                    user data
+ * @return     request_id (>0) if success, error code(<0) if fail\n
+ * @retval     PKGMGR_R_OK     success
+ * @retval     PKGMGR_R_EINVAL invalid argument
+ * @retval     PKGMGR_R_ECOMM  communication error
+*/
+int pkgmgr_client_get_size(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data);
+
+/**
  * @brief      This API provides package list
  *
  * This API is for package-manager client application.\n
index 3040e7e..7ec0523 100644 (file)
        } \
 } while (0)
 
+#define trym_if(expr, fmt, arg...) do { \
+                        if (expr) { \
+                                PKGMGR_DEBUG_ERR("(%s) "fmt, #expr, ##arg); \
+                                goto catch; \
+                        } \
+                } while (0)
+
 #define tryvm_if(expr, val, fmt, arg...) do { \
                         if (expr) { \
                                 PKGMGR_DEBUG_ERR("(%s) "fmt, #expr, ##arg); \
index ffccb2c..5f2f8e7 100755 (executable)
@@ -37,6 +37,7 @@
 #include <db-util.h>
 #include <pkgmgr-info.h>
 #include <iniparser.h>
+#include <security-server.h>
 
 #include "package-manager.h"
 #include "pkgmgr-internal.h"
@@ -52,6 +53,9 @@
 
 #define PKG_TMP_PATH "/opt/usr/apps/tmp"
 
+#define BINSH_NAME     "/bin/sh"
+#define BINSH_SIZE     7
+
 static int _get_request_id()
 {
        static int internal_req_id = 1;
@@ -76,6 +80,7 @@ typedef struct _listen_cb_info {
 
 typedef struct _pkgmgr_client_t {
        client_type ctype;
+       int status_type;
        union {
                struct _request {
                        comm_client *cc;
@@ -96,6 +101,29 @@ typedef struct _iter_data {
        void *data;
 } iter_data;
 
+static char *__get_cookie_from_security_server(void)
+{
+       int ret = 0;
+       size_t cookie_size = 0;
+       char *e_cookie = NULL;
+
+       //calculage cookie size
+       cookie_size = security_server_get_cookie_size();
+       retvm_if(cookie_size <= 0, NULL, "security_server_get_cookie_size : cookie_size is %d", cookie_size);
+
+       //get cookie from security server
+       char cookie[cookie_size];
+       cookie[0] = '\0';
+       ret = security_server_request_cookie(cookie, cookie_size);
+       retvm_if(ret < 0, NULL, "security_server_request_cookie fail (%d)", ret);
+
+       //encode cookie
+       e_cookie = g_base64_encode((const guchar *)cookie, cookie_size);
+       retvm_if(e_cookie == NULL, NULL, "g_base64_encode e_cookie is NULL");
+
+       return e_cookie;
+}
+
 static int __xsystem(const char *argv[])
 {
        int status = 0;
@@ -416,6 +444,161 @@ static char *__get_type_from_path(const char *pkg_path)
        return strdup(pkg_type);
 }
 
+static int __get_pkgid_by_appid(const char *appid, char **pkgid)
+{
+       pkgmgrinfo_appinfo_h pkgmgrinfo_appinfo = NULL;
+       int ret = -1;
+       char *pkg_id = NULL;
+       char *pkg_id_dup = NULL;
+
+       if (pkgmgrinfo_appinfo_get_appinfo(appid, &pkgmgrinfo_appinfo) != PMINFO_R_OK)
+               return -1;
+
+       if (pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo, &pkg_id) != PMINFO_R_OK)
+               goto err;
+
+       pkg_id_dup = strdup(pkg_id);
+       if (pkg_id_dup == NULL)
+               goto err;
+
+       *pkgid = pkg_id_dup;
+       ret = PMINFO_R_OK;
+
+err:
+       pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
+
+       return ret;
+}
+
+static inline ail_cb_ret_e __appinfo_cb(const ail_appinfo_h appinfo, void *user_data)
+{
+       char *package;
+       ail_cb_ret_e ret = AIL_CB_RET_CONTINUE;
+
+       ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
+
+       if (package) {
+               (* (char **) user_data) = strdup(package);
+               ret = AIL_CB_RET_CANCEL;
+       }
+
+       return ret;
+}
+
+static char *__get_app_info_from_db_by_apppath(const char *apppath)
+{
+       char *caller_appid = NULL;
+       ail_filter_h filter;
+       ail_error_e ret;
+       int count;
+
+       if (apppath == NULL)
+               return NULL;
+
+       ret = ail_filter_new(&filter);
+       if (ret != AIL_ERROR_OK) {
+               return NULL;
+       }
+
+       ret = ail_filter_add_str(filter, AIL_PROP_X_SLP_EXE_PATH, apppath);
+       if (ret != AIL_ERROR_OK) {
+               ail_filter_destroy(filter);
+               return NULL;
+       }
+
+       ret = ail_filter_count_appinfo(filter, &count);
+       if (ret != AIL_ERROR_OK) {
+               ail_filter_destroy(filter);
+               return NULL;
+       }
+       if (count < 1) {
+               ail_filter_destroy(filter);
+               return NULL;
+       }
+
+       ail_filter_list_appinfo_foreach(filter, __appinfo_cb, &caller_appid);
+
+       ail_filter_destroy(filter);
+
+       return caller_appid;
+}
+
+static inline int __read_proc(const char *path, char *buf, int size)
+{
+       int fd = 0;
+       int ret = 0;
+
+       if (buf == NULL || path == NULL)
+               return -1;
+
+       fd = open(path, O_RDONLY);
+       if (fd < 0)
+               return -1;
+
+       ret = read(fd, buf, size - 1);
+       if (ret <= 0) {
+               close(fd);
+               return -1;
+       } else
+               buf[ret] = 0;
+
+       close(fd);
+
+       return ret;
+}
+
+char *__proc_get_cmdline_bypid(int pid)
+{
+       char buf[PKG_STRING_LEN_MAX] = {'\0', };
+       int ret = 0;
+
+       snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
+       ret = __read_proc(buf, buf, sizeof(buf));
+       if (ret <= 0)
+               return NULL;
+
+       /* support app launched by shell script*/
+       if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0)
+               return strdup(&buf[BINSH_SIZE + 1]);
+       else
+               return strdup(buf);
+}
+
+static int __get_appid_bypid(int pid, char *pkgname, int len)
+{
+       char *cmdline = NULL;
+       char *caller_appid = NULL;
+
+       cmdline = __proc_get_cmdline_bypid(pid);
+       if (cmdline == NULL)
+               return -1;
+
+       caller_appid = __get_app_info_from_db_by_apppath(cmdline);
+       snprintf(pkgname, len, "%s", caller_appid);
+
+       free(cmdline);
+       free(caller_appid);
+
+       return 0;
+}
+
+static char *__get_caller_pkgid()
+{
+       char *caller_appid[PKG_STRING_LEN_MAX] = {0, };
+       char *caller_pkgid = NULL;
+
+       if (__get_appid_bypid(getpid(), caller_appid, sizeof(caller_appid)) < 0) {
+               _LOGE("get appid fail!!!\n");
+               return NULL;
+       }
+       if (__get_pkgid_by_appid(caller_appid, &caller_pkgid) < 0){
+               _LOGE("get pkgid fail!!!\n");
+               return NULL;
+       }
+
+       return caller_pkgid;
+}
+
 static inline int __pkgmgr_read_proc(const char *path, char *buf, int size)
 {
        int fd;
@@ -511,6 +694,36 @@ static int __app_list_cb (const pkgmgr_appinfo_h handle,
        return 0;
 }
 
+static int __sync_process(char *req_key)
+{
+       char info_file[PKG_STRING_LEN_MAX] = {'\0', };
+       int result = 0;
+       int check_cnt = 0;
+
+       snprintf(info_file, PKG_STRING_LEN_MAX, "%s/%s", PKG_TMP_PATH, req_key);
+       while(1)
+       {
+               check_cnt ++;
+
+               vconf_get_int(VCONFKEY_PKGMGR_STATUS, &result);
+               if (result < 0) {
+                       _LOGD("file is not generated yet.... wait\n");
+                       usleep(10 * 1000);      /* 10ms sleep*/
+               } else {
+                       _LOGD("info_file file is generated, result = %d. \n", result);
+                       break;
+               }
+
+               if (check_cnt > 6000) { /* 60s time over*/
+                       _LOGD("wait time over!!\n");
+                       break;
+               }
+       }
+
+       vconf_set_int(VCONFKEY_PKGMGR_STATUS, -1);
+
+       return result;
+}
 static int __csc_process(const char *csc_path, char *result_path)
 {
        int ret = 0;
@@ -602,11 +815,8 @@ catch:
 static int __get_size_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data)
 {
        char *req_key = NULL;
-       int req_id = 0;
        int ret =0;
-       pkgmgrinfo_pkginfo_h handle;
-       char *pkgtype = NULL;
-       char *installer_path = NULL;
+       char *pkgtype = "rpm";
        char *argv[PKG_ARGC_MAX] = { NULL, };
        char *args = NULL;
        int argcnt = 0;
@@ -614,38 +824,15 @@ static int __get_size_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_gets
        char *temp = NULL;
        int i = 0;
        char buf[128] = {'\0'};
-       char size_info_file[PKG_STRING_LEN_MAX] = {'\0', };
-       int pkg_size = 0;
-       int check_cnt = 0;
-       FILE *fp;
-       char buffer[PKG_ARGC_MAX] = {'\0', };
+       char *cookie = NULL;
 
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
        retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
 
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
-       retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed");
-
-       ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
-       tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed");
-
-       installer_path = _get_backend_path_with_type(pkgtype);
        req_key = __get_req_key(pkgid);
-       req_id = _get_request_id();
 
        snprintf(buf, 128, "%d", get_type);
-       argv[argcnt++] = installer_path;
-       /* argv[1] */
-       argv[argcnt++] = strdup("-k");
-       /* argv[2] */
-       argv[argcnt++] = req_key;
-       /* argv[3] */
-       argv[argcnt++] = strdup("-d");
-       /* argv[4] */
        argv[argcnt++] = strdup(pkgid);
-       /* argv[5] */
-       argv[argcnt++] = strdup("-t");
-       /* argv[6] */
        argv[argcnt++] = strdup(buf);
 
        /*** add quote in all string for special charactor like '\n'***   FIX */
@@ -668,47 +855,18 @@ static int __get_size_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_gets
        }
        _LOGD("[args] %s [len] %d\n", args, len);
 
-       /* 6. request install */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, NULL, 1);
-
-       snprintf(size_info_file, PKG_STRING_LEN_MAX, "%s/%s", PKG_TMP_PATH, req_key);
-       while(1)
-       {
-               check_cnt ++;
-               if (access(size_info_file, F_OK) != 0) {
-                       _LOGD("file is not generated yet.... wait\n", size_info_file);
-                       usleep(10 * 1000);      /* 10ms sleep*/
-               } else {
-                       _LOGD("size_info_file file is generated!!\n");
-
-                       fp = fopen(size_info_file, "r");
-                       if (fp == NULL) {
-                               _LOGE("fopen failed\n");
-                               break;
-                       }
-                       fread(&buffer, sizeof(buffer), 1, fp);
-                       fclose(fp);
-
-                       pkg_size = atoi(buffer);
-                       _LOGD("pkg_sizepkg_size  == > %d!!\n", pkg_size);
-
-                       break;
-               }
-
-               if (check_cnt > 500) {  /* 5s time over*/
-                       _LOGD("wait time over!!\n");
-                       break;
-               }
-       }
+       /* get cookie from security-server */
+       cookie = __get_cookie_from_security_server();
+       tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
 
-       const char *rm_argv[] = { "/bin/rm", "-rf", size_info_file, NULL };
-       ret = __xsystem(rm_argv);
+       /* request */
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, cookie, 1);
        if (ret < 0)
-               _LOGE("__xsystem failed, ret=%d\n", ret);
+               _LOGE("comm_client_request failed, ret=%d\n", ret);
 
-       ret = pkg_size;
+       ret = __sync_process(req_key);
        if (ret < 0)
-               _LOGE("request failed, ret=%d\n", ret);
+               _LOGE("get size failed, ret=%d\n", ret);
 
 catch:
        for (i = 0; i < argcnt; i++)
@@ -716,8 +874,9 @@ catch:
 
        if(args)
                free(args);
+       if (cookie)
+               free(cookie);
 
-       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
        return ret;
 }
 
@@ -736,6 +895,8 @@ static int __move_pkg_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_move
        char *temp = NULL;
        int i = 0;
        char buf[128] = {'\0'};
+       char info_file[PKG_STRING_LEN_MAX] = {'\0', };
+       char *cookie = NULL;
 
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
        retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
@@ -749,7 +910,6 @@ static int __move_pkg_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_move
        installer_path = _get_backend_path_with_type(pkgtype);
        req_key = __get_req_key(pkgid);
        req_id = _get_request_id();
-       __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
 
        /* generate argv */
        snprintf(buf, 128, "%d", move_type);
@@ -790,10 +950,19 @@ static int __move_pkg_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_move
        }
        _LOGD("[args] %s [len] %d\n", args, len);
 
-       /* 6. request install */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, NULL, 1);
+       /* get cookie from security-server */
+       cookie = __get_cookie_from_security_server();
+       tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
+
+       /* 6. request */
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, cookie, 1);
        if (ret < 0)
-               _LOGE("request failed, ret=%d\n", ret);
+               _LOGE("comm_client_request failed, ret=%d\n", ret);
+
+       snprintf(info_file, PKG_STRING_LEN_MAX, "app2sd_%s", pkgid);
+       ret = __sync_process(info_file);
+       if (ret != 0)
+               _LOGE("move pkg failed, ret=%d\n", ret);
 
 catch:
        for (i = 0; i < argcnt; i++)
@@ -801,18 +970,20 @@ catch:
 
        if(args)
                free(args);
+       if (cookie)
+               free(cookie);
 
        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
        return ret;
 }
 
-static int __kill_app_process(pkgmgr_client * pc, const char *pkgid)
+static int __check_app_process(pkgmgr_request_service_type service_type, pkgmgr_client * pc, const char *pkgid, void *data)
 {
        const char *pkgtype;
        char *req_key;
-       char *cookie = NULL;
        int ret;
        pkgmgrinfo_pkginfo_h handle;
+       int pid = -1;
 
        /* Check for NULL value of pc */
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
@@ -828,10 +999,17 @@ static int __kill_app_process(pkgmgr_client * pc, const char *pkgid)
        req_key = __get_req_key(pkgid);
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_KILL_APP, pkgtype, pkgid, NULL, NULL, 1);
+       if (service_type == PM_REQUEST_KILL_APP)
+               ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_KILL_APP, pkgtype, pkgid, NULL, NULL, 1);
+       else if (service_type == PM_REQUEST_CHECK_APP)
+               ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_CHECK_APP, pkgtype, pkgid, NULL, NULL, 1);
+
        if (ret < 0)
                _LOGE("request failed, ret=%d\n", ret);
 
+       pid  = __sync_process(req_key);
+       * (int *) data = pid;
+
 catch:
        free(req_key);
        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
@@ -845,58 +1023,36 @@ API pkgmgr_client *pkgmgr_client_new(client_type ctype)
        pkgmgr_client_t *pc = NULL;
        int ret = -1;
 
-       if (ctype != PC_REQUEST && ctype != PC_LISTENING
-           && ctype != PC_BROADCAST)
-               return NULL;
+       retvm_if(ctype != PC_REQUEST && ctype != PC_LISTENING && ctype != PC_BROADCAST, NULL, "ctype is not client_type");
 
        /* Allocate memory for ADT:pkgmgr_client */
        pc = calloc(1, sizeof(pkgmgr_client_t));
-       if (pc == NULL) {
-               _LOGE("No memory");
-               return NULL;
-       }
+       retvm_if(pc == NULL, NULL, "No memory");
 
        /* Manage pc */
        pc->ctype = ctype;
+       pc->status_type = PKGMGR_CLIENT_STATUS_ALL;
 
        if (pc->ctype == PC_REQUEST) {
                pc->info.request.cc = comm_client_new();
-               if (pc->info.request.cc == NULL) {
-                       _LOGE("client creation failed");
-                       goto err;
-               }
-               ret = comm_client_set_status_callback(pc->info.request.cc,
-                                                     __operation_callback, pc);
-               if (ret < 0) {
-                       _LOGE("comm_client_set_status_callback() failed - %d",
-                             ret);
-                       goto err;
-               }
+               trym_if(pc->info.request.cc == NULL, "client creation failed");
+
+               ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.request.cc, __operation_callback, pc);
+               trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
        } else if (pc->ctype == PC_LISTENING) {
                pc->info.listening.cc = comm_client_new();
-               if (pc->info.listening.cc == NULL) {
-                       _LOGE("client creation failed");
-                       goto err;
-               }
-               ret = comm_client_set_status_callback(pc->info.listening.cc,
-                                                     __status_callback, pc);
-               if (ret < 0) {
-                       _LOGE("comm_client_set_status_callback() failed - %d",
-                             ret);
-                       goto err;
-               }
+               trym_if(pc->info.listening.cc == NULL, "client creation failed");
+
+               ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.listening.cc, __status_callback, pc);
+               trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
        } else if (pc->ctype == PC_BROADCAST) {
-               pc->info.broadcast.bc = comm_status_broadcast_server_connect();
-               if (pc->info.broadcast.bc == NULL) {
-                       _LOGE("client creation failed");
-                       goto err;
-               }
-               ret = 0;
+               pc->info.broadcast.bc = comm_status_broadcast_server_connect(COMM_STATUS_BROADCAST_ALL);
+               trym_if(pc->info.broadcast.bc == NULL, "client creation failed");
        }
 
        return (pkgmgr_client *) pc;
 
err:
catch:
        if (pc)
                free(pc);
        return NULL;
@@ -906,11 +1062,7 @@ API int pkgmgr_client_free(pkgmgr_client *pc)
 {
        int ret = -1;
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
-
-       if (mpc == NULL) {
-               _LOGE("Invalid argument");
-               return PKGMGR_R_EINVAL;
-       }
+       retvm_if(mpc == NULL, PKGMGR_R_EINVAL, "Invalid argument");
 
        if (mpc->ctype == PC_REQUEST) {
                req_cb_info *tmp;
@@ -922,24 +1074,18 @@ API int pkgmgr_client_free(pkgmgr_client *pc)
                }
 
                ret = comm_client_free(mpc->info.request.cc);
-               if (ret < 0) {
-                       _LOGE("comm_client_free() failed - %d", ret);
-                       goto err;
-               }
+               tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed");
        } else if (mpc->ctype == PC_LISTENING) {
-               listen_cb_info *tmp;
-               listen_cb_info *prev;
-               for (tmp = mpc->info.listening.lhead; tmp;) {
-                       prev = tmp;
-                       tmp = tmp->next;
-                       free(prev);
-               }
+                       listen_cb_info *tmp;
+                       listen_cb_info *prev;
+                       for (tmp = mpc->info.listening.lhead; tmp;) {
+                               prev = tmp;
+                               tmp = tmp->next;
+                               free(prev);
+                       }
 
-               ret = comm_client_free(mpc->info.listening.cc);
-               if (ret < 0) {
-                       _LOGE("comm_client_free() failed - %d", ret);
-                       goto err;
-               }
+                       ret = comm_client_free(mpc->info.listening.cc);
+                       tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed");
        } else if (mpc->ctype == PC_BROADCAST) {
                comm_status_broadcast_server_disconnect(mpc->info.broadcast.bc);
                ret = 0;
@@ -952,7 +1098,7 @@ API int pkgmgr_client_free(pkgmgr_client *pc)
        mpc = NULL;
        return PKGMGR_R_OK;
 
err:
catch:
        if (mpc) {
                free(mpc);
                mpc = NULL;
@@ -965,53 +1111,43 @@ API int pkgmgr_client_install(pkgmgr_client * pc, const char *pkg_type,
                              const char *optional_file, pkgmgr_mode mode,
                              pkgmgr_handler event_cb, void *data)
 {
-       char *pkgtype;
-       char *installer_path;
-       char *req_key;
-       int req_id;
+       char *pkgtype = NULL;
+       char *installer_path = NULL;
+       char *req_key = NULL;
+       int req_id = 0;
        int i = 0;
        char *argv[PKG_ARGC_MAX] = { NULL, };
        char *args = NULL;
        int argcnt = 0;
        int len = 0;
        char *temp = NULL;
-       int ret;
+       int ret = 0;
        char *cookie = NULL;
+       char *caller_pkgid = NULL;
+
+       caller_pkgid = __get_caller_pkgid();
+       if (caller_pkgid == NULL)
+               _LOGE("caller dont have pkgid..\n");
 
        /* Check for NULL value of pc */
-       if (pc == NULL) {
-               _LOGD("package manager client handle is NULL\n");
-               return PKGMGR_R_EINVAL;
-       }
-       pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
+       retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL");
 
        /* 0. check the pc type */
-       if (mpc->ctype != PC_REQUEST)
-               return PKGMGR_R_EINVAL;
+       pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
+       retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST");
 
        /* 1. check argument */
        if (descriptor_path) {
-               if (strlen(descriptor_path) >= PKG_STRING_LEN_MAX)
-                       return PKGMGR_R_EINVAL;
-
-               if (access(descriptor_path, F_OK) != 0)
-                       return PKGMGR_R_EINVAL;
+               retvm_if(strlen(descriptor_path) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "descriptor_path over PKG_STRING_LEN_MAX");
+               retvm_if(access(descriptor_path, F_OK) != 0, PKGMGR_R_EINVAL, "descriptor_path access fail");
        }
 
-       if (pkg_path == NULL)
-               return PKGMGR_R_EINVAL;
-       else {
-               if (strlen(pkg_path) >= PKG_STRING_LEN_MAX)
-                       return PKGMGR_R_EINVAL;
-
-               if (access(pkg_path, F_OK) != 0)
-                       return PKGMGR_R_EINVAL;
-       }
+       retvm_if(pkg_path == NULL, PKGMGR_R_EINVAL, "pkg_path is NULL");
+       retvm_if(strlen(pkg_path) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "pkg_path over PKG_STRING_LEN_MAX");
+       retvm_if(access(pkg_path, F_OK) != 0, PKGMGR_R_EINVAL, "pkg_path access fail");
 
-       if (optional_file) {
-               if (strlen(optional_file) >= PKG_STRING_LEN_MAX)
-                       return PKGMGR_R_EINVAL;
-       }
+       if (optional_file)
+               retvm_if(strlen(optional_file) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX");
 
        /* 2. get installer path using pkg_path */
        if (pkg_type) {
@@ -1021,9 +1157,9 @@ API int pkgmgr_client_install(pkgmgr_client * pc, const char *pkg_type,
                installer_path = _get_backend_path(pkg_path);
                pkgtype = __get_type_from_path(pkg_path);
        }
-
        if (installer_path == NULL) {
                free(pkgtype);
+               _LOGE("installer_path is NULL\n");
                return PKGMGR_R_EINVAL;
        }
 
@@ -1054,7 +1190,13 @@ API int pkgmgr_client_install(pkgmgr_client * pc, const char *pkg_type,
                argv[argcnt++] = strdup("-o");
                argv[argcnt++] = strdup(optional_file);
        }
-       /* argv[6] -q option should be located at the end of command !! */
+       if (caller_pkgid) {
+               argv[argcnt++] = strdup("-p");
+               argv[argcnt++] = strdup(caller_pkgid);
+       }
+
+
+/* argv[6] -q option should be located at the end of command !! */
        if (mode == PM_QUIET)
                argv[argcnt++] = strdup("-q");
 
@@ -1066,15 +1208,8 @@ API int pkgmgr_client_install(pkgmgr_client * pc, const char *pkg_type,
        }
 
        args = (char *)calloc(len, sizeof(char));
-       if (args == NULL) {
-               _LOGD("calloc failed");
-
-               for (i = 0; i < argcnt; i++)
-                       free(argv[i]);
+       tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
 
-               free(pkgtype);
-               return PKGMGR_R_ERROR;
-       }
        strncpy(args, argv[0], len - 1);
 
        for (i = 1; i < argcnt; i++) {
@@ -1084,29 +1219,30 @@ API int pkgmgr_client_install(pkgmgr_client * pc, const char *pkg_type,
                g_free(temp);
        }
        _LOGD("[args] %s [len] %d\n", args, len);
+
+       /* get cookie from security-server */
+       cookie = __get_cookie_from_security_server();
+       tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
        /******************* end of quote ************************/
 
        /* 6. request install */
-       ret = comm_client_request(mpc->info.request.cc, req_key,
-                                 COMM_REQ_TO_INSTALLER, pkgtype, pkg_path,
-                                 args, cookie, 1);
-       if (ret < 0) {
-               _LOGE("request failed, ret=%d\n", ret);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkg_path, args, cookie, 1);
+       tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
-               for (i = 0; i < argcnt; i++)
-                       free(argv[i]);
-               free(args);
-               free(pkgtype);
-               return PKGMGR_R_ECOMM;
-       }
+       ret = req_id;
 
+catch:
        for (i = 0; i < argcnt; i++)
                free(argv[i]);
 
-       free(args);
-       free(pkgtype);
+       if (args)
+               free(args);
+       if (pkgtype)
+               free(pkgtype);
+       if (cookie)
+               free(cookie);
 
-       return req_id;
+       return ret;
 }
 
 API int pkgmgr_client_reinstall(pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
@@ -1196,6 +1332,10 @@ API int pkgmgr_client_reinstall(pkgmgr_client * pc, const char *pkg_type, const
                g_free(temp);
        }
        _LOGD("[args] %s [len] %d\n", args, len);
+
+       /* get cookie from security-server */
+       cookie = __get_cookie_from_security_server();
+       tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
        /******************* end of quote ************************/
 
        /* 6. request install */
@@ -1208,8 +1348,12 @@ catch:
        for (i = 0; i < argcnt; i++)
                free(argv[i]);
 
-       free(args);
-       free(pkgtype);
+       if (args)
+               free(args);
+       if (pkgtype)
+               free(pkgtype);
+       if (cookie)
+               free(cookie);
 
        return ret;
 }
@@ -1230,6 +1374,12 @@ API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
        char *temp = NULL;
        int ret = -1;
        char *cookie = NULL;
+       bool removable = false;
+       char *caller_pkgid = NULL;
+
+       caller_pkgid = __get_caller_pkgid();
+       if (caller_pkgid == NULL)
+               _LOGE("caller dont have pkgid..\n");
 
        /* Check for NULL value of pc */
        retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
@@ -1262,6 +1412,12 @@ API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
        tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_type fail");
        tryvm_if(pkgtype == NULL, ret = PKGMGR_R_ERROR, "pkgtype is NULL");
 
+       /*check removable, execpt "rpm" type    */
+       if (strcmp(pkgtype, "rpm")) {
+               pkgmgr_pkginfo_is_removable(handle, &removable);
+               tryvm_if(removable == false, ret = PKGMGR_R_ERROR, "Pkgid(%s) can not be removed, This is non-removalbe package...\n", pkgid);
+       }
+
        /*check pkgid length    */
        tryvm_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "pkgid is too long");
 
@@ -1288,6 +1444,10 @@ API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
        argv[argcnt++] = strdup("-d");
        /* argv[4] */
        argv[argcnt++] = strdup(pkgid);
+       if (caller_pkgid) {
+               argv[argcnt++] = strdup("-p");
+               argv[argcnt++] = caller_pkgid;
+       }
        /* argv[5] -q option should be located at the end of command !! */
        if (mode == PM_QUIET)
                argv[argcnt++] = strdup("-q");
@@ -1311,19 +1471,17 @@ API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
                g_free(temp);
        }
        _LOGD("[args] %s [len] %d\n", args, len);
+
+       /* get cookie from security-server */
+       cookie = __get_cookie_from_security_server();
+       tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
        /******************* end of quote ************************/
 
        /* 6. request install */
        ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
        tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "calloc failed");
 
-       for (i = 0; i < argcnt; i++)
-               free(argv[i]);
-
-       free(args);
-
-       pkgmgr_pkginfo_destroy_pkginfo(handle);
-       return req_id;
+       ret = req_id;
 
 catch:
        for (i = 0; i < argcnt; i++)
@@ -1331,6 +1489,8 @@ catch:
 
        if(args)
                free(args);
+       if (cookie)
+               free(cookie);
 
        pkgmgr_pkginfo_destroy_pkginfo(handle);
        PKGMGR_END();\
@@ -1454,11 +1614,143 @@ API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
        for (i = 0; i < argcnt; i++)
                free(argv[i]);
 
-       free(args);
+       if (args)
+               free(args);
 
        return req_id;
 }
 
+API int pkgmgr_client_move_pkg(pkgmgr_client *pc, const char *pkg_type,
+                               const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode,
+                               pkgmgr_handler event_cb, void *data)
+{
+       char *pkgtype;
+       char *installer_path;
+       char *req_key;
+       int req_id;
+       int i = 0;
+       char *argv[PKG_ARGC_MAX] = { NULL, };
+       char *args = NULL;
+       int argcnt = 0;
+       int len = 0;
+       char *temp = NULL;
+       int ret = -1;
+       char *cookie = NULL;
+       char buf[128] = {'\0'};
+
+       /* Check for NULL value of pc */
+       retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
+
+       pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
+
+       /* 0. check the pc type */
+       retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
+
+       /* 1. check argument */
+       retv_if(pkgid == NULL, PKGMGR_R_EINVAL);
+
+       pkgmgr_pkginfo_h handle;
+       ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
+
+       /*check package id      */
+       tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_pkginfo fail");
+       tryvm_if(handle == NULL, ret = PKGMGR_R_EINVAL, "Pkgid(%s) can not find in installed pkg DB! \n", pkgid);
+
+       /*check running app , terminate app if it is running*/
+       ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
+       tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_UI_APP fail");
+
+       /*check running app , terminate app if it is running*/
+       ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
+       tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_SVC_APP fail");
+
+       /*check type    */
+       ret = pkgmgr_pkginfo_get_type(handle, &pkgtype);
+       tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_type fail");
+       tryvm_if(pkgtype == NULL, ret = PKGMGR_R_ERROR, "pkgtype is NULL");
+
+       /*check pkgid length    */
+       tryvm_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "pkgid is too long");
+
+       /*check move_type       */
+       tryvm_if((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "move_type is not supported");
+
+       /* 2. get installer path using pkgtype */
+       installer_path = _get_backend_path_with_type(pkgtype);
+       tryvm_if(installer_path == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
+
+       /* 3. generate req_key */
+       req_key = __get_req_key(pkgid);
+
+       /* 4. add callback info - add callback info to pkgmgr_client */
+       req_id = _get_request_id();
+       __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
+
+       /* 5. generate argv */
+       snprintf(buf, 128, "%d", move_type);
+       /* argv[0] installer path */
+       argv[argcnt++] = installer_path;
+       /* argv[1] */
+       argv[argcnt++] = strdup("-k");
+       /* argv[2] */
+       argv[argcnt++] = req_key;
+       /* argv[3] */
+       argv[argcnt++] = strdup("-m");
+       /* argv[4] */
+       argv[argcnt++] = strdup(pkgid);
+       /* argv[5] */
+       argv[argcnt++] = strdup("-t");
+       /* argv[6] */
+       argv[argcnt++] = strdup(buf);
+       /* argv[5] -q option should be located at the end of command !! */
+       if (mode == PM_QUIET)
+               argv[argcnt++] = strdup("-q");
+
+       /*** add quote in all string for special charactor like '\n'***   FIX */
+       for (i = 0; i < argcnt; i++) {
+               temp = g_shell_quote(argv[i]);
+               len += (strlen(temp) + 1);
+               g_free(temp);
+       }
+
+       args = (char *)calloc(len, sizeof(char));
+       tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
+
+       strncpy(args, argv[0], len - 1);
+
+       for (i = 1; i < argcnt; i++) {
+               strncat(args, " ", strlen(" "));
+               temp = g_shell_quote(argv[i]);
+               strncat(args, temp, strlen(temp));
+               g_free(temp);
+       }
+       _LOGD("[args] %s [len] %d\n", args, len);
+
+       /* get cookie from security-server */
+       cookie = __get_cookie_from_security_server();
+       tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
+       /******************* end of quote ************************/
+
+       /* 6. request install */
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, cookie, 1);
+       tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "calloc failed");
+
+       ret = req_id;
+
+catch:
+       for (i = 0; i < argcnt; i++)
+               free(argv[i]);
+
+       if(args)
+               free(args);
+       if (cookie)
+               free(cookie);
+
+       pkgmgr_pkginfo_destroy_pkginfo(handle);
+       PKGMGR_END();\
+       return ret;
+}
+
 API int pkgmgr_client_activate(pkgmgr_client * pc, const char *pkg_type,
                               const char *pkgid)
 {
@@ -1467,46 +1759,36 @@ API int pkgmgr_client_activate(pkgmgr_client * pc, const char *pkg_type,
        char *cookie = NULL;
        int ret;
        /* Check for NULL value of pc */
-       if (pc == NULL) {
-               _LOGD("package manager client handle is NULL\n");
-               return PKGMGR_R_EINVAL;
-       }
+       retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
+
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
 
        /* 0. check the pc type */
-       if (mpc->ctype != PC_REQUEST)
-               return PKGMGR_R_EINVAL;
+       retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST");
 
        /* 1. check argument */
-       if (pkgid == NULL)
-               return PKGMGR_R_EINVAL;
+       retvm_if(pkgid == NULL, PKGMGR_R_EINVAL, "pkgid is NULL");
+       retvm_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "pkgid length over PKG_STRING_LEN_MAX ");
 
        if (pkg_type == NULL) {
                pkgtype = _get_pkg_type_from_desktop_file(pkgid);
-               if (pkgtype == NULL)
-                       return PKGMGR_R_EINVAL;
+               retvm_if(pkgtype == NULL, PKGMGR_R_EINVAL, "pkgtype is NULL");
        } else
                pkgtype = pkg_type;
 
-       if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
-               return PKGMGR_R_EINVAL;
-
        /* 2. generate req_key */
        req_key = __get_req_key(pkgid);
+       retvm_if(req_key == NULL, PKGMGR_R_EINVAL, "req_key is NULL");
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key,
-                                 COMM_REQ_TO_ACTIVATOR, pkgtype,
-                                 pkgid, "1 PKG", cookie, 1);
-       if (ret < 0) {
-               _LOGE("request failed, ret=%d\n", ret);
-               free(req_key);
-               return PKGMGR_R_ECOMM;
-       }
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, pkgid, "1 PKG", cookie, 1);
+       tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
-       free(req_key);
+       ret = PKGMGR_R_OK;
 
-       return PKGMGR_R_OK;
+catch:
+       free(req_key);
+       return ret;
 }
 
 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
@@ -1517,19 +1799,16 @@ API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
        char *cookie = NULL;
        int ret;
        /* Check for NULL value of pc */
-       if (pc == NULL) {
-               _LOGD("package manager client handle is NULL\n");
-               return PKGMGR_R_EINVAL;
-       }
+       retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
+
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
 
        /* 0. check the pc type */
-       if (mpc->ctype != PC_REQUEST)
-               return PKGMGR_R_EINVAL;
+       retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST");
 
        /* 1. check argument */
-       if (pkgid == NULL)
-               return PKGMGR_R_EINVAL;
+       retvm_if(pkgid == NULL, PKGMGR_R_EINVAL, "pkgid is NULL");
+       retvm_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "pkgid length over PKG_STRING_LEN_MAX ");
 
        if (pkg_type == NULL) {
                pkgtype = _get_pkg_type_from_desktop_file(pkgid);
@@ -1538,25 +1817,19 @@ API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
        } else
                pkgtype = pkg_type;
 
-       if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
-               return PKGMGR_R_EINVAL;
-
        /* 2. generate req_key */
        req_key = __get_req_key(pkgid);
+       retvm_if(req_key == NULL, PKGMGR_R_EINVAL, "req_key is NULL");
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key,
-                                 COMM_REQ_TO_ACTIVATOR, pkgtype,
-                                 pkgid, "0 PKG", cookie, 1);
-       if (ret < 0) {
-               _LOGE("request failed, ret=%d\n", ret);
-               free(req_key);
-               return PKGMGR_R_ECOMM;
-       }
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, pkgid, "0 PKG", cookie, 1);
+       tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
-       free(req_key);
+       ret = PKGMGR_R_OK;
 
-       return PKGMGR_R_OK;
+catch:
+       free(req_key);
+       return ret;
 }
 
 API int pkgmgr_client_activate_app(pkgmgr_client * pc, const char *appid)
@@ -1566,41 +1839,33 @@ API int pkgmgr_client_activate_app(pkgmgr_client * pc, const char *appid)
        char *cookie = NULL;
        int ret;
        /* Check for NULL value of pc */
-       if (pc == NULL) {
-               _LOGD("package manager client handle is NULL\n");
-               return PKGMGR_R_EINVAL;
-       }
+       retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
+
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
 
        /* 0. check the pc type */
-       if (mpc->ctype != PC_REQUEST)
-               return PKGMGR_R_EINVAL;
+       retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST");
 
        /* 1. check argument */
-       if (appid == NULL)
-               return PKGMGR_R_EINVAL;
-
-       if (strlen(appid) >= PKG_STRING_LEN_MAX)
-               return PKGMGR_R_EINVAL;
+       retvm_if(appid == NULL, PKGMGR_R_EINVAL, "pkgid is NULL");
+       retvm_if(strlen(appid) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "pkgid length over PKG_STRING_LEN_MAX ");
 
        pkgtype = _get_pkg_type_from_desktop_file(appid);
+       retvm_if(pkgtype == NULL, PKGMGR_R_EINVAL, "pkgtype is NULL");
 
        /* 2. generate req_key */
        req_key = __get_req_key(appid);
+       retvm_if(req_key == NULL, PKGMGR_R_EINVAL, "req_key is NULL");
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key,
-                                 COMM_REQ_TO_ACTIVATOR, pkgtype,
-                                 appid, "1 APP", cookie, 1);
-       if (ret < 0) {
-               _LOGE("request failed, ret=%d\n", ret);
-               free(req_key);
-               return PKGMGR_R_ECOMM;
-       }
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, appid, "1 APP", cookie, 1);
+       tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
-       free(req_key);
+       ret = PKGMGR_R_OK;
 
-       return PKGMGR_R_OK;
+catch:
+       free(req_key);
+       return ret;
 }
 
 API int pkgmgr_client_activate_appv(pkgmgr_client * pc, const char *appid, char *const argv[])
@@ -1616,27 +1881,23 @@ API int pkgmgr_client_activate_appv(pkgmgr_client * pc, const char *appid, char
        char *args = NULL;
        char *argsr = NULL;
        /* Check for NULL value of pc */
-       if (pc == NULL) {
-               _LOGD("package manager client handle is NULL\n");
-               return PKGMGR_R_EINVAL;
-       }
+       retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
+
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
 
        /* 0. check the pc type */
-       if (mpc->ctype != PC_REQUEST)
-               return PKGMGR_R_EINVAL;
+       retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST");
 
        /* 1. check argument */
-       if (appid == NULL)
-               return PKGMGR_R_EINVAL;
-
-       if (strlen(appid) >= PKG_STRING_LEN_MAX)
-               return PKGMGR_R_EINVAL;
+       retvm_if(appid == NULL, PKGMGR_R_EINVAL, "pkgid is NULL");
+       retvm_if(strlen(appid) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "pkgid length over PKG_STRING_LEN_MAX ");
 
        pkgtype = _get_pkg_type_from_desktop_file(appid);
+       retvm_if(pkgtype == NULL, PKGMGR_R_EINVAL, "pkgtype is NULL");
 
        /* 2. generate req_key */
        req_key = __get_req_key(appid);
+       retvm_if(req_key == NULL, PKGMGR_R_EINVAL, "req_key is NULL");
 
        /*** add quote in all string for special charactor like '\n'***   FIX */
        if (argv) {
@@ -1649,11 +1910,7 @@ API int pkgmgr_client_activate_appv(pkgmgr_client * pc, const char *appid, char
 
                if (argcnt) {
                        args = (char *)calloc(len, sizeof(char));
-                       if (args == NULL) {
-                               _LOGE("calloc failed");
-                               free(req_key);
-                               return PKGMGR_R_ERROR;
-                       }
+                       tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
                        strncpy(args, argv[0], len - 1);
 
                        for (i = 1; i < argcnt; i++) {
@@ -1666,12 +1923,8 @@ API int pkgmgr_client_activate_appv(pkgmgr_client * pc, const char *appid, char
        }
 
        argsr = (char *)calloc(strlen("1 APP")+2+len, sizeof(char));
-       if (argsr == NULL) {
-               _LOGE("calloc failed");
-               free(req_key);
-               free(args);
-               return PKGMGR_R_ERROR;
-       }
+       tryvm_if(argsr == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
+
        strncpy(argsr, "1 APP", strlen("1 APP"));
        if (argcnt) {
                strncat(argsr, " ", strlen(" "));
@@ -1682,22 +1935,18 @@ API int pkgmgr_client_activate_appv(pkgmgr_client * pc, const char *appid, char
        /******************* end of quote ************************/
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key,
-                                 COMM_REQ_TO_ACTIVATOR, pkgtype,
-                                 appid, argsr, cookie, 1);
-       if (ret < 0) {
-               _LOGE("request failed, ret=%d\n", ret);
-               free(req_key);
-               free(args);
-               free(argsr);
-               return PKGMGR_R_ECOMM;
-       }
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, appid, argsr, cookie, 1);
+       tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
+
+       ret = PKGMGR_R_OK;
+
+catch:
 
        free(req_key);
        free(args);
        free(argsr);
 
-       return PKGMGR_R_OK;
+       return ret;
 }
 
 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid)
@@ -1707,41 +1956,33 @@ API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid)
        char *cookie = NULL;
        int ret;
        /* Check for NULL value of pc */
-       if (pc == NULL) {
-               _LOGD("package manager client handle is NULL\n");
-               return PKGMGR_R_EINVAL;
-       }
+       retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
+
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
 
        /* 0. check the pc type */
-       if (mpc->ctype != PC_REQUEST)
-               return PKGMGR_R_EINVAL;
+       retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST");
 
        /* 1. check argument */
-       if (appid == NULL)
-               return PKGMGR_R_EINVAL;
-
-       if (strlen(appid) >= PKG_STRING_LEN_MAX)
-               return PKGMGR_R_EINVAL;
+       retvm_if(appid == NULL, PKGMGR_R_EINVAL, "pkgid is NULL");
+       retvm_if(strlen(appid) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "pkgid length over PKG_STRING_LEN_MAX ");
 
        pkgtype = _get_pkg_type_from_desktop_file(appid);
+       retvm_if(pkgtype == NULL, PKGMGR_R_EINVAL, "pkgtype is NULL");
 
        /* 2. generate req_key */
        req_key = __get_req_key(appid);
+       retvm_if(req_key == NULL, PKGMGR_R_EINVAL, "req_key is NULL");
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key,
-                                 COMM_REQ_TO_ACTIVATOR, pkgtype,
-                                 appid, "0 APP", cookie, 1);
-       if (ret < 0) {
-               _LOGE("request failed, ret=%d\n", ret);
-               free(req_key);
-               return PKGMGR_R_ECOMM;
-       }
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, appid, "0 APP", cookie, 1);
+       tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
-       free(req_key);
+       ret = PKGMGR_R_OK;
 
-       return PKGMGR_R_OK;
+catch:
+       free(req_key);
+       return ret;
 }
 
 
@@ -1859,29 +2100,80 @@ API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
        return PKGMGR_R_OK;
 }
 
+
+API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type)
+{
+       int ret = -1;
+
+       retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
+       retvm_if(status_type == PKGMGR_CLIENT_STATUS_ALL, PKGMGR_R_OK, "status_type is PKGMGR_CLIENT_STATUS_ALL");
+       pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
+
+       /*  free listening head */
+       listen_cb_info *tmp = NULL;
+       listen_cb_info *prev = NULL;
+       for (tmp = mpc->info.listening.lhead; tmp;) {
+               prev = tmp;
+               tmp = tmp->next;
+               free(prev);
+       }
+
+       /* free dbus connection */
+       ret = comm_client_free(mpc->info.listening.cc);
+       retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
+
+       /* Manage pc for seperated event */
+       mpc->ctype = PC_LISTENING;
+       mpc->status_type = status_type;
+
+       mpc->info.listening.cc = comm_client_new();
+       retvm_if(mpc->info.listening.cc == NULL, PKGMGR_R_EINVAL, "client creation failed");
+
+       if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL) == PKGMGR_CLIENT_STATUS_INSTALL) {
+               ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_INSTALL, mpc->info.listening.cc, __status_callback, pc);
+               retvm_if(ret < 0, PKGMGR_R_ECOMM, "PKGMGR_CLIENT_STATUS_INSTALL failed - %d", ret);
+       }
+
+       if ((mpc->status_type & PKGMGR_CLIENT_STATUS_UNINSTALL) == PKGMGR_CLIENT_STATUS_UNINSTALL) {
+               ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_UNINSTALL, mpc->info.listening.cc, __status_callback, pc);
+               retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_UNINSTALL failed - %d", ret);
+       }
+
+       if ((mpc->status_type & PKGMGR_CLIENT_STATUS_MOVE) == PKGMGR_CLIENT_STATUS_MOVE) {
+               ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_MOVE, mpc->info.listening.cc, __status_callback, pc);
+               retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_MOVE failed - %d", ret);
+       }
+
+       if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS) == PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS) {
+               ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_INSTALL_PROGRESS, mpc->info.listening.cc, __status_callback, pc);
+               retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_INSTALL_PROGRESS failed - %d", ret);
+       }
+
+   if ((mpc->status_type & PKGMGR_CLIENT_STATUS_UPGRADE) == PKGMGR_CLIENT_STATUS_UPGRADE) {
+          ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_UPGRADE, mpc->info.listening.cc, __status_callback, pc);
+          retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_UPGRADE failed - %d", ret);
+   }
+
+   return PKGMGR_R_OK;
+}
+
 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
                                    void *data)
 {
        int req_id;
        /* Check for NULL value of pc */
-       if (pc == NULL) {
-               _LOGD("package manager client handle is NULL\n");
-               return PKGMGR_R_EINVAL;
-       }
+       retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
 
-       /* 0. check the pc type */
-       if (mpc->ctype != PC_LISTENING)
-               return PKGMGR_R_EINVAL;
+       /* 0. check input */
+       retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING");
+       retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL");
 
-       /* 1. check argument */
-       if (event_cb == NULL)
-               return PKGMGR_R_EINVAL;
+       /* 1. get id */
+       req_id = _get_request_id();
 
        /* 2. add callback info to pkgmgr_client */
-       req_id = _get_request_id();
        __add_stat_cbinfo(mpc, req_id, event_cb, data);
-
        return req_id;
 }
 
@@ -1905,7 +2197,7 @@ API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
        if (mpc->ctype != PC_BROADCAST)
                return PKGMGR_R_EINVAL;
 
-       comm_status_broadcast_server_send_signal(mpc->info.broadcast.bc,
+       comm_status_broadcast_server_send_signal(COMM_STATUS_BROADCAST_ALL, mpc->info.broadcast.bc,
                                                 PKG_STATUS, pkg_type,
                                                 pkgid, key, val);
 
@@ -1942,6 +2234,7 @@ API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type,
        /* Check for NULL value of service type */
        retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
        retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n");
+       vconf_set_int(VCONFKEY_PKGMGR_STATUS, -1);
 
        switch (service_type) {
        case PM_REQUEST_CSC:
@@ -1963,31 +2256,24 @@ API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type,
                tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
 
                ret = __move_pkg_process(pc, pkgid, (pkgmgr_move_type)service_mode, event_cb, data);
-               if (ret < 0)
-                       _LOGE("__move_pkg_process fail \n");
-               else
-                       ret = PKGMGR_R_OK;
-
                break;
 
        case PM_REQUEST_GET_SIZE:
                tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
                tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
-               tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode > PM_GET_DATA_SIZE), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
+               tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode >= PM_GET_MAX), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
 
                ret = __get_size_process(pc, pkgid, (pkgmgr_getsize_type)service_mode, event_cb, data);
-               if (ret < 0)
-                       _LOGE("__get_size_process fail \n");
-
                break;
 
        case PM_REQUEST_KILL_APP:
+       case PM_REQUEST_CHECK_APP:
                tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
                tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
 
-               ret = __kill_app_process(pc, pkgid);
+               ret = __check_app_process(service_type, pc, pkgid, data);
                if (ret < 0)
-                       _LOGE("__kill_app_process fail \n");
+                       _LOGE("__check_app_process fail \n");
                else
                        ret = PKGMGR_R_OK;
 
@@ -2004,6 +2290,79 @@ catch:
        return ret;
 }
 
+API int pkgmgr_client_get_size(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data)
+{
+       char *req_key = NULL;
+       int ret =0;
+       char *pkgtype = "rpm";
+       char *argv[PKG_ARGC_MAX] = { NULL, };
+       char *args = NULL;
+       int argcnt = 0;
+       int len = 0;
+       char *temp = NULL;
+       int i = 0;
+       char buf[128] = {'\0'};
+       char *cookie = NULL;
+       int req_id = 0;
+
+       pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
+       retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
+       retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL\n");
+       retvm_if(pkgid == NULL, PKGMGR_R_EINVAL, "pkgid is NULL\n");
+
+       req_key = __get_req_key(pkgid);
+       retvm_if(req_key == NULL, PKGMGR_R_EINVAL, "req_key is NULL");
+
+       req_id = _get_request_id();
+       __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
+
+       snprintf(buf, 128, "%d", get_type);
+       argv[argcnt++] = strdup(pkgid);
+       argv[argcnt++] = strdup(buf);
+       argv[argcnt++] = strdup("-k");
+       argv[argcnt++] = req_key;
+
+       /*** add quote in all string for special charactor like '\n'***   FIX */
+       for (i = 0; i < argcnt; i++) {
+               temp = g_shell_quote(argv[i]);
+               len += (strlen(temp) + 1);
+               g_free(temp);
+       }
+
+       args = (char *)calloc(len, sizeof(char));
+       tryvm_if(args == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
+
+       strncpy(args, argv[0], len - 1);
+
+       for (i = 1; i < argcnt; i++) {
+               strncat(args, " ", strlen(" "));
+               temp = g_shell_quote(argv[i]);
+               strncat(args, temp, strlen(temp));
+               g_free(temp);
+       }
+       _LOGD("[args] %s [len] %d\n", args, len);
+
+       /* get cookie from security-server */
+       cookie = __get_cookie_from_security_server();
+       tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
+
+       /* request */
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, cookie, 1);
+       if (ret < 0)
+               _LOGE("comm_client_request failed, ret=%d\n", ret);
+
+catch:
+       for (i = 0; i < argcnt; i++)
+               free(argv[i]);
+
+       if(args)
+               free(args);
+       if (cookie)
+               free(cookie);
+
+       return ret;
+}
+
 
 #define __START_OF_OLD_API
 ail_cb_ret_e __appinfo_func(const ail_appinfo_h appinfo, void *user_data)
index ad88222..bc072b8 100755 (executable)
@@ -316,13 +316,13 @@ Backend must broadcast its installing status. You can broadcast your status by u
 /* ... */
 
 DBusConnection *conn;
-conn = comm_status_broadcast_server_connect();
+conn = comm_status_broadcast_server_connect(COMM_STATUS_BROADCAST_ALL);
 
-comm_status_broadcast_server_send_signal(conn, req_id, pkg_type, pkgid, "start", "0");
+comm_status_broadcast_server_send_signal(COMM_STATUS_BROADCAST_ALL, conn, req_id, pkg_type, pkgid, "start", "0");
 /* ... */
-comm_status_broadcast_server_send_signal(conn, req_id, pkg_type, pkgid, "install_percent", "60");
+comm_status_broadcast_server_send_signal(COMM_STATUS_BROADCAST_ALL,conn,  req_id, pkg_type, pkgid, "install_percent", "60");
 /* ... */
-comm_status_broadcast_server_send_signal(conn, req_id, pkg_type, pkgid, "end", "0");
+comm_status_broadcast_server_send_signal(COMM_STATUS_BROADCAST_ALL, conn, req_id, pkg_type, pkgid, "end", "0");
 
 /* ... */
 @endcode
index 7ab448b..13b62e4 100755 (executable)
@@ -48,7 +48,5 @@ API int comm_client_request(comm_client *cc, const char *req_id,
                            const char *pkgid, const char *args,
                            const char *cookie, int is_block);
 
-API int comm_client_set_status_callback(comm_client *cc, status_cb cb,
-                                       void *cb_data);
-
+API int comm_client_set_status_callback(int comm_status_type, comm_client *cc, status_cb cb, void *cb_data);
 #endif                         /* __COMM_CLIENT_H__ */
index 5af48a9..a39fefe 100755 (executable)
@@ -36,6 +36,8 @@
 #include <dbus/dbus-glib-lowlevel.h>
 #include <stdbool.h>
 #include <stdio.h>
+#include <dirent.h>
+#include <fcntl.h>
 
 /*******************
  * ADT description
@@ -57,6 +59,120 @@ struct comm_client {
  * Internal function description
  */
 
+static inline int __comm_read_proc(const char *path, char *buf, int size)
+{
+       int fd;
+       int ret;
+
+       if (buf == NULL || path == NULL)
+               return -1;
+
+       fd = open(path, O_RDONLY);
+       if (fd < 0)
+               return -1;
+
+       ret = read(fd, buf, size - 1);
+       if (ret <= 0) {
+               close(fd);
+               return -1;
+       } else
+               buf[ret] = 0;
+
+       close(fd);
+
+       return ret;
+}
+static inline int __comm_find_pid_by_cmdline(const char *dname,
+                                     const char *cmdline, const char *apppath)
+{
+       int pid = 0;
+
+       if (strncmp(cmdline, apppath, 1024-1) == 0) {
+               pid = atoi(dname);
+               if (pid != getpgid(pid))
+                       pid = 0;
+       }
+
+       return pid;
+}
+
+static int __comm_proc_iter_kill_cmdline(const char *apppath)
+{
+       DIR *dp;
+       struct dirent *dentry;
+       int pid;
+       int ret;
+       char buf[1024];
+
+       dp = opendir("/proc");
+       if (dp == NULL) {
+               return -1;
+       }
+
+       while ((dentry = readdir(dp)) != NULL) {
+               if (!isdigit(dentry->d_name[0]))
+                       continue;
+
+               snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
+               ret = __comm_read_proc(buf, buf, sizeof(buf));
+               if (ret <= 0)
+                       continue;
+
+               pid = __comm_find_pid_by_cmdline(dentry->d_name, buf, apppath);
+               if (pid > 0) {
+                       int pgid;
+
+                       pgid = getpgid(pid);
+                       if (pgid <= 1) {
+                               closedir(dp);
+                               return -1;
+                       }
+
+                       if (killpg(pgid, SIGKILL) < 0) {
+                               closedir(dp);
+                               return -1;
+                       }
+               }
+       }
+
+       closedir(dp);
+       return 0;
+}
+static char *__get_interface(int status_type)
+{
+       char *interface = NULL;
+
+       switch (status_type) {
+               case COMM_STATUS_BROADCAST_ALL:
+                       interface = COMM_STATUS_BROADCAST_DBUS_INTERFACE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_INSTALL:
+                       interface = COMM_STATUS_BROADCAST_DBUS_INSTALL_INTERFACE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_UNINSTALL:
+                       interface = COMM_STATUS_BROADCAST_DBUS_UNINSTALL_INTERFACE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_MOVE:
+                       interface = COMM_STATUS_BROADCAST_DBUS_MOVE_INTERFACE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_INSTALL_PROGRESS:
+                       interface = COMM_STATUS_BROADCAST_DBUS_INSTALL_PROGRESS_INTERFACE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_UPGRADE:
+                       interface = COMM_STATUS_BROADCAST_DBUS_UPGRADE_INTERFACE;
+                       break;
+
+               default:
+                       interface = NULL;
+       }
+       return interface;
+}
+
 /**
  * signal handler filter
  * Filter signal, and run user callback
@@ -83,9 +199,12 @@ _on_signal_handle_filter(DBusConnection *conn,
        sig_cb_data = (struct signal_callback_data *)user_data;
 
        /* Signal check */
-       if (dbus_message_is_signal(msg,
-                                  COMM_STATUS_BROADCAST_DBUS_INTERFACE,
-                                  COMM_STATUS_BROADCAST_SIGNAL_STATUS)) {
+       if ((dbus_message_is_signal(msg, COMM_STATUS_BROADCAST_DBUS_INTERFACE, COMM_STATUS_BROADCAST_SIGNAL_STATUS)) ||
+               (dbus_message_is_signal(msg, COMM_STATUS_BROADCAST_DBUS_INSTALL_INTERFACE, COMM_STATUS_BROADCAST_EVENT_INSTALL)) ||
+               (dbus_message_is_signal(msg, COMM_STATUS_BROADCAST_DBUS_UNINSTALL_INTERFACE, COMM_STATUS_BROADCAST_EVENT_UNINSTALL)) ||
+               (dbus_message_is_signal(msg, COMM_STATUS_BROADCAST_DBUS_MOVE_INTERFACE, COMM_STATUS_BROADCAST_EVENT_MOVE)) ||
+               (dbus_message_is_signal(msg, COMM_STATUS_BROADCAST_DBUS_UPGRADE_INTERFACE, COMM_STATUS_BROADCAST_EVENT_UPGRADE)) ||
+               (dbus_message_is_signal(msg, COMM_STATUS_BROADCAST_DBUS_INSTALL_PROGRESS_INTERFACE, COMM_STATUS_BROADCAST_EVENT_INSTALL_PROGRESS))) {
 
                /* Signal type check */
                if (dbus_message_get_args(msg, &err,
@@ -220,6 +339,7 @@ comm_client_request(
                const char *cookie,
                int is_block)
 {
+       DBusError err;
        DBusMessage *msg = NULL;
        int r = COMM_RET_ERROR; /* Default return */
 
@@ -251,6 +371,8 @@ comm_client_request(
        if (NULL == cookie)
                cookie = "";
 
+       dbus_error_init(&err);
+
        /* Append arguments */
        if (!dbus_message_append_args(msg,
                                      DBUS_TYPE_STRING, &req_id,
@@ -260,27 +382,32 @@ comm_client_request(
                                      DBUS_TYPE_STRING, &args,
                                      DBUS_TYPE_STRING, &cookie,
                                      DBUS_TYPE_INVALID)) {
-               r = COMM_RET_ERROR;
+               r = -3;
                ERR("dbus_message_append_args fail");
                goto ERROR_CLEANUP;
        }
 
-       /* Send message */
+       /* Send message , timeout -1 = _DBUS_DEFAULT_TIMEOUT_VALUE (25 * 1000) 25 seconds*/
        if (is_block == 1){
                if(!dbus_connection_send_with_reply_and_block(cc->conn, msg,
-                                                             10000, NULL)) {
+                                                             -1, NULL)) {
                        ERR("try send msg to dbus by timeout");
                        sleep(1);
                        if(!dbus_connection_send_with_reply_and_block(cc->conn, msg,
-                                                                         10000, NULL)) {
-                               r = COMM_RET_ERROR;
+                                                                         -1, &err)) {
+                               r = -4;
                                ERR("dbus_connection_send_with_reply_and_block fail");
+
+                               __comm_proc_iter_kill_cmdline("pkgmgr-server");
+
+                               if (dbus_error_is_set(&err))
+                                       ERR("dbus error:%s", err.message);
                                goto ERROR_CLEANUP;
                        }
                }
        } else {
                if (!dbus_connection_send(cc->conn, msg, NULL)) {
-                       r = COMM_RET_ERROR;
+                       r = -5;
                        ERR("dbus_connection_send fail");
                        goto ERROR_CLEANUP;
                }
@@ -290,7 +417,7 @@ comm_client_request(
        /* Cleanup and return */
        dbus_message_unref(msg);
        /* NOTE: It is not needed to free DBusMessageIter. */
-
+       dbus_error_free(&err);
        return 0;
 
  ERROR_CLEANUP:
@@ -302,6 +429,8 @@ comm_client_request(
        if (msg)
                dbus_message_unref(msg);
 
+       dbus_error_free(&err);
+
        return r;
 }
 
@@ -309,7 +438,7 @@ comm_client_request(
  * Set a callback for status signal
  */
 int
-comm_client_set_status_callback(comm_client *cc, status_cb cb, void *cb_data)
+comm_client_set_status_callback(int comm_status_type, comm_client *cc, status_cb cb, void *cb_data)
 {
        DBusError err;
        char buf[256] = { 0, };
@@ -321,8 +450,7 @@ comm_client_set_status_callback(comm_client *cc, status_cb cb, void *cb_data)
                goto ERROR_CLEANUP;
 
        /* Add a rule for signal */
-       snprintf(buf, 255, "type='signal',interface='%s'",
-                COMM_STATUS_BROADCAST_DBUS_INTERFACE);
+       snprintf(buf, 255, "type='signal',interface='%s'",      __get_interface(comm_status_type));
        dbus_bus_add_match(cc->conn, buf, &err);
        if (dbus_error_is_set(&err)) {
                ERR("dbus error:%s", err.message);
index c394285..6fa50a9 100755 (executable)
 
 #ifndef NDEBUG
 #ifdef USE_DLOG
+#undef LOG_TAG
+#ifndef LOG_TAG
 #define LOG_TAG "PKGMGR"
+#endif                         /* LOG_TAG */
 #include <dlog.h>
-#define dbg(fmtstr, args...) \
-       do { SLOGI("[comm]%s:%d:%s(): " \
-       fmtstr "\n", basename(__FILE__), __LINE__, __func__, ##args); } \
-       while (0)
-#define ERR(fmtstr, args...) \
-       do { SLOGE("[comm]%s:%d:%s(): " \
-       fmtstr "\n", basename(__FILE__), __LINE__, __func__, ##args); } \
-       while (0)
+
+#define dbg(fmt, arg...) LOGD(fmt, ##arg)
+#define ERR(fmt, arg...) LOGE(fmt, ##arg)
+
 #else
 #include <stdio.h>
 #include <sys/types.h>
        "org.tizen.slp.pkgmgr_status"
 #define COMM_STATUS_BROADCAST_SIGNAL_STATUS "status"
 
+#define COMM_STATUS_BROADCAST_DBUS_INSTALL_SERVICE_PREFIX "org.tizen.slp.pkgmgr.install"
+#define COMM_STATUS_BROADCAST_DBUS_INSTALL_PATH        "/org/tizen/slp/pkgmgr/install"
+#define COMM_STATUS_BROADCAST_DBUS_INSTALL_INTERFACE "org.tizen.slp.pkgmgr.install"
+#define COMM_STATUS_BROADCAST_EVENT_INSTALL "install"
+
+#define COMM_STATUS_BROADCAST_DBUS_UNINSTALL_SERVICE_PREFIX "org.tizen.slp.pkgmgr.uninstall"
+#define COMM_STATUS_BROADCAST_DBUS_UNINSTALL_PATH      "/org/tizen/slp/pkgmgr/uninstall"
+#define COMM_STATUS_BROADCAST_DBUS_UNINSTALL_INTERFACE "org.tizen.slp.pkgmgr.uninstall"
+#define COMM_STATUS_BROADCAST_EVENT_UNINSTALL "uninstall"
+
+#define COMM_STATUS_BROADCAST_DBUS_MOVE_SERVICE_PREFIX "org.tizen.slp.pkgmgr.move"
+#define COMM_STATUS_BROADCAST_DBUS_MOVE_PATH   "/org/tizen/slp/pkgmgr/move"
+#define COMM_STATUS_BROADCAST_DBUS_MOVE_INTERFACE "org.tizen.slp.pkgmgr.move"
+#define COMM_STATUS_BROADCAST_EVENT_MOVE "move"
+
+#define COMM_STATUS_BROADCAST_DBUS_INSTALL_PROGRESS_SERVICE_PREFIX "org.tizen.slp.pkgmgr.install.progress"
+#define COMM_STATUS_BROADCAST_DBUS_INSTALL_PROGRESS_PATH       "/org/tizen/slp/pkgmgr/install/progress"
+#define COMM_STATUS_BROADCAST_DBUS_INSTALL_PROGRESS_INTERFACE "org.tizen.slp.pkgmgr.install.progress"
+#define COMM_STATUS_BROADCAST_EVENT_INSTALL_PROGRESS "install_progress"
+
+#define COMM_STATUS_BROADCAST_DBUS_UPGRADE_SERVICE_PREFIX "org.tizen.slp.pkgmgr.upgrade"
+#define COMM_STATUS_BROADCAST_DBUS_UPGRADE_PATH        "/org/tizen/slp/pkgmgr/upgrade"
+#define COMM_STATUS_BROADCAST_DBUS_UPGRADE_INTERFACE "org.tizen.slp.pkgmgr.upgrade"
+#define COMM_STATUS_BROADCAST_EVENT_UPGRADE "upgrade"
+
 /********
  * enums
  ********/
@@ -117,6 +141,9 @@ enum {
        /*kill app */
        COMM_REQ_KILL_APP,
 
+       /*check app */
+       COMM_REQ_CHECK_APP,
+
        COMM_REQ_MAX_SENTINEL
 };
 
@@ -130,4 +157,15 @@ enum {
        COMM_RET_MAX_SENTINEL
 };
 
+/* broadcast type */
+enum {
+       COMM_STATUS_BROADCAST_ALL = 1,
+       COMM_STATUS_BROADCAST_INSTALL,
+       COMM_STATUS_BROADCAST_UNINSTALL,
+       COMM_STATUS_BROADCAST_MOVE,
+       COMM_STATUS_BROADCAST_INSTALL_PROGRESS,
+       COMM_STATUS_BROADCAST_UPGRADE,
+       COMM_STATUS_BROADCAST_MAX
+};
+
 #endif                         /* __COMM_CONFIG_H__ */
index bfc489a..3b74397 100755 (executable)
@@ -31,8 +31,8 @@
 #include <dbus/dbus.h>
 
 /* pure dbus api */
-API DBusConnection *comm_status_broadcast_server_connect(void);
-API void comm_status_broadcast_server_send_signal(DBusConnection *conn,
+API DBusConnection *comm_status_broadcast_server_connect(int comm_status_type);
+API void comm_status_broadcast_server_send_signal(int comm_status_type, DBusConnection *conn,
                                                  const char *req_id,
                                                  const char *pkg_type,
                                                  const char *pkgid,
index 14a849e..17a4c6b 100755 (executable)
 /********************************************
  * pure dbus signal service for internal use
  ********************************************/
+static char *__get_prifix(int status_type)
+{
+       char *prifix = NULL;
+
+       switch (status_type) {
+               case COMM_STATUS_BROADCAST_ALL:
+                       prifix = COMM_STATUS_BROADCAST_DBUS_SERVICE_PREFIX;
+                       break;
+
+               case COMM_STATUS_BROADCAST_INSTALL:
+                       prifix = COMM_STATUS_BROADCAST_DBUS_INSTALL_SERVICE_PREFIX;
+                       break;
+
+               case COMM_STATUS_BROADCAST_UNINSTALL:
+                       prifix = COMM_STATUS_BROADCAST_DBUS_UNINSTALL_SERVICE_PREFIX;
+                       break;
+
+               case COMM_STATUS_BROADCAST_MOVE:
+                       prifix = COMM_STATUS_BROADCAST_DBUS_MOVE_SERVICE_PREFIX;
+                       break;
+
+               case COMM_STATUS_BROADCAST_INSTALL_PROGRESS:
+                       prifix = COMM_STATUS_BROADCAST_DBUS_INSTALL_PROGRESS_SERVICE_PREFIX;
+                       break;
+
+               case COMM_STATUS_BROADCAST_UPGRADE:
+                       prifix = COMM_STATUS_BROADCAST_DBUS_UPGRADE_SERVICE_PREFIX;
+                       break;
+
+               default:
+                       prifix = NULL;
+       }
+       return prifix;
+}
+
+static char *__get_path(int status_type)
+{
+       char *path = NULL;
+
+       switch (status_type) {
+               case COMM_STATUS_BROADCAST_ALL:
+                       path = COMM_STATUS_BROADCAST_DBUS_PATH;
+                       break;
 
-API DBusConnection *comm_status_broadcast_server_connect(void)
+               case COMM_STATUS_BROADCAST_INSTALL:
+                       path = COMM_STATUS_BROADCAST_DBUS_INSTALL_PATH;
+                       break;
+
+               case COMM_STATUS_BROADCAST_UNINSTALL:
+                       path = COMM_STATUS_BROADCAST_DBUS_UNINSTALL_PATH;
+                       break;
+
+               case COMM_STATUS_BROADCAST_MOVE:
+                       path = COMM_STATUS_BROADCAST_DBUS_MOVE_PATH;
+                       break;
+
+               case COMM_STATUS_BROADCAST_INSTALL_PROGRESS:
+                       path = COMM_STATUS_BROADCAST_DBUS_INSTALL_PROGRESS_PATH;
+                       break;
+
+               case COMM_STATUS_BROADCAST_UPGRADE:
+                       path = COMM_STATUS_BROADCAST_DBUS_UPGRADE_PATH;
+                       break;
+
+               default:
+                       path = NULL;
+       }
+       return path;
+}
+
+static char *__get_interface(int status_type)
+{
+       char *interface = NULL;
+
+       switch (status_type) {
+               case COMM_STATUS_BROADCAST_ALL:
+                       interface = COMM_STATUS_BROADCAST_DBUS_INTERFACE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_INSTALL:
+                       interface = COMM_STATUS_BROADCAST_DBUS_INSTALL_INTERFACE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_UNINSTALL:
+                       interface = COMM_STATUS_BROADCAST_DBUS_UNINSTALL_INTERFACE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_MOVE:
+                       interface = COMM_STATUS_BROADCAST_DBUS_MOVE_INTERFACE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_INSTALL_PROGRESS:
+                       interface = COMM_STATUS_BROADCAST_DBUS_INSTALL_PROGRESS_INTERFACE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_UPGRADE:
+                       interface = COMM_STATUS_BROADCAST_DBUS_UPGRADE_INTERFACE;
+                       break;
+
+               default:
+                       interface = NULL;
+       }
+       return interface;
+}
+
+static char *__get_name(int status_type)
+{
+       char *name = NULL;
+
+       switch (status_type) {
+               case COMM_STATUS_BROADCAST_ALL:
+                       name = COMM_STATUS_BROADCAST_SIGNAL_STATUS;
+                       break;
+
+               case COMM_STATUS_BROADCAST_INSTALL:
+                       name = COMM_STATUS_BROADCAST_EVENT_INSTALL;
+                       break;
+
+               case COMM_STATUS_BROADCAST_UNINSTALL:
+                       name = COMM_STATUS_BROADCAST_EVENT_UNINSTALL;
+                       break;
+
+               case COMM_STATUS_BROADCAST_MOVE:
+                       name = COMM_STATUS_BROADCAST_EVENT_MOVE;
+                       break;
+
+               case COMM_STATUS_BROADCAST_INSTALL_PROGRESS:
+                       name = COMM_STATUS_BROADCAST_EVENT_INSTALL_PROGRESS;
+                       break;
+
+               case COMM_STATUS_BROADCAST_UPGRADE:
+                       name = COMM_STATUS_BROADCAST_EVENT_UPGRADE;
+                       break;
+
+               default:
+                       name = NULL;
+       }
+       return name;
+}
+
+API DBusConnection *comm_status_broadcast_server_connect(int status_type)
 {
        DBusError err;
        DBusConnection *conn;
@@ -45,22 +184,23 @@ API DBusConnection *comm_status_broadcast_server_connect(void)
                dbus_error_free(&err);
        }
        dbus_error_free(&err);
-       if (NULL == conn)
-               exit(1);
-       dbus_bus_request_name(conn,
-                             COMM_STATUS_BROADCAST_DBUS_SERVICE_PREFIX,
-                             DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &err);
+       if (NULL == conn) {
+               dbg("conn is NULL");
+               return NULL;
+       }
+
+       dbus_bus_request_name(conn, __get_prifix(status_type), DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &err);
        if (dbus_error_is_set(&err)) {
                dbg("Failed to request name: %s", err.message);
                dbus_error_free(&err);
-               exit(1);
+               return NULL;
        }
 
        return conn;
 }
 
 API void
-comm_status_broadcast_server_send_signal(DBusConnection *conn,
+comm_status_broadcast_server_send_signal(int comm_status_type, DBusConnection *conn,
                                         const char *req_id,
                                         const char *pkg_type,
                                         const char *pkgid, const char *key,
@@ -79,12 +219,15 @@ comm_status_broadcast_server_send_signal(DBusConnection *conn,
        };
        int i;
 
-       msg = dbus_message_new_signal(COMM_STATUS_BROADCAST_DBUS_PATH,
-                                     COMM_STATUS_BROADCAST_DBUS_INTERFACE,
-                                     COMM_STATUS_BROADCAST_SIGNAL_STATUS);
+       if (conn == NULL) {
+               dbg("dbus conn is NULL");
+               return;
+       }
+
+       msg = dbus_message_new_signal(__get_path(comm_status_type), __get_interface(comm_status_type), __get_name(comm_status_type));
        if (NULL == msg) {
                dbg("msg NULL");
-               exit(1);
+               return;
        }
 
        dbus_message_iter_init_append(msg, &args);
@@ -94,12 +237,12 @@ comm_status_broadcast_server_send_signal(DBusConnection *conn,
                    (&args, DBUS_TYPE_STRING, &(values[i]))) {
                        dbg("dbus_message_iter_append_basic failed:"
                        " Out of memory");
-                       exit(1);
+                       return;
                }
        }
        if (!dbus_connection_send(conn, msg, &serial)) {
                dbg("dbus_connection_send failed: Out of memory");
-               exit(1);
+               return;
        }
        dbus_connection_flush(conn);
        dbus_message_unref(msg);
@@ -111,4 +254,3 @@ API void comm_status_broadcast_server_disconnect(DBusConnection *conn)
                return;
        dbus_connection_unref(conn);
 }
-
index 37ddcd0..c8b5928 100755 (executable)
@@ -60,20 +60,63 @@ struct pkgmgr_installer {
        char *license_path;
        char *quiet_socket_path;
        char *optional_data;
+       char *caller_pkgid;
 
        DBusConnection *conn;
 };
 
-static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
+/* API */
 
-static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
+static int __send_signal_for_event(int comm_status_type, pkgmgr_installer *pi,
+                            const char *pkg_type,
+                            const char *pkgid,
+                            const char *key, const char *val)
 {
-       int *p = (int*)data;
-       *p = atoi(coltxt[0]);
-       _LOGE("exist value is %d\n", *p);
+       if (!pi)
+               return -1;
+
+       if (!pi->conn)
+               pi->conn = comm_status_broadcast_server_connect(comm_status_type);
+
+       char *sid = pi->session_id;
+       if (!sid)
+               sid = "";
+       comm_status_broadcast_server_send_signal(comm_status_type, pi->conn, sid, pkg_type, pkgid, key, val);
+
        return 0;
 }
-/* API */
+
+API int __send_event(pkgmgr_installer *pi,
+                            const char *pkg_type,
+                            const char *pkgid,
+                            const char *key, const char *val)
+{
+       int r = -1;
+
+       if (strcmp(key,PKGMGR_INSTALLER_START_KEY_STR) == 0) {
+               if(strcmp(key,PKGMGR_INSTALLER_UPGRADE_EVENT_STR) == 0) {
+                       pi->request_type = PKGMGR_REQ_UPGRADE;
+                       r = __send_signal_for_event(COMM_STATUS_BROADCAST_UPGRADE, pi, pkg_type, pkgid, key, val);
+               }
+               if(pi->request_type == PKGMGR_REQ_INSTALL) {
+                       r = __send_signal_for_event(COMM_STATUS_BROADCAST_INSTALL, pi, pkg_type, pkgid, key, val);
+               } else if (pi->request_type == PKGMGR_REQ_UNINSTALL){
+                       r = __send_signal_for_event(COMM_STATUS_BROADCAST_UNINSTALL, pi, pkg_type, pkgid, key, val);
+               }
+       } else if (strcmp(key,PKGMGR_INSTALLER_END_KEY_STR) == 0) {
+               if(pi->request_type == PKGMGR_REQ_INSTALL) {
+                       r = __send_signal_for_event(COMM_STATUS_BROADCAST_INSTALL, pi, pkg_type, pkgid, key, val);
+               } else if (pi->request_type == PKGMGR_REQ_UNINSTALL){
+                       r = __send_signal_for_event(COMM_STATUS_BROADCAST_UNINSTALL, pi, pkg_type, pkgid, key, val);
+               } else if (pi->request_type == PKGMGR_REQ_UPGRADE){
+                       r = __send_signal_for_event(COMM_STATUS_BROADCAST_UPGRADE, pi, pkg_type, pkgid, key, val);
+               }
+       } else if (strcmp(key,PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR) == 0) {
+               r = __send_signal_for_event(COMM_STATUS_BROADCAST_INSTALL_PROGRESS, pi, pkg_type, pkgid, key, val);
+       }
+
+       return r;
+}
 
 API pkgmgr_installer *pkgmgr_installer_new(void)
 {
@@ -99,6 +142,8 @@ API int pkgmgr_installer_free(pkgmgr_installer *pi)
                free(pi->session_id);
        if (pi->optional_data)
                free(pi->optional_data);
+       if (pi->caller_pkgid)
+               free(pi->caller_pkgid);
 
        if (pi->conn)
                comm_status_broadcast_server_disconnect(pi->conn);
@@ -215,6 +260,25 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
 
                        break;
 
+               case 'p': /* caller pkgid*/
+                       if (pi->caller_pkgid)
+                               free(pi->caller_pkgid);
+                       pi->caller_pkgid = strndup(optarg, MAX_STRLEN);
+
+                       break;
+
+               case 's':       /* smack */
+                       if (mode) {
+                               r = -EINVAL;
+                               goto RET;
+                       }
+                       mode = 's';
+                       pi->request_type = PKGMGR_REQ_SMACK;
+                       if (pi->pkgmgr_info)
+                               free(pi->pkgmgr_info);
+                       pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       break;
+
                case 'o': /* optional data*/
                        pi->optional_data = strndup(optarg, MAX_STRLEN);
                        break;
@@ -279,6 +343,12 @@ API int pkgmgr_installer_get_move_type(pkgmgr_installer *pi)
        return pi->move_type;
 }
 
+API const char *pkgmgr_installer_get_caller_pkgid(pkgmgr_installer *pi)
+{
+       CHK_PI_RET(PKGMGR_REQ_INVALID);
+       return pi->caller_pkgid;
+}
+
 API int
 pkgmgr_installer_send_signal(pkgmgr_installer *pi,
                             const char *pkg_type,
@@ -288,14 +358,16 @@ pkgmgr_installer_send_signal(pkgmgr_installer *pi,
        int r = 0;
 
        if (!pi->conn)
-               pi->conn = comm_status_broadcast_server_connect();
+               pi->conn = comm_status_broadcast_server_connect(COMM_STATUS_BROADCAST_ALL);
 
        char *sid = pi->session_id;
        if (!sid)
                sid = "";
-       comm_status_broadcast_server_send_signal(pi->conn, sid, pkg_type,
+       comm_status_broadcast_server_send_signal(COMM_STATUS_BROADCAST_ALL, pi->conn, sid, pkg_type,
                                                 pkgid, key, val);
 
+       __send_event(pi, pkg_type, pkgid, key, val);
+
        return r;
 }
 
index aed5b6a..661249b 100755 (executable)
@@ -43,7 +43,6 @@ extern "C" {
 #include <dlog.h>
 
 
-#define _LOGE(fmt, arg...) LOGE(fmt,##arg)
 
 /**
  * pkgmgr_installer is an opaque type for an object
@@ -52,6 +51,23 @@ typedef struct pkgmgr_installer pkgmgr_installer;
 typedef void* pkgmgr_instcertinfo_h;
 
 /**
+ * @brief listening event type in pkgmgr.
+ */
+#define PKGMGR_INSTALLER_START_KEY_STR                                                         "start"
+#define PKGMGR_INSTALLER_END_KEY_STR                                                           "end"
+#define PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR                                       "install_percent"
+
+#define PKGMGR_INSTALLER_INSTALL_EVENT_STR                                                     "install"
+#define PKGMGR_INSTALLER_UNINSTALL_EVENT_STR                                           "uninstall"
+#define PKGMGR_INSTALLER_MOVE_EVENT_STR                                                                "move"
+#define PKGMGR_INSTALLER_UPGRADE_EVENT_STR                                                     "upgrade"
+#define PKGMGR_INSTALLER_OK_EVENT_STR                                                          "ok"
+#define PKGMGR_INSTALLER_FAIL_EVENT_STR                                                                "fail"
+
+
+
+
+/**
  * Request type.
  */
 enum {
@@ -63,7 +79,9 @@ enum {
        PKGMGR_REQ_MOVE = 4,
        PKGMGR_REQ_RECOVER = 5,
        PKGMGR_REQ_REINSTALL = 6,
-       PKGMGR_REQ_GETSIZE = 7
+       PKGMGR_REQ_GETSIZE = 7,
+       PKGMGR_REQ_UPGRADE = 8,
+       PKGMGR_REQ_SMACK = 9
 };
 
 enum {
@@ -409,6 +427,40 @@ int main(int argc, char **argv)
 int pkgmgr_installer_get_move_type(pkgmgr_installer *pi);
 
 /**
+       @brief          Get caller package id
+       @pre            pkgmgr_installer_receive_request() must be called.
+       @post           None
+       @see            pkgmgr_installer_receive_request
+       @param[in]      pi      pkgmgr_installer object
+       @return         Operation result
+       @retval         enum value of move type
+       @remark         None
+       @code
+#include <pkgmgr_installer.h>
+int main(int argc, char **argv)
+{
+       pkgmgr_installer *pi;
+       int r = 0;
+       char *pkgid = NULL;
+
+       pi = pkgmgr_installer_new();
+       if(!pi) return -1;
+       if(pkgmgr_installer_receive_request(pi, argc, argv)) {
+               r = -1;
+               goto CLEANUP_RET;
+       }
+       pkgid = (char *) pkgmgr_installer_get_caller_pkgid(pi);
+
+       // Do something...
+
+       pkgmgr_installer_free(pi);
+       return r;
+}
+       @endcode
+ */
+const char *pkgmgr_installer_get_caller_pkgid(pkgmgr_installer *pi);
+
+/**
        @brief          Send a process status signal 
        @pre            None
        @post           None
index aee7291..7163d72 100755 (executable)
@@ -32,7 +32,7 @@ extern "C" {
 #endif
 
 /* Supported options */
-const char *short_opts = "k:l:i:d:c:m:t:o:r:q";
+const char *short_opts = "k:l:i:d:c:m:t:o:r:p:s:q";
 const struct option long_opts[] = {
        { "session-id", 1, NULL, 'k' },
        { "license-path", 1, NULL, 'l' },
@@ -43,6 +43,8 @@ const struct option long_opts[] = {
        { "move-type", 1, NULL, 't' },
        { "optional-data", 0, NULL, 'o' },
        { "reinstall", 0, NULL, 'r' },
+       { "caller-pkgid", 1, NULL, 'p' },
+       { "smack", 1, NULL, 's' },
        { "quiet", 1, NULL, 'q' },
        { 0, 0, 0, 0 }  /* sentinel */
 };
index dc40007..b011532 100755 (executable)
 #include <Ecore_File.h>
 #include <ail.h>
 #include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
 
 #include <X11/Xatom.h>
 #include <X11/Xutil.h>
+#include <security-server.h>
+
+#include <vconf.h>
 
 #include "pkgmgr_installer.h"
 #include "comm_pkg_mgr_server.h"
@@ -80,6 +84,8 @@ FILE *___log = NULL;
 #define LOCALEDIR "/usr/share/locale"
 #endif
 
+#define PACKAGE_RECOVERY_DIR "/opt/share/packages/.recovery/pkgmgr"
+
 #define DESKTOP_W   720.0
 
 #define NO_MATCHING_FILE 11
@@ -203,6 +209,119 @@ static void __unset_backend_mode(int position)
        backend_mode = backend_mode & ~(1<<position);
 }
 
+static void __set_recovery_mode(char *pkgid, char *pkg_type)
+{
+       char recovery_file[MAX_PKG_NAME_LEN] = { 0, };
+       char buffer[MAX_PKG_NAME_LEN] = { 0 };
+       char *pkgid_tmp = NULL;
+       FILE *rev_file = NULL;
+
+       if (pkgid == NULL) {
+               DBG("pkgid is null\n");
+               return;
+       }
+
+       /*if pkgid has a "/"charactor, that is a path name for installation, then extract pkgid from absolute path*/
+       if (strstr(pkgid, "/")) {
+               pkgid_tmp = strrchr(pkgid, '/') + 1;
+               if (pkgid_tmp == NULL) {
+                       DBG("pkgid_tmp[%s] is null\n", pkgid);
+                       return;
+               }
+               snprintf(recovery_file, MAX_PKG_NAME_LEN, "%s/%s", PACKAGE_RECOVERY_DIR, pkgid_tmp);
+       } else {
+               snprintf(recovery_file, MAX_PKG_NAME_LEN, "%s/%s", PACKAGE_RECOVERY_DIR, pkgid);
+       }
+
+       rev_file = fopen(recovery_file, "w");
+       if (rev_file== NULL) {
+               DBG("rev_file[%s] is null\n", recovery_file);
+               return;
+       }
+
+       snprintf(buffer, MAX_PKG_NAME_LEN, "pkgid : %s\n", pkgid);
+       fwrite(buffer, sizeof(char), strlen(buffer), rev_file);
+
+       fclose(rev_file);
+}
+
+static void __unset_recovery_mode(char *pkgid, char *pkg_type)
+{
+       int ret = -1;
+       char recovery_file[MAX_PKG_NAME_LEN] = { 0, };
+       char *pkgid_tmp = NULL;
+
+       if (pkgid == NULL) {
+               DBG("pkgid is null\n");
+               return;
+       }
+
+       /*if pkgid has a "/"charactor, that is a path name for installation, then extract pkgid from absolute path*/
+       if (strstr(pkgid, "/")) {
+               pkgid_tmp = strrchr(pkgid, '/') + 1;
+               if (pkgid_tmp == NULL) {
+                       DBG("pkgid_tmp[%s] is null\n", pkgid);
+                       return;
+               }
+               snprintf(recovery_file, MAX_PKG_NAME_LEN, "%s/%s", PACKAGE_RECOVERY_DIR, pkgid_tmp);
+       } else {
+               snprintf(recovery_file, MAX_PKG_NAME_LEN, "%s/%s", PACKAGE_RECOVERY_DIR, pkgid);
+       }
+
+       ret = remove(recovery_file);
+       if (ret < 0)
+               DBG("remove recovery_file[%s] fail\n", recovery_file);
+}
+
+static int __check_privilege_by_cookie(const char *e_cookie, int req_type)
+{
+       guchar *cookie = NULL;
+       gsize size;
+       int ret = PMINFO_R_OK;  //temp to success , it should be PMINFO_R_ERROR
+
+       if (e_cookie == NULL)   {
+               DBG("e_cookie is NULL!!!\n");
+               return PMINFO_R_ERROR;
+       }
+
+       cookie = g_base64_decode(e_cookie, &size);
+       if (cookie == NULL)     {
+               DBG("Unable to decode cookie!!!\n");
+               return PMINFO_R_ERROR;
+       }
+
+       switch (req_type) {
+               case COMM_REQ_TO_INSTALLER:
+                       if (SECURITY_SERVER_API_SUCCESS == security_server_check_privilege_by_cookie(cookie, "pkgmgr::svc", "r"))
+                               ret = PMINFO_R_OK;
+
+                       break;
+
+               case COMM_REQ_TO_MOVER:
+                       if (SECURITY_SERVER_API_SUCCESS == security_server_check_privilege_by_cookie(cookie, "pkgmgr::svc", "x"))
+                               ret = PMINFO_R_OK;
+                       break;
+
+               case COMM_REQ_GET_SIZE:
+                       if (SECURITY_SERVER_API_SUCCESS == security_server_check_privilege_by_cookie(cookie, "pkgmgr::info", "r"))
+                               ret = PMINFO_R_OK;
+                       break;
+
+               default:
+                       DBG("Check your request[%d]..\n", req_type);
+                       break;
+       }
+
+       DBG("security_server[req-type:%d] check cookie result = %d, \n", req_type, ret);
+
+       if (cookie){
+               g_free(cookie);
+               cookie = NULL;
+       }
+
+       return ret;
+}
+
 static int __get_position_from_pkg_type(char *pkgtype)
 {
        int i = 0;
@@ -870,6 +989,7 @@ static void sighandler(int signo)
                                if (cpid == (ptr + i)->pid) {
                                        __set_backend_free(i);
                                        __set_backend_mode(i);
+                                       __unset_recovery_mode((ptr + i)->pkgid, (ptr + i)->pkgtype);
                                        break;
                                }
                        }
@@ -882,6 +1002,7 @@ static void sighandler(int signo)
                                if (cpid == (ptr + i)->pid) {
                                        __set_backend_free(i);
                                        __set_backend_mode(i);
+                                       __unset_recovery_mode((ptr + i)->pkgid, (ptr + i)->pkgtype);
                                        strncpy(pname, (ptr + i)->pkgid, MAX_PKG_NAME_LEN-1);
                                        strncpy(ptype, (ptr + i)->pkgtype, MAX_PKG_TYPE_LEN-1);
                                        strncpy(args, (ptr + i)->args, MAX_PKG_ARGS_LEN-1);
@@ -901,6 +1022,7 @@ void req_cb(void *cb_data, const char *req_id, const int req_type,
        static int sig_reg = 0;
        int err = -1;
        int p = 0;
+       int cookie_result = 0;
 
        DBG(">> in callback >> Got request: [%s] [%d] [%s] [%s] [%s] [%s]",
            req_id, req_type, pkg_type, pkgid, args, cookie);
@@ -941,6 +1063,14 @@ void req_cb(void *cb_data, const char *req_id, const int req_type,
 
        switch (item->req_type) {
        case COMM_REQ_TO_INSTALLER:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       DBG("__check_privilege_by_cookie result fail[%d]\n", cookie_result);
+                       *ret = COMM_RET_ERROR;
+                       goto err;
+               }
+
                /* -q option should be located at the end of command !! */
                if (((quiet = strstr(args, " -q")) &&
                     (quiet[strlen(quiet)] == '\0')) ||
@@ -1028,6 +1158,14 @@ void req_cb(void *cb_data, const char *req_id, const int req_type,
                *ret = COMM_RET_OK;
                break;
        case COMM_REQ_TO_MOVER:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       DBG("__check_privilege_by_cookie result fail[%d]\n", cookie_result);
+                       *ret = COMM_RET_ERROR;
+                       goto err;
+               }
+
                /* In case of mover, there is no popup */
                err = _pm_queue_push(item);
                p = __get_position_from_pkg_type(item->pkg_type);
@@ -1049,6 +1187,14 @@ void req_cb(void *cb_data, const char *req_id, const int req_type,
                *ret = COMM_RET_OK;
                break;
        case COMM_REQ_GET_SIZE:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       DBG("__check_privilege_by_cookie result fail[%d]\n", cookie_result);
+                       *ret = COMM_RET_ERROR;
+                       goto err;
+               }
+
                err = _pm_queue_push(item);
                p = __get_position_from_pkg_type(item->pkg_type);
                __set_backend_mode(p);
@@ -1058,6 +1204,8 @@ void req_cb(void *cb_data, const char *req_id, const int req_type,
                        g_idle_add(queue_job, NULL);
                *ret = COMM_RET_OK;
                break;
+
+       case COMM_REQ_CHECK_APP:
        case COMM_REQ_KILL_APP:
                /* In case of activate, there is no popup */
                err = _pm_queue_push(item);
@@ -1291,10 +1439,9 @@ static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option)
        return 0;
 }
 
-static int __app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
+static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
 {
        char *exec = NULL;
-       char *appid = NULL;
        int ret = 0;
        int pid = -1;
        if (handle == NULL) {
@@ -1306,15 +1453,13 @@ static int __app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
                perror("Failed to get app exec path\n");
                exit(1);
        }
-       ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
-       if (ret) {
-               perror("Failed to get appid\n");
-               exit(1);
-       }
 
-       pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1);
-       if (pid > 0)
-               DBG("Appid: %s is Terminated\n", appid);
+       if (strcmp(user_data, "kill") == 0)
+               pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1);
+       else if(strcmp(user_data, "check") == 0)
+               pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0);
+
+       vconf_set_int(VCONFKEY_PKGMGR_STATUS, pid);
 
        return 0;
 }
@@ -1347,6 +1492,7 @@ pop:
                goto pop;
        }
        __set_backend_busy((pos + num_of_backends - 1) % num_of_backends);
+       __set_recovery_mode(item->pkgid, item->pkg_type);
 
        switch (item->req_type) {
        case COMM_REQ_TO_INSTALLER:
@@ -1538,17 +1684,53 @@ pop:
                                        exit(1);
                                }
                        } else { /* in case of package */
-                               DBG("(De)activate PKG");
-                               pkgmgrinfo_pkginfo_h handle;
-                               ret = pkgmgrinfo_pkginfo_get_pkginfo(item->pkgid, &handle);
-                               if (ret != PMINFO_R_OK)
+                               DBGE("(De)activate PKG[pkgid=%s, val=%d]", item->pkgid, val);
+                               char *manifest = NULL;
+                               manifest = pkgmgr_parser_get_manifest_file(item->pkgid);
+                               if (manifest == NULL) {
+                                       DBGE("Failed to fetch package manifest file\n");
                                        exit(1);
-                               ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_ALL_APP, __app_func, &val);
-                               if (ret != PMINFO_R_OK) {
-                                       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+                               }
+                               DBGE("manifest : %s\n", manifest);
+
+                               if (val) {
+                                       pkgmgrinfo_pkginfo_h handle;
+                                       ret = pkgmgrinfo_pkginfo_get_pkginfo(item->pkgid, &handle);
+                                       if (ret < 0) {
+                                               ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+                                               if (ret < 0) {
+                                                       DBGE("insert in db failed\n");
+                                               }
+
+                                               ret = ail_desktop_add(item->pkgid);
+                                               if (ret != AIL_ERROR_OK) {
+                                                       DBGE("fail to ail_desktop_add");
+                                               }
+                                       } else {
+                                               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+                                       }
+
+                                       ret = pkgmgrinfo_appinfo_set_state_enabled(item->pkgid, val);
+                                       if (ret != PMINFO_R_OK) {
+                                               perror("fail to activate/deactivte package");
+                                               exit(1);
+                                       }
+
+                                       ret = ail_desktop_appinfo_modify_bool(item->pkgid,
+                                                               AIL_PROP_X_SLP_ENABLED_BOOL,
+                                                               val, TRUE);
+                                       if (ret != AIL_ERROR_OK) {
+                                               perror("fail to ail_desktop_appinfo");
+                                               exit(1);
+                                       }
+                               }
+                               else
+                                       ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
+
+                               if (ret < 0) {
+                                       DBGE("insert in db failed\n");
                                        exit(1);
                                }
-                               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
                        }
 
                        _save_queue_status(item, "done");
@@ -1754,7 +1936,8 @@ pop:
                break;
 
        case COMM_REQ_KILL_APP:
-               DBG("COMM_REQ_KILL_APP start");
+       case COMM_REQ_CHECK_APP:
+               DBG("COMM_REQ_CHECK_APP start");
                _save_queue_status(item, "processing");
                DBG("saved queue status. Now try fork()");
                /*save pkg type and pkg name for future*/
@@ -1775,17 +1958,21 @@ pop:
                                DBG("Failed to get handle\n");
                                exit(1);
                        }
-                       ret = pkgmgrinfo_appinfo_get_list(handle, PMSVC_UI_APP, __app_list_cb, NULL);
-                       if (ret < 0) {
-                               DBG("pkgmgrinfo_appinfo_get_list() failed\n");
-                               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-                               exit(1);
-                       }
-                       ret = pkgmgrinfo_appinfo_get_list(handle, PMSVC_SVC_APP, __app_list_cb, NULL);
-                       if (ret < 0) {
-                               DBG("pkgmgrinfo_appinfo_get_list() failed\n");
-                               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-                               exit(1);
+
+                       if (item->req_type == COMM_REQ_KILL_APP) {
+                               ret = pkgmgrinfo_appinfo_get_list(handle, PMSVC_UI_APP, __pkgcmd_app_cb, "kill");
+                               if (ret < 0) {
+                                       DBG("pkgmgrinfo_appinfo_get_list() failed\n");
+                                       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+                                       exit(1);
+                               }
+                       } else if (item->req_type == COMM_REQ_CHECK_APP) {
+                               ret = pkgmgrinfo_appinfo_get_list(handle, PMSVC_UI_APP, __pkgcmd_app_cb, "check");
+                               if (ret < 0) {
+                                       DBG("pkgmgrinfo_appinfo_get_list() failed\n");
+                                       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+                                       exit(1);
+                               }
                        }
 
                        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
@@ -1806,7 +1993,6 @@ pop:
                }
                break;
 
-
        default:
                break;
        }
index 9552c7b..7183117 100755 (executable)
@@ -160,7 +160,7 @@ int _pm_queue_init()
        }
        i = n;
        /*Find number of backends (symlinks + executables)
-       The /etc/package-manager/backend dir should not conatin
+       The /usr/etc/package-manager/backend dir should not conatin
        any other file except the backends.*/
        while(n--)
        {
index 9d2db6b..d06ed5a 100755 (executable)
@@ -5,12 +5,12 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_CFLAGS}")
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/include)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs_test REQUIRED ecore dbus-1 ail libxml-2.0 bundle pkgmgr-parser pkgmgr-info)
+pkg_check_modules(pkgs_test REQUIRED ecore dbus-1 ail libxml-2.0 bundle pkgmgr-info pkgmgr-parser vconf)
 FOREACH(flag ${pkgs_test_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-pkg_check_modules(toolpkgs REQUIRED appcore-efl dlog bundle glib-2.0 pkgmgr-info pkgmgr-parser)
+pkg_check_modules(toolpkgs REQUIRED appcore-efl dlog bundle glib-2.0 pkgmgr-info pkgmgr-parser vconf)
 FOREACH(flag ${libpkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
index 1ae2cbe..ce5461a 100755 (executable)
@@ -52,11 +52,6 @@ static int __return_cb(int req_id, const char *pkg_type, const char *pkgid,
                       const char *key, const char *val, const void *pmsg,
                       void *data);
 static int __convert_to_absolute_path(char *path);
-static int __pkgcmd_read_proc(const char *path, char *buf, int size);
-static int __pkgcmd_find_pid_by_cmdline(const char *dname,
-                       const char *cmdline, const char *apppath);
-static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option);
-static int __app_list_cb(const pkgmgr_appinfo_h handle, void *user_data);
 
 /* Supported options */
 const char *short_options = "iurmcgCkaADL:lsd:p:t:n:T:S:qh";
@@ -232,125 +227,6 @@ static int __return_cb(int req_id, const char *pkg_type,
        return 0;
 }
 
-static int __pkgcmd_read_proc(const char *path, char *buf, int size)
-{
-       int fd;
-       int ret;
-       if (buf == NULL || path == NULL)
-               return -1;
-       fd = open(path, O_RDONLY);
-       if (fd < 0)
-               return -1;
-       ret = read(fd, buf, size - 1);
-       if (ret <= 0) {
-               close(fd);
-               return -1;
-       } else
-               buf[ret] = 0;
-       close(fd);
-       return ret;
-}
-
-static int __pkgcmd_find_pid_by_cmdline(const char *dname,
-                       const char *cmdline, const char *apppath)
-{
-       int pid = 0;
-
-       if (strcmp(cmdline, apppath) == 0) {
-               pid = atoi(dname);
-               if (pid != getpgid(pid))
-                       pid = 0;
-       }
-       return pid;
-}
-
-static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option)
-{
-       DIR *dp;
-       struct dirent *dentry;
-       int pid;
-       int ret;
-       char buf[1024] = {'\0'};
-       int pgid;
-
-       dp = opendir("/proc");
-       if (dp == NULL) {
-               return -1;
-       }
-
-       while ((dentry = readdir(dp)) != NULL) {
-               if (!isdigit(dentry->d_name[0]))
-                       continue;
-
-               snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
-               ret = __pkgcmd_read_proc(buf, buf, sizeof(buf));
-               if (ret <= 0)
-                       continue;
-
-               pid = __pkgcmd_find_pid_by_cmdline(dentry->d_name, buf, apppath);
-               if (pid > 0) {
-                       if (option == 0) {
-                               closedir(dp);
-                               return pid;
-                       }
-                       pgid = getpgid(pid);
-                       if (pgid <= 1) {
-                               closedir(dp);
-                               return -1;
-                       }
-                       if (killpg(pgid, SIGKILL) < 0) {
-                               closedir(dp);
-                               return -1;
-                       }
-                       closedir(dp);
-                       return pid;
-               }
-       }
-       closedir(dp);
-       return 0;
-}
-
-static int __app_list_cb(const pkgmgr_appinfo_h handle, void *user_data)
-{
-       char *exec = NULL;
-       char *appid = NULL;
-       int ret = 0;
-       int pid = -1;
-       if (handle == NULL) {
-               printf("appinfo handle is NULL\n");
-               return -1;
-       }
-       ret = pkgmgr_appinfo_get_exec(handle, &exec);
-       if (ret) {
-               printf("Failed to get app exec path\n");
-               return -1;
-       }
-       ret = pkgmgr_appinfo_get_appid(handle, &appid);
-       if (ret) {
-               printf("Failed to get appid\n");
-               return -1;
-       }
-       /*option 0 to check and option 1 to kill*/
-       switch(data.request) {
-       case CHECKAPP_REQ:
-               pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0);
-               if (pid) {
-                       printf("Appid: %s is Running\n", appid);
-               } else {
-                       printf("Appid: %s is Not Running\n", appid);
-               }
-               break;
-       case KILLAPP_REQ:
-               pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1);
-               if (pid > 0)
-                       printf("Appid: %s is Terminated\n", appid);
-               break;
-       default:
-               break;
-       }
-       return 0;
-}
-
 static int __convert_to_absolute_path(char *path)
 {
        char abs[PKG_NAME_STRING_LEN_MAX] = {'\0'};
@@ -449,6 +325,8 @@ static void __print_usage()
        printf("pkgcmd -s -t <pkg type> -n <pkg name> (-q)\n");
        printf("pkgcmd -m -t <pkg type> -T <move type> -n <pkg name> (-q)\n\n");
        printf("pkgcmd -g -T <getsize type> -n <pkgid> \n");
+       printf("pkgcmd -C -n <pkgid> \n");
+       printf("pkgcmd -k -n <pkgid> \n");
 
        printf("Example:\n");
        printf("pkgcmd -u -n com.samsung.calculator\n");
@@ -456,8 +334,8 @@ static void __print_usage()
        printf("pkgcmd -r -t rpm -n com.samsung.calculator\n");
        printf("pkgcmd -c -t rpm -n com.samsung.hello\n");
        printf("pkgcmd -m -t rpm -T 1 -n com.samsung.hello\n");
-       printf("pkgcmd -C -t rpm -n com.samsung.hello\n");
-       printf("pkgcmd -k -t rpm -n com.samsung.hello\n");
+       printf("pkgcmd -C -n com.samsung.hello\n");
+       printf("pkgcmd -k -n com.samsung.hello\n");
        printf("pkgcmd -a\n");
        printf("pkgcmd -a -t rpm -n com.samsung.hello\n");
        printf("pkgcmd -l\n");
@@ -604,12 +482,35 @@ static int __pkgmgr_list_cb (const pkgmgr_pkginfo_h handle, void *user_data)
        return ret;
 }
 
+static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       int ret = -1;
+       int size = 0;
+       char *pkgid;
+
+       ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+       if(ret < 0) {
+               printf("pkgmgr_pkginfo_get_pkgid() failed\n");
+       }
+
+       ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, (pkgmgr_client *)user_data, NULL, pkgid, 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 int __process_request()
 {
        int ret = -1;
        int mode = PM_DEFAULT;
        pkgmgr_client *pc = NULL;
        char buf[1024] = {'\0'};
+       int pid = -1;
        switch (data.request) {
        case INSTALL_REQ:
                if (data.pkg_type[0] == '\0' || data.pkg_path[0] == '\0') {
@@ -815,65 +716,39 @@ static int __process_request()
                break;
 
        case MOVE_REQ:
-               if (data.quiet == 1) {
-                       if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
-                               printf("Please provide the arguments.\n");
-                               printf("use -h option to see usage\n");
-                               ret = -1;
-                               break;
-                       }
-                       if (data.type < 0 || data.type > 1) {
-                               printf("Invalid move type...See usage\n");
-                               ret = -1;
-                               break;
-                       }
-                       pc = pkgmgr_client_new(PC_REQUEST);
-                       if (pc == NULL) {
-                               printf("PkgMgr Client Creation Failed\n");
-                               ret = -1;
-                               break;
-                       }
-                       mode = PM_QUIET;
-                       ret = __is_app_installed(data.pkgid);
-                       if (ret == -1) {
-                               printf("package is not installed\n");
-                               break;
-                       }
-                       ret = pkgmgr_client_move(pc, data.pkg_type, data.pkgid,  data.type, mode);
-                       if (ret < 0)
-                               break;
-                       ret = data.result;
-               } else {
-                       if (data.pkgid[0] == '\0') {
-                               printf("Please provide the arguments.\n");
-                               printf("use -h option to see usage\n");
-                               ret = -1;
-                               break;
-                       }
-                       if (data.type < 0 || data.type > 1) {
-                               printf("Invalid move type...See usage\n");
-                               ret = -1;
-                               break;
-                       }
-                       g_type_init();
-                       main_loop = g_main_loop_new(NULL, FALSE);
-                       pc = pkgmgr_client_new(PC_REQUEST);
-                       if (pc == NULL) {
-                               printf("PkgMgr Client Creation Failed\n");
-                               ret = -1;
-                               break;
-                       }
-                       ret = __is_app_installed(data.pkgid);
-                       if (ret == -1) {
-                               printf("package is not installed\n");
-                               break;
-                       }
-                       ret = pkgmgr_client_request_service(PM_REQUEST_MOVE, data.type, pc, NULL, data.pkgid, NULL, __return_cb, NULL);
-                       if (ret < 0)
-                               break;
-                       g_main_loop_run(main_loop);
-                       ret = data.result;
+               if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
+                       printf("Please provide the arguments.\n");
+                       printf("use -h option to see usage\n");
+                       ret = -1;
+                       break;
+               }
+               if (data.type < 0 || data.type > 1) {
+                       printf("Invalid move type...See usage\n");
+                       ret = -1;
+                       break;
+               }
+               pc = pkgmgr_client_new(PC_REQUEST);
+               if (pc == NULL) {
+                       printf("PkgMgr Client Creation Failed\n");
+                       ret = -1;
+                       break;
+               }
+               mode = PM_QUIET;
+               ret = __is_app_installed(data.pkgid);
+               if (ret == -1) {
+                       printf("package is not installed\n");
+                       break;
                }
+               if (data.quiet == 0)
+                       ret = pkgmgr_client_move(pc, data.pkg_type, data.pkgid,  data.type, mode);
+               else
+                       ret = pkgmgr_client_request_service(PM_REQUEST_MOVE, data.type, pc, NULL, data.pkgid, NULL, NULL, NULL);
+
+               printf("pkg[%s] move result = %d\n", data.pkgid, ret);
+
+               if (ret < 0)
+                       break;
+               ret = data.result;
                break;
 
        case APPPATH_REQ:
@@ -911,6 +786,7 @@ static int __process_request()
                break;
 
        case KILLAPP_REQ:
+       case CHECKAPP_REQ:
                if (data.pkgid[0] == '\0') {
                        printf("Please provide the arguments.\n");
                        printf("use -h option to see usage\n");
@@ -925,44 +801,30 @@ static int __process_request()
                        break;
                }
 
-               ret = pkgmgr_client_request_service(PM_REQUEST_KILL_APP, NULL, pc, NULL, data.pkgid, NULL, NULL, NULL);
-               if (ret < 0){
-                       data.result = PKGCMD_ERR_FATAL_ERROR;
-                       break;
-               }
-               ret = data.result;
-               break;
+               if (data.request == KILLAPP_REQ) {
+                       ret = pkgmgr_client_request_service(PM_REQUEST_KILL_APP, NULL, pc, NULL, data.pkgid, NULL, NULL, &pid);
+                       if (ret < 0){
+                               data.result = PKGCMD_ERR_FATAL_ERROR;
+                               break;
+                       }
+                       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_request_service(PM_REQUEST_CHECK_APP, NULL, pc, NULL, data.pkgid, NULL, NULL, &pid);
+                       if (ret < 0){
+                               data.result = PKGCMD_ERR_FATAL_ERROR;
+                               break;
+                       }
 
-       case CHECKAPP_REQ:
-               if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
-                       printf("Please provide the arguments.\n");
-                       printf("use -h option to see usage\n");
-                       ret = -1;
-                       break;
-               }
-               pkgmgr_pkginfo_h handle;
-               ret = pkgmgr_pkginfo_get_pkginfo(data.pkgid, &handle);
-               if (ret < 0) {
-                       printf("Failed to get handle\n");
-                       data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
-                       return  0;
-               }
-               ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
-               if (ret < 0) {
-                       printf("pkgmgr_appinfo_get_list() failed\n");
-                       pkgmgr_pkginfo_destroy_pkginfo(handle);
-                       data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
-                       return  0;
+                       if (pid)
+                               printf("Pkgid: %s is Running\n", data.pkgid);
+                       else
+                               printf("Pkgid: %s is Not Running\n", data.pkgid);
                }
-               ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
-               if (ret < 0) {
-                       printf("pkgmgr_appinfo_get_list() failed\n");
-                       pkgmgr_pkginfo_destroy_pkginfo(handle);
-                       data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
-                       return  0;
-               }
-               pkgmgr_pkginfo_destroy_pkginfo(handle);
-               ret = 0;
+               ret = data.result;
                break;
 
        case LIST_REQ:
@@ -1036,11 +898,6 @@ static int __process_request()
                if (data.pkgid[0] == '\0') {
                        printf("Please provide the arguments.\n");
                        printf("use -h option to see usage\n");
-                       data.result = PKGCMD_ERR_ARGUMENT_INVALID;
-                       break;
-               }
-               if (data.type < 0 || data.type > 1) {
-                       printf("Invalid get type...See usage\n");
                        ret = -1;
                        break;
                }
@@ -1052,7 +909,12 @@ static int __process_request()
                        break;
                }
 
-               ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, data.type, pc, NULL, data.pkgid, NULL, __return_cb, NULL);
+               if (data.type == 9) {
+                       ret = pkgmgrinfo_pkginfo_get_list(__pkg_list_cb, (void *)pc);
+                       break;
+               }
+
+               ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, data.type, pc, NULL, data.pkgid, NULL, NULL, NULL);
                if (ret < 0){
                        data.result = PKGCMD_ERR_FATAL_ERROR;
                        break;
diff --git a/tool/pkg_fota.c b/tool/pkg_fota.c
new file mode 100644 (file)
index 0000000..8c274a2
--- /dev/null
@@ -0,0 +1,305 @@
+/*
+ * slp-pkgmgr
+ *
+ * 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 <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include "pkgmgr_parser.h"
+
+#define OWNER_ROOT 0
+#define GROUP_MENU 6010
+#define BUFSZE 1024
+#define OPT_MANIFEST_DIRECTORY "/opt/share/packages"
+#define USR_MANIFEST_DIRECTORY "/usr/share/packages"
+#define PACKAGE_INFO_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
+
+#define PKG_PARSER_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
+#define PKG_PARSER_DB_FILE_JOURNAL "/opt/dbspace/.pkgmgr_parser.db-journal"
+#define PKG_CERT_DB_FILE "/opt/dbspace/.pkgmgr_cert.db"
+#define PKG_CERT_DB_FILE_JOURNAL "/opt/dbspace/.pkgmgr_cert.db-journal"
+#define PKG_INFO_DB_LABEL "pkgmgr::db"
+
+#ifdef _E
+#undef _E
+#endif
+#define _E(fmt, arg...) fprintf(stderr, "[PKG_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+#ifdef _D
+#undef _D
+#endif
+#define _D(fmt, arg...) fprintf(stderr, "[PKG_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+static int pkg_fota_count_package(void)
+{
+       int total = 0;
+
+       return total;
+}
+
+static int pkg_fota_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);
+}
+
+
+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")) {
+               _E("%s is not a manifest file", manifest);
+               free(package);
+               return NULL;
+       }
+
+       return package;
+}
+
+
+
+int pkg_fota_load_directory(const char *directory)
+{
+       DIR *dir;
+       struct dirent entry, *result;
+       int ret;
+       char buf[BUFSZE];
+
+       // desktop file
+       dir = opendir(directory);
+       if (!dir) {
+               if (strerror_r(errno, buf, sizeof(buf)) == 0)
+                       _E("Failed to access the [%s] because %s\n", directory, buf);
+               return -1;
+       }
+
+       _D("Loading manifest files from %s\n", directory);
+
+       for (ret = readdir_r(dir, &entry, &result);
+                       ret == 0 && result != NULL;
+                       ret = readdir_r(dir, &entry, &result)) {
+               char *manifest;
+
+               if (entry.d_name[0] == '.') continue;
+
+               manifest = _manifest_to_package(entry.d_name);
+               if (!manifest) {
+                       _E("Failed to convert file to package[%s]\n", entry.d_name);
+                       continue;
+               }
+
+               snprintf(buf, sizeof(buf), "%s/%s", directory, manifest);
+
+               fprintf(stderr, "pkg_initdb : manifest file %s\n", buf);
+
+               ret = pkgmgr_parser_check_manifest_validation(buf);
+               if (ret < 0) {
+                       _E("check manifest validation failed code[%d] %s\n", ret, buf);
+                       fprintf(stderr, "check manifest validation failed code[%d] %s\n", ret, buf);
+                       free(manifest);
+                       continue;
+               }
+
+
+               /*temporarily fixed due to glib abort */
+               // pkgmgr_parser_parse_manifest_for_installation(buf, NULL);
+
+               char buf2[BUFSZE];
+               snprintf(buf2, sizeof(buf2), "/usr/bin/pkginfo --fota %s", buf);
+               system(buf2);
+
+               free(manifest);
+       }
+
+       closedir(dir);
+
+       return 0;
+}
+
+
+
+static int pkg_fota_change_perm(const char *db_file)
+{
+       char buf[BUFSZE];
+       char journal_file[BUFSZE];
+       char *files[3];
+       int ret, i;
+
+       files[0] = (char *)db_file;
+       files[1] = journal_file;
+       files[2] = NULL;
+
+       if(db_file == NULL)
+               return -1;
+
+       snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
+
+       for (i = 0; files[i]; i++) {
+               ret = chown(files[i], OWNER_ROOT, OWNER_ROOT);
+               if (ret == -1) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chown %s %d.%d, because %s", db_file, OWNER_ROOT, OWNER_ROOT, buf);
+                       return -1;
+               }
+
+               ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+               if (ret == -1) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chmod %s 0664, because %s", db_file, buf);
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+static int pkg_fota_give_smack()
+{
+       int ret = 0;
+
+       const char *argv_parser[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_PARSER_DB_FILE, NULL };
+       ret = pkg_fota_xsystem(argv_parser);
+       if (ret == -1) {
+               _E("exec : argv_parser fail");
+               return -1;
+       }
+       const char *argv_parserjn[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_PARSER_DB_FILE_JOURNAL, NULL };
+       ret = pkg_fota_xsystem(argv_parserjn);
+       if (ret == -1) {
+               _E("exec : argv_parserjn fail");
+               return -1;
+       }
+       const char *argv_cert[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_CERT_DB_FILE, NULL };
+       ret = pkg_fota_xsystem(argv_cert);
+       if (ret == -1) {
+               _E("exec : argv_cert fail");
+               return -1;
+       }
+       const char *argv_certjn[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_CERT_DB_FILE_JOURNAL, NULL };
+       ret = pkg_fota_xsystem(argv_certjn);
+       if (ret == -1) {
+               _E("exec : argv_certjn fail");
+               return -1;
+       }
+
+       return 0;
+}
+
+static int __is_authorized()
+{
+       /* pkg_init db should be called by as root privilege. */
+
+       uid_t uid = getuid();
+       if ((uid_t) 0 == uid)
+               return 1;
+       else
+               return 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+       int ret;
+
+       if (!__is_authorized()) {
+               _E("You are not an authorized user!\n");
+               return -1;
+       }
+
+       /* This is for AIL initializing */
+       ret = setenv("INITDB", "1", 1);
+       _D("INITDB : %d", ret);
+
+       ret = pkg_fota_count_package();
+       if (ret > 0) {
+               _D("Some Packages in the Package Info DB.");
+               return 0;
+       }
+
+       ret = pkg_fota_load_directory(OPT_MANIFEST_DIRECTORY);
+       if (ret == -1) {
+               _E("cannot load opt manifest directory.");
+       }
+
+       ret = pkg_fota_load_directory(USR_MANIFEST_DIRECTORY);
+       if (ret == -1) {
+               _E("cannot load usr manifest directory.");
+       }
+
+       ret = pkg_fota_change_perm(PACKAGE_INFO_DB_FILE);
+       if (ret == -1) {
+               _E("cannot chown.");
+               return -1;
+       }
+
+       ret = pkg_fota_give_smack();
+       if (ret == -1) {
+               _E("cannot pkg_fota_give_smack.");
+               return -1;
+       }
+
+       return 0;
+}
+
+
index 1e4d423..3b4aeba 100644 (file)
 #include <string.h>
 
 #include <pkgmgr-info.h>
+#include <vconf.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
 
-#include "pkgmgr_installer.h"
 #include "pkgmgr-debug.h"
+#include "package-manager.h"
+#include "pkgmgr_installer.h"
 
 #undef LOG_TAG
 #ifndef LOG_TAG
 #endif                         /* LOG_TAG */
 
 #define MAX_PKG_BUF_LEN        1024
+#define BLOCK_SIZE      4096 /*in bytes*/
+
 #define PKG_TMP_PATH "/opt/usr/apps/tmp"
+#define PKG_RW_PATH "/opt/usr/apps/"
+#define PKG_RO_PATH "/usr/apps/"
 
-static int _pkg_getsize(int argc, char **argv)
+long long __get_dir_size(int dfd)
 {
-       int ret = 0;
-       char *pkgid = NULL;
-       char *type = NULL;
-       pkgmgr_installer *pi = NULL;
-       pkgmgrinfo_pkginfo_h handle = NULL;
-       int size = 0;
-       int get_type = -1;
-       char buf[MAX_PKG_BUF_LEN] = {'\0'};
-       char device_path[MAX_PKG_BUF_LEN] = {'\0', };
-       FILE* file = NULL;
-       char *pkeyid = NULL;
-       int fd = 0;
+    long long size = 0;
+    struct stat f_stat;
+    DIR *dir;
+    struct dirent *de;
+    long long tmp_size = 0;
 
-       /*make new pkgmgr_installer handle*/
-       pi = pkgmgr_installer_new();
-       retvm_if(!pi, PMINFO_R_ERROR, "service type is error\n");
+    dir = fdopendir(dfd);
+    if (dir == NULL) {
+       _LOGE("Couldn't open the directory\n");
+       close(dfd);
+        return 0;
+    }
 
-       /*get args*/
-       ret = pkgmgr_installer_receive_request(pi, argc, argv);
-       tryvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgr_installer_receive_request failed");
+    while ((de = readdir(dir))) {
+        const char *name = de->d_name;
+        if (name[0] == '.') {
+            if (name[1] == 0)
+                continue;
+            if ((name[1] == '.') && (name[2] == 0))
+                continue;
+        }
 
-       /*get pkgid from installer handle*/
-       pkgid = pkgmgr_installer_get_request_info(pi);
-       tryvm_if(pkgid == NULL, ret = PMINFO_R_ERROR, "pkgmgr_installer_get_request_info failed");
+        if (fstatat(dfd, name, &f_stat, AT_SYMLINK_NOFOLLOW) == 0) {
+                size += f_stat.st_blocks * 512;
+        }
+        if (de->d_type == DT_DIR) {
+            int subfd;
 
-       pkeyid = pkgmgr_installer_get_session_id(pi);
-       tryvm_if(pkeyid == NULL, ret = PMINFO_R_ERROR, "pkgmgr_installer_get_session_id failed");
+            subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
+            if (subfd >= 0) {
+               tmp_size = __get_dir_size(subfd);
+               size += tmp_size;
+            }
+        }
+    }
+    closedir(dir);
+    return size;
+}
 
-       get_type = pkgmgr_installer_get_move_type(pi);
-       tryvm_if(pkgid < 0, ret = PMINFO_R_ERROR, "pkgmgr_installer_get_request_info failed");
+long long __get_pkg_size(char *path)
+{
+       long long size;
+       DIR *dir;
+       int dfd;
+       struct stat f_stat;
+       if (path == NULL){
+               _LOGE("path is NULL");
+               return -1;
+       }
 
-       /*get pkgmgr handle from pkgid*/
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
-       tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_pkginfo[pkgid=%s] failed", pkgid);
+       if (lstat(path, &f_stat) == 0) {
+               if (!S_ISLNK(f_stat.st_mode)) {
+                       dir = opendir(path);
+                       if (dir == NULL) {
+                               _LOGE("Couldn't open the directory %s \n", path);
+                               return -1;
+                       }
+                       dfd = dirfd(dir);
 
-       /*get type info from handle*/
-       ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
-       tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_type[pkgid=%s] failed", pkgid);
+                       size = __get_dir_size(dfd);
+                       if (size > 0) {
+                                size = size + f_stat.st_blocks * 512;
+                       }
+                       else {
+                               _LOGE("Couldn't open the directory\n");
+                               return -1;
+                       }
+               }
+       }
+       else {
+               _LOGE("Couldn't lstat the directory %s %d \n", path, errno);
+               return -1;
+       }
 
-       /*get size info from handle
-       typedef enum {
-               PM_GET_TOTAL_SIZE= 0,
-               PM_GET_DATA_SIZE = 1,
-       }pkgmgr_getsize_type;
+       return size;
+}
 
-       */
-       if (get_type == 0) {
-               ret = pkgmgrinfo_pkginfo_get_total_size(handle, &size);
-               tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_total_size[pkgid=%s] failed", pkgid);
-       } else {
-               ret = pkgmgrinfo_pkginfo_get_data_size(handle, &size);
-               tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_data_size[pkgid=%s] failed", pkgid);
-       }
+static int __get_total_size(char *pkgid, int *size)
+
+{
+       char device_path[MAX_PKG_BUF_LEN] = { '\0', };
+       long long rw_size = 0;
+       long long ro_size= 0;
+       long long tmp_size= 0;
+       long long total_size= 0;
+
+       /* RW area */
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/bin", PKG_RW_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               rw_size += tmp_size;
+
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/info", PKG_RW_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               rw_size += tmp_size;
+
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/res", PKG_RW_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               rw_size += tmp_size;
+
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/data", PKG_RW_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               rw_size += tmp_size;
+
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/shared", PKG_RW_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               rw_size += tmp_size;
+
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/setting", PKG_RW_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               rw_size += tmp_size;
+#if 0
+       /* RO area */
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/bin", PKG_RO_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               ro_size += tmp_size;
 
-       snprintf(device_path, MAX_PKG_BUF_LEN, "%s/%s", PKG_TMP_PATH, pkeyid);
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/info", PKG_RO_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               ro_size += tmp_size;
 
-       file = fopen(device_path, "w");
-       tryvm_if(file == NULL, ret = PMINFO_R_ERROR, "cannot open result file [%s]", device_path);
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/res", PKG_RO_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               ro_size += tmp_size;
 
-       snprintf(buf, MAX_PKG_BUF_LEN - 1, "%d\n", size);
-       fwrite(buf, 1, strlen(buf), file);
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/data", PKG_RO_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               ro_size += tmp_size;
 
-catch:
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/shared", PKG_RO_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               ro_size += tmp_size;
 
-       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-       pkgmgr_installer_free(pi);
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/setting", PKG_RO_PATH, pkgid);
+       tmp_size = __get_pkg_size(device_path);
+       if (tmp_size > 0)
+               ro_size += tmp_size;
+#endif
 
-       if (file != NULL) {
-               fflush(file);
-               fd = fileno(file);
-               fsync(fd);
-               fclose(file);
+       /* Total size */
+       total_size = rw_size + ro_size;
+       *size = (int)total_size;
+
+       return PMINFO_R_OK;
+}
+
+static int __get_data_size(char *pkgid, int *size)
+{
+       char device_path[MAX_PKG_BUF_LEN] = { '\0', };
+       long long total_size= 0;
+
+       snprintf(device_path, MAX_PKG_BUF_LEN, "%s%s/data", PKG_RW_PATH, pkgid);
+       if (access(device_path, R_OK) == 0)
+               total_size = __get_pkg_size(device_path);
+       if (total_size < 0)
+               return PMINFO_R_ERROR;
+
+       *size = (int)total_size;
+
+       return PMINFO_R_OK;
+}
+
+static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       int ret = -1;
+       char *pkgid;
+
+       int size = 0;
+
+       ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+       if(ret < 0) {
+               printf("pkgmgr_pkginfo_get_pkgid() failed\n");
        }
 
-       return ret;
+       __get_total_size(pkgid, &size);
+
+       * (int *) user_data += size;
+
+       _LOGD("pkg=[%s], size=[%d]\n", pkgid, size);
+
+       return 0;
 }
 
 int main(int argc, char *argv[])
 {
        int ret = 0;
+       int size = 0;
+       int get_type = 0;
+       char *pkgid = NULL;
+       pkgmgr_installer *pi;
+       char buf[MAX_PKG_BUF_LEN] = {'\0'};
 
-       ret = _pkg_getsize(argc, argv);
-       if (ret < 0) {
-               _LOGE("_pkg_getsize failed \n");
-               return -1;
+       pkgid = argv[0];
+       get_type = atoi(argv[1]);
+
+       if (get_type == PM_GET_TOTAL_SIZE) {
+               ret = __get_total_size(pkgid, &size);
+       } else if(get_type == PM_GET_DATA_SIZE) {
+               ret = __get_data_size(pkgid, &size);
+       } else if(get_type == PM_GET_ALL_PKGS) {
+               ret = pkgmgrinfo_pkginfo_get_list(__pkg_list_cb, &size);
+       }
+       if (ret < 0)
+               _LOGD("_pkg_getsize fail \n");
+       else
+               _LOGD("_pkg_getsize success \n");
+
+       pi = pkgmgr_installer_new();
+       if (!pi) {
+               _LOGD("Failure in creating the pkgmgr_installer object");
+       } else {
+               pkgmgr_installer_receive_request(pi, argc, argv);
+               snprintf(buf, MAX_PKG_BUF_LEN - 1, "%d", size);
+               pkgmgr_installer_send_signal(pi, "get-size", pkgid, "get-size", buf);
+               pkgmgr_installer_free(pi);
        }
 
-       _LOGE("_pkg_getsize success \n");
+       vconf_set_int(VCONFKEY_PKGMGR_STATUS, size);
        return 0;
 }
index f10216e..9693a1a 100755 (executable)
@@ -43,8 +43,6 @@ static int __get_app_list(char *pkgid);
 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_app_visibility(char *appid);
-static int __set_app_visibility(char *appid);
 static int __get_pkg_list(void);
 static int __get_installed_app_list();
 static int __add_app_filter(void);
@@ -63,6 +61,153 @@ static int __app_control_list_cb(pkgmgrinfo_appcontrol_h handle, void *user_data
 static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data);
 int app_func(const pkgmgr_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;
+       pkgmgr_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 size = -1;
+       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_package_size(handle, &size);
+       if (ret < 0) {
+               printf("Failed to get package size \n");
+       }
+       printf("Package Size: %d\n", size);
+
+       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 (author_href)
+               printf("root_path : %s\n", root_path);
+
+       ret = pkgmgrinfo_pkginfo_get_mainappid(handle, &mainappid);
+       if (ret < 0) {
+               printf("Failed to get mainappid\n");
+       }
+       if (author_href)
+               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);
+
+       return 0;
+}
 int __get_app_id(const pkgmgrinfo_appinfo_h handle, void *user_data)
 {
        char *appid = NULL;
@@ -155,10 +300,6 @@ static void __print_usage()
        printf("\tpkginfo --pkg-flt\n\n");
        printf("To add metadata filter values\n");
        printf("\tpkginfo --metadata-flt\n\n");
-       printf("To get guest mode visibility of a particular application\n");
-       printf("\tpkginfo --getvisibility <appid>\n\n");
-       printf("To set guest mode visibility of a particular application\n");
-       printf("\tpkginfo --setvisibility <appid>\n\n");
 }
 
 static void __print_arg_filter_usage()
@@ -182,6 +323,7 @@ static void __print_arg_filter_usage()
        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");
 }
 
@@ -271,6 +413,7 @@ static int __add_app_filter()
                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");
                choice = __get_integer_input_data();
                switch (choice) {
                case 0:
@@ -460,6 +603,18 @@ static int __add_app_filter()
                        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;
                default:
                        printf("Invalid filter property\n");
                                pkgmgrinfo_appinfo_filter_destroy(handle);
@@ -706,7 +861,6 @@ static int __add_arg_filter(char *key, char *value)
        int ret = 0;
        int choice = -1;
        int val = -1;
-       int count = 0;
        pkgmgrinfo_appinfo_filter_h handle;
        ret = pkgmgrinfo_appinfo_filter_create(&handle);
        if (ret > 0) {
@@ -843,6 +997,15 @@ static int __add_arg_filter(char *key, char *value)
                        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;
@@ -949,6 +1112,8 @@ static int __get_certinfo_from_db(char *pkgid)
                        return -1;
                }
        }
+
+       return -1;
 }
 
 static int __compare_pkg_certinfo_from_db(char *lhs_pkgid, char *rhs_pkgid)
@@ -1393,6 +1558,23 @@ static int __insert_manifest_in_db(char *manifest)
        return 0;
 }
 
+static int __fota_insert_manifest_in_db(char *manifest)
+{
+       int ret = 0;
+       char *temp[] = {"fota=true", NULL};
+
+       if (manifest == NULL) {
+               printf("Manifest file is NULL\n");
+               return -1;
+       }
+       ret = pkgmgr_parser_parse_manifest_for_installation(manifest, temp);
+       if (ret < 0) {
+               printf("insert in db failed\n");
+               return -1;
+       }
+       return 0;
+}
+
 static int __remove_manifest_from_db(char *manifest)
 {
        int ret = 0;
@@ -1425,6 +1607,7 @@ int app_func(const pkgmgr_appinfo_h handle, void *user_data)
        bool multiple = 0;
        bool taskmanage = 0;
        pkgmgr_hwacceleration_type hwacceleration;
+       pkgmgrinfo_app_screenreader screenreader;
        bool onboot = 0;
        bool autorestart = 0;
        char *package = NULL;
@@ -1506,6 +1689,13 @@ int app_func(const pkgmgr_appinfo_h handle, void *user_data)
                        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 == PM_SVC_APP) {
                printf("component: svcapp\n");
@@ -1630,9 +1820,12 @@ static int __app_control_list_cb(pkgmgrinfo_appcontrol_h handle, void *user_data
        int oc = 0;
        int mc = 0;
        int uc = 0;
+       int sc = 0;
        char **operation = NULL;
        char **uri = NULL;
        char **mime = NULL;
+       char **subapp = NULL;
+
        ret = pkgmgrinfo_appinfo_get_operation(handle, &oc, &operation);
        if (ret < 0) {
                printf("Get Operation Failed\n");
@@ -1648,6 +1841,12 @@ static int __app_control_list_cb(pkgmgrinfo_appcontrol_h handle, void *user_data
                printf("Get Mime Failed\n");
                return -1;
        }
+       ret = pkgmgrinfo_appinfo_get_subapp(handle, &sc, &subapp);
+       if (ret < 0) {
+               printf("Get subapp Failed\n");
+               return -1;
+       }
+
        for (i = 0; i < oc; i++) {
                if (operation && operation[i])
                        printf("Operation: %s\n", operation[i]);
@@ -1660,6 +1859,11 @@ static int __app_control_list_cb(pkgmgrinfo_appcontrol_h handle, void *user_data
                if (mime && mime[i])
                        printf("Mime: %s\n", mime[i]);
        }
+       for (i = 0; i < sc; i++) {
+               if (subapp && subapp[i])
+                       printf("subapp: %s\n", subapp[i]);
+       }
+
        printf("-------------------------------------------------------\n\n");
        return 0;
 }
@@ -1722,46 +1926,6 @@ static int __get_app_control_list(char *appid)
        return 0;
 }
 
-static int __get_app_visibility(char *appid)
-{
-       int ret = -1;
-       bool status = true;
-       pkgmgr_appinfo_h handle;
-       ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
-       if (ret < 0) {
-               printf("Failed to get handle\n");
-               return -1;
-       }
-       ret = pkgmgrinfo_appinfo_is_guestmode_visibility(handle, &status);
-       if (ret < 0) {
-               printf("pkgmgrinfo_appinfo_is_guestmode_visibility failed\n");
-               pkgmgr_appinfo_destroy_appinfo(handle);
-               return -1;
-       }
-       pkgmgr_appinfo_destroy_appinfo(handle);
-       printf("visibility Status is %d\n",status);
-       return status;
-}
-
-static int __set_app_visibility(char *appid)
-{
-       int ret = 0;
-       int value = 0;
-       pkgmgrinfo_appinfo_h handle;
-       printf("Enter [0/1]: 0--Hide, 1-Show\n");
-       value = __get_integer_input_data();
-       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
-       if (ret != PMINFO_R_OK)
-               return -1;
-       ret = pkgmgrinfo_appinfo_set_guestmode_visibility(handle, value);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_appinfo_destroy_appinfo(handle);
-               return -1;
-       }
-       pkgmgrinfo_appinfo_destroy_appinfo(handle);
-       return 0;
-}
-
 static int __set_app_enabled(char *appid, bool enabled)
 {
        int ret = -1;
@@ -1799,126 +1963,19 @@ static int __get_app_list(char *pkgid)
 
 static int __get_pkg_info(char *pkgid)
 {
-       pkgmgr_pkginfo_h handle;
+       pkgmgrinfo_pkginfo_h handle;
        int ret = -1;
-       char *type = NULL;
-       char *version = NULL;
-       char *author_name = NULL;
-       char *author_email = NULL;
-       char *author_href = NULL;
-       pkgmgr_install_location location = 0;
-       char *icon = NULL;
-       char *label = NULL;
-       char *desc = NULL;
-       bool removable = 0;
-       bool preload = 0;
-       bool readonly = 0;
-       int size = -1;
-       int installed_time = -1;
 
        printf("Get Pkg Info Called [%s]\n", pkgid);
-       ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
        if (ret < 0) {
                printf("Failed to get handle\n");
                return -1;
        }
 
-       ret = pkgmgr_pkginfo_get_type(handle, &type);
-       if (ret < 0) {
-               printf("Failed to get pkg type\n");
-       }
-       if (type)
-               printf("Type: %s\n", type);
+       __get_pkgmgrinfo_pkginfo(handle, NULL);
 
-       ret = pkgmgr_pkginfo_get_version(handle, &version);
-       if (ret < 0) {
-               printf("Failed to get version\n");
-       }
-       if (version)
-               printf("Version: %s\n", version);
-
-       ret = pkgmgr_pkginfo_get_install_location(handle, &location);
-       if (ret < 0) {
-               printf("Failed to get install location\n");
-       }
-       printf("Install Location: %d\n", location);
-
-       ret = pkgmgr_pkginfo_get_package_size(handle, &size);
-       if (ret < 0) {
-               printf("Failed to get package size \n");
-       }
-       printf("Package Size: %d\n", size);
-
-       ret = pkgmgr_pkginfo_get_icon(handle, &icon);
-       if (ret < 0) {
-               printf("Failed to get icon\n");
-       }
-       if (icon)
-               printf("Icon: %s\n", icon);
-
-       ret = pkgmgr_pkginfo_get_label(handle, &label);
-       if (ret < 0) {
-               printf("Failed to get label\n");
-       }
-       if (label)
-               printf("Label: %s\n", label);
-
-       ret = pkgmgr_pkginfo_get_description(handle, &desc);
-       if (ret < 0) {
-               printf("Failed to get description\n");
-       }
-       if (desc)
-               printf("Description: %s\n", desc);
-
-       ret = pkgmgr_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 = pkgmgr_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 = pkgmgr_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 = pkgmgr_pkginfo_is_removable(handle, &removable);
-       if (ret < 0) {
-               printf("Failed to get removable\n");
-       }
-       else
-               printf("Removable: %d\n", removable);
-
-       ret = pkgmgr_pkginfo_is_preload(handle, &preload);
-       if (ret < 0) {
-               printf("Failed to get preload\n");
-       }
-       else
-               printf("Preload: %d\n", preload);
-
-       ret = pkgmgr_pkginfo_is_readonly(handle, &readonly);
-       if (ret < 0) {
-               printf("Failed to get readonly\n");
-       }
-       else
-               printf("Readonly: %d\n", readonly);
-
-       ret = pkgmgr_pkginfo_get_installed_time(handle, &installed_time);
-       if (ret < 0) {
-               printf("Failed to get install time\n");
-       }
-       printf("Install time: %d\n", installed_time);
-
-       pkgmgr_pkginfo_destroy_pkginfo(handle);
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
        return 0;
 }
 
@@ -1936,9 +1993,11 @@ static int __get_app_info(char *appid)
        bool multiple = 0;
        bool taskmanage = 0;
        pkgmgr_hwacceleration_type hwacceleration;
+       pkgmgrinfo_app_screenreader screenreader;
        bool onboot = 0;
        bool autorestart = 0;
        bool enabled = 0;
+       bool preload = 0;
        pkgmgr_appinfo_h handle;
        int ret = -1;
 
@@ -1995,6 +2054,10 @@ static int __get_app_info(char *appid)
        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 = pkgmgr_appinfo_is_onboot(handle, &onboot);
        if (ret < 0) {
                printf("Failed to get onboot\n");
@@ -2007,6 +2070,10 @@ static int __get_app_info(char *appid)
        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");
+       }
 
        if (app_id)
                printf("Appid: %s\n", app_id);
@@ -2031,6 +2098,7 @@ static int __get_app_info(char *appid)
                printf("Multiple: %d\n", multiple);
                printf("Taskmanage: %d\n", taskmanage);
                printf("Hw-Acceleration: %d\n", hwacceleration);
+               printf("Screenreader: %d\n", screenreader);
        } else if (component == PM_SVC_APP) {
                printf("component: svcapp\n");
 
@@ -2046,6 +2114,7 @@ static int __get_app_info(char *appid)
        }
 
        printf("Enabled: %d\n", enabled);
+       printf("Preload: %d\n", preload);
 
        pkgmgr_appinfo_destroy_appinfo(handle);
        return 0;
@@ -2214,6 +2283,12 @@ int main(int argc, char *argv[])
                        printf("insert in db failed\n");
                        goto end;
                }
+       } else if (strcmp(argv[1], "--fota") == 0) {
+               ret = __fota_insert_manifest_in_db(argv[2]);
+               if (ret == -1) {
+                       printf("insert in db failed\n");
+                       goto end;
+               }
        } else if (strcmp(argv[1], "--rmd") == 0) {
                ret = __remove_manifest_from_db(argv[2]);
                if (ret == -1) {
@@ -2268,18 +2343,6 @@ int main(int argc, char *argv[])
                        printf("get app control list failed\n");
                        goto end;
                }
-       } else if (strcmp(argv[1], "--getvisibility") == 0) {
-               ret = __get_app_visibility(argv[2]);
-               if (ret == -1) {
-                       printf("get app visibility failed\n");
-                       goto end;
-               }
-       } else if (strcmp(argv[1], "--setvisibility") == 0) {
-               ret = __set_app_visibility(argv[2]);
-               if (ret == -1) {
-                       printf("set app visibility failed\n");
-                       goto end;
-               }
        } else
                __print_usage();