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;
64 pkgmgr_app_handler app_event_cb;
66 struct _req_cb_info *next;
69 typedef struct _listen_cb_info {
71 pkgmgr_handler event_cb;
72 pkgmgr_app_handler app_event_cb;
74 struct _listen_cb_info *next;
77 typedef struct _pkgmgr_client_t {
87 listen_cb_info *lhead;
95 typedef struct _iter_data {
96 pkgmgr_iter_fn iter_fn;
100 static int __xsystem(const char *argv[])
107 perror("fork failed");
111 execvp(argv[0], (char *const *)argv);
117 if (waitpid(pid, &status, 0) == -1) {
118 perror("waitpid failed");
121 if (WIFSIGNALED(status)) {
125 if (!WIFEXITED(status)) {
126 /* shouldn't happen */
127 perror("should not happen");
130 return WEXITSTATUS(status);
133 static void __error_to_string(int errnumber, char **errstr)
138 case PKGCMD_ERR_PACKAGE_NOT_FOUND:
139 *errstr = PKGCMD_ERR_PACKAGE_NOT_FOUND_STR;
141 case PKGCMD_ERR_PACKAGE_INVALID:
142 *errstr = PKGCMD_ERR_PACKAGE_INVALID_STR;
144 case PKGCMD_ERR_PACKAGE_LOWER_VERSION:
145 *errstr = PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR;
147 case PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND:
148 *errstr = PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR;
150 case PKGCMD_ERR_MANIFEST_INVALID:
151 *errstr = PKGCMD_ERR_MANIFEST_INVALID_STR;
153 case PKGCMD_ERR_CONFIG_NOT_FOUND:
154 *errstr = PKGCMD_ERR_CONFIG_NOT_FOUND_STR;
156 case PKGCMD_ERR_CONFIG_INVALID:
157 *errstr = PKGCMD_ERR_CONFIG_INVALID_STR;
159 case PKGCMD_ERR_SIGNATURE_NOT_FOUND:
160 *errstr = PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR;
162 case PKGCMD_ERR_SIGNATURE_INVALID:
163 *errstr = PKGCMD_ERR_SIGNATURE_INVALID_STR;
165 case PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED:
166 *errstr = PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR;
168 case PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND:
169 *errstr = PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR;
171 case PKGCMD_ERR_CERTIFICATE_INVALID:
172 *errstr = PKGCMD_ERR_CERTIFICATE_INVALID_STR;
174 case PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
175 *errstr = PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR;
177 case PKGCMD_ERR_CERTIFICATE_EXPIRED:
178 *errstr = PKGCMD_ERR_CERTIFICATE_EXPIRED_STR;
180 case PKGCMD_ERR_INVALID_PRIVILEGE:
181 *errstr = PKGCMD_ERR_INVALID_PRIVILEGE_STR;
183 case PKGCMD_ERR_MENU_ICON_NOT_FOUND:
184 *errstr = PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR;
186 case PKGCMD_ERR_FATAL_ERROR:
187 *errstr = PKGCMD_ERR_FATAL_ERROR_STR;
189 case PKGCMD_ERR_OUT_OF_STORAGE:
190 *errstr = PKGCMD_ERR_OUT_OF_STORAGE_STR;
192 case PKGCMD_ERR_OUT_OF_MEMORY:
193 *errstr = PKGCMD_ERR_OUT_OF_MEMORY_STR;
195 case PKGCMD_ERR_ARGUMENT_INVALID:
196 *errstr = PKGCMD_ERR_ARGUMENT_INVALID_STR;
199 *errstr = PKGCMD_ERR_UNKNOWN_STR;
204 static void __add_op_cbinfo(pkgmgr_client_t * pc, int request_id,
205 const char *req_key, pkgmgr_handler event_cb, void *new_event_cb,
208 req_cb_info *cb_info;
209 req_cb_info *current;
212 cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
213 if (cb_info == NULL) {
214 DBG("calloc failed");
217 cb_info->request_id = request_id;
218 cb_info->req_key = strdup(req_key);
219 cb_info->event_cb = event_cb;
220 cb_info->data = data;
221 cb_info->next = NULL;
222 cb_info->app_event_cb = NULL;
223 pc->new_event_cb = new_event_cb;
225 if (pc->info.request.rhead == NULL)
226 pc->info.request.rhead = cb_info;
228 current = prev = pc->info.request.rhead;
231 current = current->next;
234 prev->next = cb_info;
238 static void __add_op_app_cbinfo(pkgmgr_client_t * pc, int request_id,
239 const char *req_key, pkgmgr_app_handler app_event_cb, void *data)
241 req_cb_info *cb_info;
242 req_cb_info *current;
245 cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
246 if (cb_info == NULL) {
247 DBG("calloc failed");
250 cb_info->request_id = request_id;
251 cb_info->req_key = strdup(req_key);
252 cb_info->event_cb = NULL;
253 cb_info->app_event_cb = app_event_cb;
254 cb_info->data = data;
255 cb_info->next = NULL;
256 pc->new_event_cb = NULL;
258 if (pc->info.request.rhead == NULL)
259 pc->info.request.rhead = cb_info;
261 current = prev = pc->info.request.rhead;
264 current = current->next;
267 prev->next = cb_info;
271 static req_cb_info *__find_op_cbinfo(pkgmgr_client_t *pc, const char *req_key)
275 tmp = pc->info.request.rhead;
282 DBG("tmp->req_key %s, req_key %s", tmp->req_key, req_key);
285 if (strncmp(tmp->req_key, req_key, strlen(tmp->req_key)) == 0)
292 static void __add_app_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
293 pkgmgr_app_handler event_cb, void *data)
295 listen_cb_info *cb_info;
296 listen_cb_info *current;
297 listen_cb_info *prev;
299 cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
300 if (cb_info == NULL) {
301 DBG("calloc failed");
304 cb_info->request_id = request_id;
305 cb_info->app_event_cb = event_cb;
306 cb_info->data = data;
307 cb_info->next = NULL;
309 if (pc->info.listening.lhead == NULL)
310 pc->info.listening.lhead = cb_info;
312 current = prev = pc->info.listening.lhead;
315 current = current->next;
318 prev->next = cb_info;
322 static void __add_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
323 pkgmgr_handler event_cb, void *data)
325 listen_cb_info *cb_info;
326 listen_cb_info *current;
327 listen_cb_info *prev;
329 cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
330 if (cb_info == NULL) {
331 DBG("calloc failed");
334 cb_info->request_id = request_id;
335 cb_info->event_cb = event_cb;
336 cb_info->data = data;
337 cb_info->next = NULL;
339 /* TODO - check the order of callback - FIFO or LIFO => Should be changed to LIFO */
340 if (pc->info.listening.lhead == NULL)
341 pc->info.listening.lhead = cb_info;
343 current = prev = pc->info.listening.lhead;
346 current = current->next;
349 prev->next = cb_info;
353 static void __operation_callback(void *cb_data, uid_t target_uid,
354 const char *req_id, const char *pkg_type,
355 const char *pkgid, const char *appid,
356 const char *key, const char *val)
359 req_cb_info *cb_info;
361 pc = (pkgmgr_client_t *) cb_data;
363 /* find callback info */
364 cb_info = __find_op_cbinfo(pc, req_id);
365 if (cb_info == NULL) {
366 ERR("cannot fint cb_info for req_id:%s", req_id);
371 if (appid != NULL && strlen(appid) != 0) {
372 /* run app callback */
373 if (pc->new_event_cb)
374 cb_info->app_event_cb(target_uid, cb_info->request_id,
375 pkg_type, pkgid, appid, key, val, pc,
378 cb_info->app_event_cb(target_uid, cb_info->request_id,
379 pkg_type, pkgid, appid, key, val, NULL,
382 /* run pkg callback */
383 if (pc->new_event_cb)
384 cb_info->event_cb(target_uid, cb_info->request_id,
385 pkg_type, pkgid, key, val, pc,
388 cb_info->event_cb(target_uid, cb_info->request_id,
389 pkg_type, pkgid, key, val, NULL,
396 static void __status_callback(void *cb_data, uid_t target_uid,
397 const char *req_id, const char *pkg_type,
398 const char *pkgid, const char *appid,
399 const char *key, const char *val)
404 pc = (pkgmgr_client_t *) cb_data;
406 tmp = pc->info.listening.lhead;
408 if (appid != NULL && strlen(appid) != 0) {
409 /* run app callback */
410 if (tmp->app_event_cb && tmp->app_event_cb(
411 target_uid, tmp->request_id, pkg_type, pkgid,
412 appid, key, val, NULL, tmp->data) != 0)
415 /* run pkg callback */
416 if (tmp->event_cb && tmp->event_cb(
417 target_uid, tmp->request_id, pkg_type, pkgid,
418 key, val, NULL, tmp->data) != 0)
427 static inline int __read_proc(const char *path, char *buf, int size)
432 if (buf == NULL || path == NULL)
435 fd = open(path, O_RDONLY);
439 ret = read(fd, buf, size - 1);
451 char *__proc_get_cmdline_bypid(int pid)
453 char buf[PKG_STRING_LEN_MAX] = {'\0', };
456 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
457 ret = __read_proc(buf, buf, sizeof(buf));
461 /* support app launched by shell script*/
462 if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0)
463 return strdup(&buf[BINSH_SIZE + 1]);
468 static inline int __pkgmgr_read_proc(const char *path, char *buf, int size)
473 if (buf == NULL || path == NULL)
476 fd = open(path, O_RDONLY);
480 ret = read(fd, buf, size - 1);
492 static inline int __pkgmgr_find_pid_by_cmdline(const char *dname,
493 const char *cmdline, const char *apppath)
497 if (strncmp(cmdline, apppath, PKG_STRING_LEN_MAX-1) == 0) {
499 if (pid != getpgid(pid))
506 static int __sync_process(const char *req_key)
509 char info_file[PKG_STRING_LEN_MAX] = {'\0', };
513 char buf[PKG_STRING_LEN_MAX] = {0, };
515 snprintf(info_file, PKG_STRING_LEN_MAX, "%s/%s", PKG_SIZE_INFO_PATH, req_key);
520 if (access(info_file, F_OK) == 0) {
521 fp = fopen(info_file, "r");
523 DBG("file is not generated yet.... wait\n");
524 usleep(100 * 1000); /* 100ms sleep*/
528 if (fgets(buf, PKG_STRING_LEN_MAX, fp) == NULL) {
529 ERR("failed to read info file");
535 DBG("info_file file is generated, result = %s. \n", buf);
540 DBG("file is not generated yet.... wait\n");
541 usleep(100 * 1000); /* 100ms sleep*/
543 if (check_cnt > 6000) { /* 60s * 10 time over*/
544 ERR("wait time over!!\n");
549 ret = remove(info_file);
551 ERR("file is can not remove[%s, %d]\n", info_file, ret);
556 static int __csc_process(const char *csc_path, char *result_path)
563 char *pkgtype = NULL;
565 char buf[PKG_STRING_LEN_MAX] = {0,};
566 char type_buf[1024] = { 0 };
567 char des_buf[1024] = { 0 };
568 dictionary *csc = NULL;
571 csc = iniparser_load(csc_path);
572 retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path);
574 file = fopen(result_path, "w");
575 tryvm_if(file == NULL, ret = PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path);
577 count = iniparser_getint(csc, "csc packages:count", -1);
578 tryvm_if(count == 0, ret = PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path);
580 snprintf(buf, PKG_STRING_LEN_MAX, "[result]\n");
581 fwrite(buf, 1, strlen(buf), file);
582 snprintf(buf, PKG_STRING_LEN_MAX, "count = %d\n", count);
583 fwrite(buf, 1, strlen(buf), file);
585 for(cnt = 1 ; cnt <= count ; cnt++)
587 snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt);
588 snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt);
590 pkgtype = iniparser_getstring(csc, type_buf, NULL);
591 des = iniparser_getstring(csc, des_buf, NULL);
594 if (pkgtype == NULL) {
596 snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get pkgtype\n", type_buf);
597 fwrite(buf, 1, strlen(buf), file);
599 } else if (des == NULL) {
601 snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get description\n", des_buf);
602 fwrite(buf, 1, strlen(buf), file);
606 snprintf(buf, PKG_STRING_LEN_MAX, "type_%03d = %s\n", cnt, pkgtype);
607 fwrite(buf, 1, strlen(buf), file);
608 snprintf(buf, PKG_STRING_LEN_MAX, "description_%03d = %s\n", cnt, des);
609 fwrite(buf, 1, strlen(buf), file);
611 if (strcmp(pkgtype, "tpk") == 0) {
612 const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL };
613 ret = __xsystem(ospinstaller_argv);
614 } else if (strcmp(pkgtype, "wgt")== 0) {
615 const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL };
616 ret = __xsystem(wrtinstaller_argv);
624 __error_to_string(ret, &errstr);
625 snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = fail[%s]\n", cnt, errstr);
628 snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = success\n", cnt);
630 fwrite(buf, 1, strlen(buf), file);
634 iniparser_freedict(csc);
644 static int __get_size_process(pkgmgr_client * pc, const char *pkgid, uid_t uid,
645 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
649 int ret = PKGMGR_R_ECOMM;
650 char *req_key = NULL;
651 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
653 if (pc == NULL || pkgid == NULL) {
654 ERR("invalid parameter");
655 return PKGMGR_R_EINVAL;
658 if (mpc->ctype != PC_REQUEST) {
659 ERR("mpc->ctype is not PC_REQUEST");
660 return PKGMGR_R_EINVAL;
662 result = comm_client_request(mpc->info.request.cc, "getsize",
663 g_variant_new("(usi)", uid, pkgid, get_type));
665 return PKGMGR_R_ECOMM;
667 g_variant_get(result, "(i&s)", &ret, &req_key);
668 if (req_key == NULL) {
669 g_variant_unref(result);
670 return PKGMGR_R_ECOMM;
672 if (ret != PKGMGR_R_OK) {
673 g_variant_unref(result);
677 ret = __sync_process(req_key);
679 ERR("get size failed, ret=%d\n", ret);
681 g_variant_unref(result);
686 static int __move_pkg_process(pkgmgr_client *pc, const char *pkgid,
687 const char *pkg_type, uid_t uid, pkgmgr_move_type move_type,
688 pkgmgr_handler event_cb, void *data)
692 ret = pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, 0, uid);
694 ERR("move request failed");
699 ret = __sync_process(pkgid);
701 ERR("move pkg failed, ret=%d\n", ret);
706 static int __check_app_process(pkgmgr_request_service_type service_type,
707 pkgmgr_client *pc, const char *pkgid, uid_t uid, void *data)
709 GVariant *result = NULL;
710 int ret = PKGMGR_R_ECOMM;
711 pkgmgrinfo_pkginfo_h handle;
713 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
715 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
717 if (uid != GLOBAL_USER)
718 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
720 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
721 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgrinfo_pkginfo_get_pkginfo failed");
723 if (service_type == PM_REQUEST_KILL_APP)
724 result = comm_client_request(mpc->info.request.cc, "kill",
725 g_variant_new("(us)", uid, pkgid));
726 else if (service_type == PM_REQUEST_CHECK_APP)
727 result = comm_client_request(mpc->info.request.cc, "check",
728 g_variant_new("(us)", uid, pkgid));
731 return PKGMGR_R_ECOMM;
732 g_variant_get(result, "(i)", &ret);
733 g_variant_unref(result);
734 if (ret != PKGMGR_R_OK) {
735 ERR("request failed, ret=%d", ret);
740 pid = __sync_process(pkgid);
743 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
749 static int __request_size_info(pkgmgr_client *pc, uid_t uid)
752 int ret = PKGMGR_R_ECOMM;
753 char *req_key = NULL;
754 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
757 ERR("invalid parameter");
758 return PKGMGR_R_EINVAL;
761 if (mpc->ctype != PC_REQUEST) {
762 ERR("mpc->ctype is not PC_REQUEST");
763 return PKGMGR_R_EINVAL;
766 result = comm_client_request(mpc->info.request.cc, "getsize",
767 g_variant_new("(usi)", uid, "size_info", PM_GET_SIZE_INFO));
769 return PKGMGR_R_ECOMM;
771 g_variant_get(result, "(i&s)", &ret, &req_key);
772 if (req_key == NULL) {
773 g_variant_unref(result);
774 return PKGMGR_R_ECOMM;
777 g_variant_unref(result);
782 static int __change_op_cb_for_getsize(pkgmgr_client *pc)
786 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
787 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
789 /* free listening head */
790 req_cb_info *tmp = NULL;
791 req_cb_info *prev = NULL;
792 for (tmp = mpc->info.request.rhead; tmp;) {
798 /* free dbus connection */
799 ret = comm_client_free(mpc->info.request.cc);
800 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
802 /* Manage pc for seperated event */
803 mpc->ctype = PC_REQUEST;
804 mpc->status_type = PKGMGR_CLIENT_STATUS_GET_SIZE;
807 mpc->info.request.cc = comm_client_new();
808 retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
810 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_GET_SIZE, mpc->info.request.cc, __operation_callback, pc);
811 retvm_if(ret < 0, PKGMGR_R_ERROR, "set_status_callback() failed - %d", ret);
816 static int __change_op_cb_for_enable_disable(pkgmgr_client *pc, bool is_disable)
820 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
821 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
823 /* free listening head */
824 req_cb_info *tmp = NULL;
825 req_cb_info *prev = NULL;
826 for (tmp = mpc->info.request.rhead; tmp;) {
832 /* free dbus connection */
833 ret = comm_client_free(mpc->info.request.cc);
834 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
836 /* Manage pc for seperated event */
837 mpc->ctype = PC_REQUEST;
839 mpc->status_type = PKGMGR_CLIENT_STATUS_DISABLE_APP;
841 mpc->status_type = PKGMGR_CLIENT_STATUS_ENABLE_APP;
844 mpc->info.request.cc = comm_client_new();
845 retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
848 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_DISABLE_APP, mpc->info.request.cc, __operation_callback, pc);
850 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ENABLE_APP, mpc->info.request.cc, __operation_callback, pc);
851 retvm_if(ret < 0, PKGMGR_R_ERROR, "set_status_callback() failed - %d", ret);
856 static int __get_pkg_size_info_cb(uid_t target_uid, int req_id, const char *req_type,
857 const char *pkgid, const char *key,
858 const char *value, const void *pc, void *user_data)
861 DBG("target_uid: %u, reqid: %d, req type: %s, pkgid: %s, unused key: %s, size info: %s",
862 target_uid, req_id, req_type, pkgid, key, value);
864 pkg_size_info_t *size_info = (pkg_size_info_t *)malloc(sizeof(pkg_size_info_t));
865 retvm_if(size_info == NULL, -1, "The memory is insufficient.");
867 char *save_ptr = NULL;
868 char *token = strtok_r((char*)value, ":", &save_ptr);
869 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
870 size_info->data_size = atoll(token);
871 token = strtok_r(NULL, ":", &save_ptr);
872 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
873 size_info->cache_size = atoll(token);
874 token = strtok_r(NULL, ":", &save_ptr);
875 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
876 size_info->app_size = atoll(token);
877 token = strtok_r(NULL, ":", &save_ptr);
878 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
879 size_info->ext_data_size = atoll(token);
880 token = strtok_r(NULL, ":", &save_ptr);
881 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
882 size_info->ext_cache_size = atoll(token);
883 token = strtok_r(NULL, ":", &save_ptr);
884 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
885 size_info->ext_app_size = atoll(token);
887 DBG("data: %lld, cache: %lld, app: %lld, ext_data: %lld, ext_cache: %lld, ext_app: %lld",
888 size_info->data_size, size_info->cache_size, size_info->app_size,
889 size_info->ext_data_size, size_info->ext_cache_size, size_info->ext_app_size);
891 pkgmgr_client_t *pmc = (pkgmgr_client_t *)pc;
892 tryvm_if(pmc == NULL, ret = -1, "pkgmgr_client instance is null.");
894 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
895 { // total package size info
896 pkgmgr_total_pkg_size_info_receive_cb callback = (pkgmgr_total_pkg_size_info_receive_cb)(pmc->new_event_cb);
897 callback((pkgmgr_client *)pc, size_info, user_data);
901 pkgmgr_pkg_size_info_receive_cb callback = (pkgmgr_pkg_size_info_receive_cb)(pmc->new_event_cb);
902 callback((pkgmgr_client *)pc, pkgid, size_info, user_data);
914 API pkgmgr_client *pkgmgr_client_new(client_type ctype)
916 pkgmgr_client_t *pc = NULL;
919 retvm_if(ctype == PC_BROADCAST, NULL, "broadcast type is not supported");
920 retvm_if(ctype != PC_REQUEST && ctype != PC_LISTENING, NULL, "ctype is not client_type");
922 /* Allocate memory for ADT:pkgmgr_client */
923 pc = calloc(1, sizeof(pkgmgr_client_t));
924 retvm_if(pc == NULL, NULL, "No memory");
928 pc->status_type = PKGMGR_CLIENT_STATUS_ALL;
931 if (pc->ctype == PC_REQUEST) {
932 pc->info.request.cc = comm_client_new();
933 trym_if(pc->info.request.cc == NULL, "client creation failed");
935 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.request.cc, __operation_callback, pc);
936 trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
937 } else if (pc->ctype == PC_LISTENING) {
938 pc->info.listening.cc = comm_client_new();
939 trym_if(pc->info.listening.cc == NULL, "client creation failed");
941 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.listening.cc, __status_callback, pc);
942 trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
945 return (pkgmgr_client *) pc;
953 API int pkgmgr_client_free(pkgmgr_client *pc)
956 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
957 retvm_if(mpc == NULL, PKGMGR_R_EINVAL, "Invalid argument");
959 if (mpc->ctype == PC_REQUEST) {
962 for (tmp = mpc->info.request.rhead; tmp;) {
968 ret = comm_client_free(mpc->info.request.cc);
969 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed");
970 } else if (mpc->ctype == PC_LISTENING) {
972 listen_cb_info *prev;
973 for (tmp = mpc->info.listening.lhead; tmp;) {
979 ret = comm_client_free(mpc->info.listening.cc);
980 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed");
981 } else if (mpc->ctype == PC_BROADCAST) {
984 ERR("Invalid client type\n");
985 return PKGMGR_R_EINVAL;
990 mpc->tep_path = NULL;
995 mpc->tep_move = NULL;
1007 return PKGMGR_R_ERROR;
1010 static char *__get_type_from_path(const char *pkg_path)
1013 char mimetype[255] = { '\0', };
1014 char extlist[256] = { '\0', };
1017 ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype));
1019 ERR("_get_mime_from_file() failed - error code[%d]\n", ret);
1023 ret = _get_mime_extension(mimetype, extlist, sizeof(extlist));
1025 ERR("_get_mime_extension() failed - error code[%d]\n", ret);
1029 if (strlen(extlist) == 0)
1032 if (strchr(extlist, ','))
1033 extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0';
1035 pkg_type = strchr(extlist, '.') + 1;
1036 return strdup(pkg_type);
1039 API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, char *tep_path, char *tep_move)
1041 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1042 retvm_if(tep_path == NULL, PKGMGR_R_EINVAL, "tep path is NULL");
1043 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1045 mpc->tep_path = strdup(tep_path);
1046 mpc->tep_move = strdup(tep_move);
1051 API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type,
1052 const char *descriptor_path, const char *pkg_path,
1053 const char *optional_data, pkgmgr_mode mode,
1054 pkgmgr_handler event_cb, void *data, uid_t uid)
1057 int ret = PKGMGR_R_ECOMM;
1058 char *req_key = NULL;
1059 GVariantBuilder *builder = NULL;
1060 GVariant *args = NULL;
1062 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1065 if (pc == NULL || pkg_path == NULL) {
1066 ERR("invalid parameter");
1067 return PKGMGR_R_EINVAL;
1070 if (mpc->ctype != PC_REQUEST) {
1071 ERR("mpc->ctype is not PC_REQUEST");
1072 return PKGMGR_R_EINVAL;
1075 if (access(pkg_path, F_OK) != 0) {
1076 ERR("failed to access: %s", pkg_path);
1077 return PKGMGR_R_EINVAL;
1080 if (mpc->tep_path != NULL && access(mpc->tep_path, F_OK) != 0) {
1081 ERR("failed to access: %s", mpc->tep_path);
1082 return PKGMGR_R_EINVAL;
1085 /* TODO: check pkg's type on server-side */
1086 if (pkg_type == NULL)
1087 pkgtype = __get_type_from_path(pkg_path);
1089 pkgtype = strdup(pkg_type);
1091 /* build arguments */
1092 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1093 if (mpc->tep_path) {
1094 g_variant_builder_add(builder, "s", "-e");
1095 g_variant_builder_add(builder, "s", mpc->tep_path);
1096 g_variant_builder_add(builder, "s", "-M");
1097 g_variant_builder_add(builder, "s", mpc->tep_move);
1100 args = g_variant_new("as", builder);
1101 g_variant_builder_unref(builder);
1103 result = comm_client_request(mpc->info.request.cc, "install",
1104 g_variant_new("(uss@as)", uid, pkgtype, pkg_path, args));
1107 return PKGMGR_R_ECOMM;
1108 g_variant_get(result, "(i&s)", &ret, &req_key);
1109 if (req_key == NULL) {
1110 g_variant_unref(result);
1111 return PKGMGR_R_ECOMM;
1113 if (ret != PKGMGR_R_OK) {
1114 g_variant_unref(result);
1118 req_id = _get_request_id();
1119 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1121 g_variant_unref(result);
1126 API int pkgmgr_client_install(pkgmgr_client *pc, const char *pkg_type,
1127 const char *descriptor_path, const char *pkg_path,
1128 const char *optional_data, pkgmgr_mode mode,
1129 pkgmgr_handler event_cb, void *data)
1131 return pkgmgr_client_usr_install(pc, pkg_type, descriptor_path,
1132 pkg_path, optional_data, mode, event_cb,data,
1136 API int pkgmgr_client_reinstall(pkgmgr_client *pc, const char *pkg_type,
1137 const char *pkgid, const char *optional_data, pkgmgr_mode mode,
1138 pkgmgr_handler event_cb, void *data)
1140 return pkgmgr_client_usr_reinstall(pc, pkg_type, pkgid, optional_data,
1141 mode, event_cb, data,GLOBAL_USER);
1144 API int pkgmgr_client_usr_reinstall(pkgmgr_client * pc, const char *pkg_type,
1145 const char *pkgid, const char *optional_data, pkgmgr_mode mode,
1146 pkgmgr_handler event_cb, void *data, uid_t uid)
1149 int ret = PKGMGR_R_ECOMM;
1150 char *req_key = NULL;
1152 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1154 pkgmgrinfo_pkginfo_h handle;
1156 if (pc == NULL || pkgid == NULL) {
1157 ERR("invalid parameter");
1158 return PKGMGR_R_EINVAL;
1161 if (mpc->ctype != PC_REQUEST) {
1162 ERR("mpc->ctype is not PC_REQUEST");
1163 return PKGMGR_R_EINVAL;
1166 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
1168 return PKGMGR_R_EINVAL;
1170 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
1172 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1173 return PKGMGR_R_ERROR;
1176 result = comm_client_request(mpc->info.request.cc, "reinstall",
1177 g_variant_new("(uss)", uid, pkgtype, pkgid));
1178 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1180 return PKGMGR_R_ECOMM;
1181 g_variant_get(result, "(i&s)", &ret, &req_key);
1182 if (req_key == NULL) {
1183 g_variant_unref(result);
1184 return PKGMGR_R_ECOMM;
1186 if (ret != PKGMGR_R_OK) {
1187 g_variant_unref(result);
1191 req_id = _get_request_id();
1192 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1194 g_variant_unref(result);
1199 API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
1200 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
1203 return pkgmgr_client_usr_uninstall(pc, pkg_type,pkgid, mode, event_cb,
1207 API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type,
1208 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
1209 void *data, uid_t uid)
1212 int ret = PKGMGR_R_ECOMM;
1213 char *req_key = NULL;
1215 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1217 pkgmgrinfo_pkginfo_h handle;
1219 if (pc == NULL || pkgid == NULL) {
1220 ERR("invalid parameter");
1221 return PKGMGR_R_EINVAL;
1224 if (mpc->ctype != PC_REQUEST) {
1225 ERR("mpc->ctype is not PC_REQUEST");
1226 return PKGMGR_R_EINVAL;
1229 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
1231 return PKGMGR_R_EINVAL;
1233 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
1235 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1236 return PKGMGR_R_ERROR;
1239 /* TODO: check removable ? */
1241 result = comm_client_request(mpc->info.request.cc, "uninstall",
1242 g_variant_new("(uss)", uid, pkgtype, pkgid));
1243 if (result == NULL) {
1244 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1245 return PKGMGR_R_ECOMM;
1247 g_variant_get(result, "(i&s)", &ret, &req_key);
1248 if (req_key == NULL) {
1249 g_variant_unref(result);
1250 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1251 return PKGMGR_R_ECOMM;
1253 if (ret != PKGMGR_R_OK) {
1254 g_variant_unref(result);
1255 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1259 req_id = _get_request_id();
1260 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1262 g_variant_unref(result);
1263 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1268 API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
1269 const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode)
1271 return pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, mode,
1274 API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type,
1275 const char *pkgid, pkgmgr_move_type move_type,
1276 pkgmgr_mode mode, uid_t uid)
1279 int ret = PKGMGR_R_ECOMM;
1280 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1282 if (pc == NULL || pkg_type == NULL || pkgid == NULL) {
1283 ERR("invalid parameter");
1284 return PKGMGR_R_EINVAL;
1287 if ((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD))
1288 return PKGMGR_R_EINVAL;
1290 if (mpc->ctype != PC_REQUEST) {
1291 ERR("mpc->ctype is not PC_REQUEST");
1292 return PKGMGR_R_EINVAL;
1295 result = comm_client_request(mpc->info.request.cc, "move",
1296 g_variant_new("(uss)", uid, pkg_type, pkgid));
1298 return PKGMGR_R_ECOMM;
1299 g_variant_get(result, "(i)", &ret);
1300 g_variant_unref(result);
1305 API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type,
1306 const char *pkgid, uid_t uid)
1309 int ret = PKGMGR_R_ECOMM;
1310 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1312 if (pc == NULL || pkgid == NULL || pkg_type == NULL) {
1313 ERR("invalid parameter");
1314 return PKGMGR_R_EINVAL;
1317 result = comm_client_request(mpc->info.request.cc, "enable_pkg",
1318 g_variant_new("(uss)", uid, pkg_type, pkgid));
1320 return PKGMGR_R_ECOMM;
1321 g_variant_get(result, "(i)", &ret);
1322 g_variant_unref(result);
1327 API int pkgmgr_client_activate(pkgmgr_client *pc, const char *pkg_type,
1330 return pkgmgr_client_usr_activate(pc, pkg_type, pkgid, GLOBAL_USER);
1333 API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type,
1334 const char *pkgid, uid_t uid)
1337 int ret = PKGMGR_R_ECOMM;
1338 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1340 if (pc == NULL || pkgid == NULL || pkg_type == NULL) {
1341 ERR("invalid parameter");
1342 return PKGMGR_R_EINVAL;
1345 result = comm_client_request(mpc->info.request.cc, "disable_pkg",
1346 g_variant_new("(uss)", uid, pkg_type, pkgid));
1348 return PKGMGR_R_ECOMM;
1349 g_variant_get(result, "(i)", &ret);
1350 g_variant_unref(result);
1355 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
1358 return pkgmgr_client_usr_deactivate(pc, pkg_type, pkgid, GLOBAL_USER);
1361 /* TODO: deprecate? */
1362 API int pkgmgr_client_usr_activate_appv(pkgmgr_client *pc, const char *appid,
1363 char *const argv[], uid_t uid)
1365 return pkgmgr_client_usr_activate_app(pc, appid, NULL, uid);
1368 API int pkgmgr_client_activate_appv(pkgmgr_client *pc, const char *appid,
1371 return pkgmgr_client_usr_activate_app(pc, appid, NULL, GLOBAL_USER);
1374 API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid,
1375 pkgmgr_app_handler app_event_cb, uid_t uid)
1378 int ret = PKGMGR_R_ECOMM;
1380 char *req_key = NULL;
1381 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1383 if (pc == NULL || appid == NULL) {
1384 ERR("invalid parameter");
1385 return PKGMGR_R_EINVAL;
1388 if (__change_op_cb_for_enable_disable(mpc, false) < 0) {
1389 ERR("__change_op_cb_for_enable_disable failed");
1390 return PKGMGR_R_ESYSTEM;
1393 result = comm_client_request(mpc->info.request.cc, "enable_app",
1394 g_variant_new("(us)", uid, appid));
1396 return PKGMGR_R_ECOMM;
1397 g_variant_get(result, "(i&s)", &ret, &req_key);
1398 if (req_key == NULL) {
1399 g_variant_unref(result);
1400 return PKGMGR_R_ECOMM;
1402 if (ret != PKGMGR_R_OK) {
1403 g_variant_unref(result);
1407 req_id = _get_request_id();
1408 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1409 g_variant_unref(result);
1413 API int pkgmgr_client_activate_app(pkgmgr_client * pc, const char *appid, pkgmgr_app_handler app_event_cb)
1415 return pkgmgr_client_usr_activate_app(pc, appid, app_event_cb, GLOBAL_USER);
1418 API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc,
1419 const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid)
1422 int ret = PKGMGR_R_ECOMM;
1424 char *req_key = NULL;
1425 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1427 if (pc == NULL || appid == NULL) {
1428 ERR("invalid parameter");
1429 return PKGMGR_R_EINVAL;
1432 if (__change_op_cb_for_enable_disable(mpc, false) < 0) {
1433 ERR("__change_op_cb_for_enable_disable failed");
1434 return PKGMGR_R_ESYSTEM;
1437 result = comm_client_request(mpc->info.request.cc, "enable_global_app_for_uid",
1438 g_variant_new("(us)", uid, appid));
1440 return PKGMGR_R_ECOMM;
1441 g_variant_get(result, "(i&s)", &ret, &req_key);
1442 if (req_key == NULL) {
1443 g_variant_unref(result);
1444 return PKGMGR_R_ECOMM;
1446 if (ret != PKGMGR_R_OK) {
1447 g_variant_unref(result);
1451 req_id = _get_request_id();
1452 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1457 API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid,
1458 pkgmgr_app_handler app_event_cb, uid_t uid)
1461 int ret = PKGMGR_R_ECOMM;
1462 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1464 char *req_key = NULL;
1466 if (pc == NULL || appid == NULL) {
1467 ERR("invalid parameter");
1468 return PKGMGR_R_EINVAL;
1472 if (__change_op_cb_for_enable_disable(mpc, true) < 0) {
1473 ERR("__change_op_cb_for_enable_disable failed");
1474 return PKGMGR_R_ESYSTEM;
1477 result = comm_client_request(mpc->info.request.cc, "disable_app",
1478 g_variant_new("(us)", uid, appid));
1481 return PKGMGR_R_ECOMM;
1482 g_variant_get(result, "(i&s)", &ret, &req_key);
1483 if (req_key == NULL) {
1484 g_variant_unref(result);
1485 return PKGMGR_R_ECOMM;
1487 if (ret != PKGMGR_R_OK) {
1488 g_variant_unref(result);
1492 req_id = _get_request_id();
1493 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1495 g_variant_unref(result);
1499 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid, pkgmgr_app_handler app_event_cb)
1501 return pkgmgr_client_usr_deactivate_app(pc, appid, app_event_cb, GLOBAL_USER);
1504 API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc,
1505 const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid)
1508 int ret = PKGMGR_R_ECOMM;
1510 char *req_key = NULL;
1511 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1513 if (pc == NULL || appid == NULL) {
1514 ERR("invalid parameter");
1515 return PKGMGR_R_EINVAL;
1518 if (__change_op_cb_for_enable_disable(mpc, true) < 0) {
1519 ERR("__change_op_cb_for_enable_disable failed");
1520 return PKGMGR_R_ESYSTEM;
1523 result = comm_client_request(mpc->info.request.cc, "disable_global_app_for_uid",
1524 g_variant_new("(us)", uid, appid));
1527 return PKGMGR_R_ECOMM;
1528 g_variant_get(result, "(i&s)", &ret, &req_key);
1529 if (req_key == NULL) {
1530 g_variant_unref(result);
1531 return PKGMGR_R_ECOMM;
1533 if (ret != PKGMGR_R_OK) {
1534 g_variant_unref(result);
1538 req_id = _get_request_id();
1539 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1543 API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc,
1544 const char *pkg_type, const char *appid, pkgmgr_mode mode,
1548 int ret = PKGMGR_R_ECOMM;
1549 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1551 if (pc == NULL || pkg_type == NULL || appid == NULL) {
1552 ERR("invalid parameter");
1553 return PKGMGR_R_EINVAL;
1556 if (mpc->ctype != PC_REQUEST) {
1557 ERR("mpc->ctype is not PC_REQUEST");
1558 return PKGMGR_R_EINVAL;
1561 result = comm_client_request(mpc->info.request.cc, "cleardata",
1562 g_variant_new("(uss)", uid, pkg_type, appid));
1564 return PKGMGR_R_ECOMM;
1566 g_variant_get(result, "(i)", &ret);
1567 g_variant_unref(result);
1572 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
1573 const char *appid, pkgmgr_mode mode)
1575 return pkgmgr_client_usr_clear_user_data(pc, pkg_type, appid, mode,
1579 API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type)
1583 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1584 retvm_if(status_type == PKGMGR_CLIENT_STATUS_ALL, PKGMGR_R_OK, "status_type is PKGMGR_CLIENT_STATUS_ALL");
1585 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1587 /* free listening head */
1588 listen_cb_info *tmp = NULL;
1589 listen_cb_info *prev = NULL;
1590 for (tmp = mpc->info.listening.lhead; tmp;) {
1596 /* free dbus connection */
1597 ret = comm_client_free(mpc->info.listening.cc);
1598 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
1600 /* Manage pc for seperated event */
1601 mpc->ctype = PC_LISTENING;
1602 mpc->status_type = status_type;
1604 mpc->info.listening.cc = comm_client_new();
1605 retvm_if(mpc->info.listening.cc == NULL, PKGMGR_R_EINVAL, "client creation failed");
1607 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL) == PKGMGR_CLIENT_STATUS_INSTALL) {
1608 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_INSTALL, mpc->info.listening.cc, __status_callback, pc);
1609 retvm_if(ret < 0, PKGMGR_R_ECOMM, "PKGMGR_CLIENT_STATUS_INSTALL failed - %d", ret);
1612 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_UNINSTALL) == PKGMGR_CLIENT_STATUS_UNINSTALL) {
1613 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_UNINSTALL, mpc->info.listening.cc, __status_callback, pc);
1614 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_UNINSTALL failed - %d", ret);
1617 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_MOVE) == PKGMGR_CLIENT_STATUS_MOVE) {
1618 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_MOVE, mpc->info.listening.cc, __status_callback, pc);
1619 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_MOVE failed - %d", ret);
1622 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS) == PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS) {
1623 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_INSTALL_PROGRESS, mpc->info.listening.cc, __status_callback, pc);
1624 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_INSTALL_PROGRESS failed - %d", ret);
1627 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_UPGRADE) == PKGMGR_CLIENT_STATUS_UPGRADE) {
1628 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_UPGRADE, mpc->info.listening.cc, __status_callback, pc);
1629 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_UPGRADE failed - %d", ret);
1632 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_ENABLE_APP) == PKGMGR_CLIENT_STATUS_ENABLE_APP) {
1633 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ENABLE_APP, mpc->info.listening.cc, __status_callback, pc);
1634 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_ENABLE_APP failed - %d", ret);
1637 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_DISABLE_APP) == PKGMGR_CLIENT_STATUS_DISABLE_APP) {
1638 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_DISABLE_APP, mpc->info.listening.cc, __status_callback, pc);
1639 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_DISABLE_APP failed - %d", ret);
1645 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
1649 /* Check for NULL value of pc */
1650 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1651 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1653 /* 0. check input */
1654 retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING");
1655 retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL");
1658 req_id = _get_request_id();
1660 /* 2. add callback info to pkgmgr_client */
1661 __add_stat_cbinfo(mpc, req_id, event_cb, data);
1665 API int pkgmgr_client_listen_app_status(pkgmgr_client *pc, pkgmgr_app_handler event_cb,
1669 /* Check for NULL value of pc */
1670 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1671 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1673 /* 0. check input */
1674 retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING");
1675 retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL");
1678 req_id = _get_request_id();
1680 /* 2. add app callback info to pkgmgr_client */
1681 __add_app_stat_cbinfo(mpc, req_id, event_cb, data);
1685 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
1686 const char *pkgid, const char *key,
1689 /* client cannot broadcast signal */
1693 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, int service_mode,
1694 pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
1695 const char *custom_info, pkgmgr_handler event_cb, void *data)
1697 return pkgmgr_client_usr_request_service(service_type, service_mode, pc, pkg_type, pkgid, GLOBAL_USER, custom_info, event_cb, data);
1700 API int pkgmgr_client_usr_request_service(pkgmgr_request_service_type service_type, int service_mode,
1701 pkgmgr_client * pc, const char *pkg_type, const char *pkgid, uid_t uid,
1702 const char *custom_info, pkgmgr_handler event_cb, void *data)
1706 /* Check for NULL value of service type */
1707 retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
1708 retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n");
1710 switch (service_type) {
1711 case PM_REQUEST_CSC:
1712 tryvm_if(custom_info == NULL, ret = PKGMGR_R_EINVAL, "custom_info is NULL\n");
1713 tryvm_if(strlen(custom_info) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "custom_info over PKG_STRING_LEN_MAX");
1714 tryvm_if(data == NULL, ret = PKGMGR_R_EINVAL, "data is NULL\n");
1716 ret = __csc_process(custom_info, (char *)data);
1718 ERR("__csc_process fail \n");
1724 case PM_REQUEST_MOVE:
1725 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1726 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1727 tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1729 ret = __move_pkg_process(pc, pkgid, pkg_type, uid, (pkgmgr_move_type)service_mode, event_cb, data);
1732 case PM_REQUEST_GET_SIZE:
1733 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1734 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1735 tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode >= PM_GET_MAX), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1737 ret = __get_size_process(pc, pkgid, uid, (pkgmgr_getsize_type)service_mode, event_cb, data);
1740 case PM_REQUEST_KILL_APP:
1741 case PM_REQUEST_CHECK_APP:
1742 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1743 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1745 ret = __check_app_process(service_type, pc, pkgid, uid, data);
1747 ERR("__check_app_process fail \n");
1754 ERR("Wrong Request\n");
1765 API int pkgmgr_client_usr_request_size_info(uid_t uid)
1768 pkgmgr_client *pc = NULL;
1770 pc = pkgmgr_client_new(PC_REQUEST);
1771 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "request pc is null\n");
1773 ret = __request_size_info(pc, uid);
1775 ERR("__request_size_info fail \n");
1778 pkgmgr_client_free(pc);
1782 API int pkgmgr_client_request_size_info(void) // get all package size (data, total)
1784 return pkgmgr_client_usr_request_size_info(GLOBAL_USER);
1787 API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid)
1790 int ret = PKGMGR_R_ECOMM;
1791 pkgmgr_client_t *pc;
1793 if (pkgid == NULL) {
1794 ERR("invalid parameter");
1795 return PKGMGR_R_EINVAL;
1798 pc = pkgmgr_client_new(PC_REQUEST);
1800 ERR("out of memory");
1801 return PKGMGR_R_ESYSTEM;
1804 result = comm_client_request(pc->info.request.cc, "clearcache",
1805 g_variant_new("(us)", uid, pkgid));
1807 return PKGMGR_R_ECOMM;
1808 g_variant_get(result, "(i)", &ret);
1809 g_variant_unref(result);
1814 API int pkgmgr_client_clear_cache_dir(const char *pkgid)
1816 return pkgmgr_client_usr_clear_cache_dir(pkgid, GLOBAL_USER);
1819 API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid)
1821 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, uid);
1824 API int pkgmgr_client_clear_all_cache_dir(void)
1826 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, GLOBAL_USER);
1829 API int pkgmgr_client_get_size(pkgmgr_client * pc, const char *pkgid,
1830 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
1833 return pkgmgr_client_usr_get_size(pc, pkgid, get_type, event_cb, data,
1837 API int pkgmgr_client_usr_get_size(pkgmgr_client * pc, const char *pkgid,
1838 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
1839 void *data, uid_t uid)
1842 int ret = PKGMGR_R_ECOMM;
1843 char *req_key = NULL;
1845 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1847 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
1848 ERR("invalid parameter");
1849 return PKGMGR_R_EINVAL;
1852 if (mpc->ctype != PC_REQUEST) {
1853 ERR("mpc->ctype is not PC_REQUEST");
1854 return PKGMGR_R_EINVAL;
1858 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
1859 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
1861 get_type = PM_GET_PKG_SIZE_INFO;
1862 result = comm_client_request(mpc->info.request.cc, "getsize",
1863 g_variant_new("(usi)", uid, pkgid, get_type));
1865 return PKGMGR_R_ECOMM;
1867 g_variant_get(result, "(i&s)", &ret, &req_key);
1868 if (req_key == NULL) {
1869 g_variant_unref(result);
1870 return PKGMGR_R_ECOMM;
1872 if (ret != PKGMGR_R_OK) {
1873 g_variant_unref(result);
1877 req_id = _get_request_id();
1878 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1880 g_variant_unref(result);
1885 API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc,
1886 const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb,
1887 void *user_data, uid_t uid)
1890 int ret = PKGMGR_R_ECOMM;
1891 char *req_key = NULL;
1894 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1896 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
1897 ERR("invalid parameter");
1898 return PKGMGR_R_EINVAL;
1901 if (mpc->ctype != PC_REQUEST) {
1902 ERR("mpc->ctype is not PC_REQUEST");
1903 return PKGMGR_R_EINVAL;
1907 if (__change_op_cb_for_getsize(mpc) < 0) {
1908 ERR("__change_op_cb_for_getsize failed");
1909 return PKGMGR_R_ESYSTEM;
1912 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
1913 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
1915 get_type = PM_GET_PKG_SIZE_INFO;
1916 result = comm_client_request(mpc->info.request.cc, "getsize",
1917 g_variant_new("(usi)", uid, pkgid, get_type));
1919 return PKGMGR_R_ECOMM;
1921 g_variant_get(result, "(i&s)", &ret, &req_key);
1922 if (req_key == NULL) {
1923 g_variant_unref(result);
1924 return PKGMGR_R_ECOMM;
1926 if (ret != PKGMGR_R_OK) {
1927 g_variant_unref(result);
1931 req_id = _get_request_id();
1932 __add_op_cbinfo(mpc, req_id, req_key, __get_pkg_size_info_cb, event_cb,
1935 g_variant_unref(result);
1940 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)
1942 return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb, user_data, GLOBAL_USER);
1945 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)
1946 { // total package size info
1947 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, uid);
1950 API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc, pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data)
1952 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);
1955 API int pkgmgr_client_generate_license_request(pkgmgr_client *pc,
1956 const char *resp_data, char **req_data, char **license_url)
1962 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1964 if (pc == NULL || resp_data == NULL || req_data == NULL ||
1965 license_url == NULL) {
1966 ERR("invalid parameter");
1967 return PKGMGR_R_EINVAL;
1970 if (mpc->ctype != PC_REQUEST) {
1971 ERR("mpc->ctype is not PC_REQUEST");
1972 return PKGMGR_R_EINVAL;
1975 result = comm_client_request(mpc->info.request.cc,
1976 "generate_license_request",
1977 g_variant_new("(s)", resp_data));
1979 return PKGMGR_R_ECOMM;
1981 g_variant_get(result, "(i&s&s)", &ret, &data, &url);
1982 if (ret != PKGMGR_R_OK) {
1983 ERR("generate_license_request failed: %d", ret);
1984 g_variant_unref(result);
1988 *req_data = strdup(data);
1989 *license_url = strdup(url);
1991 g_variant_unref(result);
1996 API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data)
2000 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2002 if (pc == NULL || resp_data == NULL) {
2003 ERR("invalid parameter");
2004 return PKGMGR_R_EINVAL;
2007 if (mpc->ctype != PC_REQUEST) {
2008 ERR("mpc->ctype is not PC_REQUEST");
2009 return PKGMGR_R_EINVAL;
2012 result = comm_client_request(mpc->info.request.cc,
2013 "register_license", g_variant_new("(s)", resp_data));
2015 return PKGMGR_R_ECOMM;
2017 g_variant_get(result, "(i)", &ret);
2018 g_variant_unref(result);
2019 if (ret != PKGMGR_R_OK) {
2020 ERR("register license failed: %d", ret);
2027 API int pkgmgr_client_decrypt_package(pkgmgr_client *pc,
2028 const char *drm_file_path, const char *decrypted_file_path)
2032 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2034 if (pc == NULL || drm_file_path == NULL ||
2035 decrypted_file_path == NULL) {
2036 ERR("invalid parameter");
2037 return PKGMGR_R_EINVAL;
2040 if (mpc->ctype != PC_REQUEST) {
2041 ERR("mpc->ctype is not PC_REQUEST");
2042 return PKGMGR_R_EINVAL;
2045 result = comm_client_request(mpc->info.request.cc,
2046 "decrypt_package", g_variant_new("(ss)",
2047 drm_file_path, decrypted_file_path));
2049 return PKGMGR_R_ECOMM;
2051 g_variant_get(result, "(i)", &ret);
2052 g_variant_unref(result);
2053 if (ret != PKGMGR_R_OK) {
2054 ERR("decrypt_package failed: %d", ret);
2061 API int pkgmgr_client_usr_add_blacklist(pkgmgr_client *pc, const char *pkgid,
2065 int ret = PKGMGR_R_ECOMM;
2066 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2068 if (pc == NULL || pkgid == NULL) {
2069 ERR("invalid parameter");
2070 return PKGMGR_R_EINVAL;
2073 result = comm_client_request(mpc->info.request.cc, "add_blacklist",
2074 g_variant_new("(us)", uid, pkgid));
2076 return PKGMGR_R_ECOMM;
2077 g_variant_get(result, "(i)", &ret);
2078 g_variant_unref(result);
2083 API int pkgmgr_client_add_blacklist(pkgmgr_client *pc, const char *pkgid)
2085 return pkgmgr_client_usr_add_blacklist(pc, pkgid, GLOBAL_USER);
2088 API int pkgmgr_client_usr_remove_blacklist(pkgmgr_client *pc,
2089 const char *pkgid, uid_t uid)
2092 int ret = PKGMGR_R_ECOMM;
2093 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2095 if (pc == NULL || pkgid == NULL) {
2096 ERR("invalid parameter");
2097 return PKGMGR_R_EINVAL;
2100 result = comm_client_request(mpc->info.request.cc, "remove_blacklist",
2101 g_variant_new("(us)", uid, pkgid));
2103 return PKGMGR_R_ECOMM;
2104 g_variant_get(result, "(i)", &ret);
2105 g_variant_unref(result);
2110 API int pkgmgr_client_remove_blacklist(pkgmgr_client *pc,
2113 return pkgmgr_client_usr_remove_blacklist(pc, pkgid, GLOBAL_USER);
2116 API int pkgmgr_client_usr_check_blacklist(pkgmgr_client *pc, const char *pkgid,
2117 bool *blacklist, uid_t uid)
2120 int ret = PKGMGR_R_ECOMM;
2122 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2124 if (pc == NULL || pkgid == NULL) {
2125 ERR("invalid parameter");
2126 return PKGMGR_R_EINVAL;
2129 result = comm_client_request(mpc->info.request.cc, "check_blacklist",
2130 g_variant_new("(us)", uid, pkgid));
2132 return PKGMGR_R_ECOMM;
2133 g_variant_get(result, "(ii)", &b, &ret);
2134 g_variant_unref(result);
2136 if (ret != PKGMGR_R_OK)
2147 API int pkgmgr_client_check_blacklist(pkgmgr_client *pc, const char *pkgid,
2150 return pkgmgr_client_usr_check_blacklist(pc, pkgid, blacklist,