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.
32 #include <dbus/dbus.h>
33 #include <dbus/dbus-glib-lowlevel.h>
38 #include <pkgmgr-info.h>
39 #include <iniparser.h>
40 #include <security-server.h>
42 #include "package-manager.h"
43 #include "pkgmgr-internal.h"
44 #include "pkgmgr-debug.h"
45 #include "pkgmgr-api.h"
46 #include "comm_client.h"
47 #include "comm_status_broadcast_server.h"
51 #define LOG_TAG "PKGMGR"
54 #define PKG_TMP_PATH "/opt/usr/apps/tmp"
56 static int _get_request_id()
58 static int internal_req_id = 1;
60 return internal_req_id++;
63 typedef struct _req_cb_info {
66 pkgmgr_handler event_cb;
68 struct _req_cb_info *next;
71 typedef struct _listen_cb_info {
73 pkgmgr_handler event_cb;
75 struct _listen_cb_info *next;
78 typedef struct _pkgmgr_client_t {
87 listen_cb_info *lhead;
95 typedef struct _iter_data {
96 pkgmgr_iter_fn iter_fn;
100 static char *__get_cookie_from_security_server(void)
103 size_t cookie_size = 0;
104 char *e_cookie = NULL;
106 //calculage cookie size
107 cookie_size = security_server_get_cookie_size();
108 retvm_if(cookie_size <= 0, NULL, "security_server_get_cookie_size : cookie_size is %d", cookie_size);
110 //get cookie from security server
111 char cookie[cookie_size];
113 ret = security_server_request_cookie(cookie, cookie_size);
114 retvm_if(ret < 0, NULL, "security_server_request_cookie fail (%d)", ret);
117 e_cookie = g_base64_encode((const guchar *)cookie, cookie_size);
118 retvm_if(e_cookie == NULL, NULL, "g_base64_encode e_cookie is NULL");
123 static int __xsystem(const char *argv[])
130 perror("fork failed");
134 execvp(argv[0], (char *const *)argv);
140 if (waitpid(pid, &status, 0) == -1) {
141 perror("waitpid failed");
144 if (WIFSIGNALED(status)) {
148 if (!WIFEXITED(status)) {
149 /* shouldn't happen */
150 perror("should not happen");
153 return WEXITSTATUS(status);
156 static void __error_to_string(int errnumber, char **errstr)
161 case PKGCMD_ERR_PACKAGE_NOT_FOUND:
162 *errstr = PKGCMD_ERR_PACKAGE_NOT_FOUND_STR;
164 case PKGCMD_ERR_PACKAGE_INVALID:
165 *errstr = PKGCMD_ERR_PACKAGE_INVALID_STR;
167 case PKGCMD_ERR_PACKAGE_LOWER_VERSION:
168 *errstr = PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR;
170 case PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND:
171 *errstr = PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR;
173 case PKGCMD_ERR_MANIFEST_INVALID:
174 *errstr = PKGCMD_ERR_MANIFEST_INVALID_STR;
176 case PKGCMD_ERR_CONFIG_NOT_FOUND:
177 *errstr = PKGCMD_ERR_CONFIG_NOT_FOUND_STR;
179 case PKGCMD_ERR_CONFIG_INVALID:
180 *errstr = PKGCMD_ERR_CONFIG_INVALID_STR;
182 case PKGCMD_ERR_SIGNATURE_NOT_FOUND:
183 *errstr = PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR;
185 case PKGCMD_ERR_SIGNATURE_INVALID:
186 *errstr = PKGCMD_ERR_SIGNATURE_INVALID_STR;
188 case PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED:
189 *errstr = PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR;
191 case PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND:
192 *errstr = PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR;
194 case PKGCMD_ERR_CERTIFICATE_INVALID:
195 *errstr = PKGCMD_ERR_CERTIFICATE_INVALID_STR;
197 case PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
198 *errstr = PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR;
200 case PKGCMD_ERR_CERTIFICATE_EXPIRED:
201 *errstr = PKGCMD_ERR_CERTIFICATE_EXPIRED_STR;
203 case PKGCMD_ERR_INVALID_PRIVILEGE:
204 *errstr = PKGCMD_ERR_INVALID_PRIVILEGE_STR;
206 case PKGCMD_ERR_MENU_ICON_NOT_FOUND:
207 *errstr = PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR;
209 case PKGCMD_ERR_FATAL_ERROR:
210 *errstr = PKGCMD_ERR_FATAL_ERROR_STR;
212 case PKGCMD_ERR_OUT_OF_STORAGE:
213 *errstr = PKGCMD_ERR_OUT_OF_STORAGE_STR;
215 case PKGCMD_ERR_OUT_OF_MEMORY:
216 *errstr = PKGCMD_ERR_OUT_OF_MEMORY_STR;
218 case PKGCMD_ERR_ARGUMENT_INVALID:
219 *errstr = PKGCMD_ERR_ARGUMENT_INVALID_STR;
222 *errstr = PKGCMD_ERR_UNKNOWN_STR;
227 static void __add_op_cbinfo(pkgmgr_client_t * pc, int request_id,
228 const char *req_key, pkgmgr_handler event_cb,
231 req_cb_info *cb_info;
232 req_cb_info *current;
235 cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
236 if (cb_info == NULL) {
237 _LOGD("calloc failed");
240 cb_info->request_id = request_id;
241 cb_info->req_key = strdup(req_key);
242 cb_info->event_cb = event_cb;
243 cb_info->data = data;
244 cb_info->next = NULL;
246 if (pc->info.request.rhead == NULL)
247 pc->info.request.rhead = cb_info;
249 current = prev = pc->info.request.rhead;
252 current = current->next;
255 prev->next = cb_info;
259 static req_cb_info *__find_op_cbinfo(pkgmgr_client_t *pc, const char *req_key)
263 tmp = pc->info.request.rhead;
266 _LOGE("tmp is NULL");
270 _LOGD("tmp->req_key %s, req_key %s", tmp->req_key, req_key);
273 if (strncmp(tmp->req_key, req_key, strlen(tmp->req_key)) == 0)
280 static void __remove_op_cbinfo(pkgmgr_client_t *pc, req_cb_info *info)
284 if (pc == NULL || pc->info.request.rhead == NULL || info == NULL)
287 tmp = pc->info.request.rhead;
289 if (tmp->next == info) {
290 tmp->next = info->next;
299 static void __add_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
300 pkgmgr_handler event_cb, void *data)
302 listen_cb_info *cb_info;
303 listen_cb_info *current;
304 listen_cb_info *prev;
306 cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
307 if (cb_info == NULL) {
308 _LOGD("calloc failed");
311 cb_info->request_id = request_id;
312 cb_info->event_cb = event_cb;
313 cb_info->data = data;
314 cb_info->next = NULL;
316 /* TODO - check the order of callback - FIFO or LIFO => Should be changed to LIFO */
317 if (pc->info.listening.lhead == NULL)
318 pc->info.listening.lhead = cb_info;
320 current = prev = pc->info.listening.lhead;
323 current = current->next;
326 prev->next = cb_info;
330 static void __operation_callback(void *cb_data, const char *req_id,
331 const char *pkg_type, const char *pkgid,
332 const char *key, const char *val)
335 req_cb_info *cb_info;
337 _LOGD("__operation_callback() req_id[%s] pkg_type[%s] pkgid[%s]"
338 "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val);
340 pc = (pkgmgr_client_t *) cb_data;
342 /* find callback info */
343 cb_info = __find_op_cbinfo(pc, req_id);
347 _LOGD("__find_op_cbinfo");
350 if (cb_info->event_cb) {
351 cb_info->event_cb(cb_info->request_id, pkg_type, pkgid, key,
352 val, NULL, cb_info->data);
353 _LOGD("event_cb is called");
356 /*remove callback for last call
357 if (strcmp(key, "end") == 0) {
358 __remove_op_cbinfo(pc, cb_info);
359 _LOGD("__remove_op_cbinfo");
366 static void __status_callback(void *cb_data, const char *req_id,
367 const char *pkg_type, const char *pkgid,
368 const char *key, const char *val)
373 _LOGD("__status_callback() req_id[%s] pkg_type[%s] pkgid[%s]"
374 "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val);
376 pc = (pkgmgr_client_t *) cb_data;
378 tmp = pc->info.listening.lhead;
380 if (tmp->event_cb(tmp->request_id, pkg_type, pkgid, key, val,
381 NULL, tmp->data) != 0)
389 static char *__get_req_key(const char *pkg_path)
393 char timestr[PKG_STRING_LEN_MAX];
397 gettimeofday(&tv, NULL);
398 curtime = tv.tv_sec * 1000000 + tv.tv_usec;
399 snprintf(timestr, sizeof(timestr), "%ld", curtime);
401 size = strlen(pkg_path) + strlen(timestr) + 2;
402 str_req_key = (char *)calloc(size, sizeof(char));
403 if (str_req_key == NULL) {
404 _LOGD("calloc failed");
407 snprintf(str_req_key, size, "%s_%s", pkg_path, timestr);
412 static char *__get_type_from_path(const char *pkg_path)
415 char mimetype[255] = { '\0', };
416 char extlist[256] = { '\0', };
419 ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype));
421 _LOGE("_get_mime_from_file() failed - error code[%d]\n",
426 ret = _get_mime_extension(mimetype, extlist, sizeof(extlist));
428 _LOGE("_get_mime_extension() failed - error code[%d]\n",
433 if (strlen(extlist) == 0)
436 if (strchr(extlist, ',')) {
437 extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0';
439 pkg_type = strchr(extlist, '.') + 1;
440 return strdup(pkg_type);
443 static inline int __pkgmgr_read_proc(const char *path, char *buf, int size)
448 if (buf == NULL || path == NULL)
451 fd = open(path, O_RDONLY);
455 ret = read(fd, buf, size - 1);
467 static inline int __pkgmgr_find_pid_by_cmdline(const char *dname,
468 const char *cmdline, const char *apppath)
472 if (strncmp(cmdline, apppath, PKG_STRING_LEN_MAX-1) == 0) {
474 if (pid != getpgid(pid))
482 static int __pkgmgr_proc_iter_kill_cmdline(const char *apppath)
485 struct dirent *dentry;
488 char buf[PKG_STRING_LEN_MAX];
490 dp = opendir("/proc");
495 while ((dentry = readdir(dp)) != NULL) {
496 if (!isdigit(dentry->d_name[0]))
499 snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
500 ret = __pkgmgr_read_proc(buf, buf, sizeof(buf));
504 pid = __pkgmgr_find_pid_by_cmdline(dentry->d_name, buf, apppath);
515 if (killpg(pgid, SIGKILL) < 0) {
527 static int __app_list_cb (const pkgmgr_appinfo_h handle,
531 pkgmgr_appinfo_get_exec(handle, &exec);
533 __pkgmgr_proc_iter_kill_cmdline(exec);
538 static int __sync_process(char *req_key)
541 char info_file[PKG_STRING_LEN_MAX] = {'\0', };
545 char buffer[PKG_ARGC_MAX] = {'\0', };
547 snprintf(info_file, PKG_STRING_LEN_MAX, "%s/%s", PKG_TMP_PATH, req_key);
552 vconf_get_int(VCONFKEY_PKGMGR_STATUS, &result);
554 _LOGD("file is not generated yet.... wait\n");
555 usleep(10 * 1000); /* 10ms sleep*/
557 _LOGD("info_file file is generated, result = %d. \n", result);
561 if (check_cnt > 500) { /* 5s time over*/
562 _LOGD("wait time over!!\n");
567 vconf_set_int(VCONFKEY_PKGMGR_STATUS, -1);
571 static int __csc_process(const char *csc_path, char *result_path)
578 char *pkgtype = NULL;
580 char buf[PKG_STRING_LEN_MAX] = {0,};
581 char type_buf[1024] = { 0 };
582 char des_buf[1024] = { 0 };
583 dictionary *csc = NULL;
586 csc = iniparser_load(csc_path);
587 retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path);
589 file = fopen(result_path, "w");
590 tryvm_if(file == NULL, ret = PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path);
592 count = iniparser_getint(csc, "csc packages:count", -1);
593 tryvm_if(count == 0, ret = PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path);
595 snprintf(buf, PKG_STRING_LEN_MAX, "[result]\n");
596 fwrite(buf, 1, strlen(buf), file);
597 snprintf(buf, PKG_STRING_LEN_MAX, "count = %d\n", count);
598 fwrite(buf, 1, strlen(buf), file);
600 for(cnt = 1 ; cnt <= count ; cnt++)
602 snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt);
603 snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt);
605 pkgtype = iniparser_getstr(csc, type_buf);
606 des = iniparser_getstr(csc, des_buf);
609 if (pkgtype == NULL) {
611 snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get pkgtype\n", type_buf);
612 fwrite(buf, 1, strlen(buf), file);
614 } else if (des == NULL) {
616 snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get description\n", des_buf);
617 fwrite(buf, 1, strlen(buf), file);
621 snprintf(buf, PKG_STRING_LEN_MAX, "type_%03d = %s\n", cnt, pkgtype);
622 fwrite(buf, 1, strlen(buf), file);
623 snprintf(buf, PKG_STRING_LEN_MAX, "description_%03d = %s\n", cnt, des);
624 fwrite(buf, 1, strlen(buf), file);
626 if (strcmp(pkgtype, "tpk") == 0) {
627 const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL };
628 ret = __xsystem(ospinstaller_argv);
629 } else if (strcmp(pkgtype, "wgt")== 0) {
630 const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL };
631 ret = __xsystem(wrtinstaller_argv);
639 __error_to_string(ret, &errstr);
640 snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = fail[%s]\n", cnt, errstr);
643 snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = success\n", cnt);
645 fwrite(buf, 1, strlen(buf), file);
649 iniparser_freedict(csc);
659 static int __get_size_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data)
661 char *req_key = NULL;
664 pkgmgrinfo_pkginfo_h handle;
665 char *pkgtype = NULL;
666 char *installer_path = NULL;
667 char *argv[PKG_ARGC_MAX] = { NULL, };
673 char buf[128] = {'\0'};
676 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
677 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
679 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
680 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed");
682 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
683 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed");
685 installer_path = _get_backend_path_with_type(pkgtype);
686 req_key = __get_req_key(pkgid);
687 req_id = _get_request_id();
689 snprintf(buf, 128, "%d", get_type);
690 argv[argcnt++] = installer_path;
692 argv[argcnt++] = strdup("-k");
694 argv[argcnt++] = req_key;
696 argv[argcnt++] = strdup("-d");
698 argv[argcnt++] = strdup(pkgid);
700 argv[argcnt++] = strdup("-t");
702 argv[argcnt++] = strdup(buf);
704 /*** add quote in all string for special charactor like '\n'*** FIX */
705 for (i = 0; i < argcnt; i++) {
706 temp = g_shell_quote(argv[i]);
707 len += (strlen(temp) + 1);
711 args = (char *)calloc(len, sizeof(char));
712 tryvm_if(args == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
714 strncpy(args, argv[0], len - 1);
716 for (i = 1; i < argcnt; i++) {
717 strncat(args, " ", strlen(" "));
718 temp = g_shell_quote(argv[i]);
719 strncat(args, temp, strlen(temp));
722 _LOGD("[args] %s [len] %d\n", args, len);
724 /* get cookie from security-server */
725 cookie = __get_cookie_from_security_server();
726 tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
729 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, cookie, 1);
731 _LOGE("comm_client_request failed, ret=%d\n", ret);
733 ret = __sync_process(req_key);
735 _LOGE("get size failed, ret=%d\n", ret);
738 for (i = 0; i < argcnt; i++)
746 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
750 static int __move_pkg_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_move_type move_type, pkgmgr_handler event_cb, void *data)
752 char *req_key = NULL;
755 pkgmgrinfo_pkginfo_h handle;
756 char *pkgtype = NULL;
757 char *installer_path = NULL;
758 char *argv[PKG_ARGC_MAX] = { NULL, };
764 char buf[128] = {'\0'};
765 char info_file[PKG_STRING_LEN_MAX] = {'\0', };
768 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
769 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
771 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
772 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed");
774 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
775 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed");
777 installer_path = _get_backend_path_with_type(pkgtype);
778 req_key = __get_req_key(pkgid);
779 req_id = _get_request_id();
782 snprintf(buf, 128, "%d", move_type);
783 /* argv[0] installer path */
784 argv[argcnt++] = installer_path;
786 argv[argcnt++] = strdup("-k");
788 argv[argcnt++] = req_key;
790 argv[argcnt++] = strdup("-m");
792 argv[argcnt++] = strdup(pkgid);
794 argv[argcnt++] = strdup("-t");
796 argv[argcnt++] = strdup(buf);
798 argv[argcnt++] = strdup("-q");
800 /*** add quote in all string for special charactor like '\n'*** FIX */
801 for (i = 0; i < argcnt; i++) {
802 temp = g_shell_quote(argv[i]);
803 len += (strlen(temp) + 1);
807 args = (char *)calloc(len, sizeof(char));
808 tryvm_if(args == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
810 strncpy(args, argv[0], len - 1);
812 for (i = 1; i < argcnt; i++) {
813 strncat(args, " ", strlen(" "));
814 temp = g_shell_quote(argv[i]);
815 strncat(args, temp, strlen(temp));
818 _LOGD("[args] %s [len] %d\n", args, len);
820 /* get cookie from security-server */
821 cookie = __get_cookie_from_security_server();
822 tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
825 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, cookie, 1);
827 _LOGE("comm_client_request failed, ret=%d\n", ret);
829 snprintf(info_file, PKG_STRING_LEN_MAX, "app2sd_%s", pkgid);
830 ret = __sync_process(info_file);
832 _LOGE("move pkg failed, ret=%d\n", ret);
835 for (i = 0; i < argcnt; i++)
843 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
847 static int __kill_app_process(pkgmgr_client * pc, const char *pkgid)
853 pkgmgrinfo_pkginfo_h handle;
855 /* Check for NULL value of pc */
856 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
857 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
859 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
860 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed");
862 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
863 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed");
865 /* 2. generate req_key */
866 req_key = __get_req_key(pkgid);
868 /* 3. request activate */
869 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_KILL_APP, pkgtype, pkgid, NULL, NULL, 1);
871 _LOGE("request failed, ret=%d\n", ret);
875 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
881 API pkgmgr_client *pkgmgr_client_new(client_type ctype)
883 pkgmgr_client_t *pc = NULL;
886 if (ctype != PC_REQUEST && ctype != PC_LISTENING
887 && ctype != PC_BROADCAST)
890 /* Allocate memory for ADT:pkgmgr_client */
891 pc = calloc(1, sizeof(pkgmgr_client_t));
900 if (pc->ctype == PC_REQUEST) {
901 pc->info.request.cc = comm_client_new();
902 if (pc->info.request.cc == NULL) {
903 _LOGE("client creation failed");
906 ret = comm_client_set_status_callback(pc->info.request.cc,
907 __operation_callback, pc);
909 _LOGE("comm_client_set_status_callback() failed - %d",
913 } else if (pc->ctype == PC_LISTENING) {
914 pc->info.listening.cc = comm_client_new();
915 if (pc->info.listening.cc == NULL) {
916 _LOGE("client creation failed");
919 ret = comm_client_set_status_callback(pc->info.listening.cc,
920 __status_callback, pc);
922 _LOGE("comm_client_set_status_callback() failed - %d",
926 } else if (pc->ctype == PC_BROADCAST) {
927 pc->info.broadcast.bc = comm_status_broadcast_server_connect();
928 if (pc->info.broadcast.bc == NULL) {
929 _LOGE("client creation failed");
935 return (pkgmgr_client *) pc;
943 API int pkgmgr_client_free(pkgmgr_client *pc)
946 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
949 _LOGE("Invalid argument");
950 return PKGMGR_R_EINVAL;
953 if (mpc->ctype == PC_REQUEST) {
956 for (tmp = mpc->info.request.rhead; tmp;) {
962 ret = comm_client_free(mpc->info.request.cc);
964 _LOGE("comm_client_free() failed - %d", ret);
967 } else if (mpc->ctype == PC_LISTENING) {
969 listen_cb_info *prev;
970 for (tmp = mpc->info.listening.lhead; tmp;) {
976 ret = comm_client_free(mpc->info.listening.cc);
978 _LOGE("comm_client_free() failed - %d", ret);
981 } else if (mpc->ctype == PC_BROADCAST) {
982 comm_status_broadcast_server_disconnect(mpc->info.broadcast.bc);
985 _LOGE("Invalid client type\n");
986 return PKGMGR_R_EINVAL;
998 return PKGMGR_R_ERROR;
1001 API int pkgmgr_client_install(pkgmgr_client * pc, const char *pkg_type,
1002 const char *descriptor_path, const char *pkg_path,
1003 const char *optional_file, pkgmgr_mode mode,
1004 pkgmgr_handler event_cb, void *data)
1006 char *pkgtype = NULL;
1007 char *installer_path = NULL;
1008 char *req_key = NULL;
1011 char *argv[PKG_ARGC_MAX] = { NULL, };
1017 char *cookie = NULL;
1019 /* Check for NULL value of pc */
1020 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL");
1022 /* 0. check the pc type */
1023 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1024 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST");
1026 /* 1. check argument */
1027 if (descriptor_path) {
1028 retvm_if(strlen(descriptor_path) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "descriptor_path over PKG_STRING_LEN_MAX");
1029 retvm_if(access(descriptor_path, F_OK) != 0, PKGMGR_R_EINVAL, "descriptor_path access fail");
1032 retvm_if(pkg_path == NULL, PKGMGR_R_EINVAL, "pkg_path is NULL");
1033 retvm_if(strlen(pkg_path) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "pkg_path over PKG_STRING_LEN_MAX");
1034 retvm_if(access(pkg_path, F_OK) != 0, PKGMGR_R_EINVAL, "pkg_path access fail");
1037 retvm_if(strlen(optional_file) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX");
1039 /* 2. get installer path using pkg_path */
1041 installer_path = _get_backend_path_with_type(pkg_type);
1042 pkgtype = strdup(pkg_type);
1044 installer_path = _get_backend_path(pkg_path);
1045 pkgtype = __get_type_from_path(pkg_path);
1047 if (installer_path == NULL) {
1049 _LOGE("installer_path is NULL\n");
1050 return PKGMGR_R_EINVAL;
1053 /* 3. generate req_key */
1054 req_key = __get_req_key(pkg_path);
1056 /* 4. add callback info - add callback info to pkgmgr_client */
1057 req_id = _get_request_id();
1058 __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1060 /* 5. generate argv */
1062 /* argv[0] installer path */
1063 argv[argcnt++] = installer_path;
1065 argv[argcnt++] = strdup("-k");
1067 argv[argcnt++] = req_key;
1069 argv[argcnt++] = strdup("-i");
1070 /* argv[(4)] if exists */
1071 if (descriptor_path)
1072 argv[argcnt++] = strdup(descriptor_path);
1074 argv[argcnt++] = strdup(pkg_path);
1075 /* argv[(5)] if exists */
1077 argv[argcnt++] = strdup("-o");
1078 argv[argcnt++] = strdup(optional_file);
1080 /* argv[6] -q option should be located at the end of command !! */
1081 if (mode == PM_QUIET)
1082 argv[argcnt++] = strdup("-q");
1084 /*** add quote in all string for special charactor like '\n'*** FIX */
1085 for (i = 0; i < argcnt; i++) {
1086 temp = g_shell_quote(argv[i]);
1087 len += (strlen(temp) + 1);
1091 args = (char *)calloc(len, sizeof(char));
1092 tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
1094 strncpy(args, argv[0], len - 1);
1096 for (i = 1; i < argcnt; i++) {
1097 strncat(args, " ", strlen(" "));
1098 temp = g_shell_quote(argv[i]);
1099 strncat(args, temp, strlen(temp));
1102 _LOGD("[args] %s [len] %d\n", args, len);
1104 /* get cookie from security-server */
1105 cookie = __get_cookie_from_security_server();
1106 tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
1107 /******************* end of quote ************************/
1109 /* 6. request install */
1110 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkg_path, args, cookie, 1);
1111 tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
1116 for (i = 0; i < argcnt; i++)
1129 API int pkgmgr_client_reinstall(pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
1130 const char *optional_file, pkgmgr_mode mode,
1131 pkgmgr_handler event_cb, void *data)
1133 char *pkgtype = NULL;
1134 char *installer_path = NULL;
1135 char *req_key = NULL;
1138 char *argv[PKG_ARGC_MAX] = { NULL, };
1144 char *cookie = NULL;
1146 /* Check for NULL value of pc */
1147 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
1149 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1151 /* 0. check the pc type */
1152 retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
1155 /* 1. check argument */
1156 retv_if(pkgid == NULL, PKGMGR_R_EINVAL);
1157 retv_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL);
1158 if (optional_file) {
1159 if (strlen(optional_file) >= PKG_STRING_LEN_MAX)
1160 return PKGMGR_R_EINVAL;
1163 /* 2. get installer path using pkg_path */
1164 installer_path = _get_backend_path_with_type(pkg_type);
1165 pkgtype = strdup(pkg_type);
1166 tryvm_if(installer_path == NULL, ret = PKGMGR_R_EINVAL, "installer_path is null");
1168 /* 3. generate req_key */
1169 req_key = __get_req_key(pkgid);
1171 /* 4. add callback info - add callback info to pkgmgr_client */
1172 req_id = _get_request_id();
1173 __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1175 /* 5. generate argv */
1177 /* argv[0] installer path */
1178 argv[argcnt++] = installer_path;
1180 argv[argcnt++] = strdup("-k");
1182 argv[argcnt++] = req_key;
1184 argv[argcnt++] = strdup("-r");
1186 argv[argcnt++] = strdup(pkgid);
1187 /* argv[(5)] if exists */
1189 argv[argcnt++] = strdup("-o");
1190 argv[argcnt++] = strdup(optional_file);
1193 /* argv[5] -q option should be located at the end of command !! */
1194 if (mode == PM_QUIET)
1195 argv[argcnt++] = strdup("-q");
1197 /*** add quote in all string for special charactor like '\n'*** FIX */
1198 for (i = 0; i < argcnt; i++) {
1199 temp = g_shell_quote(argv[i]);
1200 len += (strlen(temp) + 1);
1204 args = (char *)calloc(len, sizeof(char));
1205 tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
1207 strncpy(args, argv[0], len - 1);
1209 for (i = 1; i < argcnt; i++) {
1210 strncat(args, " ", strlen(" "));
1211 temp = g_shell_quote(argv[i]);
1212 strncat(args, temp, strlen(temp));
1215 _LOGD("[args] %s [len] %d\n", args, len);
1217 /* get cookie from security-server */
1218 cookie = __get_cookie_from_security_server();
1219 tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
1220 /******************* end of quote ************************/
1222 /* 6. request install */
1223 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
1224 tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed");
1229 for (i = 0; i < argcnt; i++)
1242 API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
1243 const char *pkgid, pkgmgr_mode mode,
1244 pkgmgr_handler event_cb, void *data)
1247 char *installer_path;
1251 char *argv[PKG_ARGC_MAX] = { NULL, };
1257 char *cookie = NULL;
1259 /* Check for NULL value of pc */
1260 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
1262 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1264 /* 0. check the pc type */
1265 retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
1267 /* 1. check argument */
1268 retv_if(pkgid == NULL, PKGMGR_R_EINVAL);
1270 pkgmgr_pkginfo_h handle;
1271 ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
1273 /*check package id */
1274 tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_pkginfo fail");
1275 tryvm_if(handle == NULL, ret = PKGMGR_R_EINVAL, "Pkgid(%s) can not find in installed pkg DB! \n", pkgid);
1277 /*check running app , terminate app if it is running*/
1278 ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
1279 tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_UI_APP fail");
1281 /*check running app , terminate app if it is running*/
1282 ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
1283 tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_SVC_APP fail");
1286 ret = pkgmgr_pkginfo_get_type(handle, &pkgtype);
1287 tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_type fail");
1288 tryvm_if(pkgtype == NULL, ret = PKGMGR_R_ERROR, "pkgtype is NULL");
1290 /*check pkgid length */
1291 tryvm_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "pkgid is too long");
1293 /* 2. get installer path using pkgtype */
1294 installer_path = _get_backend_path_with_type(pkgtype);
1295 tryvm_if(installer_path == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
1297 /* 3. generate req_key */
1298 req_key = __get_req_key(pkgid);
1300 /* 4. add callback info - add callback info to pkgmgr_client */
1301 req_id = _get_request_id();
1302 __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1304 /* 5. generate argv */
1306 /* argv[0] installer path */
1307 argv[argcnt++] = installer_path;
1309 argv[argcnt++] = strdup("-k");
1311 argv[argcnt++] = req_key;
1313 argv[argcnt++] = strdup("-d");
1315 argv[argcnt++] = strdup(pkgid);
1316 /* argv[5] -q option should be located at the end of command !! */
1317 if (mode == PM_QUIET)
1318 argv[argcnt++] = strdup("-q");
1320 /*** add quote in all string for special charactor like '\n'*** FIX */
1321 for (i = 0; i < argcnt; i++) {
1322 temp = g_shell_quote(argv[i]);
1323 len += (strlen(temp) + 1);
1327 args = (char *)calloc(len, sizeof(char));
1328 tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
1330 strncpy(args, argv[0], len - 1);
1332 for (i = 1; i < argcnt; i++) {
1333 strncat(args, " ", strlen(" "));
1334 temp = g_shell_quote(argv[i]);
1335 strncat(args, temp, strlen(temp));
1338 _LOGD("[args] %s [len] %d\n", args, len);
1340 /* get cookie from security-server */
1341 cookie = __get_cookie_from_security_server();
1342 tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
1343 /******************* end of quote ************************/
1345 /* 6. request install */
1346 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
1347 tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "calloc failed");
1349 for (i = 0; i < argcnt; i++)
1354 pkgmgr_pkginfo_destroy_pkginfo(handle);
1358 for (i = 0; i < argcnt; i++)
1366 pkgmgr_pkginfo_destroy_pkginfo(handle);
1371 API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
1372 const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode)
1374 const char *pkgtype = NULL;
1375 char *installer_path = NULL;
1376 char *req_key = NULL;
1378 char *argv[PKG_ARGC_MAX] = { NULL, };
1385 char *cookie = NULL;
1386 char buf[128] = {'\0'};
1388 /* Check for NULL value of pc */
1390 _LOGD("package manager client handle is NULL\n");
1391 return PKGMGR_R_EINVAL;
1393 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1394 /*check the pc type */
1395 if (mpc->ctype != PC_REQUEST)
1396 return PKGMGR_R_EINVAL;
1400 return PKGMGR_R_EINVAL;
1402 if (pkg_type == NULL) {
1403 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1404 if (pkgtype == NULL)
1405 return PKGMGR_R_EINVAL;
1409 if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1410 return PKGMGR_R_EINVAL;
1412 if ((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD))
1413 return PKGMGR_R_EINVAL;
1415 /* get installer path using pkg_path */
1416 installer_path = _get_backend_path_with_type(pkgtype);
1417 if (installer_path == NULL)
1418 return PKGMGR_R_EINVAL;
1420 /* generate req_key */
1421 req_key = __get_req_key(pkgid);
1422 req_id = _get_request_id();
1425 snprintf(buf, 128, "%d", move_type);
1426 /* argv[0] installer path */
1427 argv[argcnt++] = installer_path;
1429 argv[argcnt++] = strdup("-k");
1431 argv[argcnt++] = req_key;
1433 argv[argcnt++] = strdup("-m");
1435 argv[argcnt++] = strdup(pkgid);
1437 argv[argcnt++] = strdup("-t");
1439 argv[argcnt++] = strdup(buf);
1440 /* argv[7] -q option should be located at the end of command !! */
1441 if (mode == PM_QUIET)
1442 argv[argcnt++] = strdup("-q");
1444 /*** add quote in all string for special charactor like '\n'*** FIX */
1445 for (i = 0; i < argcnt; i++) {
1446 temp = g_shell_quote(argv[i]);
1447 len += (strlen(temp) + 1);
1451 args = (char *)calloc(len, sizeof(char));
1453 _LOGD("calloc failed");
1455 for (i = 0; i < argcnt; i++)
1458 return PKGMGR_R_ERROR;
1460 strncpy(args, argv[0], len - 1);
1462 for (i = 1; i < argcnt; i++) {
1463 strncat(args, " ", strlen(" "));
1464 temp = g_shell_quote(argv[i]);
1465 strncat(args, temp, strlen(temp));
1468 _LOGD("[args] %s [len] %d\n", args, len);
1469 /******************* end of quote ************************/
1471 /* 6. request install */
1472 ret = comm_client_request(mpc->info.request.cc, req_key,
1473 COMM_REQ_TO_MOVER, pkgtype, pkgid,
1476 _LOGE("request failed, ret=%d\n", ret);
1478 for (i = 0; i < argcnt; i++)
1482 return PKGMGR_R_ECOMM;
1485 for (i = 0; i < argcnt; i++)
1494 API int pkgmgr_client_activate(pkgmgr_client * pc, const char *pkg_type,
1497 const char *pkgtype;
1499 char *cookie = NULL;
1501 /* Check for NULL value of pc */
1503 _LOGD("package manager client handle is NULL\n");
1504 return PKGMGR_R_EINVAL;
1506 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1508 /* 0. check the pc type */
1509 if (mpc->ctype != PC_REQUEST)
1510 return PKGMGR_R_EINVAL;
1512 /* 1. check argument */
1514 return PKGMGR_R_EINVAL;
1516 if (pkg_type == NULL) {
1517 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1518 if (pkgtype == NULL)
1519 return PKGMGR_R_EINVAL;
1523 if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1524 return PKGMGR_R_EINVAL;
1526 /* 2. generate req_key */
1527 req_key = __get_req_key(pkgid);
1529 /* 3. request activate */
1530 ret = comm_client_request(mpc->info.request.cc, req_key,
1531 COMM_REQ_TO_ACTIVATOR, pkgtype,
1532 pkgid, "1 PKG", cookie, 1);
1534 _LOGE("request failed, ret=%d\n", ret);
1536 return PKGMGR_R_ECOMM;
1544 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
1547 const char *pkgtype;
1549 char *cookie = NULL;
1551 /* Check for NULL value of pc */
1553 _LOGD("package manager client handle is NULL\n");
1554 return PKGMGR_R_EINVAL;
1556 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1558 /* 0. check the pc type */
1559 if (mpc->ctype != PC_REQUEST)
1560 return PKGMGR_R_EINVAL;
1562 /* 1. check argument */
1564 return PKGMGR_R_EINVAL;
1566 if (pkg_type == NULL) {
1567 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1568 if (pkgtype == NULL)
1569 return PKGMGR_R_EINVAL;
1573 if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1574 return PKGMGR_R_EINVAL;
1576 /* 2. generate req_key */
1577 req_key = __get_req_key(pkgid);
1579 /* 3. request activate */
1580 ret = comm_client_request(mpc->info.request.cc, req_key,
1581 COMM_REQ_TO_ACTIVATOR, pkgtype,
1582 pkgid, "0 PKG", cookie, 1);
1584 _LOGE("request failed, ret=%d\n", ret);
1586 return PKGMGR_R_ECOMM;
1594 API int pkgmgr_client_activate_app(pkgmgr_client * pc, const char *appid)
1596 const char *pkgtype;
1598 char *cookie = NULL;
1600 /* Check for NULL value of pc */
1602 _LOGD("package manager client handle is NULL\n");
1603 return PKGMGR_R_EINVAL;
1605 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1607 /* 0. check the pc type */
1608 if (mpc->ctype != PC_REQUEST)
1609 return PKGMGR_R_EINVAL;
1611 /* 1. check argument */
1613 return PKGMGR_R_EINVAL;
1615 if (strlen(appid) >= PKG_STRING_LEN_MAX)
1616 return PKGMGR_R_EINVAL;
1618 pkgtype = _get_pkg_type_from_desktop_file(appid);
1620 /* 2. generate req_key */
1621 req_key = __get_req_key(appid);
1623 /* 3. request activate */
1624 ret = comm_client_request(mpc->info.request.cc, req_key,
1625 COMM_REQ_TO_ACTIVATOR, pkgtype,
1626 appid, "1 APP", cookie, 1);
1628 _LOGE("request failed, ret=%d\n", ret);
1630 return PKGMGR_R_ECOMM;
1638 API int pkgmgr_client_activate_appv(pkgmgr_client * pc, const char *appid, char *const argv[])
1640 const char *pkgtype;
1642 char *cookie = NULL;
1650 /* Check for NULL value of pc */
1652 _LOGD("package manager client handle is NULL\n");
1653 return PKGMGR_R_EINVAL;
1655 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1657 /* 0. check the pc type */
1658 if (mpc->ctype != PC_REQUEST)
1659 return PKGMGR_R_EINVAL;
1661 /* 1. check argument */
1663 return PKGMGR_R_EINVAL;
1665 if (strlen(appid) >= PKG_STRING_LEN_MAX)
1666 return PKGMGR_R_EINVAL;
1668 pkgtype = _get_pkg_type_from_desktop_file(appid);
1670 /* 2. generate req_key */
1671 req_key = __get_req_key(appid);
1673 /*** add quote in all string for special charactor like '\n'*** FIX */
1675 for (i = 0; argv[i]; i++) {
1676 temp = g_shell_quote(argv[i]);
1677 len += (strlen(temp) + 1);
1683 args = (char *)calloc(len, sizeof(char));
1685 _LOGE("calloc failed");
1687 return PKGMGR_R_ERROR;
1689 strncpy(args, argv[0], len - 1);
1691 for (i = 1; i < argcnt; i++) {
1692 strncat(args, " ", strlen(" "));
1693 temp = g_shell_quote(argv[i]);
1694 strncat(args, temp, strlen(temp));
1700 argsr = (char *)calloc(strlen("1 APP")+2+len, sizeof(char));
1701 if (argsr == NULL) {
1702 _LOGE("calloc failed");
1705 return PKGMGR_R_ERROR;
1707 strncpy(argsr, "1 APP", strlen("1 APP"));
1709 strncat(argsr, " ", strlen(" "));
1710 strncat(argsr, args, strlen(args));
1713 _LOGD("argsr [%s]\n", argsr);
1714 /******************* end of quote ************************/
1716 /* 3. request activate */
1717 ret = comm_client_request(mpc->info.request.cc, req_key,
1718 COMM_REQ_TO_ACTIVATOR, pkgtype,
1719 appid, argsr, cookie, 1);
1721 _LOGE("request failed, ret=%d\n", ret);
1725 return PKGMGR_R_ECOMM;
1735 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid)
1737 const char *pkgtype;
1739 char *cookie = NULL;
1741 /* Check for NULL value of pc */
1743 _LOGD("package manager client handle is NULL\n");
1744 return PKGMGR_R_EINVAL;
1746 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1748 /* 0. check the pc type */
1749 if (mpc->ctype != PC_REQUEST)
1750 return PKGMGR_R_EINVAL;
1752 /* 1. check argument */
1754 return PKGMGR_R_EINVAL;
1756 if (strlen(appid) >= PKG_STRING_LEN_MAX)
1757 return PKGMGR_R_EINVAL;
1759 pkgtype = _get_pkg_type_from_desktop_file(appid);
1761 /* 2. generate req_key */
1762 req_key = __get_req_key(appid);
1764 /* 3. request activate */
1765 ret = comm_client_request(mpc->info.request.cc, req_key,
1766 COMM_REQ_TO_ACTIVATOR, pkgtype,
1767 appid, "0 APP", cookie, 1);
1769 _LOGE("request failed, ret=%d\n", ret);
1771 return PKGMGR_R_ECOMM;
1780 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
1781 const char *appid, pkgmgr_mode mode)
1783 const char *pkgtype;
1784 char *installer_path;
1787 char *argv[PKG_ARGC_MAX] = { NULL, };
1793 char *cookie = NULL;
1795 /* Check for NULL value of pc */
1797 _LOGD("package manager client handle is NULL\n");
1798 return PKGMGR_R_EINVAL;
1800 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1802 /* 0. check the pc type */
1803 if (mpc->ctype != PC_REQUEST)
1804 return PKGMGR_R_EINVAL;
1806 /* 1. check argument */
1808 return PKGMGR_R_EINVAL;
1811 if (pkg_type == NULL) {
1812 pkgtype = _get_pkg_type_from_desktop_file(appid);
1813 if (pkgtype == NULL)
1814 return PKGMGR_R_EINVAL;
1818 if (strlen(appid) >= PKG_STRING_LEN_MAX)
1819 return PKGMGR_R_EINVAL;
1821 /* 2. get installer path using pkg_path */
1822 installer_path = _get_backend_path_with_type(pkgtype);
1823 if (installer_path == NULL)
1824 return PKGMGR_R_EINVAL;
1826 /* 3. generate req_key */
1827 req_key = __get_req_key(appid);
1829 /* 4. generate argv */
1831 /* argv[0] installer path */
1832 argv[argcnt++] = installer_path;
1834 argv[argcnt++] = strdup("-k");
1836 argv[argcnt++] = req_key;
1838 argv[argcnt++] = strdup("-c");
1840 argv[argcnt++] = strdup(appid);
1841 /* argv[5] -q option should be located at the end of command !! */
1842 if (mode == PM_QUIET)
1843 argv[argcnt++] = strdup("-q");
1845 /*** add quote in all string for special charactor like '\n'*** FIX */
1846 for (i = 0; i < argcnt; i++) {
1847 temp = g_shell_quote(argv[i]);
1848 len += (strlen(temp) + 1);
1852 args = (char *)calloc(len, sizeof(char));
1854 _LOGD("calloc failed");
1856 for (i = 0; i < argcnt; i++)
1859 return PKGMGR_R_ERROR;
1861 strncpy(args, argv[0], len - 1);
1863 for (i = 1; i < argcnt; i++) {
1864 strncat(args, " ", strlen(" "));
1865 temp = g_shell_quote(argv[i]);
1866 strncat(args, temp, strlen(temp));
1869 _LOGD("[args] %s [len] %d\n", args, len);
1870 /******************* end of quote ************************/
1872 /* 6. request clear */
1873 ret = comm_client_request(mpc->info.request.cc, req_key,
1874 COMM_REQ_TO_CLEARER, pkgtype, appid,
1877 _LOGE("request failed, ret=%d\n", ret);
1879 for (i = 0; i < argcnt; i++)
1883 return PKGMGR_R_ECOMM;
1886 for (i = 0; i < argcnt; i++)
1894 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
1898 /* Check for NULL value of pc */
1900 _LOGD("package manager client handle is NULL\n");
1901 return PKGMGR_R_EINVAL;
1903 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1905 /* 0. check the pc type */
1906 if (mpc->ctype != PC_LISTENING)
1907 return PKGMGR_R_EINVAL;
1909 /* 1. check argument */
1910 if (event_cb == NULL)
1911 return PKGMGR_R_EINVAL;
1913 /* 2. add callback info to pkgmgr_client */
1914 req_id = _get_request_id();
1915 __add_stat_cbinfo(mpc, req_id, event_cb, data);
1920 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
1921 const char *pkgid, const char *key,
1924 /* Check for NULL value of pc */
1926 _LOGD("package manager client handle is NULL\n");
1927 return PKGMGR_R_EINVAL;
1929 /* Check for valid arguments. NULL parameter causes DBUS to abort */
1930 if (pkgid == NULL || pkg_type == NULL || key == NULL || val == NULL) {
1931 _LOGD("Argument supplied is NULL\n");
1932 return PKGMGR_R_EINVAL;
1934 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1936 /* 0. check the pc type */
1937 if (mpc->ctype != PC_BROADCAST)
1938 return PKGMGR_R_EINVAL;
1940 comm_status_broadcast_server_send_signal(mpc->info.broadcast.bc,
1941 PKG_STATUS, pkg_type,
1947 API pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path)
1949 return pkgmgr_info_new_from_file(NULL, pkg_path);
1952 API int pkgmgr_client_free_pkginfo(pkgmgr_info * pkg_info)
1954 if (pkg_info == NULL)
1955 return PKGMGR_R_EINVAL;
1957 package_manager_pkg_detail_info_t *info = (package_manager_pkg_detail_info_t *)pkg_info;
1960 free(info->icon_buf);
1968 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, int service_mode,
1969 pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
1970 const char *custom_info, pkgmgr_handler event_cb, void *data)
1974 /* Check for NULL value of service type */
1975 retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
1976 retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n");
1977 vconf_set_int(VCONFKEY_PKGMGR_STATUS, -1);
1979 switch (service_type) {
1980 case PM_REQUEST_CSC:
1981 tryvm_if(custom_info == NULL, ret = PKGMGR_R_EINVAL, "custom_info is NULL\n");
1982 tryvm_if(strlen(custom_info) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX");
1983 tryvm_if(data == NULL, ret = PKGMGR_R_EINVAL, "data is NULL\n");
1985 ret = __csc_process(custom_info, (char *)data);
1987 _LOGE("__csc_process fail \n");
1993 case PM_REQUEST_MOVE:
1994 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1995 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1996 tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1998 ret = __move_pkg_process(pc, pkgid, (pkgmgr_move_type)service_mode, event_cb, data);
2001 case PM_REQUEST_GET_SIZE:
2002 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
2003 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
2004 tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode > PM_GET_DATA_SIZE), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
2006 ret = __get_size_process(pc, pkgid, (pkgmgr_getsize_type)service_mode, event_cb, data);
2009 case PM_REQUEST_KILL_APP:
2010 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
2011 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
2013 ret = __kill_app_process(pc, pkgid);
2015 _LOGE("__kill_app_process fail \n");
2022 _LOGE("Wrong Request\n");
2033 #define __START_OF_OLD_API
2034 ail_cb_ret_e __appinfo_func(const ail_appinfo_h appinfo, void *user_data)
2040 iter_data *udata = (iter_data *) user_data;
2042 ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_PACKAGETYPE_STR, &type);
2045 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
2046 if (package == NULL)
2048 ail_appinfo_get_str(appinfo, AIL_PROP_VERSION_STR, &version);
2049 if (version == NULL)
2052 if (udata->iter_fn(type, package, version, udata->data) != 0)
2053 return AIL_CB_RET_CANCEL;
2055 return AIL_CB_RET_CONTINUE;
2058 API int pkgmgr_get_pkg_list(pkgmgr_iter_fn iter_fn, void *data)
2061 ail_filter_h filter;
2064 if (iter_fn == NULL)
2065 return PKGMGR_R_EINVAL;
2067 ret = ail_filter_new(&filter);
2068 if (ret != AIL_ERROR_OK) {
2069 return PKGMGR_R_ERROR;
2072 ret = ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "Application");
2073 if (ret != AIL_ERROR_OK) {
2074 ail_filter_destroy(filter);
2075 return PKGMGR_R_ERROR;
2078 ret = ail_filter_add_bool(filter, AIL_PROP_X_SLP_REMOVABLE_BOOL, true);
2079 if (ret != AIL_ERROR_OK) {
2080 ail_filter_destroy(filter);
2081 return PKGMGR_R_ERROR;
2084 ret = ail_filter_count_appinfo(filter, &cnt);
2085 if (ret != AIL_ERROR_OK) {
2086 ail_filter_destroy(filter);
2087 return PKGMGR_R_ERROR;
2090 iter_data *udata = calloc(1, sizeof(iter_data));
2091 if (udata == NULL) {
2092 _LOGE("calloc failed");
2093 ail_filter_destroy(filter);
2095 return PKGMGR_R_ERROR;
2097 udata->iter_fn = iter_fn;
2100 ail_filter_list_appinfo_foreach(filter, __appinfo_func, udata);
2104 ret = ail_filter_destroy(filter);
2105 if (ret != AIL_ERROR_OK) {
2106 return PKGMGR_R_ERROR;
2112 API pkgmgr_info *pkgmgr_info_new(const char *pkg_type, const char *pkgid)
2114 const char *pkgtype;
2115 pkg_plugin_set *plugin_set = NULL;
2116 package_manager_pkg_detail_info_t *pkg_detail_info = NULL;
2118 /* 1. check argument */
2122 if (pkg_type == NULL) {
2123 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
2124 if (pkgtype == NULL)
2129 if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
2132 pkg_detail_info = calloc(1, sizeof(package_manager_pkg_detail_info_t));
2133 if (pkg_detail_info == NULL) {
2134 _LOGE("*** Failed to alloc package_handler_info.\n");
2138 plugin_set = _package_manager_load_library(pkgtype);
2139 if (plugin_set == NULL) {
2140 _LOGE("*** Failed to load library");
2141 free(pkg_detail_info);
2145 if (plugin_set->pkg_is_installed) {
2146 if (plugin_set->pkg_is_installed(pkgid) != 0) {
2147 _LOGE("*** Failed to call pkg_is_installed()");
2148 free(pkg_detail_info);
2152 if (plugin_set->get_pkg_detail_info) {
2153 if (plugin_set->get_pkg_detail_info(pkgid,
2154 pkg_detail_info) != 0) {
2155 _LOGE("*** Failed to call get_pkg_detail_info()");
2156 free(pkg_detail_info);
2162 return (pkgmgr_info *) pkg_detail_info;
2165 API char * pkgmgr_info_get_string(pkgmgr_info * pkg_info, const char *key)
2167 package_manager_pkg_detail_info_t *pkg_detail_info;
2169 if (pkg_info == NULL)
2174 pkg_detail_info = (package_manager_pkg_detail_info_t *) pkg_info;
2176 return _get_info_string(key, pkg_detail_info);
2179 API pkgmgr_info *pkgmgr_info_new_from_file(const char *pkg_type,
2180 const char *pkg_path)
2182 pkg_plugin_set *plugin_set = NULL;
2183 package_manager_pkg_detail_info_t *pkg_detail_info = NULL;
2185 if (pkg_path == NULL) {
2186 _LOGE("pkg_path is NULL\n");
2190 if (strlen(pkg_path) > PKG_URL_STRING_LEN_MAX) {
2191 _LOGE("length of pkg_path is too long - %d.\n",
2196 pkg_detail_info = calloc(1, sizeof(package_manager_pkg_detail_info_t));
2197 if (pkg_detail_info == NULL) {
2198 _LOGE("*** Failed to alloc package_handler_info.\n");
2202 if (pkg_type == NULL)
2203 pkgtype = __get_type_from_path(pkg_path);
2205 pkgtype = strdup(pkg_type);
2207 plugin_set = _package_manager_load_library(pkgtype);
2208 if (plugin_set == NULL) {
2209 free(pkg_detail_info);
2214 if (plugin_set->get_pkg_detail_info_from_package) {
2215 if (plugin_set->get_pkg_detail_info_from_package(pkg_path,
2216 pkg_detail_info) != 0) {
2217 free(pkg_detail_info);
2224 return (pkgmgr_info *) pkg_detail_info;
2227 API int pkgmgr_info_free(pkgmgr_info * pkg_info)
2229 if (pkg_info == NULL)
2230 return PKGMGR_R_EINVAL;
2238 #define __END_OF_OLD_API
2240 API int pkgmgr_pkginfo_get_list(pkgmgr_info_pkg_list_cb pkg_list_cb, void *user_data)
2243 ret = pkgmgrinfo_pkginfo_get_list(pkg_list_cb, user_data);
2247 API int pkgmgr_pkginfo_get_pkginfo(const char *pkgid, pkgmgr_pkginfo_h *handle)
2250 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, handle);
2254 API int pkgmgr_pkginfo_get_pkgname(pkgmgr_pkginfo_h handle, char **pkg_name)
2257 ret = pkgmgrinfo_pkginfo_get_pkgname(handle, pkg_name);
2262 API int pkgmgr_pkginfo_get_pkgid(pkgmgr_pkginfo_h handle, char **pkgid)
2265 ret = pkgmgrinfo_pkginfo_get_pkgid(handle, pkgid);
2269 API int pkgmgr_pkginfo_get_type(pkgmgr_pkginfo_h handle, char **type)
2272 ret = pkgmgrinfo_pkginfo_get_type(handle, type);
2276 API int pkgmgr_pkginfo_get_version(pkgmgr_pkginfo_h handle, char **version)
2279 ret = pkgmgrinfo_pkginfo_get_version(handle, version);
2283 API int pkgmgr_pkginfo_get_install_location(pkgmgr_pkginfo_h handle, pkgmgr_install_location *location)
2286 pkgmgrinfo_install_location loc;
2287 ret = pkgmgrinfo_pkginfo_get_install_location(handle, &loc);
2292 API int pkgmgr_pkginfo_get_package_size(pkgmgr_pkginfo_h handle, int *size)
2295 ret = pkgmgrinfo_pkginfo_get_package_size(handle, size);
2299 API int pkgmgr_pkginfo_get_icon(pkgmgr_pkginfo_h handle, char **icon)
2302 ret = pkgmgrinfo_pkginfo_get_icon(handle, icon);
2306 API int pkgmgr_pkginfo_get_label(pkgmgr_pkginfo_h handle, char **label)
2309 ret = pkgmgrinfo_pkginfo_get_label(handle, label);
2313 API int pkgmgr_pkginfo_get_description(pkgmgr_pkginfo_h handle, char **description)
2316 ret = pkgmgrinfo_pkginfo_get_description(handle, description);
2320 API int pkgmgr_pkginfo_get_author_name(pkgmgr_pkginfo_h handle, char **author_name)
2323 ret = pkgmgrinfo_pkginfo_get_author_name(handle, author_name);
2327 API int pkgmgr_pkginfo_get_author_email(pkgmgr_pkginfo_h handle, char **author_email)
2330 ret = pkgmgrinfo_pkginfo_get_author_email(handle, author_email);
2334 API int pkgmgr_pkginfo_get_author_href(pkgmgr_pkginfo_h handle, char **author_href)
2337 ret = pkgmgrinfo_pkginfo_get_author_href(handle, author_href);
2341 API int pkgmgr_pkginfo_is_removable(pkgmgr_pkginfo_h handle, bool *removable)
2344 ret = pkgmgrinfo_pkginfo_is_removable(handle, removable);
2348 API int pkgmgr_pkginfo_is_preload(pkgmgr_pkginfo_h handle, bool *preload)
2351 ret = pkgmgrinfo_pkginfo_is_preload(handle, preload);
2355 API int pkgmgr_pkginfo_is_readonly(pkgmgr_pkginfo_h handle, bool *readonly)
2358 ret = pkgmgrinfo_pkginfo_is_readonly(handle, readonly);
2362 API int pkgmgr_pkginfo_is_accessible(pkgmgr_pkginfo_h handle, bool *accessible)
2365 ret = pkgmgrinfo_pkginfo_is_accessible(handle, accessible);
2369 API int pkgmgr_pkginfo_destroy_pkginfo(pkgmgr_pkginfo_h handle)
2372 ret = pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2376 API int pkgmgr_pkginfo_get_installed_storage(pkgmgr_pkginfo_h handle, pkgmgr_installed_storage *storage)
2379 pkgmgrinfo_installed_storage sto;
2380 ret = pkgmgrinfo_pkginfo_get_installed_storage(handle, &sto);
2385 API int pkgmgr_pkginfo_get_installed_time(pkgmgr_pkginfo_h handle, int *installed_time)
2388 ret = pkgmgrinfo_pkginfo_get_installed_time(handle, installed_time);
2392 API int pkgmgr_appinfo_get_list(pkgmgr_pkginfo_h handle, pkgmgr_app_component component,
2393 pkgmgr_info_app_list_cb app_func, void *user_data)
2396 ret = pkgmgrinfo_appinfo_get_list(handle, component, app_func, user_data);
2400 API int pkgmgr_appinfo_foreach_category(pkgmgr_appinfo_h handle, pkgmgr_info_app_category_list_cb category_func,
2404 ret = pkgmgrinfo_appinfo_foreach_category(handle, category_func, user_data);
2408 API int pkgmgr_appinfo_get_appinfo(const char *appid, pkgmgr_appinfo_h *handle)
2411 ret = pkgmgrinfo_appinfo_get_appinfo(appid, handle);
2415 API int pkgmgr_appinfo_get_appid(pkgmgr_appinfo_h handle, char **appid)
2418 ret = pkgmgrinfo_appinfo_get_appid(handle, appid);
2422 API int pkgmgr_appinfo_get_pkgname(pkgmgr_appinfo_h handle, char **pkg_name)
2425 ret = pkgmgrinfo_appinfo_get_pkgname(handle, pkg_name);
2429 API int pkgmgr_appinfo_get_pkgid(pkgmgr_appinfo_h handle, char **pkgid)
2432 ret = pkgmgrinfo_appinfo_get_pkgid(handle, pkgid);
2436 API int pkgmgr_appinfo_get_icon(pkgmgr_appinfo_h handle, char **icon)
2439 ret = pkgmgrinfo_appinfo_get_icon(handle, icon);
2443 API int pkgmgr_appinfo_get_label(pkgmgr_appinfo_h handle, char **label)
2446 ret = pkgmgrinfo_appinfo_get_label(handle, label);
2450 API int pkgmgr_appinfo_get_exec(pkgmgr_appinfo_h handle, char **exec)
2453 ret = pkgmgrinfo_appinfo_get_exec(handle, exec);
2457 API int pkgmgr_appinfo_get_component(pkgmgr_appinfo_h handle, pkgmgr_app_component *component)
2460 pkgmgrinfo_app_component comp;
2461 ret = pkgmgrinfo_appinfo_get_component(handle, &comp);
2466 API int pkgmgr_appinfo_get_apptype(pkgmgr_appinfo_h handle, char **app_type)
2469 ret = pkgmgrinfo_appinfo_get_apptype(handle, app_type);
2473 API int pkgmgr_appinfo_is_nodisplay(pkgmgr_appinfo_h handle, bool *nodisplay)
2476 ret = pkgmgrinfo_appinfo_is_nodisplay(handle, nodisplay);
2480 API int pkgmgr_appinfo_is_multiple(pkgmgr_appinfo_h handle, bool *multiple)
2483 ret = pkgmgrinfo_appinfo_is_multiple(handle, multiple);
2487 API int pkgmgr_appinfo_is_taskmanage(pkgmgr_appinfo_h handle, bool *taskmanage)
2490 ret = pkgmgrinfo_appinfo_is_taskmanage(handle, taskmanage);
2494 API int pkgmgr_appinfo_get_hwacceleration(pkgmgr_appinfo_h handle, pkgmgr_hwacceleration_type *hwacceleration)
2497 pkgmgrinfo_app_hwacceleration hwacc;
2498 ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
2499 *hwacceleration = hwacc;
2503 API int pkgmgr_appinfo_is_onboot(pkgmgr_appinfo_h handle, bool *onboot)
2506 ret = pkgmgrinfo_appinfo_is_onboot(handle, onboot);
2510 API int pkgmgr_appinfo_is_autorestart(pkgmgr_appinfo_h handle, bool *autorestart)
2513 ret = pkgmgrinfo_appinfo_is_autorestart(handle, autorestart);
2517 API int pkgmgr_appinfo_destroy_appinfo(pkgmgr_appinfo_h handle)
2520 ret = pkgmgrinfo_appinfo_destroy_appinfo(handle);
2524 API int pkgmgr_pkginfo_create_certinfo(pkgmgr_certinfo_h *handle)
2527 ret = pkgmgrinfo_pkginfo_create_certinfo(handle);
2531 API int pkgmgr_pkginfo_load_certinfo(const char *pkgid, pkgmgr_certinfo_h handle)
2534 ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle);
2538 API int pkgmgr_pkginfo_get_cert_value(pkgmgr_certinfo_h handle, pkgmgr_cert_type cert_type, const char **cert_value)
2541 ret = pkgmgrinfo_pkginfo_get_cert_value(handle, cert_type, cert_value);
2545 API int pkgmgr_pkginfo_destroy_certinfo(pkgmgr_certinfo_h handle)
2548 ret = pkgmgrinfo_pkginfo_destroy_certinfo(handle);
2552 API int pkgmgr_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
2555 ret = pkgmgrinfo_datacontrol_get_info(providerid, type, appid, access);