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>
41 #include "package-manager.h"
42 #include "pkgmgr-internal.h"
43 #include "pkgmgr-debug.h"
44 #include "pkgmgr-api.h"
45 #include "comm_client.h"
46 #include "comm_status_broadcast_server.h"
50 #define LOG_TAG "PKGMGR"
53 #define PKG_TMP_PATH "/opt/usr/apps/tmp"
55 static int _get_request_id()
57 static int internal_req_id = 1;
59 return internal_req_id++;
62 typedef struct _req_cb_info {
65 pkgmgr_handler event_cb;
67 struct _req_cb_info *next;
70 typedef struct _listen_cb_info {
72 pkgmgr_handler event_cb;
74 struct _listen_cb_info *next;
77 typedef struct _pkgmgr_client_t {
86 listen_cb_info *lhead;
94 typedef struct _iter_data {
95 pkgmgr_iter_fn iter_fn;
99 static int __xsystem(const char *argv[])
106 perror("fork failed");
110 execvp(argv[0], (char *const *)argv);
116 if (waitpid(pid, &status, 0) == -1) {
117 perror("waitpid failed");
120 if (WIFSIGNALED(status)) {
124 if (!WIFEXITED(status)) {
125 /* shouldn't happen */
126 perror("should not happen");
129 return WEXITSTATUS(status);
132 static void __error_to_string(int errnumber, char **errstr)
137 case PKGCMD_ERR_PACKAGE_NOT_FOUND:
138 *errstr = PKGCMD_ERR_PACKAGE_NOT_FOUND_STR;
140 case PKGCMD_ERR_PACKAGE_INVALID:
141 *errstr = PKGCMD_ERR_PACKAGE_INVALID_STR;
143 case PKGCMD_ERR_PACKAGE_LOWER_VERSION:
144 *errstr = PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR;
146 case PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND:
147 *errstr = PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR;
149 case PKGCMD_ERR_MANIFEST_INVALID:
150 *errstr = PKGCMD_ERR_MANIFEST_INVALID_STR;
152 case PKGCMD_ERR_CONFIG_NOT_FOUND:
153 *errstr = PKGCMD_ERR_CONFIG_NOT_FOUND_STR;
155 case PKGCMD_ERR_CONFIG_INVALID:
156 *errstr = PKGCMD_ERR_CONFIG_INVALID_STR;
158 case PKGCMD_ERR_SIGNATURE_NOT_FOUND:
159 *errstr = PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR;
161 case PKGCMD_ERR_SIGNATURE_INVALID:
162 *errstr = PKGCMD_ERR_SIGNATURE_INVALID_STR;
164 case PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED:
165 *errstr = PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR;
167 case PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND:
168 *errstr = PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR;
170 case PKGCMD_ERR_CERTIFICATE_INVALID:
171 *errstr = PKGCMD_ERR_CERTIFICATE_INVALID_STR;
173 case PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
174 *errstr = PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR;
176 case PKGCMD_ERR_CERTIFICATE_EXPIRED:
177 *errstr = PKGCMD_ERR_CERTIFICATE_EXPIRED_STR;
179 case PKGCMD_ERR_INVALID_PRIVILEGE:
180 *errstr = PKGCMD_ERR_INVALID_PRIVILEGE_STR;
182 case PKGCMD_ERR_MENU_ICON_NOT_FOUND:
183 *errstr = PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR;
185 case PKGCMD_ERR_FATAL_ERROR:
186 *errstr = PKGCMD_ERR_FATAL_ERROR_STR;
188 case PKGCMD_ERR_OUT_OF_STORAGE:
189 *errstr = PKGCMD_ERR_OUT_OF_STORAGE_STR;
191 case PKGCMD_ERR_OUT_OF_MEMORY:
192 *errstr = PKGCMD_ERR_OUT_OF_MEMORY_STR;
194 case PKGCMD_ERR_ARGUMENT_INVALID:
195 *errstr = PKGCMD_ERR_ARGUMENT_INVALID_STR;
198 *errstr = PKGCMD_ERR_UNKNOWN_STR;
203 static void __add_op_cbinfo(pkgmgr_client_t * pc, int request_id,
204 const char *req_key, pkgmgr_handler event_cb,
207 req_cb_info *cb_info;
208 req_cb_info *current;
211 cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
212 if (cb_info == NULL) {
213 _LOGD("calloc failed");
216 cb_info->request_id = request_id;
217 cb_info->req_key = strdup(req_key);
218 cb_info->event_cb = event_cb;
219 cb_info->data = data;
220 cb_info->next = NULL;
222 if (pc->info.request.rhead == NULL)
223 pc->info.request.rhead = cb_info;
225 current = prev = pc->info.request.rhead;
228 current = current->next;
231 prev->next = cb_info;
235 static req_cb_info *__find_op_cbinfo(pkgmgr_client_t *pc, const char *req_key)
239 tmp = pc->info.request.rhead;
242 _LOGE("tmp is NULL");
246 _LOGD("tmp->req_key %s, req_key %s", tmp->req_key, req_key);
249 if (strncmp(tmp->req_key, req_key, strlen(tmp->req_key)) == 0)
256 static void __remove_op_cbinfo(pkgmgr_client_t *pc, req_cb_info *info)
260 if (pc == NULL || pc->info.request.rhead == NULL || info == NULL)
263 tmp = pc->info.request.rhead;
265 if (tmp->next == info) {
266 tmp->next = info->next;
275 static void __add_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
276 pkgmgr_handler event_cb, void *data)
278 listen_cb_info *cb_info;
279 listen_cb_info *current;
280 listen_cb_info *prev;
282 cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
283 if (cb_info == NULL) {
284 _LOGD("calloc failed");
287 cb_info->request_id = request_id;
288 cb_info->event_cb = event_cb;
289 cb_info->data = data;
290 cb_info->next = NULL;
292 /* TODO - check the order of callback - FIFO or LIFO => Should be changed to LIFO */
293 if (pc->info.listening.lhead == NULL)
294 pc->info.listening.lhead = cb_info;
296 current = prev = pc->info.listening.lhead;
299 current = current->next;
302 prev->next = cb_info;
306 static void __operation_callback(void *cb_data, const char *req_id,
307 const char *pkg_type, const char *pkgid,
308 const char *key, const char *val)
311 req_cb_info *cb_info;
313 _LOGD("__operation_callback() req_id[%s] pkg_type[%s] pkgid[%s]"
314 "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val);
316 pc = (pkgmgr_client_t *) cb_data;
318 /* find callback info */
319 cb_info = __find_op_cbinfo(pc, req_id);
323 _LOGD("__find_op_cbinfo");
326 if (cb_info->event_cb) {
327 cb_info->event_cb(cb_info->request_id, pkg_type, pkgid, key,
328 val, NULL, cb_info->data);
329 _LOGD("event_cb is called");
332 /*remove callback for last call
333 if (strcmp(key, "end") == 0) {
334 __remove_op_cbinfo(pc, cb_info);
335 _LOGD("__remove_op_cbinfo");
342 static void __status_callback(void *cb_data, const char *req_id,
343 const char *pkg_type, const char *pkgid,
344 const char *key, const char *val)
349 _LOGD("__status_callback() req_id[%s] pkg_type[%s] pkgid[%s]"
350 "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val);
352 pc = (pkgmgr_client_t *) cb_data;
354 tmp = pc->info.listening.lhead;
356 if (tmp->event_cb(tmp->request_id, pkg_type, pkgid, key, val,
357 NULL, tmp->data) != 0)
365 static char *__get_req_key(const char *pkg_path)
369 char timestr[PKG_STRING_LEN_MAX];
373 gettimeofday(&tv, NULL);
374 curtime = tv.tv_sec * 1000000 + tv.tv_usec;
375 snprintf(timestr, sizeof(timestr), "%ld", curtime);
377 size = strlen(pkg_path) + strlen(timestr) + 2;
378 str_req_key = (char *)calloc(size, sizeof(char));
379 if (str_req_key == NULL) {
380 _LOGD("calloc failed");
383 snprintf(str_req_key, size, "%s_%s", pkg_path, timestr);
388 static char *__get_type_from_path(const char *pkg_path)
391 char mimetype[255] = { '\0', };
392 char extlist[256] = { '\0', };
395 ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype));
397 _LOGE("_get_mime_from_file() failed - error code[%d]\n",
402 ret = _get_mime_extension(mimetype, extlist, sizeof(extlist));
404 _LOGE("_get_mime_extension() failed - error code[%d]\n",
409 if (strlen(extlist) == 0)
412 if (strchr(extlist, ',')) {
413 extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0';
415 pkg_type = strchr(extlist, '.') + 1;
416 return strdup(pkg_type);
419 static inline int __pkgmgr_read_proc(const char *path, char *buf, int size)
424 if (buf == NULL || path == NULL)
427 fd = open(path, O_RDONLY);
431 ret = read(fd, buf, size - 1);
443 static inline int __pkgmgr_find_pid_by_cmdline(const char *dname,
444 const char *cmdline, const char *apppath)
448 if (strncmp(cmdline, apppath, PKG_STRING_LEN_MAX-1) == 0) {
450 if (pid != getpgid(pid))
458 static int __pkgmgr_proc_iter_kill_cmdline(const char *apppath)
461 struct dirent *dentry;
464 char buf[PKG_STRING_LEN_MAX];
466 dp = opendir("/proc");
471 while ((dentry = readdir(dp)) != NULL) {
472 if (!isdigit(dentry->d_name[0]))
475 snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
476 ret = __pkgmgr_read_proc(buf, buf, sizeof(buf));
480 pid = __pkgmgr_find_pid_by_cmdline(dentry->d_name, buf, apppath);
491 if (killpg(pgid, SIGKILL) < 0) {
503 static int __app_list_cb (const pkgmgr_appinfo_h handle,
507 pkgmgr_appinfo_get_exec(handle, &exec);
509 __pkgmgr_proc_iter_kill_cmdline(exec);
514 static int __sync_process(char *req_key)
517 char info_file[PKG_STRING_LEN_MAX] = {'\0', };
521 char buffer[PKG_ARGC_MAX] = {'\0', };
523 snprintf(info_file, PKG_STRING_LEN_MAX, "%s/%s", PKG_TMP_PATH, req_key);
527 if (access(info_file, F_OK) != 0) {
528 _LOGD("file is not generated yet.... wait\n", info_file);
529 usleep(10 * 1000); /* 10ms sleep*/
531 fp = fopen(info_file, "r");
533 _LOGE("fopen failed\n");
536 fread(&buffer, sizeof(buffer), 1, fp);
539 result = atoi(buffer);
540 _LOGD("info_file file is generated, result = %d. \n", result);
544 if (check_cnt > 500) { /* 5s time over*/
545 _LOGD("wait time over!!\n");
550 const char *rm_argv[] = { "/bin/rm", "-rf", info_file, NULL };
551 ret = __xsystem(rm_argv);
553 _LOGE("__xsystem failed, ret=%d\n", ret);
557 static int __csc_process(const char *csc_path, char *result_path)
564 char *pkgtype = NULL;
566 char buf[PKG_STRING_LEN_MAX] = {0,};
567 char type_buf[1024] = { 0 };
568 char des_buf[1024] = { 0 };
569 dictionary *csc = NULL;
572 csc = iniparser_load(csc_path);
573 retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path);
575 file = fopen(result_path, "w");
576 tryvm_if(file == NULL, ret = PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path);
578 count = iniparser_getint(csc, "csc packages:count", -1);
579 tryvm_if(count == 0, ret = PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path);
581 snprintf(buf, PKG_STRING_LEN_MAX, "[result]\n");
582 fwrite(buf, 1, strlen(buf), file);
583 snprintf(buf, PKG_STRING_LEN_MAX, "count = %d\n", count);
584 fwrite(buf, 1, strlen(buf), file);
586 for(cnt = 1 ; cnt <= count ; cnt++)
588 snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt);
589 snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt);
591 pkgtype = iniparser_getstr(csc, type_buf);
592 des = iniparser_getstr(csc, des_buf);
595 if (pkgtype == NULL) {
597 snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get pkgtype\n", type_buf);
598 fwrite(buf, 1, strlen(buf), file);
600 } else if (des == NULL) {
602 snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get description\n", des_buf);
603 fwrite(buf, 1, strlen(buf), file);
607 snprintf(buf, PKG_STRING_LEN_MAX, "type_%03d = %s\n", cnt, pkgtype);
608 fwrite(buf, 1, strlen(buf), file);
609 snprintf(buf, PKG_STRING_LEN_MAX, "description_%03d = %s\n", cnt, des);
610 fwrite(buf, 1, strlen(buf), file);
612 if (strcmp(pkgtype, "tpk") == 0) {
613 const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL };
614 ret = __xsystem(ospinstaller_argv);
615 } else if (strcmp(pkgtype, "wgt")== 0) {
616 const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL };
617 ret = __xsystem(wrtinstaller_argv);
625 __error_to_string(ret, &errstr);
626 snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = fail[%s]\n", cnt, errstr);
629 snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = success\n", cnt);
631 fwrite(buf, 1, strlen(buf), file);
635 iniparser_freedict(csc);
645 static int __get_size_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data)
647 char *req_key = NULL;
650 pkgmgrinfo_pkginfo_h handle;
651 char *pkgtype = NULL;
652 char *installer_path = NULL;
653 char *argv[PKG_ARGC_MAX] = { NULL, };
659 char buf[128] = {'\0'};
661 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
662 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
664 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
665 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed");
667 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
668 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed");
670 installer_path = _get_backend_path_with_type(pkgtype);
671 req_key = __get_req_key(pkgid);
672 req_id = _get_request_id();
674 snprintf(buf, 128, "%d", get_type);
675 argv[argcnt++] = installer_path;
677 argv[argcnt++] = strdup("-k");
679 argv[argcnt++] = req_key;
681 argv[argcnt++] = strdup("-d");
683 argv[argcnt++] = strdup(pkgid);
685 argv[argcnt++] = strdup("-t");
687 argv[argcnt++] = strdup(buf);
689 /*** add quote in all string for special charactor like '\n'*** FIX */
690 for (i = 0; i < argcnt; i++) {
691 temp = g_shell_quote(argv[i]);
692 len += (strlen(temp) + 1);
696 args = (char *)calloc(len, sizeof(char));
697 tryvm_if(args == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
699 strncpy(args, argv[0], len - 1);
701 for (i = 1; i < argcnt; i++) {
702 strncat(args, " ", strlen(" "));
703 temp = g_shell_quote(argv[i]);
704 strncat(args, temp, strlen(temp));
707 _LOGD("[args] %s [len] %d\n", args, len);
710 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, NULL, 1);
712 _LOGE("comm_client_request failed, ret=%d\n", ret);
714 ret = __sync_process(req_key);
716 _LOGE("get size failed, ret=%d\n", ret);
719 for (i = 0; i < argcnt; i++)
725 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
729 static int __move_pkg_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_move_type move_type, pkgmgr_handler event_cb, void *data)
731 char *req_key = NULL;
734 pkgmgrinfo_pkginfo_h handle;
735 char *pkgtype = NULL;
736 char *installer_path = NULL;
737 char *argv[PKG_ARGC_MAX] = { NULL, };
743 char buf[128] = {'\0'};
745 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
746 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
748 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
749 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed");
751 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
752 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed");
754 installer_path = _get_backend_path_with_type(pkgtype);
755 req_key = __get_req_key(pkgid);
756 req_id = _get_request_id();
759 snprintf(buf, 128, "%d", move_type);
760 /* argv[0] installer path */
761 argv[argcnt++] = installer_path;
763 argv[argcnt++] = strdup("-k");
765 argv[argcnt++] = req_key;
767 argv[argcnt++] = strdup("-m");
769 argv[argcnt++] = strdup(pkgid);
771 argv[argcnt++] = strdup("-t");
773 argv[argcnt++] = strdup(buf);
775 argv[argcnt++] = strdup("-q");
777 /*** add quote in all string for special charactor like '\n'*** FIX */
778 for (i = 0; i < argcnt; i++) {
779 temp = g_shell_quote(argv[i]);
780 len += (strlen(temp) + 1);
784 args = (char *)calloc(len, sizeof(char));
785 tryvm_if(args == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
787 strncpy(args, argv[0], len - 1);
789 for (i = 1; i < argcnt; i++) {
790 strncat(args, " ", strlen(" "));
791 temp = g_shell_quote(argv[i]);
792 strncat(args, temp, strlen(temp));
795 _LOGD("[args] %s [len] %d\n", args, len);
798 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, NULL, 1);
800 _LOGE("comm_client_request failed, ret=%d\n", ret);
802 ret = __sync_process(pkgid);
804 _LOGE("move pkg failed, ret=%d\n", ret);
807 for (i = 0; i < argcnt; i++)
813 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
817 static int __kill_app_process(pkgmgr_client * pc, const char *pkgid)
823 pkgmgrinfo_pkginfo_h handle;
825 /* Check for NULL value of pc */
826 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
827 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
829 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
830 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed");
832 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
833 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed");
835 /* 2. generate req_key */
836 req_key = __get_req_key(pkgid);
838 /* 3. request activate */
839 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_KILL_APP, pkgtype, pkgid, NULL, NULL, 1);
841 _LOGE("request failed, ret=%d\n", ret);
845 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
851 API pkgmgr_client *pkgmgr_client_new(client_type ctype)
853 pkgmgr_client_t *pc = NULL;
856 if (ctype != PC_REQUEST && ctype != PC_LISTENING
857 && ctype != PC_BROADCAST)
860 /* Allocate memory for ADT:pkgmgr_client */
861 pc = calloc(1, sizeof(pkgmgr_client_t));
870 if (pc->ctype == PC_REQUEST) {
871 pc->info.request.cc = comm_client_new();
872 if (pc->info.request.cc == NULL) {
873 _LOGE("client creation failed");
876 ret = comm_client_set_status_callback(pc->info.request.cc,
877 __operation_callback, pc);
879 _LOGE("comm_client_set_status_callback() failed - %d",
883 } else if (pc->ctype == PC_LISTENING) {
884 pc->info.listening.cc = comm_client_new();
885 if (pc->info.listening.cc == NULL) {
886 _LOGE("client creation failed");
889 ret = comm_client_set_status_callback(pc->info.listening.cc,
890 __status_callback, pc);
892 _LOGE("comm_client_set_status_callback() failed - %d",
896 } else if (pc->ctype == PC_BROADCAST) {
897 pc->info.broadcast.bc = comm_status_broadcast_server_connect();
898 if (pc->info.broadcast.bc == NULL) {
899 _LOGE("client creation failed");
905 return (pkgmgr_client *) pc;
913 API int pkgmgr_client_free(pkgmgr_client *pc)
916 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
919 _LOGE("Invalid argument");
920 return PKGMGR_R_EINVAL;
923 if (mpc->ctype == PC_REQUEST) {
926 for (tmp = mpc->info.request.rhead; tmp;) {
932 ret = comm_client_free(mpc->info.request.cc);
934 _LOGE("comm_client_free() failed - %d", ret);
937 } else if (mpc->ctype == PC_LISTENING) {
939 listen_cb_info *prev;
940 for (tmp = mpc->info.listening.lhead; tmp;) {
946 ret = comm_client_free(mpc->info.listening.cc);
948 _LOGE("comm_client_free() failed - %d", ret);
951 } else if (mpc->ctype == PC_BROADCAST) {
952 comm_status_broadcast_server_disconnect(mpc->info.broadcast.bc);
955 _LOGE("Invalid client type\n");
956 return PKGMGR_R_EINVAL;
968 return PKGMGR_R_ERROR;
971 API int pkgmgr_client_install(pkgmgr_client * pc, const char *pkg_type,
972 const char *descriptor_path, const char *pkg_path,
973 const char *optional_file, pkgmgr_mode mode,
974 pkgmgr_handler event_cb, void *data)
977 char *installer_path;
981 char *argv[PKG_ARGC_MAX] = { NULL, };
989 /* Check for NULL value of pc */
991 _LOGD("package manager client handle is NULL\n");
992 return PKGMGR_R_EINVAL;
994 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
996 /* 0. check the pc type */
997 if (mpc->ctype != PC_REQUEST)
998 return PKGMGR_R_EINVAL;
1000 /* 1. check argument */
1001 if (descriptor_path) {
1002 if (strlen(descriptor_path) >= PKG_STRING_LEN_MAX)
1003 return PKGMGR_R_EINVAL;
1005 if (access(descriptor_path, F_OK) != 0)
1006 return PKGMGR_R_EINVAL;
1009 if (pkg_path == NULL)
1010 return PKGMGR_R_EINVAL;
1012 if (strlen(pkg_path) >= PKG_STRING_LEN_MAX)
1013 return PKGMGR_R_EINVAL;
1015 if (access(pkg_path, F_OK) != 0)
1016 return PKGMGR_R_EINVAL;
1019 if (optional_file) {
1020 if (strlen(optional_file) >= PKG_STRING_LEN_MAX)
1021 return PKGMGR_R_EINVAL;
1024 /* 2. get installer path using pkg_path */
1026 installer_path = _get_backend_path_with_type(pkg_type);
1027 pkgtype = strdup(pkg_type);
1029 installer_path = _get_backend_path(pkg_path);
1030 pkgtype = __get_type_from_path(pkg_path);
1033 if (installer_path == NULL) {
1035 return PKGMGR_R_EINVAL;
1038 /* 3. generate req_key */
1039 req_key = __get_req_key(pkg_path);
1041 /* 4. add callback info - add callback info to pkgmgr_client */
1042 req_id = _get_request_id();
1043 __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1045 /* 5. generate argv */
1047 /* argv[0] installer path */
1048 argv[argcnt++] = installer_path;
1050 argv[argcnt++] = strdup("-k");
1052 argv[argcnt++] = req_key;
1054 argv[argcnt++] = strdup("-i");
1055 /* argv[(4)] if exists */
1056 if (descriptor_path)
1057 argv[argcnt++] = strdup(descriptor_path);
1059 argv[argcnt++] = strdup(pkg_path);
1060 /* argv[(5)] if exists */
1062 argv[argcnt++] = strdup("-o");
1063 argv[argcnt++] = strdup(optional_file);
1065 /* argv[6] -q option should be located at the end of command !! */
1066 if (mode == PM_QUIET)
1067 argv[argcnt++] = strdup("-q");
1069 /*** add quote in all string for special charactor like '\n'*** FIX */
1070 for (i = 0; i < argcnt; i++) {
1071 temp = g_shell_quote(argv[i]);
1072 len += (strlen(temp) + 1);
1076 args = (char *)calloc(len, sizeof(char));
1078 _LOGD("calloc failed");
1080 for (i = 0; i < argcnt; i++)
1084 return PKGMGR_R_ERROR;
1086 strncpy(args, argv[0], len - 1);
1088 for (i = 1; i < argcnt; i++) {
1089 strncat(args, " ", strlen(" "));
1090 temp = g_shell_quote(argv[i]);
1091 strncat(args, temp, strlen(temp));
1094 _LOGD("[args] %s [len] %d\n", args, len);
1095 /******************* end of quote ************************/
1097 /* 6. request install */
1098 ret = comm_client_request(mpc->info.request.cc, req_key,
1099 COMM_REQ_TO_INSTALLER, pkgtype, pkg_path,
1102 _LOGE("request failed, ret=%d\n", ret);
1104 for (i = 0; i < argcnt; i++)
1108 return PKGMGR_R_ECOMM;
1111 for (i = 0; i < argcnt; i++)
1120 API int pkgmgr_client_reinstall(pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
1121 const char *optional_file, pkgmgr_mode mode,
1122 pkgmgr_handler event_cb, void *data)
1124 char *pkgtype = NULL;
1125 char *installer_path = NULL;
1126 char *req_key = NULL;
1129 char *argv[PKG_ARGC_MAX] = { NULL, };
1135 char *cookie = NULL;
1137 /* Check for NULL value of pc */
1138 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
1140 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1142 /* 0. check the pc type */
1143 retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
1146 /* 1. check argument */
1147 retv_if(pkgid == NULL, PKGMGR_R_EINVAL);
1148 retv_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL);
1149 if (optional_file) {
1150 if (strlen(optional_file) >= PKG_STRING_LEN_MAX)
1151 return PKGMGR_R_EINVAL;
1154 /* 2. get installer path using pkg_path */
1155 installer_path = _get_backend_path_with_type(pkg_type);
1156 pkgtype = strdup(pkg_type);
1157 tryvm_if(installer_path == NULL, ret = PKGMGR_R_EINVAL, "installer_path is null");
1159 /* 3. generate req_key */
1160 req_key = __get_req_key(pkgid);
1162 /* 4. add callback info - add callback info to pkgmgr_client */
1163 req_id = _get_request_id();
1164 __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1166 /* 5. generate argv */
1168 /* argv[0] installer path */
1169 argv[argcnt++] = installer_path;
1171 argv[argcnt++] = strdup("-k");
1173 argv[argcnt++] = req_key;
1175 argv[argcnt++] = strdup("-r");
1177 argv[argcnt++] = strdup(pkgid);
1178 /* argv[(5)] if exists */
1180 argv[argcnt++] = strdup("-o");
1181 argv[argcnt++] = strdup(optional_file);
1184 /* argv[5] -q option should be located at the end of command !! */
1185 if (mode == PM_QUIET)
1186 argv[argcnt++] = strdup("-q");
1188 /*** add quote in all string for special charactor like '\n'*** FIX */
1189 for (i = 0; i < argcnt; i++) {
1190 temp = g_shell_quote(argv[i]);
1191 len += (strlen(temp) + 1);
1195 args = (char *)calloc(len, sizeof(char));
1196 tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
1198 strncpy(args, argv[0], len - 1);
1200 for (i = 1; i < argcnt; i++) {
1201 strncat(args, " ", strlen(" "));
1202 temp = g_shell_quote(argv[i]);
1203 strncat(args, temp, strlen(temp));
1206 _LOGD("[args] %s [len] %d\n", args, len);
1207 /******************* end of quote ************************/
1209 /* 6. request install */
1210 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
1211 tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed");
1216 for (i = 0; i < argcnt; i++)
1225 API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
1226 const char *pkgid, pkgmgr_mode mode,
1227 pkgmgr_handler event_cb, void *data)
1230 char *installer_path;
1234 char *argv[PKG_ARGC_MAX] = { NULL, };
1240 char *cookie = NULL;
1242 /* Check for NULL value of pc */
1243 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
1245 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1247 /* 0. check the pc type */
1248 retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
1250 /* 1. check argument */
1251 retv_if(pkgid == NULL, PKGMGR_R_EINVAL);
1253 pkgmgr_pkginfo_h handle;
1254 ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
1256 /*check package id */
1257 tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_pkginfo fail");
1258 tryvm_if(handle == NULL, ret = PKGMGR_R_EINVAL, "Pkgid(%s) can not find in installed pkg DB! \n", pkgid);
1260 /*check running app , terminate app if it is running*/
1261 ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
1262 tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_UI_APP fail");
1264 /*check running app , terminate app if it is running*/
1265 ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
1266 tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_SVC_APP fail");
1269 ret = pkgmgr_pkginfo_get_type(handle, &pkgtype);
1270 tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_type fail");
1271 tryvm_if(pkgtype == NULL, ret = PKGMGR_R_ERROR, "pkgtype is NULL");
1273 /*check pkgid length */
1274 tryvm_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "pkgid is too long");
1276 /* 2. get installer path using pkgtype */
1277 installer_path = _get_backend_path_with_type(pkgtype);
1278 tryvm_if(installer_path == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
1280 /* 3. generate req_key */
1281 req_key = __get_req_key(pkgid);
1283 /* 4. add callback info - add callback info to pkgmgr_client */
1284 req_id = _get_request_id();
1285 __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1287 /* 5. generate argv */
1289 /* argv[0] installer path */
1290 argv[argcnt++] = installer_path;
1292 argv[argcnt++] = strdup("-k");
1294 argv[argcnt++] = req_key;
1296 argv[argcnt++] = strdup("-d");
1298 argv[argcnt++] = strdup(pkgid);
1299 /* argv[5] -q option should be located at the end of command !! */
1300 if (mode == PM_QUIET)
1301 argv[argcnt++] = strdup("-q");
1303 /*** add quote in all string for special charactor like '\n'*** FIX */
1304 for (i = 0; i < argcnt; i++) {
1305 temp = g_shell_quote(argv[i]);
1306 len += (strlen(temp) + 1);
1310 args = (char *)calloc(len, sizeof(char));
1311 tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
1313 strncpy(args, argv[0], len - 1);
1315 for (i = 1; i < argcnt; i++) {
1316 strncat(args, " ", strlen(" "));
1317 temp = g_shell_quote(argv[i]);
1318 strncat(args, temp, strlen(temp));
1321 _LOGD("[args] %s [len] %d\n", args, len);
1322 /******************* end of quote ************************/
1324 /* 6. request install */
1325 ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
1326 tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "calloc failed");
1328 for (i = 0; i < argcnt; i++)
1333 pkgmgr_pkginfo_destroy_pkginfo(handle);
1337 for (i = 0; i < argcnt; i++)
1343 pkgmgr_pkginfo_destroy_pkginfo(handle);
1348 API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
1349 const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode)
1351 const char *pkgtype = NULL;
1352 char *installer_path = NULL;
1353 char *req_key = NULL;
1355 char *argv[PKG_ARGC_MAX] = { NULL, };
1362 char *cookie = NULL;
1363 char buf[128] = {'\0'};
1365 /* Check for NULL value of pc */
1367 _LOGD("package manager client handle is NULL\n");
1368 return PKGMGR_R_EINVAL;
1370 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1371 /*check the pc type */
1372 if (mpc->ctype != PC_REQUEST)
1373 return PKGMGR_R_EINVAL;
1377 return PKGMGR_R_EINVAL;
1379 if (pkg_type == NULL) {
1380 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1381 if (pkgtype == NULL)
1382 return PKGMGR_R_EINVAL;
1386 if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1387 return PKGMGR_R_EINVAL;
1389 if ((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD))
1390 return PKGMGR_R_EINVAL;
1392 /* get installer path using pkg_path */
1393 installer_path = _get_backend_path_with_type(pkgtype);
1394 if (installer_path == NULL)
1395 return PKGMGR_R_EINVAL;
1397 /* generate req_key */
1398 req_key = __get_req_key(pkgid);
1399 req_id = _get_request_id();
1402 snprintf(buf, 128, "%d", move_type);
1403 /* argv[0] installer path */
1404 argv[argcnt++] = installer_path;
1406 argv[argcnt++] = strdup("-k");
1408 argv[argcnt++] = req_key;
1410 argv[argcnt++] = strdup("-m");
1412 argv[argcnt++] = strdup(pkgid);
1414 argv[argcnt++] = strdup("-t");
1416 argv[argcnt++] = strdup(buf);
1417 /* argv[7] -q option should be located at the end of command !! */
1418 if (mode == PM_QUIET)
1419 argv[argcnt++] = strdup("-q");
1421 /*** add quote in all string for special charactor like '\n'*** FIX */
1422 for (i = 0; i < argcnt; i++) {
1423 temp = g_shell_quote(argv[i]);
1424 len += (strlen(temp) + 1);
1428 args = (char *)calloc(len, sizeof(char));
1430 _LOGD("calloc failed");
1432 for (i = 0; i < argcnt; i++)
1435 return PKGMGR_R_ERROR;
1437 strncpy(args, argv[0], len - 1);
1439 for (i = 1; i < argcnt; i++) {
1440 strncat(args, " ", strlen(" "));
1441 temp = g_shell_quote(argv[i]);
1442 strncat(args, temp, strlen(temp));
1445 _LOGD("[args] %s [len] %d\n", args, len);
1446 /******************* end of quote ************************/
1448 /* 6. request install */
1449 ret = comm_client_request(mpc->info.request.cc, req_key,
1450 COMM_REQ_TO_MOVER, pkgtype, pkgid,
1453 _LOGE("request failed, ret=%d\n", ret);
1455 for (i = 0; i < argcnt; i++)
1459 return PKGMGR_R_ECOMM;
1462 for (i = 0; i < argcnt; i++)
1470 API int pkgmgr_client_activate(pkgmgr_client * pc, const char *pkg_type,
1473 const char *pkgtype;
1475 char *cookie = NULL;
1477 /* Check for NULL value of pc */
1479 _LOGD("package manager client handle is NULL\n");
1480 return PKGMGR_R_EINVAL;
1482 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1484 /* 0. check the pc type */
1485 if (mpc->ctype != PC_REQUEST)
1486 return PKGMGR_R_EINVAL;
1488 /* 1. check argument */
1490 return PKGMGR_R_EINVAL;
1492 if (pkg_type == NULL) {
1493 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1494 if (pkgtype == NULL)
1495 return PKGMGR_R_EINVAL;
1499 if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1500 return PKGMGR_R_EINVAL;
1502 /* 2. generate req_key */
1503 req_key = __get_req_key(pkgid);
1505 /* 3. request activate */
1506 ret = comm_client_request(mpc->info.request.cc, req_key,
1507 COMM_REQ_TO_ACTIVATOR, pkgtype,
1508 pkgid, "1 PKG", cookie, 1);
1510 _LOGE("request failed, ret=%d\n", ret);
1512 return PKGMGR_R_ECOMM;
1520 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
1523 const char *pkgtype;
1525 char *cookie = NULL;
1527 /* Check for NULL value of pc */
1529 _LOGD("package manager client handle is NULL\n");
1530 return PKGMGR_R_EINVAL;
1532 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1534 /* 0. check the pc type */
1535 if (mpc->ctype != PC_REQUEST)
1536 return PKGMGR_R_EINVAL;
1538 /* 1. check argument */
1540 return PKGMGR_R_EINVAL;
1542 if (pkg_type == NULL) {
1543 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1544 if (pkgtype == NULL)
1545 return PKGMGR_R_EINVAL;
1549 if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1550 return PKGMGR_R_EINVAL;
1552 /* 2. generate req_key */
1553 req_key = __get_req_key(pkgid);
1555 /* 3. request activate */
1556 ret = comm_client_request(mpc->info.request.cc, req_key,
1557 COMM_REQ_TO_ACTIVATOR, pkgtype,
1558 pkgid, "0 PKG", cookie, 1);
1560 _LOGE("request failed, ret=%d\n", ret);
1562 return PKGMGR_R_ECOMM;
1570 API int pkgmgr_client_activate_app(pkgmgr_client * pc, const char *appid)
1572 const char *pkgtype;
1574 char *cookie = NULL;
1576 /* Check for NULL value of pc */
1578 _LOGD("package manager client handle is NULL\n");
1579 return PKGMGR_R_EINVAL;
1581 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1583 /* 0. check the pc type */
1584 if (mpc->ctype != PC_REQUEST)
1585 return PKGMGR_R_EINVAL;
1587 /* 1. check argument */
1589 return PKGMGR_R_EINVAL;
1591 if (strlen(appid) >= PKG_STRING_LEN_MAX)
1592 return PKGMGR_R_EINVAL;
1594 pkgtype = _get_pkg_type_from_desktop_file(appid);
1596 /* 2. generate req_key */
1597 req_key = __get_req_key(appid);
1599 /* 3. request activate */
1600 ret = comm_client_request(mpc->info.request.cc, req_key,
1601 COMM_REQ_TO_ACTIVATOR, pkgtype,
1602 appid, "1 APP", cookie, 1);
1604 _LOGE("request failed, ret=%d\n", ret);
1606 return PKGMGR_R_ECOMM;
1614 API int pkgmgr_client_activate_appv(pkgmgr_client * pc, const char *appid, char *const argv[])
1616 const char *pkgtype;
1618 char *cookie = NULL;
1626 /* Check for NULL value of pc */
1628 _LOGD("package manager client handle is NULL\n");
1629 return PKGMGR_R_EINVAL;
1631 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1633 /* 0. check the pc type */
1634 if (mpc->ctype != PC_REQUEST)
1635 return PKGMGR_R_EINVAL;
1637 /* 1. check argument */
1639 return PKGMGR_R_EINVAL;
1641 if (strlen(appid) >= PKG_STRING_LEN_MAX)
1642 return PKGMGR_R_EINVAL;
1644 pkgtype = _get_pkg_type_from_desktop_file(appid);
1646 /* 2. generate req_key */
1647 req_key = __get_req_key(appid);
1649 /*** add quote in all string for special charactor like '\n'*** FIX */
1651 for (i = 0; argv[i]; i++) {
1652 temp = g_shell_quote(argv[i]);
1653 len += (strlen(temp) + 1);
1659 args = (char *)calloc(len, sizeof(char));
1661 _LOGE("calloc failed");
1663 return PKGMGR_R_ERROR;
1665 strncpy(args, argv[0], len - 1);
1667 for (i = 1; i < argcnt; i++) {
1668 strncat(args, " ", strlen(" "));
1669 temp = g_shell_quote(argv[i]);
1670 strncat(args, temp, strlen(temp));
1676 argsr = (char *)calloc(strlen("1 APP")+2+len, sizeof(char));
1677 if (argsr == NULL) {
1678 _LOGE("calloc failed");
1681 return PKGMGR_R_ERROR;
1683 strncpy(argsr, "1 APP", strlen("1 APP"));
1685 strncat(argsr, " ", strlen(" "));
1686 strncat(argsr, args, strlen(args));
1689 _LOGD("argsr [%s]\n", argsr);
1690 /******************* end of quote ************************/
1692 /* 3. request activate */
1693 ret = comm_client_request(mpc->info.request.cc, req_key,
1694 COMM_REQ_TO_ACTIVATOR, pkgtype,
1695 appid, argsr, cookie, 1);
1697 _LOGE("request failed, ret=%d\n", ret);
1701 return PKGMGR_R_ECOMM;
1711 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid)
1713 const char *pkgtype;
1715 char *cookie = NULL;
1717 /* Check for NULL value of pc */
1719 _LOGD("package manager client handle is NULL\n");
1720 return PKGMGR_R_EINVAL;
1722 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1724 /* 0. check the pc type */
1725 if (mpc->ctype != PC_REQUEST)
1726 return PKGMGR_R_EINVAL;
1728 /* 1. check argument */
1730 return PKGMGR_R_EINVAL;
1732 if (strlen(appid) >= PKG_STRING_LEN_MAX)
1733 return PKGMGR_R_EINVAL;
1735 pkgtype = _get_pkg_type_from_desktop_file(appid);
1737 /* 2. generate req_key */
1738 req_key = __get_req_key(appid);
1740 /* 3. request activate */
1741 ret = comm_client_request(mpc->info.request.cc, req_key,
1742 COMM_REQ_TO_ACTIVATOR, pkgtype,
1743 appid, "0 APP", cookie, 1);
1745 _LOGE("request failed, ret=%d\n", ret);
1747 return PKGMGR_R_ECOMM;
1756 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
1757 const char *appid, pkgmgr_mode mode)
1759 const char *pkgtype;
1760 char *installer_path;
1763 char *argv[PKG_ARGC_MAX] = { NULL, };
1769 char *cookie = NULL;
1771 /* Check for NULL value of pc */
1773 _LOGD("package manager client handle is NULL\n");
1774 return PKGMGR_R_EINVAL;
1776 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1778 /* 0. check the pc type */
1779 if (mpc->ctype != PC_REQUEST)
1780 return PKGMGR_R_EINVAL;
1782 /* 1. check argument */
1784 return PKGMGR_R_EINVAL;
1787 if (pkg_type == NULL) {
1788 pkgtype = _get_pkg_type_from_desktop_file(appid);
1789 if (pkgtype == NULL)
1790 return PKGMGR_R_EINVAL;
1794 if (strlen(appid) >= PKG_STRING_LEN_MAX)
1795 return PKGMGR_R_EINVAL;
1797 /* 2. get installer path using pkg_path */
1798 installer_path = _get_backend_path_with_type(pkgtype);
1799 if (installer_path == NULL)
1800 return PKGMGR_R_EINVAL;
1802 /* 3. generate req_key */
1803 req_key = __get_req_key(appid);
1805 /* 4. generate argv */
1807 /* argv[0] installer path */
1808 argv[argcnt++] = installer_path;
1810 argv[argcnt++] = strdup("-k");
1812 argv[argcnt++] = req_key;
1814 argv[argcnt++] = strdup("-c");
1816 argv[argcnt++] = strdup(appid);
1817 /* argv[5] -q option should be located at the end of command !! */
1818 if (mode == PM_QUIET)
1819 argv[argcnt++] = strdup("-q");
1821 /*** add quote in all string for special charactor like '\n'*** FIX */
1822 for (i = 0; i < argcnt; i++) {
1823 temp = g_shell_quote(argv[i]);
1824 len += (strlen(temp) + 1);
1828 args = (char *)calloc(len, sizeof(char));
1830 _LOGD("calloc failed");
1832 for (i = 0; i < argcnt; i++)
1835 return PKGMGR_R_ERROR;
1837 strncpy(args, argv[0], len - 1);
1839 for (i = 1; i < argcnt; i++) {
1840 strncat(args, " ", strlen(" "));
1841 temp = g_shell_quote(argv[i]);
1842 strncat(args, temp, strlen(temp));
1845 _LOGD("[args] %s [len] %d\n", args, len);
1846 /******************* end of quote ************************/
1848 /* 6. request clear */
1849 ret = comm_client_request(mpc->info.request.cc, req_key,
1850 COMM_REQ_TO_CLEARER, pkgtype, appid,
1853 _LOGE("request failed, ret=%d\n", ret);
1855 for (i = 0; i < argcnt; i++)
1859 return PKGMGR_R_ECOMM;
1862 for (i = 0; i < argcnt; i++)
1870 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
1874 /* Check for NULL value of pc */
1876 _LOGD("package manager client handle is NULL\n");
1877 return PKGMGR_R_EINVAL;
1879 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1881 /* 0. check the pc type */
1882 if (mpc->ctype != PC_LISTENING)
1883 return PKGMGR_R_EINVAL;
1885 /* 1. check argument */
1886 if (event_cb == NULL)
1887 return PKGMGR_R_EINVAL;
1889 /* 2. add callback info to pkgmgr_client */
1890 req_id = _get_request_id();
1891 __add_stat_cbinfo(mpc, req_id, event_cb, data);
1896 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
1897 const char *pkgid, const char *key,
1900 /* Check for NULL value of pc */
1902 _LOGD("package manager client handle is NULL\n");
1903 return PKGMGR_R_EINVAL;
1905 /* Check for valid arguments. NULL parameter causes DBUS to abort */
1906 if (pkgid == NULL || pkg_type == NULL || key == NULL || val == NULL) {
1907 _LOGD("Argument supplied is NULL\n");
1908 return PKGMGR_R_EINVAL;
1910 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1912 /* 0. check the pc type */
1913 if (mpc->ctype != PC_BROADCAST)
1914 return PKGMGR_R_EINVAL;
1916 comm_status_broadcast_server_send_signal(mpc->info.broadcast.bc,
1917 PKG_STATUS, pkg_type,
1923 API pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path)
1925 return pkgmgr_info_new_from_file(NULL, pkg_path);
1928 API int pkgmgr_client_free_pkginfo(pkgmgr_info * pkg_info)
1930 if (pkg_info == NULL)
1931 return PKGMGR_R_EINVAL;
1933 package_manager_pkg_detail_info_t *info = (package_manager_pkg_detail_info_t *)pkg_info;
1936 free(info->icon_buf);
1944 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, int service_mode,
1945 pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
1946 const char *custom_info, pkgmgr_handler event_cb, void *data)
1950 /* Check for NULL value of service type */
1951 retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
1952 retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n");
1954 switch (service_type) {
1955 case PM_REQUEST_CSC:
1956 tryvm_if(custom_info == NULL, ret = PKGMGR_R_EINVAL, "custom_info is NULL\n");
1957 tryvm_if(strlen(custom_info) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX");
1958 tryvm_if(data == NULL, ret = PKGMGR_R_EINVAL, "data is NULL\n");
1960 ret = __csc_process(custom_info, (char *)data);
1962 _LOGE("__csc_process fail \n");
1968 case PM_REQUEST_MOVE:
1969 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1970 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1971 tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1973 ret = __move_pkg_process(pc, pkgid, (pkgmgr_move_type)service_mode, event_cb, data);
1976 case PM_REQUEST_GET_SIZE:
1977 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1978 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1979 tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode > PM_GET_DATA_SIZE), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1981 ret = __get_size_process(pc, pkgid, (pkgmgr_getsize_type)service_mode, event_cb, data);
1984 case PM_REQUEST_KILL_APP:
1985 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1986 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1988 ret = __kill_app_process(pc, pkgid);
1990 _LOGE("__kill_app_process fail \n");
1997 _LOGE("Wrong Request\n");
2008 #define __START_OF_OLD_API
2009 ail_cb_ret_e __appinfo_func(const ail_appinfo_h appinfo, void *user_data)
2015 iter_data *udata = (iter_data *) user_data;
2017 ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_PACKAGETYPE_STR, &type);
2020 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
2021 if (package == NULL)
2023 ail_appinfo_get_str(appinfo, AIL_PROP_VERSION_STR, &version);
2024 if (version == NULL)
2027 if (udata->iter_fn(type, package, version, udata->data) != 0)
2028 return AIL_CB_RET_CANCEL;
2030 return AIL_CB_RET_CONTINUE;
2033 API int pkgmgr_get_pkg_list(pkgmgr_iter_fn iter_fn, void *data)
2036 ail_filter_h filter;
2039 if (iter_fn == NULL)
2040 return PKGMGR_R_EINVAL;
2042 ret = ail_filter_new(&filter);
2043 if (ret != AIL_ERROR_OK) {
2044 return PKGMGR_R_ERROR;
2047 ret = ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "Application");
2048 if (ret != AIL_ERROR_OK) {
2049 ail_filter_destroy(filter);
2050 return PKGMGR_R_ERROR;
2053 ret = ail_filter_add_bool(filter, AIL_PROP_X_SLP_REMOVABLE_BOOL, true);
2054 if (ret != AIL_ERROR_OK) {
2055 ail_filter_destroy(filter);
2056 return PKGMGR_R_ERROR;
2059 ret = ail_filter_count_appinfo(filter, &cnt);
2060 if (ret != AIL_ERROR_OK) {
2061 ail_filter_destroy(filter);
2062 return PKGMGR_R_ERROR;
2065 iter_data *udata = calloc(1, sizeof(iter_data));
2066 if (udata == NULL) {
2067 _LOGE("calloc failed");
2068 ail_filter_destroy(filter);
2070 return PKGMGR_R_ERROR;
2072 udata->iter_fn = iter_fn;
2075 ail_filter_list_appinfo_foreach(filter, __appinfo_func, udata);
2079 ret = ail_filter_destroy(filter);
2080 if (ret != AIL_ERROR_OK) {
2081 return PKGMGR_R_ERROR;
2087 API pkgmgr_info *pkgmgr_info_new(const char *pkg_type, const char *pkgid)
2089 const char *pkgtype;
2090 pkg_plugin_set *plugin_set = NULL;
2091 package_manager_pkg_detail_info_t *pkg_detail_info = NULL;
2093 /* 1. check argument */
2097 if (pkg_type == NULL) {
2098 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
2099 if (pkgtype == NULL)
2104 if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
2107 pkg_detail_info = calloc(1, sizeof(package_manager_pkg_detail_info_t));
2108 if (pkg_detail_info == NULL) {
2109 _LOGE("*** Failed to alloc package_handler_info.\n");
2113 plugin_set = _package_manager_load_library(pkgtype);
2114 if (plugin_set == NULL) {
2115 _LOGE("*** Failed to load library");
2116 free(pkg_detail_info);
2120 if (plugin_set->pkg_is_installed) {
2121 if (plugin_set->pkg_is_installed(pkgid) != 0) {
2122 _LOGE("*** Failed to call pkg_is_installed()");
2123 free(pkg_detail_info);
2127 if (plugin_set->get_pkg_detail_info) {
2128 if (plugin_set->get_pkg_detail_info(pkgid,
2129 pkg_detail_info) != 0) {
2130 _LOGE("*** Failed to call get_pkg_detail_info()");
2131 free(pkg_detail_info);
2137 return (pkgmgr_info *) pkg_detail_info;
2140 API char * pkgmgr_info_get_string(pkgmgr_info * pkg_info, const char *key)
2142 package_manager_pkg_detail_info_t *pkg_detail_info;
2144 if (pkg_info == NULL)
2149 pkg_detail_info = (package_manager_pkg_detail_info_t *) pkg_info;
2151 return _get_info_string(key, pkg_detail_info);
2154 API pkgmgr_info *pkgmgr_info_new_from_file(const char *pkg_type,
2155 const char *pkg_path)
2157 pkg_plugin_set *plugin_set = NULL;
2158 package_manager_pkg_detail_info_t *pkg_detail_info = NULL;
2160 if (pkg_path == NULL) {
2161 _LOGE("pkg_path is NULL\n");
2165 if (strlen(pkg_path) > PKG_URL_STRING_LEN_MAX) {
2166 _LOGE("length of pkg_path is too long - %d.\n",
2171 pkg_detail_info = calloc(1, sizeof(package_manager_pkg_detail_info_t));
2172 if (pkg_detail_info == NULL) {
2173 _LOGE("*** Failed to alloc package_handler_info.\n");
2177 if (pkg_type == NULL)
2178 pkgtype = __get_type_from_path(pkg_path);
2180 pkgtype = strdup(pkg_type);
2182 plugin_set = _package_manager_load_library(pkgtype);
2183 if (plugin_set == NULL) {
2184 free(pkg_detail_info);
2189 if (plugin_set->get_pkg_detail_info_from_package) {
2190 if (plugin_set->get_pkg_detail_info_from_package(pkg_path,
2191 pkg_detail_info) != 0) {
2192 free(pkg_detail_info);
2199 return (pkgmgr_info *) pkg_detail_info;
2202 API int pkgmgr_info_free(pkgmgr_info * pkg_info)
2204 if (pkg_info == NULL)
2205 return PKGMGR_R_EINVAL;
2213 #define __END_OF_OLD_API
2215 API int pkgmgr_pkginfo_get_list(pkgmgr_info_pkg_list_cb pkg_list_cb, void *user_data)
2218 ret = pkgmgrinfo_pkginfo_get_list(pkg_list_cb, user_data);
2222 API int pkgmgr_pkginfo_get_pkginfo(const char *pkgid, pkgmgr_pkginfo_h *handle)
2225 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, handle);
2229 API int pkgmgr_pkginfo_get_pkgname(pkgmgr_pkginfo_h handle, char **pkg_name)
2232 ret = pkgmgrinfo_pkginfo_get_pkgname(handle, pkg_name);
2237 API int pkgmgr_pkginfo_get_pkgid(pkgmgr_pkginfo_h handle, char **pkgid)
2240 ret = pkgmgrinfo_pkginfo_get_pkgid(handle, pkgid);
2244 API int pkgmgr_pkginfo_get_type(pkgmgr_pkginfo_h handle, char **type)
2247 ret = pkgmgrinfo_pkginfo_get_type(handle, type);
2251 API int pkgmgr_pkginfo_get_version(pkgmgr_pkginfo_h handle, char **version)
2254 ret = pkgmgrinfo_pkginfo_get_version(handle, version);
2258 API int pkgmgr_pkginfo_get_install_location(pkgmgr_pkginfo_h handle, pkgmgr_install_location *location)
2261 pkgmgrinfo_install_location loc;
2262 ret = pkgmgrinfo_pkginfo_get_install_location(handle, &loc);
2267 API int pkgmgr_pkginfo_get_package_size(pkgmgr_pkginfo_h handle, int *size)
2270 ret = pkgmgrinfo_pkginfo_get_package_size(handle, size);
2274 API int pkgmgr_pkginfo_get_icon(pkgmgr_pkginfo_h handle, char **icon)
2277 ret = pkgmgrinfo_pkginfo_get_icon(handle, icon);
2281 API int pkgmgr_pkginfo_get_label(pkgmgr_pkginfo_h handle, char **label)
2284 ret = pkgmgrinfo_pkginfo_get_label(handle, label);
2288 API int pkgmgr_pkginfo_get_description(pkgmgr_pkginfo_h handle, char **description)
2291 ret = pkgmgrinfo_pkginfo_get_description(handle, description);
2295 API int pkgmgr_pkginfo_get_author_name(pkgmgr_pkginfo_h handle, char **author_name)
2298 ret = pkgmgrinfo_pkginfo_get_author_name(handle, author_name);
2302 API int pkgmgr_pkginfo_get_author_email(pkgmgr_pkginfo_h handle, char **author_email)
2305 ret = pkgmgrinfo_pkginfo_get_author_email(handle, author_email);
2309 API int pkgmgr_pkginfo_get_author_href(pkgmgr_pkginfo_h handle, char **author_href)
2312 ret = pkgmgrinfo_pkginfo_get_author_href(handle, author_href);
2316 API int pkgmgr_pkginfo_is_removable(pkgmgr_pkginfo_h handle, bool *removable)
2319 ret = pkgmgrinfo_pkginfo_is_removable(handle, removable);
2323 API int pkgmgr_pkginfo_is_preload(pkgmgr_pkginfo_h handle, bool *preload)
2326 ret = pkgmgrinfo_pkginfo_is_preload(handle, preload);
2330 API int pkgmgr_pkginfo_is_readonly(pkgmgr_pkginfo_h handle, bool *readonly)
2333 ret = pkgmgrinfo_pkginfo_is_readonly(handle, readonly);
2337 API int pkgmgr_pkginfo_is_accessible(pkgmgr_pkginfo_h handle, bool *accessible)
2340 ret = pkgmgrinfo_pkginfo_is_accessible(handle, accessible);
2344 API int pkgmgr_pkginfo_destroy_pkginfo(pkgmgr_pkginfo_h handle)
2347 ret = pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2351 API int pkgmgr_pkginfo_get_installed_storage(pkgmgr_pkginfo_h handle, pkgmgr_installed_storage *storage)
2354 pkgmgrinfo_installed_storage sto;
2355 ret = pkgmgrinfo_pkginfo_get_installed_storage(handle, &sto);
2360 API int pkgmgr_pkginfo_get_installed_time(pkgmgr_pkginfo_h handle, int *installed_time)
2363 ret = pkgmgrinfo_pkginfo_get_installed_time(handle, installed_time);
2367 API int pkgmgr_appinfo_get_list(pkgmgr_pkginfo_h handle, pkgmgr_app_component component,
2368 pkgmgr_info_app_list_cb app_func, void *user_data)
2371 ret = pkgmgrinfo_appinfo_get_list(handle, component, app_func, user_data);
2375 API int pkgmgr_appinfo_foreach_category(pkgmgr_appinfo_h handle, pkgmgr_info_app_category_list_cb category_func,
2379 ret = pkgmgrinfo_appinfo_foreach_category(handle, category_func, user_data);
2383 API int pkgmgr_appinfo_get_appinfo(const char *appid, pkgmgr_appinfo_h *handle)
2386 ret = pkgmgrinfo_appinfo_get_appinfo(appid, handle);
2390 API int pkgmgr_appinfo_get_appid(pkgmgr_appinfo_h handle, char **appid)
2393 ret = pkgmgrinfo_appinfo_get_appid(handle, appid);
2397 API int pkgmgr_appinfo_get_pkgname(pkgmgr_appinfo_h handle, char **pkg_name)
2400 ret = pkgmgrinfo_appinfo_get_pkgname(handle, pkg_name);
2404 API int pkgmgr_appinfo_get_pkgid(pkgmgr_appinfo_h handle, char **pkgid)
2407 ret = pkgmgrinfo_appinfo_get_pkgid(handle, pkgid);
2411 API int pkgmgr_appinfo_get_icon(pkgmgr_appinfo_h handle, char **icon)
2414 ret = pkgmgrinfo_appinfo_get_icon(handle, icon);
2418 API int pkgmgr_appinfo_get_label(pkgmgr_appinfo_h handle, char **label)
2421 ret = pkgmgrinfo_appinfo_get_label(handle, label);
2425 API int pkgmgr_appinfo_get_exec(pkgmgr_appinfo_h handle, char **exec)
2428 ret = pkgmgrinfo_appinfo_get_exec(handle, exec);
2432 API int pkgmgr_appinfo_get_component(pkgmgr_appinfo_h handle, pkgmgr_app_component *component)
2435 pkgmgrinfo_app_component comp;
2436 ret = pkgmgrinfo_appinfo_get_component(handle, &comp);
2441 API int pkgmgr_appinfo_get_apptype(pkgmgr_appinfo_h handle, char **app_type)
2444 ret = pkgmgrinfo_appinfo_get_apptype(handle, app_type);
2448 API int pkgmgr_appinfo_is_nodisplay(pkgmgr_appinfo_h handle, bool *nodisplay)
2451 ret = pkgmgrinfo_appinfo_is_nodisplay(handle, nodisplay);
2455 API int pkgmgr_appinfo_is_multiple(pkgmgr_appinfo_h handle, bool *multiple)
2458 ret = pkgmgrinfo_appinfo_is_multiple(handle, multiple);
2462 API int pkgmgr_appinfo_is_taskmanage(pkgmgr_appinfo_h handle, bool *taskmanage)
2465 ret = pkgmgrinfo_appinfo_is_taskmanage(handle, taskmanage);
2469 API int pkgmgr_appinfo_get_hwacceleration(pkgmgr_appinfo_h handle, pkgmgr_hwacceleration_type *hwacceleration)
2472 pkgmgrinfo_app_hwacceleration hwacc;
2473 ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
2474 *hwacceleration = hwacc;
2478 API int pkgmgr_appinfo_is_onboot(pkgmgr_appinfo_h handle, bool *onboot)
2481 ret = pkgmgrinfo_appinfo_is_onboot(handle, onboot);
2485 API int pkgmgr_appinfo_is_autorestart(pkgmgr_appinfo_h handle, bool *autorestart)
2488 ret = pkgmgrinfo_appinfo_is_autorestart(handle, autorestart);
2492 API int pkgmgr_appinfo_destroy_appinfo(pkgmgr_appinfo_h handle)
2495 ret = pkgmgrinfo_appinfo_destroy_appinfo(handle);
2499 API int pkgmgr_pkginfo_create_certinfo(pkgmgr_certinfo_h *handle)
2502 ret = pkgmgrinfo_pkginfo_create_certinfo(handle);
2506 API int pkgmgr_pkginfo_load_certinfo(const char *pkgid, pkgmgr_certinfo_h handle)
2509 ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle);
2513 API int pkgmgr_pkginfo_get_cert_value(pkgmgr_certinfo_h handle, pkgmgr_cert_type cert_type, const char **cert_value)
2516 ret = pkgmgrinfo_pkginfo_get_cert_value(handle, cert_type, cert_value);
2520 API int pkgmgr_pkginfo_destroy_certinfo(pkgmgr_certinfo_h handle)
2523 ret = pkgmgrinfo_pkginfo_destroy_certinfo(handle);
2527 API int pkgmgr_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
2530 ret = pkgmgrinfo_datacontrol_get_info(providerid, type, appid, access);