4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
35 #include <pkgmgr-info.h>
36 #include <iniparser.h>
37 /* For multi-user support */
38 #include <tzplatform_config.h>
40 #include "package-manager.h"
41 #include "pkgmgr-internal.h"
42 #include "pkgmgr-debug.h"
43 #include "comm_client.h"
44 #include "comm_config.h"
46 /* API export macro */
48 #define API __attribute__ ((visibility("default")))
51 #define PKG_TMP_PATH tzplatform_mkpath(TZ_USER_APP, "tmp")
53 #define BINSH_NAME "/bin/sh"
56 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
57 #define REGULAR_USER 5000
59 static inline uid_t _getuid(void)
63 if (uid < REGULAR_USER)
69 static int _get_request_id()
71 static int internal_req_id = 1;
73 return internal_req_id++;
76 typedef struct _req_cb_info {
79 pkgmgr_handler event_cb;
80 pkgmgr_app_handler app_event_cb;
82 struct _req_cb_info *next;
85 typedef struct _listen_cb_info {
87 pkgmgr_handler event_cb;
88 pkgmgr_app_handler app_event_cb;
90 struct _listen_cb_info *next;
93 typedef struct _pkgmgr_client_t {
103 listen_cb_info *lhead;
111 typedef struct _iter_data {
112 pkgmgr_iter_fn iter_fn;
116 static int __xsystem(const char *argv[])
123 perror("fork failed");
127 execvp(argv[0], (char *const *)argv);
133 if (waitpid(pid, &status, 0) == -1) {
134 perror("waitpid failed");
137 if (WIFSIGNALED(status)) {
141 if (!WIFEXITED(status)) {
142 /* shouldn't happen */
143 perror("should not happen");
146 return WEXITSTATUS(status);
149 static void __error_to_string(int errnumber, char **errstr)
154 case PKGCMD_ERR_PACKAGE_NOT_FOUND:
155 *errstr = PKGCMD_ERR_PACKAGE_NOT_FOUND_STR;
157 case PKGCMD_ERR_PACKAGE_INVALID:
158 *errstr = PKGCMD_ERR_PACKAGE_INVALID_STR;
160 case PKGCMD_ERR_PACKAGE_LOWER_VERSION:
161 *errstr = PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR;
163 case PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND:
164 *errstr = PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR;
166 case PKGCMD_ERR_MANIFEST_INVALID:
167 *errstr = PKGCMD_ERR_MANIFEST_INVALID_STR;
169 case PKGCMD_ERR_CONFIG_NOT_FOUND:
170 *errstr = PKGCMD_ERR_CONFIG_NOT_FOUND_STR;
172 case PKGCMD_ERR_CONFIG_INVALID:
173 *errstr = PKGCMD_ERR_CONFIG_INVALID_STR;
175 case PKGCMD_ERR_SIGNATURE_NOT_FOUND:
176 *errstr = PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR;
178 case PKGCMD_ERR_SIGNATURE_INVALID:
179 *errstr = PKGCMD_ERR_SIGNATURE_INVALID_STR;
181 case PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED:
182 *errstr = PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR;
184 case PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND:
185 *errstr = PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR;
187 case PKGCMD_ERR_CERTIFICATE_INVALID:
188 *errstr = PKGCMD_ERR_CERTIFICATE_INVALID_STR;
190 case PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
191 *errstr = PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR;
193 case PKGCMD_ERR_CERTIFICATE_EXPIRED:
194 *errstr = PKGCMD_ERR_CERTIFICATE_EXPIRED_STR;
196 case PKGCMD_ERR_INVALID_PRIVILEGE:
197 *errstr = PKGCMD_ERR_INVALID_PRIVILEGE_STR;
199 case PKGCMD_ERR_MENU_ICON_NOT_FOUND:
200 *errstr = PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR;
202 case PKGCMD_ERR_FATAL_ERROR:
203 *errstr = PKGCMD_ERR_FATAL_ERROR_STR;
205 case PKGCMD_ERR_OUT_OF_STORAGE:
206 *errstr = PKGCMD_ERR_OUT_OF_STORAGE_STR;
208 case PKGCMD_ERR_OUT_OF_MEMORY:
209 *errstr = PKGCMD_ERR_OUT_OF_MEMORY_STR;
211 case PKGCMD_ERR_ARGUMENT_INVALID:
212 *errstr = PKGCMD_ERR_ARGUMENT_INVALID_STR;
215 *errstr = PKGCMD_ERR_UNKNOWN_STR;
220 static void __add_op_cbinfo(pkgmgr_client_t * pc, int request_id,
221 const char *req_key, pkgmgr_handler event_cb, void *new_event_cb,
224 req_cb_info *cb_info;
225 req_cb_info *current;
228 cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
229 if (cb_info == NULL) {
230 DBG("calloc failed");
233 cb_info->request_id = request_id;
234 cb_info->req_key = strdup(req_key);
235 cb_info->event_cb = event_cb;
236 cb_info->data = data;
237 cb_info->next = NULL;
238 cb_info->app_event_cb = NULL;
239 pc->new_event_cb = new_event_cb;
241 if (pc->info.request.rhead == NULL)
242 pc->info.request.rhead = cb_info;
244 current = prev = pc->info.request.rhead;
247 current = current->next;
250 prev->next = cb_info;
254 static void __add_op_app_cbinfo(pkgmgr_client_t * pc, int request_id,
255 const char *req_key, pkgmgr_app_handler app_event_cb, void *data)
257 req_cb_info *cb_info;
258 req_cb_info *current;
261 cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
262 if (cb_info == NULL) {
263 DBG("calloc failed");
266 cb_info->request_id = request_id;
267 cb_info->req_key = strdup(req_key);
268 cb_info->event_cb = NULL;
269 cb_info->app_event_cb = app_event_cb;
270 cb_info->data = data;
271 cb_info->next = NULL;
272 pc->new_event_cb = NULL;
274 if (pc->info.request.rhead == NULL)
275 pc->info.request.rhead = cb_info;
277 current = prev = pc->info.request.rhead;
280 current = current->next;
283 prev->next = cb_info;
287 static req_cb_info *__find_op_cbinfo(pkgmgr_client_t *pc, const char *req_key)
291 tmp = pc->info.request.rhead;
298 DBG("tmp->req_key %s, req_key %s", tmp->req_key, req_key);
301 if (strncmp(tmp->req_key, req_key, strlen(tmp->req_key)) == 0)
308 static int __remove_stat_cbinfo(pkgmgr_client_t *pc)
310 listen_cb_info *info = pc->info.listening.lhead;
311 listen_cb_info *next = NULL;
313 while (info != NULL) {
319 pc->info.listening.lhead = NULL;
323 static void __add_app_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
324 pkgmgr_app_handler event_cb, void *data)
326 listen_cb_info *cb_info;
327 listen_cb_info *current;
328 listen_cb_info *prev;
330 cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
331 if (cb_info == NULL) {
332 DBG("calloc failed");
335 cb_info->request_id = request_id;
336 cb_info->app_event_cb = event_cb;
337 cb_info->data = data;
338 cb_info->next = NULL;
340 if (pc->info.listening.lhead == NULL)
341 pc->info.listening.lhead = cb_info;
343 current = prev = pc->info.listening.lhead;
346 current = current->next;
349 prev->next = cb_info;
353 static void __add_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
354 pkgmgr_handler event_cb, void *data)
356 listen_cb_info *cb_info;
357 listen_cb_info *current;
358 listen_cb_info *prev;
360 cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
361 if (cb_info == NULL) {
362 DBG("calloc failed");
365 cb_info->request_id = request_id;
366 cb_info->event_cb = event_cb;
367 cb_info->data = data;
368 cb_info->next = NULL;
370 /* TODO - check the order of callback - FIFO or LIFO => Should be changed to LIFO */
371 if (pc->info.listening.lhead == NULL)
372 pc->info.listening.lhead = cb_info;
374 current = prev = pc->info.listening.lhead;
377 current = current->next;
380 prev->next = cb_info;
384 static void __operation_callback(void *cb_data, uid_t target_uid,
385 const char *req_id, const char *pkg_type,
386 const char *pkgid, const char *appid,
387 const char *key, const char *val)
390 req_cb_info *cb_info;
392 pc = (pkgmgr_client_t *) cb_data;
394 /* find callback info */
395 cb_info = __find_op_cbinfo(pc, req_id);
396 if (cb_info == NULL) {
397 ERR("cannot fint cb_info for req_id:%s", req_id);
402 if (appid != NULL && strlen(appid) != 0 && cb_info->app_event_cb) {
403 /* run app callback */
404 if (pc->new_event_cb)
405 cb_info->app_event_cb(target_uid, cb_info->request_id,
406 pkg_type, pkgid, appid, key, val, pc,
409 cb_info->app_event_cb(target_uid, cb_info->request_id,
410 pkg_type, pkgid, appid, key, val, NULL,
412 } else if (cb_info->event_cb) {
413 /* run pkg callback */
414 if (pc->new_event_cb)
415 cb_info->event_cb(target_uid, cb_info->request_id,
416 pkg_type, pkgid, key, val, pc,
419 cb_info->event_cb(target_uid, cb_info->request_id,
420 pkg_type, pkgid, key, val, NULL,
427 static void __status_callback(void *cb_data, uid_t target_uid,
428 const char *req_id, const char *pkg_type,
429 const char *pkgid, const char *appid,
430 const char *key, const char *val)
435 pc = (pkgmgr_client_t *) cb_data;
437 tmp = pc->info.listening.lhead;
439 if (appid != NULL && strlen(appid) != 0) {
440 /* run app callback */
441 if (tmp->app_event_cb && tmp->app_event_cb(
442 target_uid, tmp->request_id, pkg_type, pkgid,
443 appid, key, val, NULL, tmp->data) != 0)
446 /* run pkg callback */
447 if (tmp->event_cb && tmp->event_cb(
448 target_uid, tmp->request_id, pkg_type, pkgid,
449 key, val, NULL, tmp->data) != 0)
458 static inline int __read_proc(const char *path, char *buf, int size)
463 if (buf == NULL || path == NULL)
466 fd = open(path, O_RDONLY);
470 ret = read(fd, buf, size - 1);
482 char *__proc_get_cmdline_bypid(int pid)
484 char buf[PKG_STRING_LEN_MAX] = {'\0', };
487 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
488 ret = __read_proc(buf, buf, sizeof(buf));
492 /* support app launched by shell script*/
493 if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0)
494 return strdup(&buf[BINSH_SIZE + 1]);
499 static inline int __pkgmgr_read_proc(const char *path, char *buf, int size)
504 if (buf == NULL || path == NULL)
507 fd = open(path, O_RDONLY);
511 ret = read(fd, buf, size - 1);
523 static inline int __pkgmgr_find_pid_by_cmdline(const char *dname,
524 const char *cmdline, const char *apppath)
528 if (strncmp(cmdline, apppath, PKG_STRING_LEN_MAX-1) == 0) {
530 if (pid != getpgid(pid))
537 static int __sync_process(const char *req_key)
540 char info_file[PKG_STRING_LEN_MAX] = {'\0', };
544 char buf[PKG_STRING_LEN_MAX] = {0, };
546 snprintf(info_file, PKG_STRING_LEN_MAX, "%s/%s", PKG_SIZE_INFO_PATH, req_key);
551 if (access(info_file, F_OK) == 0) {
552 fp = fopen(info_file, "r");
554 DBG("file is not generated yet.... wait\n");
555 usleep(100 * 1000); /* 100ms sleep*/
559 if (fgets(buf, PKG_STRING_LEN_MAX, fp) == NULL) {
560 ERR("failed to read info file");
566 DBG("info_file file is generated, result = %s. \n", buf);
571 DBG("file is not generated yet.... wait\n");
572 usleep(100 * 1000); /* 100ms sleep*/
574 if (check_cnt > 6000) { /* 60s * 10 time over*/
575 ERR("wait time over!!\n");
580 ret = remove(info_file);
582 ERR("file is can not remove[%s, %d]\n", info_file, ret);
587 static int __csc_process(const char *csc_path, char *result_path)
594 char *pkgtype = NULL;
596 char buf[PKG_STRING_LEN_MAX] = {0,};
597 char type_buf[1024] = { 0 };
598 char des_buf[1024] = { 0 };
599 dictionary *csc = NULL;
602 csc = iniparser_load(csc_path);
603 retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path);
605 file = fopen(result_path, "w");
606 tryvm_if(file == NULL, ret = PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path);
608 count = iniparser_getint(csc, "csc packages:count", -1);
609 tryvm_if(count == 0, ret = PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path);
611 snprintf(buf, PKG_STRING_LEN_MAX, "[result]\n");
612 fwrite(buf, 1, strlen(buf), file);
613 snprintf(buf, PKG_STRING_LEN_MAX, "count = %d\n", count);
614 fwrite(buf, 1, strlen(buf), file);
616 for(cnt = 1 ; cnt <= count ; cnt++)
618 snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt);
619 snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt);
621 pkgtype = iniparser_getstring(csc, type_buf, NULL);
622 des = iniparser_getstring(csc, des_buf, NULL);
625 if (pkgtype == NULL) {
627 snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get pkgtype\n", type_buf);
628 fwrite(buf, 1, strlen(buf), file);
630 } else if (des == NULL) {
632 snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get description\n", des_buf);
633 fwrite(buf, 1, strlen(buf), file);
637 snprintf(buf, PKG_STRING_LEN_MAX, "type_%03d = %s\n", cnt, pkgtype);
638 fwrite(buf, 1, strlen(buf), file);
639 snprintf(buf, PKG_STRING_LEN_MAX, "description_%03d = %s\n", cnt, des);
640 fwrite(buf, 1, strlen(buf), file);
642 if (strcmp(pkgtype, "tpk") == 0) {
643 const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL };
644 ret = __xsystem(ospinstaller_argv);
645 } else if (strcmp(pkgtype, "wgt")== 0) {
646 const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL };
647 ret = __xsystem(wrtinstaller_argv);
655 __error_to_string(ret, &errstr);
656 snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = fail[%s]\n", cnt, errstr);
659 snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = success\n", cnt);
661 fwrite(buf, 1, strlen(buf), file);
665 iniparser_freedict(csc);
675 static int __get_size_process(pkgmgr_client * pc, const char *pkgid, uid_t uid,
676 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
680 int ret = PKGMGR_R_ECOMM;
681 char *req_key = NULL;
682 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
684 if (pc == NULL || pkgid == NULL) {
685 ERR("invalid parameter");
686 return PKGMGR_R_EINVAL;
689 if (mpc->ctype != PC_REQUEST) {
690 ERR("mpc->ctype is not PC_REQUEST");
691 return PKGMGR_R_EINVAL;
694 ret = comm_client_request(mpc->info.request.cc, "getsize",
695 g_variant_new("(usi)", uid, pkgid, get_type), &result);
696 if (ret != PKGMGR_R_OK) {
697 ERR("request failed: %d", ret);
701 g_variant_get(result, "(i&s)", &ret, &req_key);
702 if (req_key == NULL) {
703 g_variant_unref(result);
704 return PKGMGR_R_ECOMM;
706 if (ret != PKGMGR_R_OK) {
707 g_variant_unref(result);
711 ret = __sync_process(req_key);
713 ERR("get size failed, ret=%d\n", ret);
715 g_variant_unref(result);
720 static int __move_pkg_process(pkgmgr_client *pc, const char *pkgid,
721 const char *pkg_type, uid_t uid, pkgmgr_move_type move_type,
722 pkgmgr_handler event_cb, void *data)
726 ret = pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, 0, uid);
728 ERR("move request failed");
735 static int __check_app_process(pkgmgr_request_service_type service_type,
736 pkgmgr_client *pc, const char *pkgid, uid_t uid, void *data)
739 int ret = PKGMGR_R_ECOMM;
740 pkgmgrinfo_pkginfo_h handle;
742 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
744 retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
746 if (uid != GLOBAL_USER)
747 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
749 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
750 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgrinfo_pkginfo_get_pkginfo failed");
752 if (service_type == PM_REQUEST_KILL_APP)
753 ret = comm_client_request(mpc->info.request.cc, "kill",
754 g_variant_new("(us)", uid, pkgid), &result);
755 else if (service_type == PM_REQUEST_CHECK_APP)
756 ret = comm_client_request(mpc->info.request.cc, "check",
757 g_variant_new("(us)", uid, pkgid), &result);
758 if (ret != PKGMGR_R_OK) {
759 ERR("request failed: %d", ret);
763 g_variant_get(result, "(i)", &ret);
764 g_variant_unref(result);
765 if (ret != PKGMGR_R_OK) {
766 ERR("request failed, ret=%d", ret);
771 pid = __sync_process(pkgid);
774 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
780 static int __request_size_info(pkgmgr_client *pc, uid_t uid)
783 int ret = PKGMGR_R_ECOMM;
784 char *req_key = NULL;
785 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
788 ERR("invalid parameter");
789 return PKGMGR_R_EINVAL;
792 if (mpc->ctype != PC_REQUEST) {
793 ERR("mpc->ctype is not PC_REQUEST");
794 return PKGMGR_R_EINVAL;
797 ret = comm_client_request(mpc->info.request.cc, "getsize",
798 g_variant_new("(usi)", uid, "size_info",
801 if (ret != PKGMGR_R_OK) {
802 ERR("request failed: %d", ret);
806 g_variant_get(result, "(i&s)", &ret, &req_key);
807 if (req_key == NULL) {
808 g_variant_unref(result);
809 return PKGMGR_R_ECOMM;
812 g_variant_unref(result);
817 static int __change_op_cb_for_getsize(pkgmgr_client *pc)
821 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
822 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
824 /* free listening head */
825 req_cb_info *tmp = NULL;
826 req_cb_info *prev = NULL;
827 for (tmp = mpc->info.request.rhead; tmp;) {
833 /* free dbus connection */
834 ret = comm_client_free(mpc->info.request.cc);
835 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
837 /* Manage pc for seperated event */
838 mpc->ctype = PC_REQUEST;
839 mpc->status_type = PKGMGR_CLIENT_STATUS_GET_SIZE;
842 mpc->info.request.cc = comm_client_new();
843 retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
845 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_GET_SIZE, mpc->info.request.cc, __operation_callback, pc);
846 retvm_if(ret < 0, PKGMGR_R_ERROR, "set_status_callback() failed - %d", ret);
851 static int __change_op_cb_for_enable_disable(pkgmgr_client *pc, bool is_disable)
855 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
856 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
858 /* free listening head */
859 req_cb_info *tmp = NULL;
860 req_cb_info *prev = NULL;
861 for (tmp = mpc->info.request.rhead; tmp;) {
867 /* free dbus connection */
868 ret = comm_client_free(mpc->info.request.cc);
869 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
871 /* Manage pc for seperated event */
872 mpc->ctype = PC_REQUEST;
874 mpc->status_type = PKGMGR_CLIENT_STATUS_DISABLE_APP;
876 mpc->status_type = PKGMGR_CLIENT_STATUS_ENABLE_APP;
879 mpc->info.request.cc = comm_client_new();
880 retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
883 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_DISABLE_APP, mpc->info.request.cc, __operation_callback, pc);
885 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ENABLE_APP, mpc->info.request.cc, __operation_callback, pc);
886 retvm_if(ret < 0, PKGMGR_R_ERROR, "set_status_callback() failed - %d", ret);
891 static int __get_pkg_size_info_cb(uid_t target_uid, int req_id, const char *req_type,
892 const char *pkgid, const char *key,
893 const char *value, const void *pc, void *user_data)
896 DBG("target_uid: %u, reqid: %d, req type: %s, pkgid: %s, unused key: %s, size info: %s",
897 target_uid, req_id, req_type, pkgid, key, value);
899 pkg_size_info_t *size_info = (pkg_size_info_t *)malloc(sizeof(pkg_size_info_t));
900 retvm_if(size_info == NULL, -1, "The memory is insufficient.");
902 char *save_ptr = NULL;
903 char *token = strtok_r((char*)value, ":", &save_ptr);
904 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
905 size_info->data_size = atoll(token);
906 token = strtok_r(NULL, ":", &save_ptr);
907 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
908 size_info->cache_size = atoll(token);
909 token = strtok_r(NULL, ":", &save_ptr);
910 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
911 size_info->app_size = atoll(token);
912 token = strtok_r(NULL, ":", &save_ptr);
913 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
914 size_info->ext_data_size = atoll(token);
915 token = strtok_r(NULL, ":", &save_ptr);
916 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
917 size_info->ext_cache_size = atoll(token);
918 token = strtok_r(NULL, ":", &save_ptr);
919 tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo");
920 size_info->ext_app_size = atoll(token);
922 DBG("data: %lld, cache: %lld, app: %lld, ext_data: %lld, ext_cache: %lld, ext_app: %lld",
923 size_info->data_size, size_info->cache_size, size_info->app_size,
924 size_info->ext_data_size, size_info->ext_cache_size, size_info->ext_app_size);
926 pkgmgr_client_t *pmc = (pkgmgr_client_t *)pc;
927 tryvm_if(pmc == NULL, ret = -1, "pkgmgr_client instance is null.");
929 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
930 { // total package size info
931 pkgmgr_total_pkg_size_info_receive_cb callback = (pkgmgr_total_pkg_size_info_receive_cb)(pmc->new_event_cb);
932 callback((pkgmgr_client *)pc, size_info, user_data);
936 pkgmgr_pkg_size_info_receive_cb callback = (pkgmgr_pkg_size_info_receive_cb)(pmc->new_event_cb);
937 callback((pkgmgr_client *)pc, pkgid, size_info, user_data);
949 API pkgmgr_client *pkgmgr_client_new(client_type ctype)
951 pkgmgr_client_t *pc = NULL;
954 retvm_if(ctype == PC_BROADCAST, NULL, "broadcast type is not supported");
955 retvm_if(ctype != PC_REQUEST && ctype != PC_LISTENING, NULL, "ctype is not client_type");
957 /* Allocate memory for ADT:pkgmgr_client */
958 pc = calloc(1, sizeof(pkgmgr_client_t));
959 retvm_if(pc == NULL, NULL, "No memory");
963 pc->status_type = PKGMGR_CLIENT_STATUS_ALL;
966 if (pc->ctype == PC_REQUEST) {
967 pc->info.request.cc = comm_client_new();
968 trym_if(pc->info.request.cc == NULL, "client creation failed");
970 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.request.cc, __operation_callback, pc);
971 trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
972 } else if (pc->ctype == PC_LISTENING) {
973 pc->info.listening.cc = comm_client_new();
974 trym_if(pc->info.listening.cc == NULL, "client creation failed");
976 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.listening.cc, __status_callback, pc);
977 trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
980 return (pkgmgr_client *) pc;
988 API int pkgmgr_client_free(pkgmgr_client *pc)
991 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
992 retvm_if(mpc == NULL, PKGMGR_R_EINVAL, "Invalid argument");
994 if (mpc->ctype == PC_REQUEST) {
997 for (tmp = mpc->info.request.rhead; tmp;) {
1003 ret = comm_client_free(mpc->info.request.cc);
1004 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed");
1005 } else if (mpc->ctype == PC_LISTENING) {
1006 listen_cb_info *tmp;
1007 listen_cb_info *prev;
1008 for (tmp = mpc->info.listening.lhead; tmp;) {
1014 ret = comm_client_free(mpc->info.listening.cc);
1015 tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed");
1016 } else if (mpc->ctype == PC_BROADCAST) {
1019 ERR("Invalid client type\n");
1020 return PKGMGR_R_EINVAL;
1023 if (mpc->tep_path) {
1024 free(mpc->tep_path);
1025 mpc->tep_path = NULL;
1028 if (mpc->tep_move) {
1029 free(mpc->tep_move);
1030 mpc->tep_move = NULL;
1042 return PKGMGR_R_ERROR;
1045 static char *__get_type_from_path(const char *pkg_path)
1048 char mimetype[255] = { '\0', };
1049 char extlist[256] = { '\0', };
1052 ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype));
1054 ERR("_get_mime_from_file() failed - error code[%d]\n", ret);
1058 ret = _get_mime_extension(mimetype, extlist, sizeof(extlist));
1060 ERR("_get_mime_extension() failed - error code[%d]\n", ret);
1064 if (strlen(extlist) == 0)
1067 if (strchr(extlist, ','))
1068 extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0';
1070 pkg_type = strchr(extlist, '.') + 1;
1071 return strdup(pkg_type);
1074 static int __change_op_cb_for_enable_disable_splash_screen(pkgmgr_client *pc,
1078 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1083 ERR("package mananger client pc is NULL");
1084 return PKGMGR_R_EINVAL;
1087 for (tmp = mpc->info.request.rhead; tmp;) {
1093 ret = comm_client_free(mpc->info.request.cc);
1095 ERR("comm_client_free() failed - %d", ret);
1096 return PKGMGR_R_ERROR;
1099 mpc->ctype = PC_REQUEST;
1101 mpc->status_type = PKGMGR_CLIENT_STATUS_ENABLE_APP_SPLASH_SCREEN;
1103 mpc->status_type = PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN;
1105 mpc->info.request.cc = comm_client_new();
1106 if (mpc->info.request.cc == NULL) {
1107 ERR("client creation failed");
1108 return PKGMGR_R_ENOMEM;
1112 ret = comm_client_set_status_callback(
1113 COMM_STATUS_BROADCAST_ENABLE_APP_SPLASH_SCREEN,
1114 mpc->info.request.cc, __operation_callback, pc);
1116 ret = comm_client_set_status_callback(
1117 COMM_STATUS_BROADCAST_DISABLE_APP_SPLASH_SCREEN,
1118 mpc->info.request.cc, __operation_callback, pc);
1121 ERR("set_status_callback() failed - %d", ret);
1122 return PKGMGR_R_ERROR;
1128 API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, char *tep_path, char *tep_move)
1130 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1131 retvm_if(tep_path == NULL, PKGMGR_R_EINVAL, "tep path is NULL");
1132 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1134 mpc->tep_path = strdup(tep_path);
1135 mpc->tep_move = strdup(tep_move);
1140 API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type,
1141 const char *descriptor_path, const char *pkg_path,
1142 const char *optional_data, pkgmgr_mode mode,
1143 pkgmgr_handler event_cb, void *data, uid_t uid)
1146 int ret = PKGMGR_R_ECOMM;
1147 char *req_key = NULL;
1148 GVariantBuilder *builder = NULL;
1149 GVariant *args = NULL;
1151 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1154 if (pc == NULL || pkg_path == NULL) {
1155 ERR("invalid parameter");
1156 return PKGMGR_R_EINVAL;
1159 if (mpc->ctype != PC_REQUEST) {
1160 ERR("mpc->ctype is not PC_REQUEST");
1161 return PKGMGR_R_EINVAL;
1164 if (access(pkg_path, F_OK) != 0) {
1165 ERR("failed to access: %s", pkg_path);
1166 return PKGMGR_R_EINVAL;
1169 if (mpc->tep_path != NULL && access(mpc->tep_path, F_OK) != 0) {
1170 ERR("failed to access: %s", mpc->tep_path);
1171 return PKGMGR_R_EINVAL;
1174 /* TODO: check pkg's type on server-side */
1175 if (pkg_type == NULL)
1176 pkgtype = __get_type_from_path(pkg_path);
1178 pkgtype = strdup(pkg_type);
1180 /* build arguments */
1181 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1182 if (mpc->tep_path) {
1183 g_variant_builder_add(builder, "s", "-e");
1184 g_variant_builder_add(builder, "s", mpc->tep_path);
1185 g_variant_builder_add(builder, "s", "-M");
1186 g_variant_builder_add(builder, "s", mpc->tep_move);
1189 args = g_variant_new("as", builder);
1190 g_variant_builder_unref(builder);
1192 ret = comm_client_request(mpc->info.request.cc, "install",
1193 g_variant_new("(uss@as)", uid, pkgtype, pkg_path, args),
1195 if (ret != PKGMGR_R_OK) {
1196 ERR("request failed: %d", ret);
1200 g_variant_get(result, "(i&s)", &ret, &req_key);
1201 if (req_key == NULL) {
1202 g_variant_unref(result);
1203 return PKGMGR_R_ECOMM;
1205 if (ret != PKGMGR_R_OK) {
1206 g_variant_unref(result);
1210 req_id = _get_request_id();
1211 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1213 g_variant_unref(result);
1218 API int pkgmgr_client_install(pkgmgr_client *pc, const char *pkg_type,
1219 const char *descriptor_path, const char *pkg_path,
1220 const char *optional_data, pkgmgr_mode mode,
1221 pkgmgr_handler event_cb, void *data)
1223 return pkgmgr_client_usr_install(pc, pkg_type, descriptor_path,
1224 pkg_path, optional_data, mode, event_cb,data,
1228 API int pkgmgr_client_reinstall(pkgmgr_client *pc, const char *pkg_type,
1229 const char *pkgid, const char *optional_data, pkgmgr_mode mode,
1230 pkgmgr_handler event_cb, void *data)
1232 return pkgmgr_client_usr_reinstall(pc, pkg_type, pkgid, optional_data,
1233 mode, event_cb, data, _getuid());
1236 API int pkgmgr_client_usr_reinstall(pkgmgr_client * pc, const char *pkg_type,
1237 const char *pkgid, const char *optional_data, pkgmgr_mode mode,
1238 pkgmgr_handler event_cb, void *data, uid_t uid)
1241 int ret = PKGMGR_R_ECOMM;
1242 char *req_key = NULL;
1244 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1246 pkgmgrinfo_pkginfo_h handle;
1248 if (pc == NULL || pkgid == NULL) {
1249 ERR("invalid parameter");
1250 return PKGMGR_R_EINVAL;
1253 if (mpc->ctype != PC_REQUEST) {
1254 ERR("mpc->ctype is not PC_REQUEST");
1255 return PKGMGR_R_EINVAL;
1258 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
1260 return PKGMGR_R_EINVAL;
1262 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
1264 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1265 return PKGMGR_R_ERROR;
1268 ret = comm_client_request(mpc->info.request.cc, "reinstall",
1269 g_variant_new("(uss)", uid, pkgtype, pkgid), &result);
1270 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1271 if (ret != PKGMGR_R_OK) {
1272 ERR("request failed: %d", ret);
1276 g_variant_get(result, "(i&s)", &ret, &req_key);
1277 if (req_key == NULL) {
1278 g_variant_unref(result);
1279 return PKGMGR_R_ECOMM;
1281 if (ret != PKGMGR_R_OK) {
1282 g_variant_unref(result);
1286 req_id = _get_request_id();
1287 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1289 g_variant_unref(result);
1294 API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type,
1295 const char *descriptor_path, const char *pkg_path,
1296 const char *optional_data, pkgmgr_mode mode,
1297 pkgmgr_handler event_cb, void *data, uid_t uid)
1300 int ret = PKGMGR_R_ECOMM;
1301 char *req_key = NULL;
1302 GVariantBuilder *builder = NULL;
1303 GVariant *args = NULL;
1305 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1308 if (pc == NULL || pkg_path == NULL) {
1309 ERR("invalid parameter");
1310 return PKGMGR_R_EINVAL;
1313 if (mpc->ctype != PC_REQUEST) {
1314 ERR("mpc->ctype is not PC_REQUEST");
1315 return PKGMGR_R_EINVAL;
1318 if (access(pkg_path, F_OK) != 0) {
1319 ERR("failed to access: %s", pkg_path);
1320 return PKGMGR_R_EINVAL;
1323 if (mpc->tep_path != NULL && access(mpc->tep_path, F_OK) != 0) {
1324 ERR("failed to access: %s", mpc->tep_path);
1325 return PKGMGR_R_EINVAL;
1328 /* TODO: check pkg's type on server-side */
1329 if (pkg_type == NULL)
1330 pkgtype = __get_type_from_path(pkg_path);
1332 pkgtype = strdup(pkg_type);
1334 /* build arguments */
1335 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1336 if (mpc->tep_path) {
1337 g_variant_builder_add(builder, "s", "-e");
1338 g_variant_builder_add(builder, "s", mpc->tep_path);
1339 g_variant_builder_add(builder, "s", "-M");
1340 g_variant_builder_add(builder, "s", mpc->tep_move);
1343 args = g_variant_new("as", builder);
1344 g_variant_builder_unref(builder);
1346 ret = comm_client_request(mpc->info.request.cc, "mount_install",
1347 g_variant_new("(uss@as)", uid, pkgtype, pkg_path, args),
1349 if (ret != PKGMGR_R_OK) {
1350 ERR("request failed: %d", ret);
1354 g_variant_get(result, "(i&s)", &ret, &req_key);
1355 if (req_key == NULL) {
1356 g_variant_unref(result);
1357 return PKGMGR_R_ECOMM;
1359 if (ret != PKGMGR_R_OK) {
1360 g_variant_unref(result);
1364 req_id = _get_request_id();
1365 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1367 g_variant_unref(result);
1372 API int pkgmgr_client_mount_install(pkgmgr_client *pc, const char *pkg_type,
1373 const char *descriptor_path, const char *pkg_path,
1374 const char *optional_data, pkgmgr_mode mode,
1375 pkgmgr_handler event_cb, void *data)
1377 return pkgmgr_client_usr_mount_install(pc, pkg_type, descriptor_path,
1378 pkg_path, optional_data, mode, event_cb,data,
1382 API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
1383 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
1386 return pkgmgr_client_usr_uninstall(pc, pkg_type,pkgid, mode, event_cb,
1390 API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type,
1391 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
1392 void *data, uid_t uid)
1395 int ret = PKGMGR_R_ECOMM;
1396 char *req_key = NULL;
1398 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1400 pkgmgrinfo_pkginfo_h handle;
1402 if (pc == NULL || pkgid == NULL) {
1403 ERR("invalid parameter");
1404 return PKGMGR_R_EINVAL;
1407 if (mpc->ctype != PC_REQUEST) {
1408 ERR("mpc->ctype is not PC_REQUEST");
1409 return PKGMGR_R_EINVAL;
1412 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
1414 return PKGMGR_R_EINVAL;
1416 ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
1418 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1419 return PKGMGR_R_ERROR;
1422 ret = comm_client_request(mpc->info.request.cc, "uninstall",
1423 g_variant_new("(uss)", uid, pkgtype, pkgid), &result);
1424 if (ret != PKGMGR_R_OK) {
1425 ERR("request failed: %d", ret);
1426 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1430 g_variant_get(result, "(i&s)", &ret, &req_key);
1431 if (req_key == NULL) {
1432 g_variant_unref(result);
1433 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1434 return PKGMGR_R_ECOMM;
1436 if (ret != PKGMGR_R_OK) {
1437 g_variant_unref(result);
1438 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1442 req_id = _get_request_id();
1443 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1445 g_variant_unref(result);
1446 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1451 API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
1452 const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode)
1454 return pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, mode,
1457 API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type,
1458 const char *pkgid, pkgmgr_move_type move_type,
1459 pkgmgr_mode mode, uid_t uid)
1462 int ret = PKGMGR_R_ECOMM;
1463 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1465 if (pc == NULL || pkg_type == NULL || pkgid == NULL) {
1466 ERR("invalid parameter");
1467 return PKGMGR_R_EINVAL;
1470 if ((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD))
1471 return PKGMGR_R_EINVAL;
1473 if (mpc->ctype != PC_REQUEST) {
1474 ERR("mpc->ctype is not PC_REQUEST");
1475 return PKGMGR_R_EINVAL;
1478 ret = comm_client_request(mpc->info.request.cc, "move",
1479 g_variant_new("(ussi)", uid, pkg_type, pkgid, move_type), &result);
1480 if (ret != PKGMGR_R_OK) {
1481 ERR("request failed: %d", ret);
1485 g_variant_get(result, "(i)", &ret);
1486 g_variant_unref(result);
1491 API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type,
1492 const char *pkgid, uid_t uid)
1495 int ret = PKGMGR_R_ECOMM;
1496 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1498 if (pc == NULL || pkgid == NULL || pkg_type == NULL) {
1499 ERR("invalid parameter");
1500 return PKGMGR_R_EINVAL;
1503 ret = comm_client_request(mpc->info.request.cc, "enable_pkg",
1504 g_variant_new("(uss)", uid, pkg_type, pkgid), &result);
1505 if (ret != PKGMGR_R_OK) {
1506 ERR("request failed: %d", ret);
1510 g_variant_get(result, "(i)", &ret);
1511 g_variant_unref(result);
1516 API int pkgmgr_client_activate(pkgmgr_client *pc, const char *pkg_type,
1519 return pkgmgr_client_usr_activate(pc, pkg_type, pkgid, _getuid());
1522 API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type,
1523 const char *pkgid, uid_t uid)
1526 int ret = PKGMGR_R_ECOMM;
1527 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1529 if (pc == NULL || pkgid == NULL || pkg_type == NULL) {
1530 ERR("invalid parameter");
1531 return PKGMGR_R_EINVAL;
1534 ret = comm_client_request(mpc->info.request.cc, "disable_pkg",
1535 g_variant_new("(uss)", uid, pkg_type, pkgid), &result);
1536 if (ret != PKGMGR_R_OK) {
1537 ERR("request failed: %d", ret);
1541 g_variant_get(result, "(i)", &ret);
1542 g_variant_unref(result);
1547 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
1550 return pkgmgr_client_usr_deactivate(pc, pkg_type, pkgid, _getuid());
1553 /* TODO: deprecate? */
1554 API int pkgmgr_client_usr_activate_appv(pkgmgr_client *pc, const char *appid,
1555 char *const argv[], uid_t uid)
1557 return pkgmgr_client_usr_activate_app(pc, appid, NULL, uid);
1560 API int pkgmgr_client_activate_appv(pkgmgr_client *pc, const char *appid,
1563 return pkgmgr_client_usr_activate_app(pc, appid, NULL, _getuid());
1566 API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid,
1567 pkgmgr_app_handler app_event_cb, uid_t uid)
1570 int ret = PKGMGR_R_ECOMM;
1572 char *req_key = NULL;
1573 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1575 if (pc == NULL || appid == NULL) {
1576 ERR("invalid parameter");
1577 return PKGMGR_R_EINVAL;
1580 if (__change_op_cb_for_enable_disable(mpc, false) < 0) {
1581 ERR("__change_op_cb_for_enable_disable failed");
1582 return PKGMGR_R_ESYSTEM;
1585 ret = comm_client_request(mpc->info.request.cc, "enable_app",
1586 g_variant_new("(us)", uid, appid), &result);
1587 if (ret != PKGMGR_R_OK) {
1588 ERR("request failed: %d", ret);
1592 g_variant_get(result, "(i&s)", &ret, &req_key);
1593 if (req_key == NULL) {
1594 g_variant_unref(result);
1595 return PKGMGR_R_ECOMM;
1597 if (ret != PKGMGR_R_OK) {
1598 g_variant_unref(result);
1602 req_id = _get_request_id();
1603 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1604 g_variant_unref(result);
1608 API int pkgmgr_client_activate_app(pkgmgr_client * pc, const char *appid, pkgmgr_app_handler app_event_cb)
1610 return pkgmgr_client_usr_activate_app(pc, appid, app_event_cb, _getuid());
1613 API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc,
1614 const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid)
1617 int ret = PKGMGR_R_ECOMM;
1619 char *req_key = NULL;
1620 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1622 if (pc == NULL || appid == NULL) {
1623 ERR("invalid parameter");
1624 return PKGMGR_R_EINVAL;
1627 if (__change_op_cb_for_enable_disable(mpc, false) < 0) {
1628 ERR("__change_op_cb_for_enable_disable failed");
1629 return PKGMGR_R_ESYSTEM;
1632 ret = comm_client_request(mpc->info.request.cc, "enable_global_app_for_uid",
1633 g_variant_new("(us)", uid, appid), &result);
1634 if (ret != PKGMGR_R_OK) {
1635 ERR("request failed: %d", ret);
1639 g_variant_get(result, "(i&s)", &ret, &req_key);
1640 if (req_key == NULL) {
1641 g_variant_unref(result);
1642 return PKGMGR_R_ECOMM;
1644 if (ret != PKGMGR_R_OK) {
1645 g_variant_unref(result);
1649 req_id = _get_request_id();
1650 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1655 API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid,
1656 pkgmgr_app_handler app_event_cb, uid_t uid)
1659 int ret = PKGMGR_R_ECOMM;
1660 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1662 char *req_key = NULL;
1664 if (pc == NULL || appid == NULL) {
1665 ERR("invalid parameter");
1666 return PKGMGR_R_EINVAL;
1670 if (__change_op_cb_for_enable_disable(mpc, true) < 0) {
1671 ERR("__change_op_cb_for_enable_disable failed");
1672 return PKGMGR_R_ESYSTEM;
1675 ret = comm_client_request(mpc->info.request.cc, "disable_app",
1676 g_variant_new("(us)", uid, appid), &result);
1677 if (ret != PKGMGR_R_OK) {
1678 ERR("request failed: %d", ret);
1682 g_variant_get(result, "(i&s)", &ret, &req_key);
1683 if (req_key == NULL) {
1684 g_variant_unref(result);
1685 return PKGMGR_R_ECOMM;
1687 if (ret != PKGMGR_R_OK) {
1688 g_variant_unref(result);
1692 req_id = _get_request_id();
1693 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1695 g_variant_unref(result);
1699 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid, pkgmgr_app_handler app_event_cb)
1701 return pkgmgr_client_usr_deactivate_app(pc, appid, app_event_cb, _getuid());
1704 API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc,
1705 const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid)
1708 int ret = PKGMGR_R_ECOMM;
1710 char *req_key = NULL;
1711 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1713 if (pc == NULL || appid == NULL) {
1714 ERR("invalid parameter");
1715 return PKGMGR_R_EINVAL;
1718 if (__change_op_cb_for_enable_disable(mpc, true) < 0) {
1719 ERR("__change_op_cb_for_enable_disable failed");
1720 return PKGMGR_R_ESYSTEM;
1723 ret = comm_client_request(mpc->info.request.cc, "disable_global_app_for_uid",
1724 g_variant_new("(us)", uid, appid), &result);
1725 if (ret != PKGMGR_R_OK) {
1726 ERR("request failed: %d", ret);
1730 g_variant_get(result, "(i&s)", &ret, &req_key);
1731 if (req_key == NULL) {
1732 g_variant_unref(result);
1733 return PKGMGR_R_ECOMM;
1735 if (ret != PKGMGR_R_OK) {
1736 g_variant_unref(result);
1740 req_id = _get_request_id();
1741 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1745 API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc,
1746 const char *pkg_type, const char *appid, pkgmgr_mode mode,
1750 int ret = PKGMGR_R_ECOMM;
1751 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1753 if (pc == NULL || pkg_type == NULL || appid == NULL) {
1754 ERR("invalid parameter");
1755 return PKGMGR_R_EINVAL;
1758 if (mpc->ctype != PC_REQUEST) {
1759 ERR("mpc->ctype is not PC_REQUEST");
1760 return PKGMGR_R_EINVAL;
1763 ret = comm_client_request(mpc->info.request.cc, "cleardata",
1764 g_variant_new("(uss)", uid, pkg_type, appid), &result);
1765 if (ret == PKGMGR_R_OK) {
1766 ERR("request failed: %d", ret);
1770 g_variant_get(result, "(i)", &ret);
1771 g_variant_unref(result);
1776 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
1777 const char *appid, pkgmgr_mode mode)
1779 return pkgmgr_client_usr_clear_user_data(pc, pkg_type, appid, mode,
1783 API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type)
1787 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1788 retvm_if(status_type == PKGMGR_CLIENT_STATUS_ALL, PKGMGR_R_OK, "status_type is PKGMGR_CLIENT_STATUS_ALL");
1789 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1791 /* free listening head */
1792 listen_cb_info *tmp = NULL;
1793 listen_cb_info *prev = NULL;
1794 for (tmp = mpc->info.listening.lhead; tmp;) {
1800 /* free dbus connection */
1801 ret = comm_client_free(mpc->info.listening.cc);
1802 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
1804 /* Manage pc for seperated event */
1805 mpc->ctype = PC_LISTENING;
1806 mpc->status_type = status_type;
1808 mpc->info.listening.cc = comm_client_new();
1809 retvm_if(mpc->info.listening.cc == NULL, PKGMGR_R_EINVAL, "client creation failed");
1811 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL) == PKGMGR_CLIENT_STATUS_INSTALL) {
1812 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_INSTALL, mpc->info.listening.cc, __status_callback, pc);
1813 retvm_if(ret < 0, PKGMGR_R_ECOMM, "PKGMGR_CLIENT_STATUS_INSTALL failed - %d", ret);
1816 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_UNINSTALL) == PKGMGR_CLIENT_STATUS_UNINSTALL) {
1817 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_UNINSTALL, mpc->info.listening.cc, __status_callback, pc);
1818 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_UNINSTALL failed - %d", ret);
1821 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_MOVE) == PKGMGR_CLIENT_STATUS_MOVE) {
1822 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_MOVE, mpc->info.listening.cc, __status_callback, pc);
1823 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_MOVE failed - %d", ret);
1826 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS) == PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS) {
1827 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_INSTALL_PROGRESS, mpc->info.listening.cc, __status_callback, pc);
1828 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_INSTALL_PROGRESS failed - %d", ret);
1831 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_UPGRADE) == PKGMGR_CLIENT_STATUS_UPGRADE) {
1832 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_UPGRADE, mpc->info.listening.cc, __status_callback, pc);
1833 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_UPGRADE failed - %d", ret);
1836 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_ENABLE_APP) == PKGMGR_CLIENT_STATUS_ENABLE_APP) {
1837 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ENABLE_APP, mpc->info.listening.cc, __status_callback, pc);
1838 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_ENABLE_APP failed - %d", ret);
1841 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_DISABLE_APP) == PKGMGR_CLIENT_STATUS_DISABLE_APP) {
1842 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_DISABLE_APP, mpc->info.listening.cc, __status_callback, pc);
1843 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_DISABLE_APP failed - %d", ret);
1846 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_ENABLE_APP_SPLASH_SCREEN) == PKGMGR_CLIENT_STATUS_ENABLE_APP_SPLASH_SCREEN) {
1847 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ENABLE_APP_SPLASH_SCREEN, mpc->info.listening.cc, __status_callback, pc);
1848 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_ENABLE_APP_SPLASH_SCREEN failed - %d", ret);
1851 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN) == PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN) {
1852 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_DISABLE_APP_SPLASH_SCREEN, mpc->info.listening.cc, __status_callback, pc);
1853 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_DISABLE_APP_SPLASH_SCREEN failed - %d", ret);
1859 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
1863 /* Check for NULL value of pc */
1864 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1865 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1867 /* 0. check input */
1868 retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING");
1869 retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL");
1872 req_id = _get_request_id();
1874 /* 2. add callback info to pkgmgr_client */
1875 __add_stat_cbinfo(mpc, req_id, event_cb, data);
1879 API int pkgmgr_client_listen_app_status(pkgmgr_client *pc, pkgmgr_app_handler event_cb,
1883 /* Check for NULL value of pc */
1884 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1885 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1887 /* 0. check input */
1888 retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING");
1889 retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL");
1892 req_id = _get_request_id();
1894 /* 2. add app callback info to pkgmgr_client */
1895 __add_app_stat_cbinfo(mpc, req_id, event_cb, data);
1899 API int pkgmgr_client_remove_listen_status(pkgmgr_client *pc)
1903 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1904 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1906 ret = __remove_stat_cbinfo(mpc);
1908 ERR("failed to remove status callback");
1909 return PKGMGR_R_ERROR;
1915 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
1916 const char *pkgid, const char *key,
1919 /* client cannot broadcast signal */
1923 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, int service_mode,
1924 pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
1925 const char *custom_info, pkgmgr_handler event_cb, void *data)
1927 return pkgmgr_client_usr_request_service(service_type, service_mode, pc, pkg_type, pkgid, _getuid(), custom_info, event_cb, data);
1930 API int pkgmgr_client_usr_request_service(pkgmgr_request_service_type service_type, int service_mode,
1931 pkgmgr_client * pc, const char *pkg_type, const char *pkgid, uid_t uid,
1932 const char *custom_info, pkgmgr_handler event_cb, void *data)
1936 /* Check for NULL value of service type */
1937 retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
1938 retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n");
1940 switch (service_type) {
1941 case PM_REQUEST_CSC:
1942 tryvm_if(custom_info == NULL, ret = PKGMGR_R_EINVAL, "custom_info is NULL\n");
1943 tryvm_if(strlen(custom_info) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "custom_info over PKG_STRING_LEN_MAX");
1944 tryvm_if(data == NULL, ret = PKGMGR_R_EINVAL, "data is NULL\n");
1946 ret = __csc_process(custom_info, (char *)data);
1948 ERR("__csc_process fail \n");
1954 case PM_REQUEST_MOVE:
1955 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1956 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1957 tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1959 ret = __move_pkg_process(pc, pkgid, pkg_type, uid, (pkgmgr_move_type)service_mode, event_cb, data);
1962 case PM_REQUEST_GET_SIZE:
1963 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1964 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1965 tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode >= PM_GET_MAX), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1967 ret = __get_size_process(pc, pkgid, uid, (pkgmgr_getsize_type)service_mode, event_cb, data);
1970 case PM_REQUEST_KILL_APP:
1971 case PM_REQUEST_CHECK_APP:
1972 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1973 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1975 ret = __check_app_process(service_type, pc, pkgid, uid, data);
1977 ERR("__check_app_process fail \n");
1984 ERR("Wrong Request\n");
1995 API int pkgmgr_client_usr_request_size_info(uid_t uid)
1998 pkgmgr_client *pc = NULL;
2000 pc = pkgmgr_client_new(PC_REQUEST);
2001 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "request pc is null\n");
2003 ret = __request_size_info(pc, uid);
2005 ERR("__request_size_info fail \n");
2008 pkgmgr_client_free(pc);
2012 API int pkgmgr_client_request_size_info(void) // get all package size (data, total)
2014 return pkgmgr_client_usr_request_size_info(_getuid());
2017 API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid)
2020 int ret = PKGMGR_R_ECOMM;
2021 pkgmgr_client_t *pc;
2023 if (pkgid == NULL) {
2024 ERR("invalid parameter");
2025 return PKGMGR_R_EINVAL;
2028 pc = pkgmgr_client_new(PC_REQUEST);
2030 ERR("out of memory");
2031 return PKGMGR_R_ESYSTEM;
2034 ret = comm_client_request(pc->info.request.cc, "clearcache",
2035 g_variant_new("(us)", uid, pkgid), &result);
2036 if (ret != PKGMGR_R_OK) {
2037 ERR("request failed: %d", ret);
2041 g_variant_get(result, "(i)", &ret);
2042 g_variant_unref(result);
2047 API int pkgmgr_client_clear_cache_dir(const char *pkgid)
2049 return pkgmgr_client_usr_clear_cache_dir(pkgid, _getuid());
2052 API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid)
2054 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, uid);
2057 API int pkgmgr_client_clear_all_cache_dir(void)
2059 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, _getuid());
2062 API int pkgmgr_client_get_size(pkgmgr_client * pc, const char *pkgid,
2063 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
2066 return pkgmgr_client_usr_get_size(pc, pkgid, get_type, event_cb, data,
2070 API int pkgmgr_client_usr_get_size(pkgmgr_client * pc, const char *pkgid,
2071 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
2072 void *data, uid_t uid)
2075 int ret = PKGMGR_R_ECOMM;
2076 char *req_key = NULL;
2078 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2080 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
2081 ERR("invalid parameter");
2082 return PKGMGR_R_EINVAL;
2085 if (mpc->ctype != PC_REQUEST) {
2086 ERR("mpc->ctype is not PC_REQUEST");
2087 return PKGMGR_R_EINVAL;
2091 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
2092 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
2094 get_type = PM_GET_PKG_SIZE_INFO;
2096 ret = comm_client_request(mpc->info.request.cc, "getsize",
2097 g_variant_new("(usi)", uid, pkgid, get_type), &result);
2098 if (ret != PKGMGR_R_OK) {
2099 ERR("request failed: %d", ret);
2103 g_variant_get(result, "(i&s)", &ret, &req_key);
2104 if (req_key == NULL) {
2105 g_variant_unref(result);
2106 return PKGMGR_R_ECOMM;
2108 if (ret != PKGMGR_R_OK) {
2109 g_variant_unref(result);
2113 req_id = _get_request_id();
2114 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
2116 g_variant_unref(result);
2121 API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc,
2122 const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb,
2123 void *user_data, uid_t uid)
2126 int ret = PKGMGR_R_ECOMM;
2127 char *req_key = NULL;
2130 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2132 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
2133 ERR("invalid parameter");
2134 return PKGMGR_R_EINVAL;
2137 if (mpc->ctype != PC_REQUEST) {
2138 ERR("mpc->ctype is not PC_REQUEST");
2139 return PKGMGR_R_EINVAL;
2143 if (__change_op_cb_for_getsize(mpc) < 0) {
2144 ERR("__change_op_cb_for_getsize failed");
2145 return PKGMGR_R_ESYSTEM;
2148 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
2149 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
2151 get_type = PM_GET_PKG_SIZE_INFO;
2153 ret = comm_client_request(mpc->info.request.cc, "getsize",
2154 g_variant_new("(usi)", uid, pkgid, get_type), &result);
2155 if (ret != PKGMGR_R_OK) {
2156 ERR("request failed: %d", ret);
2160 g_variant_get(result, "(i&s)", &ret, &req_key);
2161 if (req_key == NULL) {
2162 g_variant_unref(result);
2163 return PKGMGR_R_ECOMM;
2165 if (ret != PKGMGR_R_OK) {
2166 g_variant_unref(result);
2170 req_id = _get_request_id();
2171 __add_op_cbinfo(mpc, req_id, req_key, __get_pkg_size_info_cb, event_cb,
2174 g_variant_unref(result);
2179 API int pkgmgr_client_get_package_size_info(pkgmgr_client *pc, const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb, void *user_data)
2181 return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb, user_data, _getuid());
2184 API int pkgmgr_client_usr_get_total_package_size_info(pkgmgr_client *pc, pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data, uid_t uid)
2185 { // total package size info
2186 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, uid);
2189 API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc, pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data)
2191 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, _getuid());
2194 API int pkgmgr_client_generate_license_request(pkgmgr_client *pc,
2195 const char *resp_data, char **req_data, char **license_url)
2201 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2203 if (pc == NULL || resp_data == NULL || req_data == NULL ||
2204 license_url == NULL) {
2205 ERR("invalid parameter");
2206 return PKGMGR_R_EINVAL;
2209 if (mpc->ctype != PC_REQUEST) {
2210 ERR("mpc->ctype is not PC_REQUEST");
2211 return PKGMGR_R_EINVAL;
2214 ret = comm_client_request(mpc->info.request.cc,
2215 "generate_license_request",
2216 g_variant_new("(s)", resp_data), &result);
2217 if (ret != PKGMGR_R_OK) {
2218 ERR("request failed: %d", ret);
2222 g_variant_get(result, "(i&s&s)", &ret, &data, &url);
2223 if (ret != PKGMGR_R_OK) {
2224 ERR("generate_license_request failed: %d", ret);
2225 g_variant_unref(result);
2229 *req_data = strdup(data);
2230 *license_url = strdup(url);
2232 g_variant_unref(result);
2237 API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data)
2241 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2243 if (pc == NULL || resp_data == NULL) {
2244 ERR("invalid parameter");
2245 return PKGMGR_R_EINVAL;
2248 if (mpc->ctype != PC_REQUEST) {
2249 ERR("mpc->ctype is not PC_REQUEST");
2250 return PKGMGR_R_EINVAL;
2253 ret = comm_client_request(mpc->info.request.cc,
2254 "register_license", g_variant_new("(s)", resp_data),
2256 if (ret != PKGMGR_R_OK) {
2257 ERR("request failed: %d", ret);
2261 g_variant_get(result, "(i)", &ret);
2262 g_variant_unref(result);
2263 if (ret != PKGMGR_R_OK) {
2264 ERR("register license failed: %d", ret);
2271 API int pkgmgr_client_decrypt_package(pkgmgr_client *pc,
2272 const char *drm_file_path, const char *decrypted_file_path)
2276 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2278 if (pc == NULL || drm_file_path == NULL ||
2279 decrypted_file_path == NULL) {
2280 ERR("invalid parameter");
2281 return PKGMGR_R_EINVAL;
2284 if (mpc->ctype != PC_REQUEST) {
2285 ERR("mpc->ctype is not PC_REQUEST");
2286 return PKGMGR_R_EINVAL;
2289 ret = comm_client_request(mpc->info.request.cc,
2291 g_variant_new("(ss)", drm_file_path,
2292 decrypted_file_path),
2294 if (ret != PKGMGR_R_OK) {
2295 ERR("request failed: %d", ret);
2299 g_variant_get(result, "(i)", &ret);
2300 g_variant_unref(result);
2301 if (ret != PKGMGR_R_OK) {
2302 ERR("decrypt_package failed: %d", ret);
2309 API int pkgmgr_client_enable_splash_screen(pkgmgr_client *pc, const char *appid)
2311 return pkgmgr_client_usr_enable_splash_screen(pc, appid, _getuid());
2314 API int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc,
2315 const char *appid, uid_t uid)
2319 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2321 if (pc == NULL || appid == NULL) {
2322 ERR("Invalid parameter");
2323 return PKGMGR_R_EINVAL;
2326 ret = __change_op_cb_for_enable_disable_splash_screen(mpc, true);
2328 ERR("__change_op_cb_for_enable_disable_splash_screen failed");
2329 return PKGMGR_R_ESYSTEM;
2332 ret = comm_client_request(mpc->info.request.cc,
2333 "enable_app_splash_screen",
2334 g_variant_new("(us)", uid, appid), &result);
2335 if (ret != PKGMGR_R_OK) {
2336 ERR("request failed: %d", ret);
2340 g_variant_get(result, "(i)", &ret);
2341 if (ret != PKGMGR_R_OK) {
2342 g_variant_unref(result);
2346 g_variant_unref(result);
2351 API int pkgmgr_client_disable_splash_screen(pkgmgr_client *pc,
2354 return pkgmgr_client_usr_disable_splash_screen(pc, appid,
2358 API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc,
2359 const char *appid, uid_t uid)
2363 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2365 if (pc == NULL || appid == NULL) {
2366 ERR("Invalid parameter");
2367 return PKGMGR_R_EINVAL;
2370 ret = __change_op_cb_for_enable_disable_splash_screen(mpc, false);
2372 ERR("__change_op_cb_for_enable_disable_splash_screen failed");
2376 ret = comm_client_request(mpc->info.request.cc,
2377 "disable_app_splash_screen",
2378 g_variant_new("(us)", uid, appid), &result);
2379 if (ret != PKGMGR_R_OK) {
2380 ERR("request failed: %d", ret);
2384 g_variant_get(result, "(i)", &ret);
2385 if (ret != PKGMGR_R_OK) {
2386 g_variant_unref(result);
2390 g_variant_unref(result);
2395 static int __set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2398 int ret = PKGMGR_R_ECOMM;
2399 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2401 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) {
2402 ERR("invalid parameter");
2403 return PKGMGR_R_EINVAL;
2406 ret = comm_client_request(mpc->info.request.cc, "set_restriction_mode",
2407 g_variant_new("(usi)", uid, pkgid, mode), &result);
2408 if (ret != PKGMGR_R_OK) {
2409 ERR("request failed: %d", ret);
2413 g_variant_get(result, "(i)", &ret);
2414 g_variant_unref(result);
2419 API int pkgmgr_client_usr_set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2421 return __set_pkg_restriction_mode(pc, pkgid, mode, uid);
2424 API int pkgmgr_client_set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode)
2426 return pkgmgr_client_usr_set_pkg_restriction_mode(pc, pkgid, mode, _getuid());
2429 static int __unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2432 int ret = PKGMGR_R_ECOMM;
2433 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2435 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) {
2436 ERR("invalid parameter");
2437 return PKGMGR_R_EINVAL;
2440 ret = comm_client_request(mpc->info.request.cc,
2441 "unset_restriction_mode",
2442 g_variant_new("(usi)", uid, pkgid, mode), &result);
2443 if (ret != PKGMGR_R_OK) {
2444 ERR("request failed: %d", ret);
2448 g_variant_get(result, "(i)", &ret);
2449 g_variant_unref(result);
2455 API int pkgmgr_client_usr_unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2457 return __unset_pkg_restriction_mode(pc, pkgid, mode, uid);
2460 API int pkgmgr_client_unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode)
2462 return pkgmgr_client_usr_unset_pkg_restriction_mode(pc, pkgid, mode, _getuid());
2465 static int __get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode, uid_t uid)
2468 int ret = PKGMGR_R_ECOMM;
2470 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2472 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0) {
2473 ERR("invalid parameter");
2474 return PKGMGR_R_EINVAL;
2477 ret = comm_client_request(mpc->info.request.cc,
2478 "get_restriction_mode",
2479 g_variant_new("(us)", uid, pkgid), &result);
2480 if (ret != PKGMGR_R_OK) {
2481 ERR("request failed: %d", ret);
2485 g_variant_get(result, "(ii)", &m, &ret);
2486 g_variant_unref(result);
2487 if (ret != PKGMGR_R_OK)
2495 API int pkgmgr_client_usr_get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode, uid_t uid)
2497 return __get_pkg_restriction_mode(pc, pkgid, mode, uid);
2500 API int pkgmgr_client_get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode)
2502 return pkgmgr_client_usr_get_pkg_restriction_mode(pc, pkgid, mode, _getuid());
2505 API int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode,
2509 int ret = PKGMGR_R_ECOMM;
2510 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2513 ERR("invalid parameter");
2514 return PKGMGR_R_EINVAL;
2517 ret = comm_client_request(mpc->info.request.cc, "set_restriction_mode",
2518 g_variant_new("(usi)", uid, "", mode), &result);
2519 if (ret != PKGMGR_R_OK) {
2520 ERR("request failed: %d", ret);
2524 g_variant_get(result, "(i)", &ret);
2525 g_variant_unref(result);
2530 API int pkgmgr_client_set_restriction_mode(pkgmgr_client *pc, int mode)
2532 return pkgmgr_client_usr_set_restriction_mode(pc, mode, _getuid());
2535 API int pkgmgr_client_usr_unset_restriction_mode(pkgmgr_client *pc, int mode,
2539 int ret = PKGMGR_R_ECOMM;
2540 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2543 ERR("invalid parameter");
2544 return PKGMGR_R_EINVAL;
2547 ret = comm_client_request(mpc->info.request.cc,
2548 "unset_restriction_mode",
2549 g_variant_new("(usi)", uid, "", mode), &result);
2550 if (ret != PKGMGR_R_OK) {
2551 ERR("request failed: %d", ret);
2555 g_variant_get(result, "(i)", &ret);
2556 g_variant_unref(result);
2561 API int pkgmgr_client_unset_restriction_mode(pkgmgr_client *pc, int mode)
2563 return pkgmgr_client_usr_unset_restriction_mode(pc, mode, _getuid());
2566 API int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc,
2567 int *mode, uid_t uid)
2570 int ret = PKGMGR_R_ECOMM;
2572 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2575 ERR("invalid parameter");
2576 return PKGMGR_R_EINVAL;
2579 ret = comm_client_request(mpc->info.request.cc,
2580 "get_restriction_mode",
2581 g_variant_new("(us)", uid, ""), &result);
2582 if (ret != PKGMGR_R_OK) {
2583 ERR("request failed: %d", ret);
2587 g_variant_get(result, "(ii)", &m, &ret);
2588 g_variant_unref(result);
2589 if (ret != PKGMGR_R_OK)
2597 API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc,
2600 return pkgmgr_client_usr_get_restriction_mode(pc, mode, _getuid());