Add new functions 02/310702/3
authorInkyun Kil <inkyun.kil@samsung.com>
Tue, 7 May 2024 04:51:20 +0000 (13:51 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Wed, 8 May 2024 01:09:46 +0000 (10:09 +0900)
- uninstall-resource
- clear-cache

Change-Id: Id60dd2d810248093cd631a7c653493b3b4e5529c
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
src/pkgcmd/pkg_cmd.c

index 44af6e80b83ef9f3ffab15d77eda2f503a3d5c88..a55c9490912908a088ffdc8e49bfa87bda8a7430 100644 (file)
@@ -56,6 +56,7 @@
 #define OPTVAL_GLOBAL 1000
 #define OPTVAL_CLEAR_ALL 1001
 #define OPTVAL_UID 1002
+#define OPTVAL_CLEAR_CACHE 1003
 
 static int __is_app_installed(char *pkgid, uid_t uid);
 static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type,
@@ -70,6 +71,7 @@ enum pm_tool_request_e {
        GETSIZE_REQ,
        CLEAR_REQ,
        CLEAR_ALL_REQ,
+       CLEAR_CACHE_REQ,
        MOVE_REQ,
        ACTIVATE_REQ,
        DEACTIVATE_REQ,
@@ -82,6 +84,7 @@ enum pm_tool_request_e {
        GET_PKG_SIZE_INFO_REQ,
        REGISTER_UPDATE_INFO_REQ,
        UNREGISTER_UPDATE_INFO_REQ,
+       UNINSTALL_RESOURCE_REQ,
 };
 typedef enum pm_tool_request_e req_type;
 
@@ -431,6 +434,7 @@ static void __print_usage()
        printf("-w, --mount-install     mount install the package\n");
        printf("-c, --clear             clear user data\n");
        printf("    --clear-all         clear user data for all packages or packages type\n");
+       printf("    --clear-cache       clear cache data for the package\n");
        printf("-m, --move              move package\n");
        printf("-g, --getsize           get size of given package\n");
        printf("-T, --getsize-type      get type [0: total size / 1: data size]\n");
@@ -456,6 +460,7 @@ static void __print_usage()
        printf("-S, --skip-optimization install the package with skip optimization for sdk\n");
        printf("-R, --reg-updateinfo    registers the update information[0: NONE, 1: FORCE, 2: OPTIONAL]\n");
        printf("-U, --unreg-updateinfo  unregisters the update information[0: ONE, 1: ALL]\n");
+       printf("-E, --uninstall-res     request for uninstall resource\n");
        printf("-h, --help              print this help\n");
 
        printf("\n");
@@ -473,10 +478,12 @@ static void __print_usage()
        printf("pkgcmd -C -n <pkgid>\n");
        printf("pkgcmd -k -n <pkgid>\n");
        printf("pkgcmd --clear-all (-t <pkg type>)\n");
+       printf("pkgcmd --clear-cache -n <pkgid>\n");
        printf("pkgcmd -X <old_pkg> -Y <new_pkg> -Z <delta_pkg>\n");
        printf("pkgcmd -D -t <pkg type> -n <pkgid> (--global) (--uid <uid>)\n");
-       printf("pkgcmd -R <update info type> 0 -n <pkgid> <version> \n");
-       printf("pkgcmd -U <mode> 0 -n <pkgid> \n");
+       printf("pkgcmd -R <update info type> -n <pkgid> <version> \n");
+       printf("pkgcmd -U <mode> -n <pkgid> \n");
+       printf("pkgcmd -E -n <pkgid> \n");
 
        printf("\n");
        printf("Example:\n");
@@ -486,6 +493,7 @@ static void __print_usage()
        printf("pkgcmd -w -t tpk -p /tmp/org.example.hello-1.0.0-arm.tpk\n");
        printf("pkgcmd -c -t tpk -n org.example.hello\n");
        printf("pkgcmd --clear-all -t wgt\n");
+       printf("pkgcmd --clear-cache -n org.example.hello\n");
        printf("pkgcmd -m -t tpk -T 1 -n org.example.hello\n");
        printf("pkgcmd -C -n org.example.hello\n");
        printf("pkgcmd -k -n org.example.hello\n");
@@ -498,6 +506,7 @@ static void __print_usage()
        printf("pkgcmd -D -t app -n org.example.helloapp --global\n");
        printf("pkgcmd -R 0 -n org.example.hellopkg 1.0\n");
        printf("pkgcmd -U 0 -n org.example.hellopkg\n");
+       printf("pkgcmd -E -n org.example.helloapp \n");
 
        printf("\n");
        exit(0);
@@ -1047,6 +1056,29 @@ static int __clear_all_req_dispatcher(pm_tool_args *data, uid_t target_uid)
        return ret;
 }
 
+static int __clear_cache_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+       int ret;
+
+       if (data->pkgid[0] == '\0') {
+               __invalid_arg_handler(data);
+               return -1;
+       }
+
+       ret = __is_app_installed(data->pkgid, target_uid);
+       if (ret == -1) {
+               printf("package is not installed\n");
+               return ret;
+       }
+
+       ret = pkgmgr_client_usr_clear_cache_dir(data->pkgid, target_uid);
+       if (ret < 0)
+               printf("pkgmgr_client_usr_clear_cache_dir failed : %d \n", ret);
+
+       printf("pkgmgr_client_usr_clear_cache_dir success\n");
+       return ret;
+}
+
 static int __move_req_dispatcher(pm_tool_args *data, uid_t target_uid)
 {
        int ret;
@@ -1669,6 +1701,38 @@ static int __unregister_update_info_req_dispatcher(pm_tool_args *data, uid_t tar
        return 0;
 }
 
+static int __uninstall_resource_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+       int ret = 0;
+       pkgmgr_client *pc;
+
+       if (data->pkgid[0] == '\0') {
+               __invalid_arg_handler(data);
+               return -1;
+       }
+
+       pc = pkgmgr_client_new(PC_REQUEST);
+       if (pc == NULL) {
+               printf("PkgMgr Client Creation Failed\n");
+               data->result = PKGMGR_INSTALLER_ERR_FATAL_ERROR;
+               return -1;
+       }
+
+       ret = pkgmgr_client_res_usr_uninstall(pc, data->pkgid, target_uid);
+       if (ret != PKGMGR_R_OK)
+               printf("pkgmgr_client_res_usr_uninstall Failed [%d]\n", ret);
+
+       if (ret < 0) {
+               data->result = PKGMGR_INSTALLER_ERR_FATAL_ERROR;
+               pkgmgr_client_free(pc);
+               return ret;
+       }
+
+       printf("uninstall resource ret: %d\n", ret);
+       pkgmgr_client_free(pc);
+       return data->result;
+}
+
 static dispatch_func __process_request_func_ptr[] = {
        [INSTALL_REQ] = __install_req_dispatcher,
        [UNINSTALL_REQ] = __uninstall_req_dispatcher,
@@ -1677,6 +1741,7 @@ static dispatch_func __process_request_func_ptr[] = {
        [GETSIZE_REQ] = __getsize_req_dispatcher,
        [CLEAR_REQ] = __clear_req_dispatcher,
        [CLEAR_ALL_REQ] = __clear_all_req_dispatcher,
+       [CLEAR_CACHE_REQ] = __clear_cache_req_dispatcher,
        [MOVE_REQ] = __move_req_dispatcher,
        [ACTIVATE_REQ] = __activate_req_dispatcher,
        [DEACTIVATE_REQ] = __deactivate_req_dispatcher,
@@ -1689,6 +1754,7 @@ static dispatch_func __process_request_func_ptr[] = {
        [GET_PKG_SIZE_INFO_REQ] = __get_pkg_size_info_req_dispatcher,
        [REGISTER_UPDATE_INFO_REQ] = __register_update_info_req_dispatcher,
        [UNREGISTER_UPDATE_INFO_REQ] = __unregister_update_info_req_dispatcher,
+       [UNINSTALL_RESOURCE_REQ] = __uninstall_resource_req_dispatcher,
 };
 
 static int __process_request(pm_tool_args *data, uid_t target_uid)
@@ -1733,9 +1799,10 @@ int main(int argc, char *argv[])
        bool is_root_cmd = false;
        pm_tool_args *data;
        GList *list;
+
        /* Supported options */
        /* Note: 'G' is reserved */
-       const char *short_options = "iurwmcgxCkaADL:lsd:p:t:n:T:e:M:X:Y:Z:R:U:qhGS";
+       const char *short_options = "iurwmcgxCkaADL:lsd:p:t:n:T:e:M:X:Y:Z:R:U:qhGSE";
        const struct option long_options[] = {
                {"install", 0, NULL, 'i'},
                {"uninstall", 0, NULL, 'u'},
@@ -1744,6 +1811,7 @@ int main(int argc, char *argv[])
                {"move", 0, NULL, 'm'},
                {"clear", 0, NULL, 'c'},
                {"clear-all", 0, NULL, OPTVAL_CLEAR_ALL},
+               {"clear-cache", 0, NULL, OPTVAL_CLEAR_CACHE},
                {"getsize", 0, NULL, 'g'},
                {"activate", 0, NULL, 'A'},
                {"deactivate", 0, NULL, 'D'},
@@ -1773,6 +1841,7 @@ int main(int argc, char *argv[])
                {"skip-optimization", 0, NULL, 'S'},
                {"reg-updateinfo", 1, NULL, 'R'},
                {"unreg-updateinfo", 1, NULL, 'U'},
+               {"uninstall-res", 0, NULL, 'E'},
                {0, 0, 0, 0}            /* sentinel */
        };
 
@@ -1826,6 +1895,10 @@ int main(int argc, char *argv[])
                        data->request = CLEAR_ALL_REQ;
                        break;
 
+               case OPTVAL_CLEAR_CACHE:  /* clear cache */
+                       data->request = CLEAR_CACHE_REQ;
+                       break;
+
                case 'g':  /* get pkg size */
                        data->request = GETSIZE_REQ;
                        break;
@@ -1979,6 +2052,10 @@ int main(int argc, char *argv[])
                        printf("TEP path is %s\n", data->tep_path);
                        break;
 
+               case 'E':  /* Uninstall Resource */
+                       data->request = UNINSTALL_RESOURCE_REQ;
+                       break;
+
                case 'M':  /*tep move*/
                        if (optarg)
                                data->tep_move = (atoi(optarg) == 1) ? true : false;