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 "comm_client.h"
45 /* API export macro */
47 #define API __attribute__ ((visibility("default")))
50 #define PKG_TMP_PATH tzplatform_mkpath(TZ_USER_APP, "tmp")
52 #define BINSH_NAME "/bin/sh"
55 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
56 #define REGULAR_USER 5000
58 static inline uid_t _getuid(void)
62 if (uid < REGULAR_USER)
68 static int _get_request_id()
70 static int internal_req_id = 1;
72 return internal_req_id++;
75 typedef struct _req_cb_info {
78 pkgmgr_handler event_cb;
79 pkgmgr_app_handler app_event_cb;
81 struct _req_cb_info *next;
84 typedef struct _listen_cb_info {
86 pkgmgr_handler event_cb;
87 pkgmgr_app_handler app_event_cb;
89 struct _listen_cb_info *next;
92 typedef struct _pkgmgr_client_t {
102 listen_cb_info *lhead;
110 typedef struct _iter_data {
111 pkgmgr_iter_fn iter_fn;
115 static void __add_op_cbinfo(pkgmgr_client_t *pc, int request_id,
116 const char *req_key, pkgmgr_handler event_cb, void *new_event_cb,
119 req_cb_info *cb_info;
120 req_cb_info *current;
123 cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
124 if (cb_info == NULL) {
125 DBG("calloc failed");
128 cb_info->request_id = request_id;
129 cb_info->req_key = strdup(req_key);
130 cb_info->event_cb = event_cb;
131 cb_info->data = data;
132 cb_info->next = NULL;
133 cb_info->app_event_cb = NULL;
134 pc->new_event_cb = new_event_cb;
136 if (pc->info.request.rhead == NULL)
137 pc->info.request.rhead = cb_info;
139 current = prev = pc->info.request.rhead;
142 current = current->next;
145 prev->next = cb_info;
149 static void __add_op_app_cbinfo(pkgmgr_client_t *pc, int request_id,
150 const char *req_key, pkgmgr_app_handler app_event_cb, void *data)
152 req_cb_info *cb_info;
153 req_cb_info *current;
156 cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
157 if (cb_info == NULL) {
158 DBG("calloc failed");
161 cb_info->request_id = request_id;
162 cb_info->req_key = strdup(req_key);
163 cb_info->event_cb = NULL;
164 cb_info->app_event_cb = app_event_cb;
165 cb_info->data = data;
166 cb_info->next = NULL;
167 pc->new_event_cb = NULL;
169 if (pc->info.request.rhead == NULL)
170 pc->info.request.rhead = cb_info;
172 current = prev = pc->info.request.rhead;
175 current = current->next;
178 prev->next = cb_info;
182 static req_cb_info *__find_op_cbinfo(pkgmgr_client_t *pc, const char *req_key)
186 tmp = pc->info.request.rhead;
193 DBG("tmp->req_key %s, req_key %s", tmp->req_key, req_key);
196 if (strncmp(tmp->req_key, req_key, strlen(tmp->req_key)) == 0)
203 static int __remove_stat_cbinfo(pkgmgr_client_t *pc)
205 listen_cb_info *info = pc->info.listening.lhead;
206 listen_cb_info *next = NULL;
208 while (info != NULL) {
214 pc->info.listening.lhead = NULL;
218 static void __add_app_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
219 pkgmgr_app_handler event_cb, void *data)
221 listen_cb_info *cb_info;
222 listen_cb_info *current;
223 listen_cb_info *prev;
225 cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
226 if (cb_info == NULL) {
227 DBG("calloc failed");
230 cb_info->request_id = request_id;
231 cb_info->app_event_cb = event_cb;
232 cb_info->data = data;
233 cb_info->next = NULL;
235 if (pc->info.listening.lhead == NULL)
236 pc->info.listening.lhead = cb_info;
238 current = prev = pc->info.listening.lhead;
241 current = current->next;
244 prev->next = cb_info;
248 static void __add_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
249 pkgmgr_handler event_cb, void *data)
251 listen_cb_info *cb_info;
252 listen_cb_info *current;
253 listen_cb_info *prev;
255 cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
256 if (cb_info == NULL) {
257 DBG("calloc failed");
260 cb_info->request_id = request_id;
261 cb_info->event_cb = event_cb;
262 cb_info->data = data;
263 cb_info->next = NULL;
265 /* TODO - check the order of callback - FIFO or LIFO => Should be changed to LIFO */
266 if (pc->info.listening.lhead == NULL)
267 pc->info.listening.lhead = cb_info;
269 current = prev = pc->info.listening.lhead;
272 current = current->next;
275 prev->next = cb_info;
279 static void __operation_callback(void *cb_data, uid_t target_uid,
280 const char *req_id, const char *pkg_type,
281 const char *pkgid, const char *appid,
282 const char *key, const char *val)
285 req_cb_info *cb_info;
287 pc = (pkgmgr_client_t *) cb_data;
289 /* find callback info */
290 cb_info = __find_op_cbinfo(pc, req_id);
291 if (cb_info == NULL) {
292 ERR("cannot find cb_info for req_id:%s", req_id);
297 if (appid != NULL && strlen(appid) != 0 && cb_info->app_event_cb) {
298 /* run app callback */
299 if (pc->new_event_cb)
300 cb_info->app_event_cb(target_uid, cb_info->request_id,
301 pkg_type, pkgid, appid, key, val, pc,
304 cb_info->app_event_cb(target_uid, cb_info->request_id,
305 pkg_type, pkgid, appid, key, val, NULL,
307 } else if (cb_info->event_cb) {
308 /* run pkg callback */
309 if (pc->new_event_cb)
310 cb_info->event_cb(target_uid, cb_info->request_id,
311 pkg_type, pkgid, key, val, pc,
314 cb_info->event_cb(target_uid, cb_info->request_id,
315 pkg_type, pkgid, key, val, NULL,
322 static void __status_callback(void *cb_data, uid_t target_uid,
323 const char *req_id, const char *pkg_type,
324 const char *pkgid, const char *appid,
325 const char *key, const char *val)
330 pc = (pkgmgr_client_t *) cb_data;
332 tmp = pc->info.listening.lhead;
334 if (appid != NULL && strlen(appid) != 0) {
335 /* run app callback */
336 if (tmp->app_event_cb && tmp->app_event_cb(
337 target_uid, tmp->request_id, pkg_type, pkgid,
338 appid, key, val, NULL, tmp->data) != 0)
341 /* run pkg callback */
342 if (tmp->event_cb && tmp->event_cb(
343 target_uid, tmp->request_id, pkg_type, pkgid,
344 key, val, NULL, tmp->data) != 0)
353 static inline int __read_proc(const char *path, char *buf, int size)
358 if (buf == NULL || path == NULL)
361 fd = open(path, O_RDONLY);
365 ret = read(fd, buf, size - 1);
377 char *__proc_get_cmdline_bypid(int pid)
379 char buf[PKG_STRING_LEN_MAX] = {'\0', };
382 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
383 ret = __read_proc(buf, buf, sizeof(buf));
387 /* support app launched by shell script*/
388 if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0)
389 return strdup(&buf[BINSH_SIZE + 1]);
394 static inline int __pkgmgr_read_proc(const char *path, char *buf, int size)
399 if (buf == NULL || path == NULL)
402 fd = open(path, O_RDONLY);
406 ret = read(fd, buf, size - 1);
418 static int __sync_process(const char *req_key)
421 char info_file[PKG_STRING_LEN_MAX] = {'\0', };
425 char buf[PKG_STRING_LEN_MAX] = {0, };
427 snprintf(info_file, PKG_STRING_LEN_MAX, "%s/%s", PKG_SIZE_INFO_PATH, req_key);
431 if (access(info_file, F_OK) == 0) {
432 fp = fopen(info_file, "r");
434 DBG("file is not generated yet.... wait\n");
435 usleep(100 * 1000); /* 100ms sleep*/
439 if (fgets(buf, PKG_STRING_LEN_MAX, fp) == NULL) {
440 ERR("failed to read info file");
446 DBG("info_file file is generated, result = %s. \n", buf);
451 DBG("file is not generated yet.... wait\n");
452 usleep(100 * 1000); /* 100ms sleep*/
454 if (check_cnt > 6000) { /* 60s * 10 time over*/
455 ERR("wait time over!!\n");
460 ret = remove(info_file);
462 ERR("file is can not remove[%s, %d]\n", info_file, ret);
467 static int __get_size_process(pkgmgr_client *pc, const char *pkgid, uid_t uid,
468 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
472 int ret = PKGMGR_R_ECOMM;
473 char *req_key = NULL;
474 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
476 if (pc == NULL || pkgid == NULL) {
477 ERR("invalid parameter");
478 return PKGMGR_R_EINVAL;
481 if (mpc->ctype != PC_REQUEST) {
482 ERR("mpc->ctype is not PC_REQUEST");
483 return PKGMGR_R_EINVAL;
486 ret = comm_client_request(mpc->info.request.cc, "getsize",
487 g_variant_new("(usi)", uid, pkgid, get_type), &result);
488 if (ret != PKGMGR_R_OK) {
489 ERR("request failed: %d", ret);
493 g_variant_get(result, "(i&s)", &ret, &req_key);
494 if (req_key == NULL) {
495 g_variant_unref(result);
496 return PKGMGR_R_ECOMM;
498 if (ret != PKGMGR_R_OK) {
499 g_variant_unref(result);
503 ret = __sync_process(req_key);
505 ERR("get size failed, ret=%d\n", ret);
507 g_variant_unref(result);
512 static int __move_pkg_process(pkgmgr_client *pc, const char *pkgid,
513 const char *pkg_type, uid_t uid, pkgmgr_move_type move_type,
514 pkgmgr_handler event_cb, void *data)
518 ret = pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, event_cb, data, uid);
520 ERR("move request failed");
527 static int __check_app_process(pkgmgr_request_service_type service_type,
528 pkgmgr_client *pc, const char *pkgid, uid_t uid, void *data)
531 int ret = PKGMGR_R_ECOMM;
532 pkgmgrinfo_pkginfo_h handle;
534 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
536 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
538 if (uid != GLOBAL_USER)
539 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
541 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
542 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgrinfo_pkginfo_get_pkginfo failed");
544 if (service_type == PM_REQUEST_KILL_APP)
545 ret = comm_client_request(mpc->info.request.cc, "kill",
546 g_variant_new("(us)", uid, pkgid), &result);
547 else if (service_type == PM_REQUEST_CHECK_APP)
548 ret = comm_client_request(mpc->info.request.cc, "check",
549 g_variant_new("(us)", uid, pkgid), &result);
550 if (ret != PKGMGR_R_OK) {
551 ERR("request failed: %d", ret);
555 g_variant_get(result, "(i)", &ret);
556 g_variant_unref(result);
557 if (ret != PKGMGR_R_OK) {
558 ERR("request failed, ret=%d", ret);
563 pid = __sync_process(pkgid);
566 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
572 static int __request_size_info(pkgmgr_client *pc, uid_t uid)
575 int ret = PKGMGR_R_ECOMM;
576 char *req_key = NULL;
577 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
580 ERR("invalid parameter");
581 return PKGMGR_R_EINVAL;
584 if (mpc->ctype != PC_REQUEST) {
585 ERR("mpc->ctype is not PC_REQUEST");
586 return PKGMGR_R_EINVAL;
589 ret = comm_client_request(mpc->info.request.cc, "getsize",
590 g_variant_new("(usi)", uid, "size_info",
593 if (ret != PKGMGR_R_OK) {
594 ERR("request failed: %d", ret);
598 g_variant_get(result, "(i&s)", &ret, &req_key);
599 if (req_key == NULL) {
600 g_variant_unref(result);
601 return PKGMGR_R_ECOMM;
604 g_variant_unref(result);
609 static int __change_op_cb_for_getsize(pkgmgr_client *pc)
613 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
614 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
616 /* free listening head */
617 req_cb_info *tmp = NULL;
618 req_cb_info *prev = NULL;
619 for (tmp = mpc->info.request.rhead; tmp;) {
625 /* free dbus connection */
626 ret = comm_client_free(mpc->info.request.cc);
627 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
629 /* Manage pc for seperated event */
630 mpc->ctype = PC_REQUEST;
631 mpc->status_type = PKGMGR_CLIENT_STATUS_GET_SIZE;
634 mpc->info.request.cc = comm_client_new(PC_REQUEST);
635 retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
637 ret = comm_client_set_status_callback(PKGMGR_CLIENT_STATUS_GET_SIZE, mpc->info.request.cc, __operation_callback, pc);
638 retvm_if(ret < 0, PKGMGR_R_ERROR, "set_status_callback() failed - %d", ret);
643 static int __change_op_cb_for_enable_disable(pkgmgr_client *pc, bool is_disable)
647 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
648 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
650 /* free listening head */
651 req_cb_info *tmp = NULL;
652 req_cb_info *prev = NULL;
653 for (tmp = mpc->info.request.rhead; tmp;) {
659 /* free dbus connection */
660 ret = comm_client_free(mpc->info.request.cc);
661 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
663 /* Manage pc for seperated event */
664 mpc->ctype = PC_REQUEST;
666 mpc->status_type = PKGMGR_CLIENT_STATUS_DISABLE_APP;
668 mpc->status_type = PKGMGR_CLIENT_STATUS_ENABLE_APP;
671 mpc->info.request.cc = comm_client_new(PC_REQUEST);
672 retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
674 ret = comm_client_set_status_callback(mpc->status_type, mpc->info.request.cc, __operation_callback, pc);
675 retvm_if(ret < 0, PKGMGR_R_ERROR, "set_status_callback() failed - %d", ret);
680 static int __get_pkg_size_info_cb(uid_t target_uid, int req_id, const char *req_type,
681 const char *pkgid, const char *key,
682 const char *value, const void *pc, void *user_data)
685 DBG("target_uid: %u, reqid: %d, req type: %s, pkgid: %s, unused key: %s, size info: %s",
686 target_uid, req_id, req_type, pkgid, key, value);
688 pkg_size_info_t *size_info = (pkg_size_info_t *)malloc(sizeof(pkg_size_info_t));
689 retvm_if(size_info == NULL, -1, "The memory is insufficient.");
691 char *save_ptr = NULL;
692 char *token = strtok_r((char *)value, ":", &save_ptr);
693 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
694 size_info->data_size = atoll(token);
695 token = strtok_r(NULL, ":", &save_ptr);
696 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
697 size_info->cache_size = atoll(token);
698 token = strtok_r(NULL, ":", &save_ptr);
699 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
700 size_info->app_size = atoll(token);
701 token = strtok_r(NULL, ":", &save_ptr);
702 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
703 size_info->ext_data_size = atoll(token);
704 token = strtok_r(NULL, ":", &save_ptr);
705 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
706 size_info->ext_cache_size = atoll(token);
707 token = strtok_r(NULL, ":", &save_ptr);
708 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
709 size_info->ext_app_size = atoll(token);
711 DBG("data: %lld, cache: %lld, app: %lld, ext_data: %lld, ext_cache: %lld, ext_app: %lld",
712 size_info->data_size, size_info->cache_size, size_info->app_size,
713 size_info->ext_data_size, size_info->ext_cache_size, size_info->ext_app_size);
715 pkgmgr_client_t *pmc = (pkgmgr_client_t *)pc;
716 tryvm_if(pmc == NULL, ret = -1, "pkgmgr_client instance is null.");
718 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0) { /* total package size info */
719 pkgmgr_total_pkg_size_info_receive_cb callback = (pkgmgr_total_pkg_size_info_receive_cb)(pmc->new_event_cb);
720 callback((pkgmgr_client *)pc, size_info, user_data);
722 pkgmgr_pkg_size_info_receive_cb callback = (pkgmgr_pkg_size_info_receive_cb)(pmc->new_event_cb);
723 callback((pkgmgr_client *)pc, pkgid, size_info, user_data);
735 API pkgmgr_client *pkgmgr_client_new(client_type ctype)
737 pkgmgr_client_t *pc = NULL;
740 retvm_if(ctype == PC_BROADCAST, NULL, "broadcast type is not supported");
741 retvm_if(ctype != PC_REQUEST && ctype != PC_LISTENING, NULL, "ctype is not client_type");
743 /* Allocate memory for ADT:pkgmgr_client */
744 pc = calloc(1, sizeof(pkgmgr_client_t));
745 retvm_if(pc == NULL, NULL, "No memory");
749 pc->status_type = PKGMGR_CLIENT_STATUS_ALL;
752 if (pc->ctype == PC_REQUEST) {
753 pc->info.request.cc = comm_client_new(PC_REQUEST);
754 trym_if(pc->info.request.cc == NULL, "client creation failed");
756 ret = comm_client_set_status_callback(PKGMGR_CLIENT_STATUS_ALL, pc->info.request.cc, __operation_callback, pc);
757 trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
758 } else if (pc->ctype == PC_LISTENING) {
759 pc->info.listening.cc = comm_client_new(PC_LISTENING);
760 trym_if(pc->info.listening.cc == NULL, "client creation failed");
762 ret = comm_client_set_status_callback(PKGMGR_CLIENT_STATUS_ALL, pc->info.listening.cc, __status_callback, pc);
763 trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
766 return (pkgmgr_client *)pc;
774 API int pkgmgr_client_free(pkgmgr_client *pc)
777 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
778 retvm_if(mpc == NULL, PKGMGR_R_EINVAL, "Invalid argument");
780 if (mpc->ctype == PC_REQUEST) {
783 for (tmp = mpc->info.request.rhead; tmp;) {
789 ret = comm_client_free(mpc->info.request.cc);
790 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed");
791 } else if (mpc->ctype == PC_LISTENING) {
793 listen_cb_info *prev;
794 for (tmp = mpc->info.listening.lhead; tmp;) {
800 ret = comm_client_free(mpc->info.listening.cc);
801 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed");
802 } else if (mpc->ctype == PC_BROADCAST) {
805 ERR("Invalid client type\n");
806 return PKGMGR_R_EINVAL;
811 mpc->tep_path = NULL;
823 return PKGMGR_R_ERROR;
826 static char *__get_type_from_path(const char *pkg_path)
829 char mimetype[255] = { '\0', };
830 char extlist[256] = { '\0', };
833 ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype));
835 ERR("_get_mime_from_file() failed - error code[%d]\n", ret);
839 ret = _get_mime_extension(mimetype, extlist, sizeof(extlist));
841 ERR("_get_mime_extension() failed - error code[%d]\n", ret);
845 if (strlen(extlist) == 0)
848 if (strchr(extlist, ','))
849 extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0';
851 pkg_type = strchr(extlist, '.') + 1;
852 return strdup(pkg_type);
855 static int __change_op_cb_for_enable_disable_splash_screen(pkgmgr_client *pc,
859 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
864 ERR("package mananger client pc is NULL");
865 return PKGMGR_R_EINVAL;
868 for (tmp = mpc->info.request.rhead; tmp;) {
874 ret = comm_client_free(mpc->info.request.cc);
876 ERR("comm_client_free() failed - %d", ret);
877 return PKGMGR_R_ERROR;
880 mpc->ctype = PC_REQUEST;
882 mpc->status_type = PKGMGR_CLIENT_STATUS_ENABLE_APP_SPLASH_SCREEN;
884 mpc->status_type = PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN;
886 mpc->info.request.cc = comm_client_new(PC_REQUEST);
887 if (mpc->info.request.cc == NULL) {
888 ERR("client creation failed");
889 return PKGMGR_R_ENOMEM;
892 ret = comm_client_set_status_callback(mpc->status_type,
893 mpc->info.request.cc, __operation_callback, pc);
895 ERR("set_status_callback() failed - %d", ret);
896 return PKGMGR_R_ERROR;
902 API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, char *tep_path, bool tep_move)
904 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
905 retvm_if(tep_path == NULL, PKGMGR_R_EINVAL, "tep path is NULL");
906 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
911 mpc->tep_path = strdup(tep_path);
912 mpc->tep_move = tep_move;
917 API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type,
918 const char *descriptor_path, const char *pkg_path,
919 const char *optional_data, pkgmgr_mode mode,
920 pkgmgr_handler event_cb, void *data, uid_t uid)
923 int ret = PKGMGR_R_ECOMM;
924 char *req_key = NULL;
925 GVariantBuilder *builder = NULL;
926 GVariant *args = NULL;
928 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
931 if (pc == NULL || pkg_path == NULL) {
932 ERR("invalid parameter");
933 return PKGMGR_R_EINVAL;
936 if (mpc->ctype != PC_REQUEST) {
937 ERR("mpc->ctype is not PC_REQUEST");
938 return PKGMGR_R_EINVAL;
941 if (access(pkg_path, F_OK) != 0) {
942 ERR("failed to access: %s", pkg_path);
943 return PKGMGR_R_EINVAL;
946 if (mpc->tep_path != NULL && access(mpc->tep_path, F_OK) != 0) {
947 ERR("failed to access: %s", mpc->tep_path);
948 return PKGMGR_R_EINVAL;
951 /* TODO: check pkg's type on server-side */
952 if (pkg_type == NULL)
953 pkgtype = __get_type_from_path(pkg_path);
955 pkgtype = strdup(pkg_type);
957 /* build arguments */
958 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
960 g_variant_builder_add(builder, "s", "-e");
961 g_variant_builder_add(builder, "s", mpc->tep_path);
962 g_variant_builder_add(builder, "s", "-M");
963 /* TODO: revise tep_move */
964 g_variant_builder_add(builder, "s",
965 mpc->tep_move ? "tep_move" : "tep_copy");
968 args = g_variant_new("as", builder);
969 g_variant_builder_unref(builder);
971 ret = comm_client_request(mpc->info.request.cc, "install",
972 g_variant_new("(uss@as)", uid, pkgtype, pkg_path, args),
974 if (ret != PKGMGR_R_OK) {
975 ERR("request failed: %d", ret);
979 g_variant_get(result, "(i&s)", &ret, &req_key);
980 if (req_key == NULL) {
981 g_variant_unref(result);
982 return PKGMGR_R_ECOMM;
984 if (ret != PKGMGR_R_OK) {
985 g_variant_unref(result);
989 req_id = _get_request_id();
990 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
992 g_variant_unref(result);
997 API int pkgmgr_client_install(pkgmgr_client *pc, const char *pkg_type,
998 const char *descriptor_path, const char *pkg_path,
999 const char *optional_data, pkgmgr_mode mode,
1000 pkgmgr_handler event_cb, void *data)
1002 return pkgmgr_client_usr_install(pc, pkg_type, descriptor_path,
1003 pkg_path, optional_data, mode, event_cb, data,
1007 API int pkgmgr_client_reinstall(pkgmgr_client *pc, const char *pkg_type,
1008 const char *pkgid, const char *optional_data, pkgmgr_mode mode,
1009 pkgmgr_handler event_cb, void *data)
1011 return pkgmgr_client_usr_reinstall(pc, pkg_type, pkgid, optional_data,
1012 mode, event_cb, data, _getuid());
1015 API int pkgmgr_client_usr_reinstall(pkgmgr_client *pc, const char *pkg_type,
1016 const char *pkgid, const char *optional_data, pkgmgr_mode mode,
1017 pkgmgr_handler event_cb, void *data, uid_t uid)
1020 int ret = PKGMGR_R_ECOMM;
1021 char *req_key = NULL;
1023 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1025 pkgmgrinfo_pkginfo_h handle;
1027 if (pc == NULL || pkgid == NULL) {
1028 ERR("invalid parameter");
1029 return PKGMGR_R_EINVAL;
1032 if (mpc->ctype != PC_REQUEST) {
1033 ERR("mpc->ctype is not PC_REQUEST");
1034 return PKGMGR_R_EINVAL;
1037 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
1039 return PKGMGR_R_EINVAL;
1041 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
1043 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1044 return PKGMGR_R_ERROR;
1047 ret = comm_client_request(mpc->info.request.cc, "reinstall",
1048 g_variant_new("(uss)", uid, pkgtype, pkgid), &result);
1049 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1050 if (ret != PKGMGR_R_OK) {
1051 ERR("request failed: %d", ret);
1055 g_variant_get(result, "(i&s)", &ret, &req_key);
1056 if (req_key == NULL) {
1057 g_variant_unref(result);
1058 return PKGMGR_R_ECOMM;
1060 if (ret != PKGMGR_R_OK) {
1061 g_variant_unref(result);
1065 req_id = _get_request_id();
1066 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1068 g_variant_unref(result);
1073 API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type,
1074 const char *descriptor_path, const char *pkg_path,
1075 const char *optional_data, pkgmgr_mode mode,
1076 pkgmgr_handler event_cb, void *data, uid_t uid)
1079 int ret = PKGMGR_R_ECOMM;
1080 char *req_key = NULL;
1081 GVariantBuilder *builder = NULL;
1082 GVariant *args = NULL;
1084 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1087 if (pc == NULL || pkg_path == NULL) {
1088 ERR("invalid parameter");
1089 return PKGMGR_R_EINVAL;
1092 if (mpc->ctype != PC_REQUEST) {
1093 ERR("mpc->ctype is not PC_REQUEST");
1094 return PKGMGR_R_EINVAL;
1097 if (access(pkg_path, F_OK) != 0) {
1098 ERR("failed to access: %s", pkg_path);
1099 return PKGMGR_R_EINVAL;
1102 if (mpc->tep_path != NULL && access(mpc->tep_path, F_OK) != 0) {
1103 ERR("failed to access: %s", mpc->tep_path);
1104 return PKGMGR_R_EINVAL;
1107 /* TODO: check pkg's type on server-side */
1108 if (pkg_type == NULL)
1109 pkgtype = __get_type_from_path(pkg_path);
1111 pkgtype = strdup(pkg_type);
1113 /* build arguments */
1114 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1115 if (mpc->tep_path) {
1116 g_variant_builder_add(builder, "s", "-e");
1117 g_variant_builder_add(builder, "s", mpc->tep_path);
1118 g_variant_builder_add(builder, "s", "-M");
1119 /* TODO: revise tep_move */
1120 g_variant_builder_add(builder, "s",
1121 mpc->tep_move ? "tep_move" : "tep_copy");
1124 args = g_variant_new("as", builder);
1125 g_variant_builder_unref(builder);
1127 ret = comm_client_request(mpc->info.request.cc, "mount_install",
1128 g_variant_new("(uss@as)", uid, pkgtype, pkg_path, args),
1130 if (ret != PKGMGR_R_OK) {
1131 ERR("request failed: %d", ret);
1135 g_variant_get(result, "(i&s)", &ret, &req_key);
1136 if (req_key == NULL) {
1137 g_variant_unref(result);
1138 return PKGMGR_R_ECOMM;
1140 if (ret != PKGMGR_R_OK) {
1141 g_variant_unref(result);
1145 req_id = _get_request_id();
1146 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1148 g_variant_unref(result);
1153 API int pkgmgr_client_mount_install(pkgmgr_client *pc, const char *pkg_type,
1154 const char *descriptor_path, const char *pkg_path,
1155 const char *optional_data, pkgmgr_mode mode,
1156 pkgmgr_handler event_cb, void *data)
1158 return pkgmgr_client_usr_mount_install(pc, pkg_type, descriptor_path,
1159 pkg_path, optional_data, mode, event_cb, data,
1163 API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
1164 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
1167 return pkgmgr_client_usr_uninstall(pc, pkg_type, pkgid, mode, event_cb,
1171 API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type,
1172 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
1173 void *data, uid_t uid)
1176 int ret = PKGMGR_R_ECOMM;
1177 char *req_key = NULL;
1179 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1181 pkgmgrinfo_pkginfo_h handle;
1183 if (pc == NULL || pkgid == NULL) {
1184 ERR("invalid parameter");
1185 return PKGMGR_R_EINVAL;
1188 if (mpc->ctype != PC_REQUEST) {
1189 ERR("mpc->ctype is not PC_REQUEST");
1190 return PKGMGR_R_EINVAL;
1193 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
1195 return PKGMGR_R_EINVAL;
1197 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
1199 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1200 return PKGMGR_R_ERROR;
1203 ret = comm_client_request(mpc->info.request.cc, "uninstall",
1204 g_variant_new("(uss)", uid, pkgtype, pkgid), &result);
1205 if (ret != PKGMGR_R_OK) {
1206 ERR("request failed: %d", ret);
1207 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1211 g_variant_get(result, "(i&s)", &ret, &req_key);
1212 if (req_key == NULL) {
1213 g_variant_unref(result);
1214 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1215 return PKGMGR_R_ECOMM;
1217 if (ret != PKGMGR_R_OK) {
1218 g_variant_unref(result);
1219 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1223 req_id = _get_request_id();
1224 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1226 g_variant_unref(result);
1227 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1232 API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
1233 const char *pkgid, pkgmgr_move_type move_type,
1234 pkgmgr_handler event_cb, void *data)
1236 return pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type,
1237 event_cb, data, _getuid());
1239 API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type,
1240 const char *pkgid, pkgmgr_move_type move_type,
1241 pkgmgr_handler event_cb, void *data, uid_t uid)
1244 int ret = PKGMGR_R_ECOMM;
1246 char *req_key = NULL;
1247 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1249 if (pc == NULL || pkg_type == NULL || pkgid == NULL) {
1250 ERR("invalid parameter");
1251 return PKGMGR_R_EINVAL;
1254 if ((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD))
1255 return PKGMGR_R_EINVAL;
1257 if (mpc->ctype != PC_REQUEST) {
1258 ERR("mpc->ctype is not PC_REQUEST");
1259 return PKGMGR_R_EINVAL;
1262 ret = comm_client_request(mpc->info.request.cc, "move",
1263 g_variant_new("(ussi)", uid, pkg_type, pkgid, move_type), &result);
1264 if (ret != PKGMGR_R_OK) {
1265 ERR("request failed: %d", ret);
1269 g_variant_get(result, "(i&s)", &ret, &req_key);
1270 if (req_key == NULL) {
1271 g_variant_unref(result);
1272 return PKGMGR_R_ECOMM;
1274 if (ret != PKGMGR_R_OK) {
1275 g_variant_unref(result);
1279 req_id = _get_request_id();
1280 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1281 g_variant_unref(result);
1286 API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type,
1287 const char *pkgid, uid_t uid)
1290 int ret = PKGMGR_R_ECOMM;
1291 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1293 if (pc == NULL || pkgid == NULL || pkg_type == NULL) {
1294 ERR("invalid parameter");
1295 return PKGMGR_R_EINVAL;
1298 ret = comm_client_request(mpc->info.request.cc, "enable_pkg",
1299 g_variant_new("(uss)", uid, pkg_type, pkgid), &result);
1300 if (ret != PKGMGR_R_OK) {
1301 ERR("request failed: %d", ret);
1305 g_variant_get(result, "(i)", &ret);
1306 g_variant_unref(result);
1311 API int pkgmgr_client_activate(pkgmgr_client *pc, const char *pkg_type,
1314 return pkgmgr_client_usr_activate(pc, pkg_type, pkgid, _getuid());
1317 API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type,
1318 const char *pkgid, uid_t uid)
1321 int ret = PKGMGR_R_ECOMM;
1322 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1324 if (pc == NULL || pkgid == NULL || pkg_type == NULL) {
1325 ERR("invalid parameter");
1326 return PKGMGR_R_EINVAL;
1329 ret = comm_client_request(mpc->info.request.cc, "disable_pkg",
1330 g_variant_new("(uss)", uid, pkg_type, pkgid), &result);
1331 if (ret != PKGMGR_R_OK) {
1332 ERR("request failed: %d", ret);
1336 g_variant_get(result, "(i)", &ret);
1337 g_variant_unref(result);
1342 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
1345 return pkgmgr_client_usr_deactivate(pc, pkg_type, pkgid, _getuid());
1348 API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid,
1349 pkgmgr_app_handler app_event_cb, uid_t uid)
1352 int ret = PKGMGR_R_ECOMM;
1354 char *req_key = NULL;
1355 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1357 if (pc == NULL || appid == NULL) {
1358 ERR("invalid parameter");
1359 return PKGMGR_R_EINVAL;
1362 if (__change_op_cb_for_enable_disable(mpc, false) < 0) {
1363 ERR("__change_op_cb_for_enable_disable failed");
1364 return PKGMGR_R_ESYSTEM;
1367 ret = comm_client_request(mpc->info.request.cc, "enable_app",
1368 g_variant_new("(us)", uid, appid), &result);
1369 if (ret != PKGMGR_R_OK) {
1370 ERR("request failed: %d", ret);
1374 g_variant_get(result, "(i&s)", &ret, &req_key);
1375 if (req_key == NULL) {
1376 g_variant_unref(result);
1377 return PKGMGR_R_ECOMM;
1379 if (ret != PKGMGR_R_OK) {
1380 g_variant_unref(result);
1384 req_id = _get_request_id();
1385 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1386 g_variant_unref(result);
1390 API int pkgmgr_client_activate_app(pkgmgr_client *pc, const char *appid, pkgmgr_app_handler app_event_cb)
1392 return pkgmgr_client_usr_activate_app(pc, appid, app_event_cb, _getuid());
1395 API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc,
1396 const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid)
1399 int ret = PKGMGR_R_ECOMM;
1401 char *req_key = NULL;
1402 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1404 if (pc == NULL || appid == NULL) {
1405 ERR("invalid parameter");
1406 return PKGMGR_R_EINVAL;
1409 if (__change_op_cb_for_enable_disable(mpc, false) < 0) {
1410 ERR("__change_op_cb_for_enable_disable failed");
1411 return PKGMGR_R_ESYSTEM;
1414 ret = comm_client_request(mpc->info.request.cc, "enable_global_app_for_uid",
1415 g_variant_new("(us)", uid, appid), &result);
1416 if (ret != PKGMGR_R_OK) {
1417 ERR("request failed: %d", ret);
1421 g_variant_get(result, "(i&s)", &ret, &req_key);
1422 if (req_key == NULL) {
1423 g_variant_unref(result);
1424 return PKGMGR_R_ECOMM;
1426 if (ret != PKGMGR_R_OK) {
1427 g_variant_unref(result);
1431 req_id = _get_request_id();
1432 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1437 API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid,
1438 pkgmgr_app_handler app_event_cb, uid_t uid)
1441 int ret = PKGMGR_R_ECOMM;
1442 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1444 char *req_key = NULL;
1446 if (pc == NULL || appid == NULL) {
1447 ERR("invalid parameter");
1448 return PKGMGR_R_EINVAL;
1452 if (__change_op_cb_for_enable_disable(mpc, true) < 0) {
1453 ERR("__change_op_cb_for_enable_disable failed");
1454 return PKGMGR_R_ESYSTEM;
1457 ret = comm_client_request(mpc->info.request.cc, "disable_app",
1458 g_variant_new("(us)", uid, appid), &result);
1459 if (ret != PKGMGR_R_OK) {
1460 ERR("request failed: %d", ret);
1464 g_variant_get(result, "(i&s)", &ret, &req_key);
1465 if (req_key == NULL) {
1466 g_variant_unref(result);
1467 return PKGMGR_R_ECOMM;
1469 if (ret != PKGMGR_R_OK) {
1470 g_variant_unref(result);
1474 req_id = _get_request_id();
1475 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1477 g_variant_unref(result);
1481 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid, pkgmgr_app_handler app_event_cb)
1483 return pkgmgr_client_usr_deactivate_app(pc, appid, app_event_cb, _getuid());
1486 API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc,
1487 const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid)
1490 int ret = PKGMGR_R_ECOMM;
1492 char *req_key = NULL;
1493 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1495 if (pc == NULL || appid == NULL) {
1496 ERR("invalid parameter");
1497 return PKGMGR_R_EINVAL;
1500 if (__change_op_cb_for_enable_disable(mpc, true) < 0) {
1501 ERR("__change_op_cb_for_enable_disable failed");
1502 return PKGMGR_R_ESYSTEM;
1505 ret = comm_client_request(mpc->info.request.cc, "disable_global_app_for_uid",
1506 g_variant_new("(us)", uid, appid), &result);
1507 if (ret != PKGMGR_R_OK) {
1508 ERR("request failed: %d", ret);
1512 g_variant_get(result, "(i&s)", &ret, &req_key);
1513 if (req_key == NULL) {
1514 g_variant_unref(result);
1515 return PKGMGR_R_ECOMM;
1517 if (ret != PKGMGR_R_OK) {
1518 g_variant_unref(result);
1522 req_id = _get_request_id();
1523 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1527 API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc,
1528 const char *pkg_type, const char *appid, pkgmgr_mode mode,
1532 int ret = PKGMGR_R_ECOMM;
1533 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1535 if (pc == NULL || pkg_type == NULL || appid == NULL) {
1536 ERR("invalid parameter");
1537 return PKGMGR_R_EINVAL;
1540 if (mpc->ctype != PC_REQUEST) {
1541 ERR("mpc->ctype is not PC_REQUEST");
1542 return PKGMGR_R_EINVAL;
1545 ret = comm_client_request(mpc->info.request.cc, "cleardata",
1546 g_variant_new("(uss)", uid, pkg_type, appid), &result);
1547 if (ret == PKGMGR_R_OK) {
1548 ERR("request failed: %d", ret);
1552 g_variant_get(result, "(i)", &ret);
1553 g_variant_unref(result);
1558 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
1559 const char *appid, pkgmgr_mode mode)
1561 return pkgmgr_client_usr_clear_user_data(pc, pkg_type, appid, mode,
1565 API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type)
1569 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1570 retvm_if(status_type == PKGMGR_CLIENT_STATUS_ALL, PKGMGR_R_OK, "status_type is PKGMGR_CLIENT_STATUS_ALL");
1571 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1573 /* free listening head */
1574 listen_cb_info *tmp = NULL;
1575 listen_cb_info *prev = NULL;
1576 for (tmp = mpc->info.listening.lhead; tmp;) {
1582 /* free dbus connection */
1583 ret = comm_client_free(mpc->info.listening.cc);
1584 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
1586 /* Manage pc for seperated event */
1587 mpc->ctype = PC_LISTENING;
1588 mpc->status_type = status_type;
1590 mpc->info.listening.cc = comm_client_new(PC_LISTENING);
1591 retvm_if(mpc->info.listening.cc == NULL, PKGMGR_R_EINVAL, "client creation failed");
1593 ret = comm_client_set_status_callback(status_type, mpc->info.listening.cc, __status_callback, pc);
1594 retvm_if(ret < 0, PKGMGR_R_ECOMM, "comm_client_set_status_callback failed - %d", ret);
1599 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
1603 /* Check for NULL value of pc */
1604 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1605 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1607 /* 0. check input */
1608 retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING");
1609 retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL");
1612 req_id = _get_request_id();
1614 /* 2. add callback info to pkgmgr_client */
1615 __add_stat_cbinfo(mpc, req_id, event_cb, data);
1619 API int pkgmgr_client_listen_app_status(pkgmgr_client *pc, pkgmgr_app_handler event_cb,
1623 /* Check for NULL value of pc */
1624 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1625 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1627 /* 0. check input */
1628 retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING");
1629 retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL");
1632 req_id = _get_request_id();
1634 /* 2. add app callback info to pkgmgr_client */
1635 __add_app_stat_cbinfo(mpc, req_id, event_cb, data);
1639 API int pkgmgr_client_remove_listen_status(pkgmgr_client *pc)
1643 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1644 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1646 ret = __remove_stat_cbinfo(mpc);
1648 ERR("failed to remove status callback");
1649 return PKGMGR_R_ERROR;
1655 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
1656 const char *pkgid, const char *key,
1659 /* client cannot broadcast signal */
1663 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, int service_mode,
1664 pkgmgr_client *pc, const char *pkg_type, const char *pkgid,
1665 const char *custom_info, pkgmgr_handler event_cb, void *data)
1667 return pkgmgr_client_usr_request_service(service_type, service_mode, pc, pkg_type, pkgid, _getuid(), custom_info, event_cb, data);
1670 API int pkgmgr_client_usr_request_service(pkgmgr_request_service_type service_type, int service_mode,
1671 pkgmgr_client *pc, const char *pkg_type, const char *pkgid, uid_t uid,
1672 const char *custom_info, pkgmgr_handler event_cb, void *data)
1676 /* Check for NULL value of service type */
1677 retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
1678 retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n");
1680 switch (service_type) {
1681 case PM_REQUEST_MOVE:
1682 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1683 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1684 tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1686 ret = __move_pkg_process(pc, pkgid, pkg_type, uid, (pkgmgr_move_type)service_mode, event_cb, data);
1689 case PM_REQUEST_GET_SIZE:
1690 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1691 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1692 tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode >= PM_GET_MAX), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1694 ret = __get_size_process(pc, pkgid, uid, (pkgmgr_getsize_type)service_mode, event_cb, data);
1697 case PM_REQUEST_KILL_APP:
1698 case PM_REQUEST_CHECK_APP:
1699 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1700 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1702 ret = __check_app_process(service_type, pc, pkgid, uid, data);
1704 ERR("__check_app_process fail \n");
1711 ERR("Wrong Request\n");
1722 API int pkgmgr_client_usr_request_size_info(uid_t uid)
1725 pkgmgr_client *pc = NULL;
1727 pc = pkgmgr_client_new(PC_REQUEST);
1728 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "request pc is null\n");
1730 ret = __request_size_info(pc, uid);
1732 ERR("__request_size_info fail \n");
1734 pkgmgr_client_free(pc);
1738 API int pkgmgr_client_request_size_info(void) /* get all package size (data, total) */
1740 return pkgmgr_client_usr_request_size_info(_getuid());
1743 API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid)
1746 int ret = PKGMGR_R_ECOMM;
1747 pkgmgr_client_t *pc;
1749 if (pkgid == NULL) {
1750 ERR("invalid parameter");
1751 return PKGMGR_R_EINVAL;
1754 pc = pkgmgr_client_new(PC_REQUEST);
1756 ERR("out of memory");
1757 return PKGMGR_R_ESYSTEM;
1760 ret = comm_client_request(pc->info.request.cc, "clearcache",
1761 g_variant_new("(us)", uid, pkgid), &result);
1762 if (ret != PKGMGR_R_OK) {
1763 ERR("request failed: %d", ret);
1767 g_variant_get(result, "(i)", &ret);
1768 g_variant_unref(result);
1773 API int pkgmgr_client_clear_cache_dir(const char *pkgid)
1775 return pkgmgr_client_usr_clear_cache_dir(pkgid, _getuid());
1778 API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid)
1780 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, uid);
1783 API int pkgmgr_client_clear_all_cache_dir(void)
1785 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, _getuid());
1788 API int pkgmgr_client_get_size(pkgmgr_client *pc, const char *pkgid,
1789 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
1792 return pkgmgr_client_usr_get_size(pc, pkgid, get_type, event_cb, data,
1796 API int pkgmgr_client_usr_get_size(pkgmgr_client *pc, const char *pkgid,
1797 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
1798 void *data, uid_t uid)
1801 int ret = PKGMGR_R_ECOMM;
1802 char *req_key = NULL;
1804 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1806 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
1807 ERR("invalid parameter");
1808 return PKGMGR_R_EINVAL;
1811 if (mpc->ctype != PC_REQUEST) {
1812 ERR("mpc->ctype is not PC_REQUEST");
1813 return PKGMGR_R_EINVAL;
1817 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
1818 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
1820 get_type = PM_GET_PKG_SIZE_INFO;
1822 ret = comm_client_request(mpc->info.request.cc, "getsize",
1823 g_variant_new("(usi)", uid, pkgid, get_type), &result);
1824 if (ret != PKGMGR_R_OK) {
1825 ERR("request failed: %d", ret);
1829 g_variant_get(result, "(i&s)", &ret, &req_key);
1830 if (req_key == NULL) {
1831 g_variant_unref(result);
1832 return PKGMGR_R_ECOMM;
1834 if (ret != PKGMGR_R_OK) {
1835 g_variant_unref(result);
1839 req_id = _get_request_id();
1840 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1842 g_variant_unref(result);
1847 API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc,
1848 const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb,
1849 void *user_data, uid_t uid)
1852 int ret = PKGMGR_R_ECOMM;
1853 char *req_key = NULL;
1856 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1858 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
1859 ERR("invalid parameter");
1860 return PKGMGR_R_EINVAL;
1863 if (mpc->ctype != PC_REQUEST) {
1864 ERR("mpc->ctype is not PC_REQUEST");
1865 return PKGMGR_R_EINVAL;
1869 if (__change_op_cb_for_getsize(mpc) < 0) {
1870 ERR("__change_op_cb_for_getsize failed");
1871 return PKGMGR_R_ESYSTEM;
1874 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
1875 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
1877 get_type = PM_GET_PKG_SIZE_INFO;
1879 ret = comm_client_request(mpc->info.request.cc, "getsize",
1880 g_variant_new("(usi)", uid, pkgid, get_type), &result);
1881 if (ret != PKGMGR_R_OK) {
1882 ERR("request failed: %d", ret);
1886 g_variant_get(result, "(i&s)", &ret, &req_key);
1887 if (req_key == NULL) {
1888 g_variant_unref(result);
1889 return PKGMGR_R_ECOMM;
1891 if (ret != PKGMGR_R_OK) {
1892 g_variant_unref(result);
1896 req_id = _get_request_id();
1897 __add_op_cbinfo(mpc, req_id, req_key, __get_pkg_size_info_cb, event_cb,
1900 g_variant_unref(result);
1905 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)
1907 return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb, user_data, _getuid());
1910 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)
1911 { /* total package size info */
1912 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, uid);
1915 API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc, pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data)
1917 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, _getuid());
1920 API int pkgmgr_client_generate_license_request(pkgmgr_client *pc,
1921 const char *resp_data, char **req_data, char **license_url)
1927 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1929 if (pc == NULL || resp_data == NULL || req_data == NULL ||
1930 license_url == NULL) {
1931 ERR("invalid parameter");
1932 return PKGMGR_R_EINVAL;
1935 if (mpc->ctype != PC_REQUEST) {
1936 ERR("mpc->ctype is not PC_REQUEST");
1937 return PKGMGR_R_EINVAL;
1940 ret = comm_client_request(mpc->info.request.cc,
1941 "generate_license_request",
1942 g_variant_new("(s)", resp_data), &result);
1943 if (ret != PKGMGR_R_OK) {
1944 ERR("request failed: %d", ret);
1948 g_variant_get(result, "(i&s&s)", &ret, &data, &url);
1949 if (ret != PKGMGR_R_OK) {
1950 ERR("generate_license_request failed: %d", ret);
1951 g_variant_unref(result);
1955 *req_data = strdup(data);
1956 *license_url = strdup(url);
1958 g_variant_unref(result);
1963 API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data)
1967 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1969 if (pc == NULL || resp_data == NULL) {
1970 ERR("invalid parameter");
1971 return PKGMGR_R_EINVAL;
1974 if (mpc->ctype != PC_REQUEST) {
1975 ERR("mpc->ctype is not PC_REQUEST");
1976 return PKGMGR_R_EINVAL;
1979 ret = comm_client_request(mpc->info.request.cc,
1980 "register_license", g_variant_new("(s)", resp_data),
1982 if (ret != PKGMGR_R_OK) {
1983 ERR("request failed: %d", ret);
1987 g_variant_get(result, "(i)", &ret);
1988 g_variant_unref(result);
1989 if (ret != PKGMGR_R_OK) {
1990 ERR("register license failed: %d", ret);
1997 API int pkgmgr_client_decrypt_package(pkgmgr_client *pc,
1998 const char *drm_file_path, const char *decrypted_file_path)
2002 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2004 if (pc == NULL || drm_file_path == NULL ||
2005 decrypted_file_path == NULL) {
2006 ERR("invalid parameter");
2007 return PKGMGR_R_EINVAL;
2010 if (mpc->ctype != PC_REQUEST) {
2011 ERR("mpc->ctype is not PC_REQUEST");
2012 return PKGMGR_R_EINVAL;
2015 ret = comm_client_request(mpc->info.request.cc,
2017 g_variant_new("(ss)", drm_file_path,
2018 decrypted_file_path),
2020 if (ret != PKGMGR_R_OK) {
2021 ERR("request failed: %d", ret);
2025 g_variant_get(result, "(i)", &ret);
2026 g_variant_unref(result);
2027 if (ret != PKGMGR_R_OK) {
2028 ERR("decrypt_package failed: %d", ret);
2035 API int pkgmgr_client_enable_splash_screen(pkgmgr_client *pc, const char *appid)
2037 return pkgmgr_client_usr_enable_splash_screen(pc, appid, _getuid());
2040 API int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc,
2041 const char *appid, uid_t uid)
2045 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2047 if (pc == NULL || appid == NULL) {
2048 ERR("Invalid parameter");
2049 return PKGMGR_R_EINVAL;
2052 ret = __change_op_cb_for_enable_disable_splash_screen(mpc, true);
2054 ERR("__change_op_cb_for_enable_disable_splash_screen failed");
2055 return PKGMGR_R_ESYSTEM;
2058 ret = comm_client_request(mpc->info.request.cc,
2059 "enable_app_splash_screen",
2060 g_variant_new("(us)", uid, appid), &result);
2061 if (ret != PKGMGR_R_OK) {
2062 ERR("request failed: %d", ret);
2066 g_variant_get(result, "(i)", &ret);
2067 if (ret != PKGMGR_R_OK) {
2068 g_variant_unref(result);
2072 g_variant_unref(result);
2077 API int pkgmgr_client_disable_splash_screen(pkgmgr_client *pc,
2080 return pkgmgr_client_usr_disable_splash_screen(pc, appid,
2084 API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc,
2085 const char *appid, uid_t uid)
2089 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2091 if (pc == NULL || appid == NULL) {
2092 ERR("Invalid parameter");
2093 return PKGMGR_R_EINVAL;
2096 ret = __change_op_cb_for_enable_disable_splash_screen(mpc, false);
2098 ERR("__change_op_cb_for_enable_disable_splash_screen failed");
2102 ret = comm_client_request(mpc->info.request.cc,
2103 "disable_app_splash_screen",
2104 g_variant_new("(us)", uid, appid), &result);
2105 if (ret != PKGMGR_R_OK) {
2106 ERR("request failed: %d", ret);
2110 g_variant_get(result, "(i)", &ret);
2111 if (ret != PKGMGR_R_OK) {
2112 g_variant_unref(result);
2116 g_variant_unref(result);
2121 static int __set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2124 int ret = PKGMGR_R_ECOMM;
2125 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2127 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) {
2128 ERR("invalid parameter");
2129 return PKGMGR_R_EINVAL;
2132 ret = comm_client_request(mpc->info.request.cc, "set_restriction_mode",
2133 g_variant_new("(usi)", uid, pkgid, mode), &result);
2134 if (ret != PKGMGR_R_OK) {
2135 ERR("request failed: %d", ret);
2139 g_variant_get(result, "(i)", &ret);
2140 g_variant_unref(result);
2145 API int pkgmgr_client_usr_set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2147 return __set_pkg_restriction_mode(pc, pkgid, mode, uid);
2150 API int pkgmgr_client_set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode)
2152 return pkgmgr_client_usr_set_pkg_restriction_mode(pc, pkgid, mode, _getuid());
2155 static int __unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2158 int ret = PKGMGR_R_ECOMM;
2159 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2161 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) {
2162 ERR("invalid parameter");
2163 return PKGMGR_R_EINVAL;
2166 ret = comm_client_request(mpc->info.request.cc,
2167 "unset_restriction_mode",
2168 g_variant_new("(usi)", uid, pkgid, mode), &result);
2169 if (ret != PKGMGR_R_OK) {
2170 ERR("request failed: %d", ret);
2174 g_variant_get(result, "(i)", &ret);
2175 g_variant_unref(result);
2181 API int pkgmgr_client_usr_unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2183 return __unset_pkg_restriction_mode(pc, pkgid, mode, uid);
2186 API int pkgmgr_client_unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode)
2188 return pkgmgr_client_usr_unset_pkg_restriction_mode(pc, pkgid, mode, _getuid());
2191 static int __get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode, uid_t uid)
2194 int ret = PKGMGR_R_ECOMM;
2196 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2198 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0) {
2199 ERR("invalid parameter");
2200 return PKGMGR_R_EINVAL;
2203 ret = comm_client_request(mpc->info.request.cc,
2204 "get_restriction_mode",
2205 g_variant_new("(us)", uid, pkgid), &result);
2206 if (ret != PKGMGR_R_OK) {
2207 ERR("request failed: %d", ret);
2211 g_variant_get(result, "(ii)", &m, &ret);
2212 g_variant_unref(result);
2213 if (ret != PKGMGR_R_OK)
2221 API int pkgmgr_client_usr_get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode, uid_t uid)
2223 return __get_pkg_restriction_mode(pc, pkgid, mode, uid);
2226 API int pkgmgr_client_get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode)
2228 return pkgmgr_client_usr_get_pkg_restriction_mode(pc, pkgid, mode, _getuid());
2231 API int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode,
2235 int ret = PKGMGR_R_ECOMM;
2236 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2239 ERR("invalid parameter");
2240 return PKGMGR_R_EINVAL;
2243 ret = comm_client_request(mpc->info.request.cc, "set_restriction_mode",
2244 g_variant_new("(usi)", uid, "", mode), &result);
2245 if (ret != PKGMGR_R_OK) {
2246 ERR("request failed: %d", ret);
2250 g_variant_get(result, "(i)", &ret);
2251 g_variant_unref(result);
2256 API int pkgmgr_client_set_restriction_mode(pkgmgr_client *pc, int mode)
2258 return pkgmgr_client_usr_set_restriction_mode(pc, mode, _getuid());
2261 API int pkgmgr_client_usr_unset_restriction_mode(pkgmgr_client *pc, int mode,
2265 int ret = PKGMGR_R_ECOMM;
2266 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2269 ERR("invalid parameter");
2270 return PKGMGR_R_EINVAL;
2273 ret = comm_client_request(mpc->info.request.cc,
2274 "unset_restriction_mode",
2275 g_variant_new("(usi)", uid, "", mode), &result);
2276 if (ret != PKGMGR_R_OK) {
2277 ERR("request failed: %d", ret);
2281 g_variant_get(result, "(i)", &ret);
2282 g_variant_unref(result);
2287 API int pkgmgr_client_unset_restriction_mode(pkgmgr_client *pc, int mode)
2289 return pkgmgr_client_usr_unset_restriction_mode(pc, mode, _getuid());
2292 API int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc,
2293 int *mode, uid_t uid)
2296 int ret = PKGMGR_R_ECOMM;
2298 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2301 ERR("invalid parameter");
2302 return PKGMGR_R_EINVAL;
2305 ret = comm_client_request(mpc->info.request.cc,
2306 "get_restriction_mode",
2307 g_variant_new("(us)", uid, ""), &result);
2308 if (ret != PKGMGR_R_OK) {
2309 ERR("request failed: %d", ret);
2313 g_variant_get(result, "(ii)", &m, &ret);
2314 g_variant_unref(result);
2315 if (ret != PKGMGR_R_OK)
2323 API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc,
2326 return pkgmgr_client_usr_get_restriction_mode(pc, mode, _getuid());