Updates pkgcmd tool 54/310154/2
authorInkyun Kil <inkyun.kil@samsung.com>
Tue, 23 Apr 2024 07:01:45 +0000 (16:01 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Tue, 23 Apr 2024 08:11:48 +0000 (17:11 +0900)
- Adds omitted message for getting size
- Adds code for EnableApps, DisableApps
- Adds code for UpdateInfo

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

index 291ce0b59b6e77b6a73917b6b353490b6f1945d5..4ee59dbd02dd3c8bb895b55e8f6e54cb45b63039 100644 (file)
@@ -79,7 +79,9 @@ enum pm_tool_request_e {
        LIST_REQ,
        SHOW_REQ,
        CREATE_DELTA,
-       GET_PKG_SIZE_INFO_REQ
+       GET_PKG_SIZE_INFO_REQ,
+       REGISTER_UPDATE_INFO_REQ,
+       UNREGISTER_UPDATE_INFO_REQ,
 };
 typedef enum pm_tool_request_e req_type;
 
@@ -108,6 +110,7 @@ struct pm_tool_args_t {
        int uid;
        bool debug_mode;
        bool skip_optimization;
+       int update_info_type;
 };
 typedef struct pm_tool_args_t pm_tool_args;
 
@@ -296,6 +299,33 @@ static int __app_return_cb(uid_t target_uid, int req_id, const char *pkg_type,
        return 0;
 }
 
+static int __apps_return_cb(uid_t target_uid, int req_id, const char *pkg_type,
+                      const char *pkgid, const char *appid, const char *key, const char *val,
+                      const void *pmsg, void *priv_data)
+{
+       int ret_val;
+       pm_tool_args *data = (pm_tool_args *)priv_data;
+
+       if (strncmp(key, "error", strlen("error")) == 0) {
+               ret_val = atoi(val);
+               data->result = ret_val;
+       }
+
+       printf("__app_return_cb req_id[%d] pkg_type[%s] pkgid[%s] appid[%s] " \
+                               "key[%s] val[%s]\n",
+                               req_id, pkg_type, pkgid, appid, key, val);
+
+       if (strncmp(key, "end", strlen("end")) == 0) {
+               if ((strncmp(val, "fail", strlen("fail")) == 0) && data->result == 0)
+                       data->result = PKGMGR_INSTALLER_ERRCODE_ERROR;
+               data->end_count--;
+               if (data->end_count == 0)
+                       g_main_loop_quit(main_loop);
+       }
+
+       return 0;
+}
+
 static int __convert_to_absolute_path(pm_tool_args *data)
 {
        char *abs;
@@ -404,6 +434,7 @@ static void __print_usage()
        printf("-m, --move              move package\n");
        printf("-g, --getsize           get size of given package\n");
        printf("-T, --getsize-type      get type [0: total size / 1: data size]\n");
+       printf("-x, --getsizeinfo       get size info of given package\n");
        printf("-l, --list              display list of installed packages available for the current user\n");
        printf("                        i.e. user's specific apps and global apps\n");
        printf("-s, --show              show detail package info\n");
@@ -420,9 +451,11 @@ static void __print_usage()
        printf("-e, --tep-path          provide TEP package path\n");
        printf("-M, --tep-move          decide move/copy of TEP package [0: copy TEP package / 1: move TEP package]\n");
        printf("-G, --debug-mode        install the package with debug mode for sdk\n");
-       printf("-D, --deactivate        disable package or app\n");
-       printf("-A, --activate          enable package or app\n");
+       printf("-D, --deactivate        disable package or app or apps or splash-screen\n");
+       printf("-A, --activate          enable package or app or apps or splash-screen\n");
        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("-h, --help              print this help\n");
 
        printf("\n");
@@ -436,11 +469,14 @@ static void __print_usage()
        printf("pkgcmd -s -t <pkg type> -n <pkg name>\n");
        printf("pkgcmd -m -t <pkg type> -T <move type> -n <pkg name>\n");
        printf("pkgcmd -g -T <getsize type> -n <pkgid>\n");
+       printf("pkgcmd -x -n <pkgid>\n");
        printf("pkgcmd -C -n <pkgid>\n");
        printf("pkgcmd -k -n <pkgid>\n");
        printf("pkgcmd --clear-all (-t <pkg type>)\n");
        printf("pkgcmd -X <old_pkg> -Y <new_pkg> -Z <delta_pkg>\n");
        printf("pkgcmd -D -t <pkg type> -n <pkgid> (--global) (--uid <uid>)\n");
+       printf("pkgcmd -R <update info type> 0 -n <pkgid> <version> \n");
+       printf("pkgcmd -U <mode> 0 -n <pkgid> \n");
 
        printf("\n");
        printf("Example:\n");
@@ -460,6 +496,8 @@ static void __print_usage()
        printf("pkgcmd -g -T 0 -n org.example.hello\n");
        printf("pkgcmd -D -t tpk -n org.example.hellopkg\n");
        printf("pkgcmd -D -t app -n org.example.helloapp --global\n");
+       printf("pkgcmd -R 0 -n org.example.hellopkg 1.0\n");
+       printf("pkgcmd -U 0 -n org.example.hellopkg\n");
 
        printf("\n");
        exit(0);
@@ -1054,6 +1092,10 @@ static int __activate_req_dispatcher(pm_tool_args *data, uid_t target_uid)
        pkgmgrinfo_appinfo_h appinfo_h;
        pkgmgr_client *pc;
        pkgmgr_client *listen_pc = NULL;
+       const char **pkgs = NULL;
+       GList *list;
+       int i;
+       int n_apps = 0;
 
        if (data->pkg_type[0] == '\0' || data->pkgid[0] == '\0') {
                __invalid_arg_handler(data);
@@ -1109,9 +1151,30 @@ static int __activate_req_dispatcher(pm_tool_args *data, uid_t target_uid)
                                ret = pkgmgr_client_usr_activate_app(pc, data->pkgid,
                                                __app_return_cb, data, GLOBAL_USER);
                } else {
+                       /* enable local apps */
+                       n_apps = g_list_length(data->pkgs);
+                       if (n_apps) {
+                               pkgs = malloc(sizeof(char *) * n_apps);
+                               if (pkgs == NULL)
+                                       printf("Out of memory\n");
+
+                               for (list = data->pkgs, i = 0; list; list = list->next, i++) {
+                                       printf("ensable multiple apps %s\n", (char *)list->data);
+                                       pkgs[i] = (char *)list->data;
+                               }
+
+                               data->end_count = n_apps;
+                               ret = pkgmgr_client_usr_activate_apps(pc, pkgs, n_apps,
+                                               __apps_return_cb, data, target_uid);
+
+                               if (pkgs)
+                                       free(pkgs);
+                       } else {
                        /* enable local app */
+                       printf("enable apps %s\n", data->pkgid);
                        ret = pkgmgr_client_usr_activate_app(pc, data->pkgid,
                                        __app_return_cb, data, target_uid);
+                       }
                }
                pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
        } else {
@@ -1152,6 +1215,10 @@ static int __deactivate_req_dispatcher(pm_tool_args *data, uid_t target_uid)
        pkgmgrinfo_appinfo_h appinfo_h;
        pkgmgr_client *pc;
        pkgmgr_client *listen_pc = NULL;
+       const char **pkgs = NULL;
+       GList *list;
+       int i;
+       int n_apps = 0;
 
        if (data->pkg_type[0] == '\0' || data->pkgid[0] == '\0') {
                __invalid_arg_handler(data);
@@ -1191,9 +1258,29 @@ static int __deactivate_req_dispatcher(pm_tool_args *data, uid_t target_uid)
                                ret = pkgmgr_client_usr_deactivate_app(pc, data->pkgid,
                                                __app_return_cb, NULL, GLOBAL_USER);
                } else {
-                       /* disable local app */
-                       ret = pkgmgr_client_usr_deactivate_app(pc, data->pkgid,
-                                       __app_return_cb, NULL, target_uid);
+                       /* disable local apps */
+                       n_apps = g_list_length(data->pkgs);
+                       if (n_apps) {
+                               pkgs = malloc(sizeof(char *) * n_apps);
+                               if (pkgs == NULL)
+                                       printf("Out of memory\n");
+
+                               for (list = data->pkgs, i = 0; list; list = list->next, i++) {
+                                       printf("disable multiple apps %s\n", (char *)list->data);
+                                       pkgs[i] = (char *)list->data;
+                               }
+
+                               data->end_count = n_apps;
+                               ret = pkgmgr_client_usr_deactivate_apps(pc, pkgs, n_apps,
+                                               __apps_return_cb, data, target_uid);
+
+                               if (pkgs)
+                                       free(pkgs);
+                       } else {
+                               /* disable local app */
+                               ret = pkgmgr_client_usr_deactivate_app(pc, data->pkgid,
+                                               __app_return_cb, NULL, target_uid);
+                       }
                }
 
                pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
@@ -1497,6 +1584,80 @@ static int __get_pkg_size_info_req_dispatcher(pm_tool_args *data, uid_t target_u
        return data->result;
 }
 
+static int __register_update_info_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+       int ret;
+       pkg_update_info_t info = {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");
+               return -1;
+       }
+
+       info.pkgid = data->pkgid;
+       for (GList *list = data->pkgs; list; list = list->next) {
+                       info.version = (char *)list->data;
+                       break;
+       }
+       info.type = data->update_info_type;
+
+       ret = pkgmgr_client_usr_register_pkg_update_info(pc, &info, target_uid);
+       if (ret < 0) {
+               pkgmgr_client_free(pc);
+               return ret;
+       }
+
+       printf("register pkg update info ret: %d\n", ret);
+       pkgmgr_client_free(pc);
+
+       return 0;
+}
+
+static int __unregister_update_info_req_dispatcher(pm_tool_args *data, uid_t target_uid)
+{
+       int ret;
+       pkgmgr_client *pc;
+
+       if (data->pkgid[0] == '\0') {
+               __invalid_arg_handler(data);
+               return -1;
+       }
+
+       pc = pkgmgr_client_new(PC_REQUEST);
+       if (pc == NULL) {
+               printf("PkgMgr Client Creation Failed\n");
+               return -1;
+       }
+
+       if (data->update_info_type == 0) {
+               ret = pkgmgr_client_usr_unregister_pkg_update_info(pc, data->pkgid, target_uid);
+               if (ret < 0) {
+                       printf("unregister pkg update info failed : %d[%s]\n", ret, data->pkgid);
+                       pkgmgr_client_free(pc);
+                       return ret;
+               }
+       } else if (data->update_info_type == 1) {
+               ret = pkgmgr_client_usr_unregister_all_pkg_update_info(pc, target_uid);
+               if (ret < 0) {
+                       printf("unregister all pkg update info failed : %d\n", ret);
+                       pkgmgr_client_free(pc);
+                       return ret;
+               }
+       }
+
+       printf("unregister pkg update info ret: %d\n", ret);
+       pkgmgr_client_free(pc);
+
+       return 0;
+}
+
 static dispatch_func __process_request_func_ptr[] = {
        [INSTALL_REQ] = __install_req_dispatcher,
        [UNINSTALL_REQ] = __uninstall_req_dispatcher,
@@ -1515,6 +1676,8 @@ static dispatch_func __process_request_func_ptr[] = {
        [SHOW_REQ] = __show_req_dispatcher,
        [CREATE_DELTA] = __create_delta_dispatcher,
        [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,
 };
 
 static int __process_request(pm_tool_args *data, uid_t target_uid)
@@ -1561,7 +1724,7 @@ int main(int argc, char *argv[])
        GList *list;
        /* Supported options */
        /* Note: 'G' is reserved */
-       const char *short_options = "iurwmcgxCkaADL:lsd:p:t:n:T:e:M:X:Y:Z:qhGS";
+       const char *short_options = "iurwmcgxCkaADL:lsd:p:t:n:T:e:M:X:Y:Z:R:U:qhGS";
        const struct option long_options[] = {
                {"install", 0, NULL, 'i'},
                {"uninstall", 0, NULL, 'u'},
@@ -1597,6 +1760,8 @@ int main(int argc, char *argv[])
                {"getsizeinfo", 0, NULL, 'x'},
                {"uid", 1, NULL, OPTVAL_UID},
                {"skip-optimization", 0, NULL, 'S'},
+               {"reg-updateinfo", 1, NULL, 'R'},
+               {"unreg-updateinfo", 1, NULL, 'U'},
                {0, 0, 0, 0}            /* sentinel */
        };
 
@@ -1697,6 +1862,23 @@ int main(int argc, char *argv[])
                        data->request = SHOW_REQ;
                        break;
 
+               case 'R':  /* register update info */
+                       data->request = REGISTER_UPDATE_INFO_REQ;
+                       if (optarg)
+                               data->update_info_type = atoi(optarg);
+                               /* 0: PM_UPDATEINFO_TYPE_NONE,
+                                       1: PM_UPDATEINFO_TYPE_FORCE,
+                                       2: PM_UPDATEINFO_TYPE_OPTIONAL */
+                       break;
+
+               case 'U':  /* unregister update info */
+                       data->request = UNREGISTER_UPDATE_INFO_REQ;
+                       if (optarg)
+                               data->update_info_type = atoi(optarg);
+                               /* 0: one package,
+                                       1: all packages*/
+                       break;
+
                case 'p':  /* package path */
                        if (optarg)
                                snprintf(data->pkg_path, sizeof(data->pkg_path),