4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
35 #include <pkgmgr-info.h>
36 #include <iniparser.h>
37 /* For multi-user support */
38 #include <tzplatform_config.h>
40 #include "package-manager.h"
41 #include "pkgmgr-internal.h"
42 #include "pkgmgr-debug.h"
43 #include "pkgmgr-api.h"
44 #include "comm_client.h"
46 #define PKG_TMP_PATH tzplatform_mkpath(TZ_USER_APP, "tmp")
48 #define BINSH_NAME "/bin/sh"
51 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
53 static int _get_request_id()
55 static int internal_req_id = 1;
57 return internal_req_id++;
60 typedef struct _req_cb_info {
63 pkgmgr_handler event_cb;
65 struct _req_cb_info *next;
68 typedef struct _listen_cb_info {
70 pkgmgr_handler event_cb;
72 struct _listen_cb_info *next;
75 typedef struct _pkgmgr_client_t {
85 listen_cb_info *lhead;
93 typedef struct _iter_data {
94 pkgmgr_iter_fn iter_fn;
98 static int __xsystem(const char *argv[])
105 perror("fork failed");
109 execvp(argv[0], (char *const *)argv);
115 if (waitpid(pid, &status, 0) == -1) {
116 perror("waitpid failed");
119 if (WIFSIGNALED(status)) {
123 if (!WIFEXITED(status)) {
124 /* shouldn't happen */
125 perror("should not happen");
128 return WEXITSTATUS(status);
131 static void __error_to_string(int errnumber, char **errstr)
136 case PKGCMD_ERR_PACKAGE_NOT_FOUND:
137 *errstr = PKGCMD_ERR_PACKAGE_NOT_FOUND_STR;
139 case PKGCMD_ERR_PACKAGE_INVALID:
140 *errstr = PKGCMD_ERR_PACKAGE_INVALID_STR;
142 case PKGCMD_ERR_PACKAGE_LOWER_VERSION:
143 *errstr = PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR;
145 case PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND:
146 *errstr = PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR;
148 case PKGCMD_ERR_MANIFEST_INVALID:
149 *errstr = PKGCMD_ERR_MANIFEST_INVALID_STR;
151 case PKGCMD_ERR_CONFIG_NOT_FOUND:
152 *errstr = PKGCMD_ERR_CONFIG_NOT_FOUND_STR;
154 case PKGCMD_ERR_CONFIG_INVALID:
155 *errstr = PKGCMD_ERR_CONFIG_INVALID_STR;
157 case PKGCMD_ERR_SIGNATURE_NOT_FOUND:
158 *errstr = PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR;
160 case PKGCMD_ERR_SIGNATURE_INVALID:
161 *errstr = PKGCMD_ERR_SIGNATURE_INVALID_STR;
163 case PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED:
164 *errstr = PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR;
166 case PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND:
167 *errstr = PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR;
169 case PKGCMD_ERR_CERTIFICATE_INVALID:
170 *errstr = PKGCMD_ERR_CERTIFICATE_INVALID_STR;
172 case PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
173 *errstr = PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR;
175 case PKGCMD_ERR_CERTIFICATE_EXPIRED:
176 *errstr = PKGCMD_ERR_CERTIFICATE_EXPIRED_STR;
178 case PKGCMD_ERR_INVALID_PRIVILEGE:
179 *errstr = PKGCMD_ERR_INVALID_PRIVILEGE_STR;
181 case PKGCMD_ERR_MENU_ICON_NOT_FOUND:
182 *errstr = PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR;
184 case PKGCMD_ERR_FATAL_ERROR:
185 *errstr = PKGCMD_ERR_FATAL_ERROR_STR;
187 case PKGCMD_ERR_OUT_OF_STORAGE:
188 *errstr = PKGCMD_ERR_OUT_OF_STORAGE_STR;
190 case PKGCMD_ERR_OUT_OF_MEMORY:
191 *errstr = PKGCMD_ERR_OUT_OF_MEMORY_STR;
193 case PKGCMD_ERR_ARGUMENT_INVALID:
194 *errstr = PKGCMD_ERR_ARGUMENT_INVALID_STR;
197 *errstr = PKGCMD_ERR_UNKNOWN_STR;
202 static void __add_op_cbinfo(pkgmgr_client_t * pc, int request_id,
203 const char *req_key, pkgmgr_handler event_cb, void *new_event_cb,
206 req_cb_info *cb_info;
207 req_cb_info *current;
210 cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
211 if (cb_info == NULL) {
212 DBG("calloc failed");
215 cb_info->request_id = request_id;
216 cb_info->req_key = strdup(req_key);
217 cb_info->event_cb = event_cb;
218 cb_info->data = data;
219 cb_info->next = NULL;
220 pc->new_event_cb = new_event_cb;
222 if (pc->info.request.rhead == NULL)
223 pc->info.request.rhead = cb_info;
225 current = prev = pc->info.request.rhead;
228 current = current->next;
231 prev->next = cb_info;
235 static req_cb_info *__find_op_cbinfo(pkgmgr_client_t *pc, const char *req_key)
239 tmp = pc->info.request.rhead;
246 DBG("tmp->req_key %s, req_key %s", tmp->req_key, req_key);
249 if (strncmp(tmp->req_key, req_key, strlen(tmp->req_key)) == 0)
256 static void __add_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
257 pkgmgr_handler event_cb, void *data)
259 listen_cb_info *cb_info;
260 listen_cb_info *current;
261 listen_cb_info *prev;
263 cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
264 if (cb_info == NULL) {
265 DBG("calloc failed");
268 cb_info->request_id = request_id;
269 cb_info->event_cb = event_cb;
270 cb_info->data = data;
271 cb_info->next = NULL;
273 /* TODO - check the order of callback - FIFO or LIFO => Should be changed to LIFO */
274 if (pc->info.listening.lhead == NULL)
275 pc->info.listening.lhead = cb_info;
277 current = prev = pc->info.listening.lhead;
280 current = current->next;
283 prev->next = cb_info;
287 static void __operation_callback(void *cb_data, uid_t target_uid,
288 const char *req_id, const char *pkg_type,
289 const char *pkgid, const char *key,
293 req_cb_info *cb_info;
295 pc = (pkgmgr_client_t *) cb_data;
297 /* find callback info */
298 cb_info = __find_op_cbinfo(pc, req_id);
299 if (cb_info == NULL) {
300 ERR("cannot fint cb_info for req_id:%s", req_id);
305 if (cb_info->event_cb) {
306 if (pc->new_event_cb)
307 cb_info->event_cb(target_uid, cb_info->request_id,
308 pkg_type, pkgid, key, val, pc,
311 cb_info->event_cb(target_uid, cb_info->request_id,
312 pkg_type, pkgid, key, val, NULL,
319 static void __status_callback(void *cb_data, uid_t target_uid,
320 const char *req_id, const char *pkg_type,
321 const char *pkgid, const char *key,
327 pc = (pkgmgr_client_t *) cb_data;
329 tmp = pc->info.listening.lhead;
331 if (tmp->event_cb(target_uid, tmp->request_id, pkg_type, pkgid,
332 key, val, NULL, tmp->data) != 0)
340 static inline int __read_proc(const char *path, char *buf, int size)
345 if (buf == NULL || path == NULL)
348 fd = open(path, O_RDONLY);
352 ret = read(fd, buf, size - 1);
364 char *__proc_get_cmdline_bypid(int pid)
366 char buf[PKG_STRING_LEN_MAX] = {'\0', };
369 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
370 ret = __read_proc(buf, buf, sizeof(buf));
374 /* support app launched by shell script*/
375 if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0)
376 return strdup(&buf[BINSH_SIZE + 1]);
381 static inline int __pkgmgr_read_proc(const char *path, char *buf, int size)
386 if (buf == NULL || path == NULL)
389 fd = open(path, O_RDONLY);
393 ret = read(fd, buf, size - 1);
405 static inline int __pkgmgr_find_pid_by_cmdline(const char *dname,
406 const char *cmdline, const char *apppath)
410 if (strncmp(cmdline, apppath, PKG_STRING_LEN_MAX-1) == 0) {
412 if (pid != getpgid(pid))
419 static int __sync_process(const char *req_key)
422 char info_file[PKG_STRING_LEN_MAX] = {'\0', };
426 char buf[PKG_STRING_LEN_MAX] = {0, };
428 snprintf(info_file, PKG_STRING_LEN_MAX, "%s/%s", PKG_SIZE_INFO_PATH, req_key);
433 if (access(info_file, F_OK) == 0) {
434 fp = fopen(info_file, "r");
436 DBG("file is not generated yet.... wait\n");
437 usleep(100 * 1000); /* 100ms sleep*/
441 if (fgets(buf, PKG_STRING_LEN_MAX, fp) == NULL) {
442 ERR("failed to read info file");
448 DBG("info_file file is generated, result = %s. \n", buf);
453 DBG("file is not generated yet.... wait\n");
454 usleep(100 * 1000); /* 100ms sleep*/
456 if (check_cnt > 6000) { /* 60s * 10 time over*/
457 ERR("wait time over!!\n");
462 ret = remove(info_file);
464 ERR("file is can not remove[%s, %d]\n", info_file, ret);
469 static int __csc_process(const char *csc_path, char *result_path)
476 char *pkgtype = NULL;
478 char buf[PKG_STRING_LEN_MAX] = {0,};
479 char type_buf[1024] = { 0 };
480 char des_buf[1024] = { 0 };
481 dictionary *csc = NULL;
484 csc = iniparser_load(csc_path);
485 retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path);
487 file = fopen(result_path, "w");
488 tryvm_if(file == NULL, ret = PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path);
490 count = iniparser_getint(csc, "csc packages:count", -1);
491 tryvm_if(count == 0, ret = PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path);
493 snprintf(buf, PKG_STRING_LEN_MAX, "[result]\n");
494 fwrite(buf, 1, strlen(buf), file);
495 snprintf(buf, PKG_STRING_LEN_MAX, "count = %d\n", count);
496 fwrite(buf, 1, strlen(buf), file);
498 for(cnt = 1 ; cnt <= count ; cnt++)
500 snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt);
501 snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt);
503 pkgtype = iniparser_getstring(csc, type_buf, NULL);
504 des = iniparser_getstring(csc, des_buf, NULL);
507 if (pkgtype == NULL) {
509 snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get pkgtype\n", type_buf);
510 fwrite(buf, 1, strlen(buf), file);
512 } else if (des == NULL) {
514 snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get description\n", des_buf);
515 fwrite(buf, 1, strlen(buf), file);
519 snprintf(buf, PKG_STRING_LEN_MAX, "type_%03d = %s\n", cnt, pkgtype);
520 fwrite(buf, 1, strlen(buf), file);
521 snprintf(buf, PKG_STRING_LEN_MAX, "description_%03d = %s\n", cnt, des);
522 fwrite(buf, 1, strlen(buf), file);
524 if (strcmp(pkgtype, "tpk") == 0) {
525 const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL };
526 ret = __xsystem(ospinstaller_argv);
527 } else if (strcmp(pkgtype, "wgt")== 0) {
528 const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL };
529 ret = __xsystem(wrtinstaller_argv);
537 __error_to_string(ret, &errstr);
538 snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = fail[%s]\n", cnt, errstr);
541 snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = success\n", cnt);
543 fwrite(buf, 1, strlen(buf), file);
547 iniparser_freedict(csc);
557 static int __get_size_process(pkgmgr_client * pc, const char *pkgid, uid_t uid,
558 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
562 int ret = PKGMGR_R_ECOMM;
563 char *req_key = NULL;
564 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
566 if (pc == NULL || pkgid == NULL) {
567 ERR("invalid parameter");
568 return PKGMGR_R_EINVAL;
571 if (mpc->ctype != PC_REQUEST) {
572 ERR("mpc->ctype is not PC_REQUEST");
573 return PKGMGR_R_EINVAL;
575 result = comm_client_request(mpc->info.request.cc, "getsize",
576 g_variant_new("(si)", pkgid, get_type));
578 return PKGMGR_R_ECOMM;
580 g_variant_get(result, "(i&s)", &ret, &req_key);
581 if (req_key == NULL) {
582 g_variant_unref(result);
583 return PKGMGR_R_ECOMM;
585 if (ret != PKGMGR_R_OK) {
586 g_variant_unref(result);
590 ret = __sync_process(req_key);
592 ERR("get size failed, ret=%d\n", ret);
594 g_variant_unref(result);
599 static int __move_pkg_process(pkgmgr_client *pc, const char *pkgid,
600 const char *pkg_type, uid_t uid, pkgmgr_move_type move_type,
601 pkgmgr_handler event_cb, void *data)
605 ret = pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, 0, uid);
607 ERR("move request failed");
612 ret = __sync_process(pkgid);
614 ERR("move pkg failed, ret=%d\n", ret);
619 static int __check_app_process(pkgmgr_request_service_type service_type,
620 pkgmgr_client *pc, const char *pkgid, uid_t uid, void *data)
622 GVariant *result = NULL;
623 int ret = PKGMGR_R_ECOMM;
624 pkgmgrinfo_pkginfo_h handle;
626 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
628 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
630 if (uid != GLOBAL_USER)
631 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
633 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
634 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgrinfo_pkginfo_get_pkginfo failed");
636 if (service_type == PM_REQUEST_KILL_APP)
637 result = comm_client_request(mpc->info.request.cc, "kill",
638 g_variant_new("(us)", uid, pkgid));
639 else if (service_type == PM_REQUEST_CHECK_APP)
640 result = comm_client_request(mpc->info.request.cc, "check",
641 g_variant_new("(us)", uid, pkgid));
644 return PKGMGR_R_ECOMM;
645 g_variant_get(result, "(i)", &ret);
646 g_variant_unref(result);
647 if (ret != PKGMGR_R_OK) {
648 ERR("request failed, ret=%d", ret);
653 pid = __sync_process(pkgid);
656 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
662 static int __request_size_info(pkgmgr_client *pc, uid_t uid)
665 int ret = PKGMGR_R_ECOMM;
666 char *req_key = NULL;
667 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
670 ERR("invalid parameter");
671 return PKGMGR_R_EINVAL;
674 if (mpc->ctype != PC_REQUEST) {
675 ERR("mpc->ctype is not PC_REQUEST");
676 return PKGMGR_R_EINVAL;
679 result = comm_client_request(mpc->info.request.cc, "getsize",
680 g_variant_new("(si)", "size_info", PM_GET_SIZE_INFO));
682 return PKGMGR_R_ECOMM;
684 g_variant_get(result, "(i&s)", &ret, &req_key);
685 if (req_key == NULL) {
686 g_variant_unref(result);
687 return PKGMGR_R_ECOMM;
690 g_variant_unref(result);
695 static int __change_op_cb_for_getsize(pkgmgr_client *pc)
699 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
700 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
702 /* free listening head */
703 req_cb_info *tmp = NULL;
704 req_cb_info *prev = NULL;
705 for (tmp = mpc->info.request.rhead; tmp;) {
711 /* free dbus connection */
712 ret = comm_client_free(mpc->info.request.cc);
713 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
715 /* Manage pc for seperated event */
716 mpc->ctype = PC_REQUEST;
717 mpc->status_type = PKGMGR_CLIENT_STATUS_GET_SIZE;
720 mpc->info.request.cc = comm_client_new();
721 retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
723 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_GET_SIZE, mpc->info.request.cc, __operation_callback, pc);
724 retvm_if(ret < 0, PKGMGR_R_ERROR, "set_status_callback() failed - %d", ret);
729 static int __get_pkg_size_info_cb(uid_t target_uid, int req_id, const char *req_type,
730 const char *pkgid, const char *key,
731 const char *value, const void *pc, void *user_data)
734 DBG("target_uid: %u, reqid: %d, req type: %s, pkgid: %s, unused key: %s, size info: %s",
735 target_uid, req_id, req_type, pkgid, key, value);
737 pkg_size_info_t *size_info = (pkg_size_info_t *)malloc(sizeof(pkg_size_info_t));
738 retvm_if(size_info == NULL, -1, "The memory is insufficient.");
740 char *save_ptr = NULL;
741 char *token = strtok_r((char*)value, ":", &save_ptr);
742 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
743 size_info->data_size = atoll(token);
744 token = strtok_r(NULL, ":", &save_ptr);
745 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
746 size_info->cache_size = atoll(token);
747 token = strtok_r(NULL, ":", &save_ptr);
748 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
749 size_info->app_size = atoll(token);
750 token = strtok_r(NULL, ":", &save_ptr);
751 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
752 size_info->ext_data_size = atoll(token);
753 token = strtok_r(NULL, ":", &save_ptr);
754 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
755 size_info->ext_cache_size = atoll(token);
756 token = strtok_r(NULL, ":", &save_ptr);
757 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
758 size_info->ext_app_size = atoll(token);
760 DBG("data: %lld, cache: %lld, app: %lld, ext_data: %lld, ext_cache: %lld, ext_app: %lld",
761 size_info->data_size, size_info->cache_size, size_info->app_size,
762 size_info->ext_data_size, size_info->ext_cache_size, size_info->ext_app_size);
764 pkgmgr_client_t *pmc = (pkgmgr_client_t *)pc;
765 tryvm_if(pmc == NULL, ret = -1, "pkgmgr_client instance is null.");
767 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
768 { // total package size info
769 pkgmgr_total_pkg_size_info_receive_cb callback = (pkgmgr_total_pkg_size_info_receive_cb)(pmc->new_event_cb);
770 callback((pkgmgr_client *)pc, size_info, user_data);
774 pkgmgr_pkg_size_info_receive_cb callback = (pkgmgr_pkg_size_info_receive_cb)(pmc->new_event_cb);
775 callback((pkgmgr_client *)pc, pkgid, size_info, user_data);
787 API pkgmgr_client *pkgmgr_client_new(client_type ctype)
789 pkgmgr_client_t *pc = NULL;
792 retvm_if(ctype == PC_BROADCAST, NULL, "broadcast type is not supported");
793 retvm_if(ctype != PC_REQUEST && ctype != PC_LISTENING, NULL, "ctype is not client_type");
795 /* Allocate memory for ADT:pkgmgr_client */
796 pc = calloc(1, sizeof(pkgmgr_client_t));
797 retvm_if(pc == NULL, NULL, "No memory");
801 pc->status_type = PKGMGR_CLIENT_STATUS_ALL;
804 if (pc->ctype == PC_REQUEST) {
805 pc->info.request.cc = comm_client_new();
806 trym_if(pc->info.request.cc == NULL, "client creation failed");
808 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.request.cc, __operation_callback, pc);
809 trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
810 } else if (pc->ctype == PC_LISTENING) {
811 pc->info.listening.cc = comm_client_new();
812 trym_if(pc->info.listening.cc == NULL, "client creation failed");
814 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.listening.cc, __status_callback, pc);
815 trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
818 return (pkgmgr_client *) pc;
826 API int pkgmgr_client_free(pkgmgr_client *pc)
829 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
830 retvm_if(mpc == NULL, PKGMGR_R_EINVAL, "Invalid argument");
832 if (mpc->ctype == PC_REQUEST) {
835 for (tmp = mpc->info.request.rhead; tmp;) {
841 ret = comm_client_free(mpc->info.request.cc);
842 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed");
843 } else if (mpc->ctype == PC_LISTENING) {
845 listen_cb_info *prev;
846 for (tmp = mpc->info.listening.lhead; tmp;) {
852 ret = comm_client_free(mpc->info.listening.cc);
853 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed");
854 } else if (mpc->ctype == PC_BROADCAST) {
857 ERR("Invalid client type\n");
858 return PKGMGR_R_EINVAL;
863 mpc->tep_path = NULL;
868 mpc->tep_move = NULL;
880 return PKGMGR_R_ERROR;
883 static char *__get_type_from_path(const char *pkg_path)
886 char mimetype[255] = { '\0', };
887 char extlist[256] = { '\0', };
890 ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype));
892 ERR("_get_mime_from_file() failed - error code[%d]\n", ret);
896 ret = _get_mime_extension(mimetype, extlist, sizeof(extlist));
898 ERR("_get_mime_extension() failed - error code[%d]\n", ret);
902 if (strlen(extlist) == 0)
905 if (strchr(extlist, ','))
906 extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0';
908 pkg_type = strchr(extlist, '.') + 1;
909 return strdup(pkg_type);
912 API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, char *tep_path, char *tep_move)
914 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
915 retvm_if(tep_path == NULL, PKGMGR_R_EINVAL, "tep path is NULL");
916 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
918 mpc->tep_path = strdup(tep_path);
919 mpc->tep_move = strdup(tep_move);
924 API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type,
925 const char *descriptor_path, const char *pkg_path,
926 const char *optional_file, pkgmgr_mode mode,
927 pkgmgr_handler event_cb, void *data, uid_t uid)
930 int ret = PKGMGR_R_ECOMM;
931 char *req_key = NULL;
932 GVariantBuilder *builder = NULL;
933 GVariant *args = NULL;
935 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
938 if (pc == NULL || pkg_path == NULL) {
939 ERR("invalid parameter");
940 return PKGMGR_R_EINVAL;
943 if (mpc->ctype != PC_REQUEST) {
944 ERR("mpc->ctype is not PC_REQUEST");
945 return PKGMGR_R_EINVAL;
948 if (access(pkg_path, F_OK) != 0) {
949 ERR("failed to access: %s", pkg_path);
950 return PKGMGR_R_EINVAL;
953 if (mpc->tep_path != NULL && access(mpc->tep_path, F_OK) != 0) {
954 ERR("failed to access: %s", mpc->tep_path);
955 return PKGMGR_R_EINVAL;
958 /* TODO: check pkg's type on server-side */
959 if (pkg_type == NULL)
960 pkgtype = __get_type_from_path(pkg_path);
962 pkgtype = strdup(pkg_type);
964 /* build arguments */
965 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
967 g_variant_builder_add(builder, "s", "-e");
968 g_variant_builder_add(builder, "s", mpc->tep_path);
969 g_variant_builder_add(builder, "s", "-M");
970 g_variant_builder_add(builder, "s", mpc->tep_move);
973 args = g_variant_new("as", builder);
974 g_variant_builder_unref(builder);
976 result = comm_client_request(mpc->info.request.cc, "install",
977 g_variant_new("(uss@as)", uid, pkgtype, pkg_path, args));
980 return PKGMGR_R_ECOMM;
981 g_variant_get(result, "(i&s)", &ret, &req_key);
982 if (req_key == NULL) {
983 g_variant_unref(result);
984 return PKGMGR_R_ECOMM;
986 if (ret != PKGMGR_R_OK) {
987 g_variant_unref(result);
991 req_id = _get_request_id();
992 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
994 g_variant_unref(result);
999 API int pkgmgr_client_install(pkgmgr_client *pc, const char *pkg_type,
1000 const char *descriptor_path, const char *pkg_path,
1001 const char *optional_file, pkgmgr_mode mode,
1002 pkgmgr_handler event_cb, void *data)
1004 return pkgmgr_client_usr_install(pc, pkg_type, descriptor_path,
1005 pkg_path, optional_file, mode, event_cb,data,
1009 API int pkgmgr_client_reinstall(pkgmgr_client *pc, const char *pkg_type,
1010 const char *pkgid, const char *optional_file, pkgmgr_mode mode,
1011 pkgmgr_handler event_cb, void *data)
1013 return pkgmgr_client_usr_reinstall(pc, pkg_type, pkgid, optional_file,
1014 mode, event_cb, data,GLOBAL_USER);
1017 API int pkgmgr_client_usr_reinstall(pkgmgr_client * pc, const char *pkg_type,
1018 const char *pkgid, const char *optional_file, pkgmgr_mode mode,
1019 pkgmgr_handler event_cb, void *data, uid_t uid)
1022 int ret = PKGMGR_R_ECOMM;
1023 char *req_key = NULL;
1025 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1027 pkgmgrinfo_pkginfo_h handle;
1029 if (pc == NULL || pkgid == NULL) {
1030 ERR("invalid parameter");
1031 return PKGMGR_R_EINVAL;
1034 if (mpc->ctype != PC_REQUEST) {
1035 ERR("mpc->ctype is not PC_REQUEST");
1036 return PKGMGR_R_EINVAL;
1039 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
1041 return PKGMGR_R_EINVAL;
1043 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
1045 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1046 return PKGMGR_R_ERROR;
1049 result = comm_client_request(mpc->info.request.cc, "reinstall",
1050 g_variant_new("(uss)", uid, pkgtype, pkgid));
1051 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1053 return PKGMGR_R_ECOMM;
1054 g_variant_get(result, "(i&s)", &ret, &req_key);
1055 if (req_key == NULL) {
1056 g_variant_unref(result);
1057 return PKGMGR_R_ECOMM;
1059 if (ret != PKGMGR_R_OK) {
1060 g_variant_unref(result);
1064 req_id = _get_request_id();
1065 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1067 g_variant_unref(result);
1072 API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
1073 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
1076 return pkgmgr_client_usr_uninstall(pc, pkg_type,pkgid, mode, event_cb,
1080 API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type,
1081 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
1082 void *data, uid_t uid)
1085 int ret = PKGMGR_R_ECOMM;
1086 char *req_key = NULL;
1088 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1090 pkgmgrinfo_pkginfo_h handle;
1092 if (pc == NULL || pkgid == NULL) {
1093 ERR("invalid parameter");
1094 return PKGMGR_R_EINVAL;
1097 if (mpc->ctype != PC_REQUEST) {
1098 ERR("mpc->ctype is not PC_REQUEST");
1099 return PKGMGR_R_EINVAL;
1102 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
1104 return PKGMGR_R_EINVAL;
1106 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
1108 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1109 return PKGMGR_R_ERROR;
1112 /* TODO: check removable ? */
1114 result = comm_client_request(mpc->info.request.cc, "uninstall",
1115 g_variant_new("(uss)", uid, pkgtype, pkgid));
1116 if (result == NULL) {
1117 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1118 return PKGMGR_R_ECOMM;
1120 g_variant_get(result, "(i&s)", &ret, &req_key);
1121 if (req_key == NULL) {
1122 g_variant_unref(result);
1123 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1124 return PKGMGR_R_ECOMM;
1126 if (ret != PKGMGR_R_OK) {
1127 g_variant_unref(result);
1128 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1132 req_id = _get_request_id();
1133 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1135 g_variant_unref(result);
1136 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1141 API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
1142 const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode)
1144 return pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, mode,
1147 API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type,
1148 const char *pkgid, pkgmgr_move_type move_type,
1149 pkgmgr_mode mode, uid_t uid)
1152 int ret = PKGMGR_R_ECOMM;
1153 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1155 if (pc == NULL || pkg_type == NULL || pkgid == NULL) {
1156 ERR("invalid parameter");
1157 return PKGMGR_R_EINVAL;
1160 if ((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD))
1161 return PKGMGR_R_EINVAL;
1163 if (mpc->ctype != PC_REQUEST) {
1164 ERR("mpc->ctype is not PC_REQUEST");
1165 return PKGMGR_R_EINVAL;
1168 result = comm_client_request(mpc->info.request.cc, "move",
1169 g_variant_new("(uss)", uid, pkg_type, pkgid));
1171 return PKGMGR_R_ECOMM;
1172 g_variant_get(result, "(i)", &ret);
1173 g_variant_unref(result);
1178 API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type,
1179 const char *pkgid, uid_t uid)
1182 int ret = PKGMGR_R_ECOMM;
1183 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1185 if (pc == NULL || pkgid == NULL) {
1186 ERR("invalid parameter");
1187 return PKGMGR_R_EINVAL;
1190 result = comm_client_request(mpc->info.request.cc, "enable_pkg",
1191 g_variant_new("(us)", uid, pkgid));
1193 return PKGMGR_R_ECOMM;
1194 g_variant_get(result, "(i)", &ret);
1195 g_variant_unref(result);
1200 API int pkgmgr_client_activate(pkgmgr_client *pc, const char *pkg_type,
1203 return pkgmgr_client_usr_activate(pc, pkg_type, pkgid, GLOBAL_USER);
1206 API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type,
1207 const char *pkgid, uid_t uid)
1210 int ret = PKGMGR_R_ECOMM;
1211 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1213 if (pc == NULL || pkgid == NULL) {
1214 ERR("invalid parameter");
1215 return PKGMGR_R_EINVAL;
1218 result = comm_client_request(mpc->info.request.cc, "disable_pkg",
1219 g_variant_new("(us)", uid, pkgid));
1221 return PKGMGR_R_ECOMM;
1222 g_variant_get(result, "(i)", &ret);
1223 g_variant_unref(result);
1228 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
1231 return pkgmgr_client_usr_deactivate(pc, pkg_type, pkgid, GLOBAL_USER);
1234 API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid,
1238 int ret = PKGMGR_R_ECOMM;
1239 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1241 if (pc == NULL || appid == NULL) {
1242 ERR("invalid parameter");
1243 return PKGMGR_R_EINVAL;
1246 result = comm_client_request(mpc->info.request.cc, "enable_app",
1247 g_variant_new("(us)", uid, appid));
1249 return PKGMGR_R_ECOMM;
1250 g_variant_get(result, "(i)", &ret);
1251 g_variant_unref(result);
1256 API int pkgmgr_client_activate_app(pkgmgr_client * pc, const char *appid)
1258 return pkgmgr_client_usr_activate_app(pc, appid, GLOBAL_USER);
1261 /* TODO: deprecate? */
1262 API int pkgmgr_client_usr_activate_appv(pkgmgr_client *pc, const char *appid,
1263 char *const argv[], uid_t uid)
1265 return pkgmgr_client_usr_activate_app(pc, appid, uid);
1268 API int pkgmgr_client_activate_appv(pkgmgr_client *pc, const char *appid,
1271 return pkgmgr_client_usr_activate_app(pc, appid, GLOBAL_USER);
1274 API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid,
1278 int ret = PKGMGR_R_ECOMM;
1279 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1281 if (pc == NULL || appid == NULL) {
1282 ERR("invalid parameter");
1283 return PKGMGR_R_EINVAL;
1286 result = comm_client_request(mpc->info.request.cc, "disable_app",
1287 g_variant_new("(us)", uid, appid));
1289 return PKGMGR_R_ECOMM;
1290 g_variant_get(result, "(i)", &ret);
1291 g_variant_unref(result);
1296 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid)
1298 return pkgmgr_client_usr_deactivate_app(pc, appid, GLOBAL_USER);
1301 API int pkgmgr_client_usr_deactivate_global_app(pkgmgr_client *pc,
1302 const char *appid, uid_t uid)
1305 int ret = PKGMGR_R_ECOMM;
1306 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1308 if (pc == NULL || appid == NULL) {
1309 ERR("invalid parameter");
1310 return PKGMGR_R_EINVAL;
1313 result = comm_client_request(mpc->info.request.cc, "disable_global_app",
1314 g_variant_new("(us)", uid, appid));
1316 return PKGMGR_R_ECOMM;
1317 g_variant_get(result, "(i)", &ret);
1318 g_variant_unref(result);
1323 API int pkgmgr_client_usr_activate_global_app(pkgmgr_client *pc,
1324 const char *appid, uid_t uid)
1327 int ret = PKGMGR_R_ECOMM;
1328 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1330 if (pc == NULL || appid == NULL) {
1331 ERR("invalid parameter");
1332 return PKGMGR_R_EINVAL;
1335 result = comm_client_request(mpc->info.request.cc, "enable_global_app",
1336 g_variant_new("(us)", uid, appid));
1338 return PKGMGR_R_ECOMM;
1339 g_variant_get(result, "(i)", &ret);
1340 g_variant_unref(result);
1345 API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc,
1346 const char *pkg_type, const char *appid, pkgmgr_mode mode,
1350 int ret = PKGMGR_R_ECOMM;
1351 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1353 if (pc == NULL || pkg_type == NULL || appid == NULL) {
1354 ERR("invalid parameter");
1355 return PKGMGR_R_EINVAL;
1358 if (mpc->ctype != PC_REQUEST) {
1359 ERR("mpc->ctype is not PC_REQUEST");
1360 return PKGMGR_R_EINVAL;
1363 result = comm_client_request(mpc->info.request.cc, "cleardata",
1364 g_variant_new("(uss)", uid, pkg_type, appid));
1366 return PKGMGR_R_ECOMM;
1368 g_variant_get(result, "(i)", &ret);
1369 g_variant_unref(result);
1374 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
1375 const char *appid, pkgmgr_mode mode)
1377 return pkgmgr_client_usr_clear_user_data(pc, pkg_type, appid, mode,
1381 API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type)
1385 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1386 retvm_if(status_type == PKGMGR_CLIENT_STATUS_ALL, PKGMGR_R_OK, "status_type is PKGMGR_CLIENT_STATUS_ALL");
1387 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1389 /* free listening head */
1390 listen_cb_info *tmp = NULL;
1391 listen_cb_info *prev = NULL;
1392 for (tmp = mpc->info.listening.lhead; tmp;) {
1398 /* free dbus connection */
1399 ret = comm_client_free(mpc->info.listening.cc);
1400 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
1402 /* Manage pc for seperated event */
1403 mpc->ctype = PC_LISTENING;
1404 mpc->status_type = status_type;
1406 mpc->info.listening.cc = comm_client_new();
1407 retvm_if(mpc->info.listening.cc == NULL, PKGMGR_R_EINVAL, "client creation failed");
1409 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL) == PKGMGR_CLIENT_STATUS_INSTALL) {
1410 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_INSTALL, mpc->info.listening.cc, __status_callback, pc);
1411 retvm_if(ret < 0, PKGMGR_R_ECOMM, "PKGMGR_CLIENT_STATUS_INSTALL failed - %d", ret);
1414 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_UNINSTALL) == PKGMGR_CLIENT_STATUS_UNINSTALL) {
1415 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_UNINSTALL, mpc->info.listening.cc, __status_callback, pc);
1416 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_UNINSTALL failed - %d", ret);
1419 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_MOVE) == PKGMGR_CLIENT_STATUS_MOVE) {
1420 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_MOVE, mpc->info.listening.cc, __status_callback, pc);
1421 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_MOVE failed - %d", ret);
1424 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS) == PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS) {
1425 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_INSTALL_PROGRESS, mpc->info.listening.cc, __status_callback, pc);
1426 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_INSTALL_PROGRESS failed - %d", ret);
1429 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_UPGRADE) == PKGMGR_CLIENT_STATUS_UPGRADE) {
1430 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_UPGRADE, mpc->info.listening.cc, __status_callback, pc);
1431 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_UPGRADE failed - %d", ret);
1437 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
1441 /* Check for NULL value of pc */
1442 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1443 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1445 /* 0. check input */
1446 retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING");
1447 retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL");
1450 req_id = _get_request_id();
1452 /* 2. add callback info to pkgmgr_client */
1453 __add_stat_cbinfo(mpc, req_id, event_cb, data);
1457 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
1458 const char *pkgid, const char *key,
1461 /* client cannot broadcast signal */
1465 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, int service_mode,
1466 pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
1467 const char *custom_info, pkgmgr_handler event_cb, void *data)
1469 return pkgmgr_client_usr_request_service(service_type, service_mode, pc, pkg_type, pkgid, GLOBAL_USER, custom_info, event_cb, data);
1472 API int pkgmgr_client_usr_request_service(pkgmgr_request_service_type service_type, int service_mode,
1473 pkgmgr_client * pc, const char *pkg_type, const char *pkgid, uid_t uid,
1474 const char *custom_info, pkgmgr_handler event_cb, void *data)
1478 /* Check for NULL value of service type */
1479 retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
1480 retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n");
1482 switch (service_type) {
1483 case PM_REQUEST_CSC:
1484 tryvm_if(custom_info == NULL, ret = PKGMGR_R_EINVAL, "custom_info is NULL\n");
1485 tryvm_if(strlen(custom_info) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX");
1486 tryvm_if(data == NULL, ret = PKGMGR_R_EINVAL, "data is NULL\n");
1488 ret = __csc_process(custom_info, (char *)data);
1490 ERR("__csc_process fail \n");
1496 case PM_REQUEST_MOVE:
1497 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1498 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1499 tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1501 ret = __move_pkg_process(pc, pkgid, pkg_type, uid, (pkgmgr_move_type)service_mode, event_cb, data);
1504 case PM_REQUEST_GET_SIZE:
1505 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1506 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1507 tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode >= PM_GET_MAX), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1509 ret = __get_size_process(pc, pkgid, uid, (pkgmgr_getsize_type)service_mode, event_cb, data);
1512 case PM_REQUEST_KILL_APP:
1513 case PM_REQUEST_CHECK_APP:
1514 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1515 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1517 ret = __check_app_process(service_type, pc, pkgid, uid, data);
1519 ERR("__check_app_process fail \n");
1526 ERR("Wrong Request\n");
1537 API int pkgmgr_client_usr_request_size_info(uid_t uid)
1540 pkgmgr_client *pc = NULL;
1542 pc = pkgmgr_client_new(PC_REQUEST);
1543 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "request pc is null\n");
1545 ret = __request_size_info(pc, uid);
1547 ERR("__request_size_info fail \n");
1550 pkgmgr_client_free(pc);
1554 API int pkgmgr_client_request_size_info(void) // get all package size (data, total)
1556 return pkgmgr_client_usr_request_size_info(GLOBAL_USER);
1559 API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid)
1562 int ret = PKGMGR_R_ECOMM;
1563 pkgmgr_client_t *pc;
1565 if (pkgid == NULL) {
1566 ERR("invalid parameter");
1567 return PKGMGR_R_EINVAL;
1570 pc = pkgmgr_client_new(PC_REQUEST);
1572 ERR("out of memory");
1573 return PKGMGR_R_ESYSTEM;
1576 result = comm_client_request(pc->info.request.cc, "clearcache",
1577 g_variant_new("(us)", uid, pkgid));
1579 return PKGMGR_R_ECOMM;
1580 g_variant_get(result, "(i)", &ret);
1581 g_variant_unref(result);
1586 API int pkgmgr_client_clear_cache_dir(const char *pkgid)
1588 return pkgmgr_client_usr_clear_cache_dir(pkgid, GLOBAL_USER);
1591 API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid)
1593 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, uid);
1596 API int pkgmgr_client_clear_all_cache_dir(void)
1598 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, GLOBAL_USER);
1601 API int pkgmgr_client_get_size(pkgmgr_client * pc, const char *pkgid,
1602 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
1605 return pkgmgr_client_usr_get_size(pc, pkgid, get_type, event_cb, data,
1609 API int pkgmgr_client_usr_get_size(pkgmgr_client * pc, const char *pkgid,
1610 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
1611 void *data, uid_t uid)
1614 int ret = PKGMGR_R_ECOMM;
1615 char *req_key = NULL;
1617 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1619 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
1620 ERR("invalid parameter");
1621 return PKGMGR_R_EINVAL;
1624 if (mpc->ctype != PC_REQUEST) {
1625 ERR("mpc->ctype is not PC_REQUEST");
1626 return PKGMGR_R_EINVAL;
1630 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
1631 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
1633 get_type = PM_GET_PKG_SIZE_INFO;
1634 result = comm_client_request(mpc->info.request.cc, "getsize",
1635 g_variant_new("(usi)", uid, pkgid, get_type));
1637 return PKGMGR_R_ECOMM;
1639 g_variant_get(result, "(i&s)", &ret, &req_key);
1640 if (req_key == NULL) {
1641 g_variant_unref(result);
1642 return PKGMGR_R_ECOMM;
1644 if (ret != PKGMGR_R_OK) {
1645 g_variant_unref(result);
1649 req_id = _get_request_id();
1650 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1652 g_variant_unref(result);
1657 API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc,
1658 const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb,
1659 void *user_data, uid_t uid)
1662 int ret = PKGMGR_R_ECOMM;
1663 char *req_key = NULL;
1666 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1668 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
1669 ERR("invalid parameter");
1670 return PKGMGR_R_EINVAL;
1673 if (mpc->ctype != PC_REQUEST) {
1674 ERR("mpc->ctype is not PC_REQUEST");
1675 return PKGMGR_R_EINVAL;
1679 if (__change_op_cb_for_getsize(mpc) < 0) {
1680 ERR("__change_op_cb_for_getsize failed");
1681 return PKGMGR_R_ESYSTEM;
1684 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
1685 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
1687 get_type = PM_GET_PKG_SIZE_INFO;
1688 result = comm_client_request(mpc->info.request.cc, "getsize",
1689 g_variant_new("(usi)", uid, pkgid, get_type));
1691 return PKGMGR_R_ECOMM;
1693 g_variant_get(result, "(i&s)", &ret, &req_key);
1694 if (req_key == NULL) {
1695 g_variant_unref(result);
1696 return PKGMGR_R_ECOMM;
1698 if (ret != PKGMGR_R_OK) {
1699 g_variant_unref(result);
1703 req_id = _get_request_id();
1704 __add_op_cbinfo(mpc, req_id, req_key, __get_pkg_size_info_cb, event_cb,
1707 g_variant_unref(result);
1712 API int pkgmgr_client_get_package_size_info(pkgmgr_client *pc, const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb, void *user_data)
1714 return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb, user_data, GLOBAL_USER);
1717 API int pkgmgr_client_usr_get_total_package_size_info(pkgmgr_client *pc, pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data, uid_t uid)
1718 { // total package size info
1719 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, uid);
1722 API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc, pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data)
1724 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, GLOBAL_USER);
1727 API int pkgmgr_client_generate_license_request(pkgmgr_client *pc,
1728 const char *resp_data, char **req_data, char **license_url)
1734 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1736 if (pc == NULL || resp_data == NULL || req_data == NULL ||
1737 license_url == NULL) {
1738 ERR("invalid parameter");
1739 return PKGMGR_R_EINVAL;
1742 if (mpc->ctype != PC_REQUEST) {
1743 ERR("mpc->ctype is not PC_REQUEST");
1744 return PKGMGR_R_EINVAL;
1747 result = comm_client_request(mpc->info.request.cc,
1748 "generate_license_request",
1749 g_variant_new("(s)", resp_data));
1751 return PKGMGR_R_ECOMM;
1753 g_variant_get(result, "(i&s&s)", &ret, &data, &url);
1754 if (ret != PKGMGR_R_OK) {
1755 ERR("generate_license_request failed: %d", ret);
1756 g_variant_unref(result);
1760 *req_data = strdup(data);
1761 *license_url = strdup(url);
1763 g_variant_unref(result);
1768 API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data)
1772 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1774 if (pc == NULL || resp_data == NULL) {
1775 ERR("invalid parameter");
1776 return PKGMGR_R_EINVAL;
1779 if (mpc->ctype != PC_REQUEST) {
1780 ERR("mpc->ctype is not PC_REQUEST");
1781 return PKGMGR_R_EINVAL;
1784 result = comm_client_request(mpc->info.request.cc,
1785 "register_license", g_variant_new("(s)", resp_data));
1787 return PKGMGR_R_ECOMM;
1789 g_variant_get(result, "(i)", &ret);
1790 g_variant_unref(result);
1791 if (ret != PKGMGR_R_OK) {
1792 ERR("register license failed: %d", ret);
1799 API int pkgmgr_client_decrypt_package(pkgmgr_client *pc,
1800 const char *drm_file_path, const char *decrypted_file_path)
1804 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1806 if (pc == NULL || drm_file_path == NULL ||
1807 decrypted_file_path == NULL) {
1808 ERR("invalid parameter");
1809 return PKGMGR_R_EINVAL;
1812 if (mpc->ctype != PC_REQUEST) {
1813 ERR("mpc->ctype is not PC_REQUEST");
1814 return PKGMGR_R_EINVAL;
1817 result = comm_client_request(mpc->info.request.cc,
1818 "decrypt_package", g_variant_new("(ss)",
1819 drm_file_path, decrypted_file_path));
1821 return PKGMGR_R_ECOMM;
1823 g_variant_get(result, "(i)", &ret);
1824 g_variant_unref(result);
1825 if (ret != PKGMGR_R_OK) {
1826 ERR("decrypt_package failed: %d", ret);
1833 API int pkgmgr_client_usr_add_blacklist(pkgmgr_client *pc, const char *pkgid,
1837 int ret = PKGMGR_R_ECOMM;
1838 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1840 if (pc == NULL || pkgid == NULL) {
1841 ERR("invalid parameter");
1842 return PKGMGR_R_EINVAL;
1845 result = comm_client_request(mpc->info.request.cc, "add_blacklist",
1846 g_variant_new("(us)", uid, pkgid));
1848 return PKGMGR_R_ECOMM;
1849 g_variant_get(result, "(i)", &ret);
1850 g_variant_unref(result);
1855 API int pkgmgr_client_add_blacklist(pkgmgr_client *pc, const char *pkgid)
1857 return pkgmgr_client_usr_add_blacklist(pc, pkgid, GLOBAL_USER);
1860 API int pkgmgr_client_usr_remove_blacklist(pkgmgr_client *pc,
1861 const char *pkgid, uid_t uid)
1864 int ret = PKGMGR_R_ECOMM;
1865 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1867 if (pc == NULL || pkgid == NULL) {
1868 ERR("invalid parameter");
1869 return PKGMGR_R_EINVAL;
1872 result = comm_client_request(mpc->info.request.cc, "remove_blacklist",
1873 g_variant_new("(us)", uid, pkgid));
1875 return PKGMGR_R_ECOMM;
1876 g_variant_get(result, "(i)", &ret);
1877 g_variant_unref(result);
1882 API int pkgmgr_client_remove_blacklist(pkgmgr_client *pc,
1885 return pkgmgr_client_usr_remove_blacklist(pc, pkgid, GLOBAL_USER);
1888 API int pkgmgr_client_usr_check_blacklist(pkgmgr_client *pc, const char *pkgid,
1889 bool *blacklist, uid_t uid)
1892 int ret = PKGMGR_R_ECOMM;
1894 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1896 if (pc == NULL || pkgid == NULL) {
1897 ERR("invalid parameter");
1898 return PKGMGR_R_EINVAL;
1901 result = comm_client_request(mpc->info.request.cc, "check_blacklist",
1902 g_variant_new("(us)", uid, pkgid));
1904 return PKGMGR_R_ECOMM;
1905 g_variant_get(result, "(ii)", &b, &ret);
1906 g_variant_unref(result);
1908 if (ret != PKGMGR_R_OK)
1919 API int pkgmgr_client_check_blacklist(pkgmgr_client *pc, const char *pkgid,
1922 return pkgmgr_client_usr_check_blacklist(pc, pkgid, blacklist,