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 find 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, event_cb, data, 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,
1453 pkgmgr_handler event_cb, void *data)
1455 return pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type,
1456 event_cb, data, _getuid());
1458 API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type,
1459 const char *pkgid, pkgmgr_move_type move_type,
1460 pkgmgr_handler event_cb, void *data, uid_t uid)
1463 int ret = PKGMGR_R_ECOMM;
1465 char *req_key = NULL;
1466 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1468 if (pc == NULL || pkg_type == NULL || pkgid == NULL) {
1469 ERR("invalid parameter");
1470 return PKGMGR_R_EINVAL;
1473 if ((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD))
1474 return PKGMGR_R_EINVAL;
1476 if (mpc->ctype != PC_REQUEST) {
1477 ERR("mpc->ctype is not PC_REQUEST");
1478 return PKGMGR_R_EINVAL;
1481 ret = comm_client_request(mpc->info.request.cc, "move",
1482 g_variant_new("(ussi)", uid, pkg_type, pkgid, move_type), &result);
1483 if (ret != PKGMGR_R_OK) {
1484 ERR("request failed: %d", ret);
1488 g_variant_get(result, "(i&s)", &ret, &req_key);
1489 if (req_key == NULL) {
1490 g_variant_unref(result);
1491 return PKGMGR_R_ECOMM;
1493 if (ret != PKGMGR_R_OK) {
1494 g_variant_unref(result);
1498 req_id = _get_request_id();
1499 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
1500 g_variant_unref(result);
1505 API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type,
1506 const char *pkgid, uid_t uid)
1509 int ret = PKGMGR_R_ECOMM;
1510 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1512 if (pc == NULL || pkgid == NULL || pkg_type == NULL) {
1513 ERR("invalid parameter");
1514 return PKGMGR_R_EINVAL;
1517 ret = comm_client_request(mpc->info.request.cc, "enable_pkg",
1518 g_variant_new("(uss)", uid, pkg_type, pkgid), &result);
1519 if (ret != PKGMGR_R_OK) {
1520 ERR("request failed: %d", ret);
1524 g_variant_get(result, "(i)", &ret);
1525 g_variant_unref(result);
1530 API int pkgmgr_client_activate(pkgmgr_client *pc, const char *pkg_type,
1533 return pkgmgr_client_usr_activate(pc, pkg_type, pkgid, _getuid());
1536 API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type,
1537 const char *pkgid, uid_t uid)
1540 int ret = PKGMGR_R_ECOMM;
1541 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1543 if (pc == NULL || pkgid == NULL || pkg_type == NULL) {
1544 ERR("invalid parameter");
1545 return PKGMGR_R_EINVAL;
1548 ret = comm_client_request(mpc->info.request.cc, "disable_pkg",
1549 g_variant_new("(uss)", uid, pkg_type, pkgid), &result);
1550 if (ret != PKGMGR_R_OK) {
1551 ERR("request failed: %d", ret);
1555 g_variant_get(result, "(i)", &ret);
1556 g_variant_unref(result);
1561 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
1564 return pkgmgr_client_usr_deactivate(pc, pkg_type, pkgid, _getuid());
1567 /* TODO: deprecate? */
1568 API int pkgmgr_client_usr_activate_appv(pkgmgr_client *pc, const char *appid,
1569 char *const argv[], uid_t uid)
1571 return pkgmgr_client_usr_activate_app(pc, appid, NULL, uid);
1574 API int pkgmgr_client_activate_appv(pkgmgr_client *pc, const char *appid,
1577 return pkgmgr_client_usr_activate_app(pc, appid, NULL, _getuid());
1580 API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid,
1581 pkgmgr_app_handler app_event_cb, uid_t uid)
1584 int ret = PKGMGR_R_ECOMM;
1586 char *req_key = NULL;
1587 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1589 if (pc == NULL || appid == NULL) {
1590 ERR("invalid parameter");
1591 return PKGMGR_R_EINVAL;
1594 if (__change_op_cb_for_enable_disable(mpc, false) < 0) {
1595 ERR("__change_op_cb_for_enable_disable failed");
1596 return PKGMGR_R_ESYSTEM;
1599 ret = comm_client_request(mpc->info.request.cc, "enable_app",
1600 g_variant_new("(us)", uid, appid), &result);
1601 if (ret != PKGMGR_R_OK) {
1602 ERR("request failed: %d", ret);
1606 g_variant_get(result, "(i&s)", &ret, &req_key);
1607 if (req_key == NULL) {
1608 g_variant_unref(result);
1609 return PKGMGR_R_ECOMM;
1611 if (ret != PKGMGR_R_OK) {
1612 g_variant_unref(result);
1616 req_id = _get_request_id();
1617 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1618 g_variant_unref(result);
1622 API int pkgmgr_client_activate_app(pkgmgr_client * pc, const char *appid, pkgmgr_app_handler app_event_cb)
1624 return pkgmgr_client_usr_activate_app(pc, appid, app_event_cb, _getuid());
1627 API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc,
1628 const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid)
1631 int ret = PKGMGR_R_ECOMM;
1633 char *req_key = NULL;
1634 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1636 if (pc == NULL || appid == NULL) {
1637 ERR("invalid parameter");
1638 return PKGMGR_R_EINVAL;
1641 if (__change_op_cb_for_enable_disable(mpc, false) < 0) {
1642 ERR("__change_op_cb_for_enable_disable failed");
1643 return PKGMGR_R_ESYSTEM;
1646 ret = comm_client_request(mpc->info.request.cc, "enable_global_app_for_uid",
1647 g_variant_new("(us)", uid, appid), &result);
1648 if (ret != PKGMGR_R_OK) {
1649 ERR("request failed: %d", ret);
1653 g_variant_get(result, "(i&s)", &ret, &req_key);
1654 if (req_key == NULL) {
1655 g_variant_unref(result);
1656 return PKGMGR_R_ECOMM;
1658 if (ret != PKGMGR_R_OK) {
1659 g_variant_unref(result);
1663 req_id = _get_request_id();
1664 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1669 API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid,
1670 pkgmgr_app_handler app_event_cb, uid_t uid)
1673 int ret = PKGMGR_R_ECOMM;
1674 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1676 char *req_key = NULL;
1678 if (pc == NULL || appid == NULL) {
1679 ERR("invalid parameter");
1680 return PKGMGR_R_EINVAL;
1684 if (__change_op_cb_for_enable_disable(mpc, true) < 0) {
1685 ERR("__change_op_cb_for_enable_disable failed");
1686 return PKGMGR_R_ESYSTEM;
1689 ret = comm_client_request(mpc->info.request.cc, "disable_app",
1690 g_variant_new("(us)", uid, appid), &result);
1691 if (ret != PKGMGR_R_OK) {
1692 ERR("request failed: %d", ret);
1696 g_variant_get(result, "(i&s)", &ret, &req_key);
1697 if (req_key == NULL) {
1698 g_variant_unref(result);
1699 return PKGMGR_R_ECOMM;
1701 if (ret != PKGMGR_R_OK) {
1702 g_variant_unref(result);
1706 req_id = _get_request_id();
1707 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1709 g_variant_unref(result);
1713 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid, pkgmgr_app_handler app_event_cb)
1715 return pkgmgr_client_usr_deactivate_app(pc, appid, app_event_cb, _getuid());
1718 API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc,
1719 const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid)
1722 int ret = PKGMGR_R_ECOMM;
1724 char *req_key = NULL;
1725 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1727 if (pc == NULL || appid == NULL) {
1728 ERR("invalid parameter");
1729 return PKGMGR_R_EINVAL;
1732 if (__change_op_cb_for_enable_disable(mpc, true) < 0) {
1733 ERR("__change_op_cb_for_enable_disable failed");
1734 return PKGMGR_R_ESYSTEM;
1737 ret = comm_client_request(mpc->info.request.cc, "disable_global_app_for_uid",
1738 g_variant_new("(us)", uid, appid), &result);
1739 if (ret != PKGMGR_R_OK) {
1740 ERR("request failed: %d", ret);
1744 g_variant_get(result, "(i&s)", &ret, &req_key);
1745 if (req_key == NULL) {
1746 g_variant_unref(result);
1747 return PKGMGR_R_ECOMM;
1749 if (ret != PKGMGR_R_OK) {
1750 g_variant_unref(result);
1754 req_id = _get_request_id();
1755 __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL);
1759 API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc,
1760 const char *pkg_type, const char *appid, pkgmgr_mode mode,
1764 int ret = PKGMGR_R_ECOMM;
1765 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1767 if (pc == NULL || pkg_type == NULL || appid == NULL) {
1768 ERR("invalid parameter");
1769 return PKGMGR_R_EINVAL;
1772 if (mpc->ctype != PC_REQUEST) {
1773 ERR("mpc->ctype is not PC_REQUEST");
1774 return PKGMGR_R_EINVAL;
1777 ret = comm_client_request(mpc->info.request.cc, "cleardata",
1778 g_variant_new("(uss)", uid, pkg_type, appid), &result);
1779 if (ret == PKGMGR_R_OK) {
1780 ERR("request failed: %d", ret);
1784 g_variant_get(result, "(i)", &ret);
1785 g_variant_unref(result);
1790 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
1791 const char *appid, pkgmgr_mode mode)
1793 return pkgmgr_client_usr_clear_user_data(pc, pkg_type, appid, mode,
1797 API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type)
1801 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1802 retvm_if(status_type == PKGMGR_CLIENT_STATUS_ALL, PKGMGR_R_OK, "status_type is PKGMGR_CLIENT_STATUS_ALL");
1803 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
1805 /* free listening head */
1806 listen_cb_info *tmp = NULL;
1807 listen_cb_info *prev = NULL;
1808 for (tmp = mpc->info.listening.lhead; tmp;) {
1814 /* free dbus connection */
1815 ret = comm_client_free(mpc->info.listening.cc);
1816 retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret);
1818 /* Manage pc for seperated event */
1819 mpc->ctype = PC_LISTENING;
1820 mpc->status_type = status_type;
1822 mpc->info.listening.cc = comm_client_new();
1823 retvm_if(mpc->info.listening.cc == NULL, PKGMGR_R_EINVAL, "client creation failed");
1825 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL) == PKGMGR_CLIENT_STATUS_INSTALL) {
1826 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_INSTALL, mpc->info.listening.cc, __status_callback, pc);
1827 retvm_if(ret < 0, PKGMGR_R_ECOMM, "PKGMGR_CLIENT_STATUS_INSTALL failed - %d", ret);
1830 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_UNINSTALL) == PKGMGR_CLIENT_STATUS_UNINSTALL) {
1831 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_UNINSTALL, mpc->info.listening.cc, __status_callback, pc);
1832 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_UNINSTALL failed - %d", ret);
1835 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_MOVE) == PKGMGR_CLIENT_STATUS_MOVE) {
1836 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_MOVE, mpc->info.listening.cc, __status_callback, pc);
1837 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_MOVE failed - %d", ret);
1840 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS) == PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS) {
1841 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_INSTALL_PROGRESS, mpc->info.listening.cc, __status_callback, pc);
1842 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_INSTALL_PROGRESS failed - %d", ret);
1845 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_UPGRADE) == PKGMGR_CLIENT_STATUS_UPGRADE) {
1846 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_UPGRADE, mpc->info.listening.cc, __status_callback, pc);
1847 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_UPGRADE failed - %d", ret);
1850 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_ENABLE_APP) == PKGMGR_CLIENT_STATUS_ENABLE_APP) {
1851 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ENABLE_APP, mpc->info.listening.cc, __status_callback, pc);
1852 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_ENABLE_APP failed - %d", ret);
1855 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_DISABLE_APP) == PKGMGR_CLIENT_STATUS_DISABLE_APP) {
1856 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_DISABLE_APP, mpc->info.listening.cc, __status_callback, pc);
1857 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_DISABLE_APP failed - %d", ret);
1860 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_ENABLE_APP_SPLASH_SCREEN) == PKGMGR_CLIENT_STATUS_ENABLE_APP_SPLASH_SCREEN) {
1861 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ENABLE_APP_SPLASH_SCREEN, mpc->info.listening.cc, __status_callback, pc);
1862 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_ENABLE_APP_SPLASH_SCREEN failed - %d", ret);
1865 if ((mpc->status_type & PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN) == PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN) {
1866 ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_DISABLE_APP_SPLASH_SCREEN, mpc->info.listening.cc, __status_callback, pc);
1867 retvm_if(ret < 0, PKGMGR_R_ECOMM, "COMM_STATUS_BROADCAST_DISABLE_APP_SPLASH_SCREEN failed - %d", ret);
1873 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
1877 /* Check for NULL value of pc */
1878 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1879 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1881 /* 0. check input */
1882 retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING");
1883 retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL");
1886 req_id = _get_request_id();
1888 /* 2. add callback info to pkgmgr_client */
1889 __add_stat_cbinfo(mpc, req_id, event_cb, data);
1893 API int pkgmgr_client_listen_app_status(pkgmgr_client *pc, pkgmgr_app_handler event_cb,
1897 /* Check for NULL value of pc */
1898 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1899 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1901 /* 0. check input */
1902 retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING");
1903 retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL");
1906 req_id = _get_request_id();
1908 /* 2. add app callback info to pkgmgr_client */
1909 __add_app_stat_cbinfo(mpc, req_id, event_cb, data);
1913 API int pkgmgr_client_remove_listen_status(pkgmgr_client *pc)
1917 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL");
1918 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1920 ret = __remove_stat_cbinfo(mpc);
1922 ERR("failed to remove status callback");
1923 return PKGMGR_R_ERROR;
1929 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
1930 const char *pkgid, const char *key,
1933 /* client cannot broadcast signal */
1937 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, int service_mode,
1938 pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
1939 const char *custom_info, pkgmgr_handler event_cb, void *data)
1941 return pkgmgr_client_usr_request_service(service_type, service_mode, pc, pkg_type, pkgid, _getuid(), custom_info, event_cb, data);
1944 API int pkgmgr_client_usr_request_service(pkgmgr_request_service_type service_type, int service_mode,
1945 pkgmgr_client * pc, const char *pkg_type, const char *pkgid, uid_t uid,
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, "custom_info 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 ERR("__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, pkg_type, uid, (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_MAX), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1981 ret = __get_size_process(pc, pkgid, uid, (pkgmgr_getsize_type)service_mode, event_cb, data);
1984 case PM_REQUEST_KILL_APP:
1985 case PM_REQUEST_CHECK_APP:
1986 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1987 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1989 ret = __check_app_process(service_type, pc, pkgid, uid, data);
1991 ERR("__check_app_process fail \n");
1998 ERR("Wrong Request\n");
2009 API int pkgmgr_client_usr_request_size_info(uid_t uid)
2012 pkgmgr_client *pc = NULL;
2014 pc = pkgmgr_client_new(PC_REQUEST);
2015 retvm_if(pc == NULL, PKGMGR_R_EINVAL, "request pc is null\n");
2017 ret = __request_size_info(pc, uid);
2019 ERR("__request_size_info fail \n");
2022 pkgmgr_client_free(pc);
2026 API int pkgmgr_client_request_size_info(void) // get all package size (data, total)
2028 return pkgmgr_client_usr_request_size_info(_getuid());
2031 API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid)
2034 int ret = PKGMGR_R_ECOMM;
2035 pkgmgr_client_t *pc;
2037 if (pkgid == NULL) {
2038 ERR("invalid parameter");
2039 return PKGMGR_R_EINVAL;
2042 pc = pkgmgr_client_new(PC_REQUEST);
2044 ERR("out of memory");
2045 return PKGMGR_R_ESYSTEM;
2048 ret = comm_client_request(pc->info.request.cc, "clearcache",
2049 g_variant_new("(us)", uid, pkgid), &result);
2050 if (ret != PKGMGR_R_OK) {
2051 ERR("request failed: %d", ret);
2055 g_variant_get(result, "(i)", &ret);
2056 g_variant_unref(result);
2061 API int pkgmgr_client_clear_cache_dir(const char *pkgid)
2063 return pkgmgr_client_usr_clear_cache_dir(pkgid, _getuid());
2066 API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid)
2068 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, uid);
2071 API int pkgmgr_client_clear_all_cache_dir(void)
2073 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, _getuid());
2076 API int pkgmgr_client_get_size(pkgmgr_client * pc, const char *pkgid,
2077 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
2080 return pkgmgr_client_usr_get_size(pc, pkgid, get_type, event_cb, data,
2084 API int pkgmgr_client_usr_get_size(pkgmgr_client * pc, const char *pkgid,
2085 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
2086 void *data, uid_t uid)
2089 int ret = PKGMGR_R_ECOMM;
2090 char *req_key = NULL;
2092 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2094 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
2095 ERR("invalid parameter");
2096 return PKGMGR_R_EINVAL;
2099 if (mpc->ctype != PC_REQUEST) {
2100 ERR("mpc->ctype is not PC_REQUEST");
2101 return PKGMGR_R_EINVAL;
2105 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
2106 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
2108 get_type = PM_GET_PKG_SIZE_INFO;
2110 ret = comm_client_request(mpc->info.request.cc, "getsize",
2111 g_variant_new("(usi)", uid, pkgid, get_type), &result);
2112 if (ret != PKGMGR_R_OK) {
2113 ERR("request failed: %d", ret);
2117 g_variant_get(result, "(i&s)", &ret, &req_key);
2118 if (req_key == NULL) {
2119 g_variant_unref(result);
2120 return PKGMGR_R_ECOMM;
2122 if (ret != PKGMGR_R_OK) {
2123 g_variant_unref(result);
2127 req_id = _get_request_id();
2128 __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data);
2130 g_variant_unref(result);
2135 API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc,
2136 const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb,
2137 void *user_data, uid_t uid)
2140 int ret = PKGMGR_R_ECOMM;
2141 char *req_key = NULL;
2144 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2146 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
2147 ERR("invalid parameter");
2148 return PKGMGR_R_EINVAL;
2151 if (mpc->ctype != PC_REQUEST) {
2152 ERR("mpc->ctype is not PC_REQUEST");
2153 return PKGMGR_R_EINVAL;
2157 if (__change_op_cb_for_getsize(mpc) < 0) {
2158 ERR("__change_op_cb_for_getsize failed");
2159 return PKGMGR_R_ESYSTEM;
2162 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
2163 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
2165 get_type = PM_GET_PKG_SIZE_INFO;
2167 ret = comm_client_request(mpc->info.request.cc, "getsize",
2168 g_variant_new("(usi)", uid, pkgid, get_type), &result);
2169 if (ret != PKGMGR_R_OK) {
2170 ERR("request failed: %d", ret);
2174 g_variant_get(result, "(i&s)", &ret, &req_key);
2175 if (req_key == NULL) {
2176 g_variant_unref(result);
2177 return PKGMGR_R_ECOMM;
2179 if (ret != PKGMGR_R_OK) {
2180 g_variant_unref(result);
2184 req_id = _get_request_id();
2185 __add_op_cbinfo(mpc, req_id, req_key, __get_pkg_size_info_cb, event_cb,
2188 g_variant_unref(result);
2193 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)
2195 return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb, user_data, _getuid());
2198 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)
2199 { // total package size info
2200 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, uid);
2203 API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc, pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data)
2205 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, _getuid());
2208 API int pkgmgr_client_generate_license_request(pkgmgr_client *pc,
2209 const char *resp_data, char **req_data, char **license_url)
2215 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2217 if (pc == NULL || resp_data == NULL || req_data == NULL ||
2218 license_url == NULL) {
2219 ERR("invalid parameter");
2220 return PKGMGR_R_EINVAL;
2223 if (mpc->ctype != PC_REQUEST) {
2224 ERR("mpc->ctype is not PC_REQUEST");
2225 return PKGMGR_R_EINVAL;
2228 ret = comm_client_request(mpc->info.request.cc,
2229 "generate_license_request",
2230 g_variant_new("(s)", resp_data), &result);
2231 if (ret != PKGMGR_R_OK) {
2232 ERR("request failed: %d", ret);
2236 g_variant_get(result, "(i&s&s)", &ret, &data, &url);
2237 if (ret != PKGMGR_R_OK) {
2238 ERR("generate_license_request failed: %d", ret);
2239 g_variant_unref(result);
2243 *req_data = strdup(data);
2244 *license_url = strdup(url);
2246 g_variant_unref(result);
2251 API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data)
2255 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2257 if (pc == NULL || resp_data == NULL) {
2258 ERR("invalid parameter");
2259 return PKGMGR_R_EINVAL;
2262 if (mpc->ctype != PC_REQUEST) {
2263 ERR("mpc->ctype is not PC_REQUEST");
2264 return PKGMGR_R_EINVAL;
2267 ret = comm_client_request(mpc->info.request.cc,
2268 "register_license", g_variant_new("(s)", resp_data),
2270 if (ret != PKGMGR_R_OK) {
2271 ERR("request failed: %d", ret);
2275 g_variant_get(result, "(i)", &ret);
2276 g_variant_unref(result);
2277 if (ret != PKGMGR_R_OK) {
2278 ERR("register license failed: %d", ret);
2285 API int pkgmgr_client_decrypt_package(pkgmgr_client *pc,
2286 const char *drm_file_path, const char *decrypted_file_path)
2290 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2292 if (pc == NULL || drm_file_path == NULL ||
2293 decrypted_file_path == NULL) {
2294 ERR("invalid parameter");
2295 return PKGMGR_R_EINVAL;
2298 if (mpc->ctype != PC_REQUEST) {
2299 ERR("mpc->ctype is not PC_REQUEST");
2300 return PKGMGR_R_EINVAL;
2303 ret = comm_client_request(mpc->info.request.cc,
2305 g_variant_new("(ss)", drm_file_path,
2306 decrypted_file_path),
2308 if (ret != PKGMGR_R_OK) {
2309 ERR("request failed: %d", ret);
2313 g_variant_get(result, "(i)", &ret);
2314 g_variant_unref(result);
2315 if (ret != PKGMGR_R_OK) {
2316 ERR("decrypt_package failed: %d", ret);
2323 API int pkgmgr_client_enable_splash_screen(pkgmgr_client *pc, const char *appid)
2325 return pkgmgr_client_usr_enable_splash_screen(pc, appid, _getuid());
2328 API int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc,
2329 const char *appid, uid_t uid)
2333 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2335 if (pc == NULL || appid == NULL) {
2336 ERR("Invalid parameter");
2337 return PKGMGR_R_EINVAL;
2340 ret = __change_op_cb_for_enable_disable_splash_screen(mpc, true);
2342 ERR("__change_op_cb_for_enable_disable_splash_screen failed");
2343 return PKGMGR_R_ESYSTEM;
2346 ret = comm_client_request(mpc->info.request.cc,
2347 "enable_app_splash_screen",
2348 g_variant_new("(us)", uid, appid), &result);
2349 if (ret != PKGMGR_R_OK) {
2350 ERR("request failed: %d", ret);
2354 g_variant_get(result, "(i)", &ret);
2355 if (ret != PKGMGR_R_OK) {
2356 g_variant_unref(result);
2360 g_variant_unref(result);
2365 API int pkgmgr_client_disable_splash_screen(pkgmgr_client *pc,
2368 return pkgmgr_client_usr_disable_splash_screen(pc, appid,
2372 API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc,
2373 const char *appid, uid_t uid)
2377 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2379 if (pc == NULL || appid == NULL) {
2380 ERR("Invalid parameter");
2381 return PKGMGR_R_EINVAL;
2384 ret = __change_op_cb_for_enable_disable_splash_screen(mpc, false);
2386 ERR("__change_op_cb_for_enable_disable_splash_screen failed");
2390 ret = comm_client_request(mpc->info.request.cc,
2391 "disable_app_splash_screen",
2392 g_variant_new("(us)", uid, appid), &result);
2393 if (ret != PKGMGR_R_OK) {
2394 ERR("request failed: %d", ret);
2398 g_variant_get(result, "(i)", &ret);
2399 if (ret != PKGMGR_R_OK) {
2400 g_variant_unref(result);
2404 g_variant_unref(result);
2409 static int __set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2412 int ret = PKGMGR_R_ECOMM;
2413 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2415 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) {
2416 ERR("invalid parameter");
2417 return PKGMGR_R_EINVAL;
2420 ret = comm_client_request(mpc->info.request.cc, "set_restriction_mode",
2421 g_variant_new("(usi)", uid, pkgid, mode), &result);
2422 if (ret != PKGMGR_R_OK) {
2423 ERR("request failed: %d", ret);
2427 g_variant_get(result, "(i)", &ret);
2428 g_variant_unref(result);
2433 API int pkgmgr_client_usr_set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2435 return __set_pkg_restriction_mode(pc, pkgid, mode, uid);
2438 API int pkgmgr_client_set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode)
2440 return pkgmgr_client_usr_set_pkg_restriction_mode(pc, pkgid, mode, _getuid());
2443 static int __unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2446 int ret = PKGMGR_R_ECOMM;
2447 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2449 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) {
2450 ERR("invalid parameter");
2451 return PKGMGR_R_EINVAL;
2454 ret = comm_client_request(mpc->info.request.cc,
2455 "unset_restriction_mode",
2456 g_variant_new("(usi)", uid, pkgid, mode), &result);
2457 if (ret != PKGMGR_R_OK) {
2458 ERR("request failed: %d", ret);
2462 g_variant_get(result, "(i)", &ret);
2463 g_variant_unref(result);
2469 API int pkgmgr_client_usr_unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid)
2471 return __unset_pkg_restriction_mode(pc, pkgid, mode, uid);
2474 API int pkgmgr_client_unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode)
2476 return pkgmgr_client_usr_unset_pkg_restriction_mode(pc, pkgid, mode, _getuid());
2479 static int __get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode, uid_t uid)
2482 int ret = PKGMGR_R_ECOMM;
2484 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2486 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0) {
2487 ERR("invalid parameter");
2488 return PKGMGR_R_EINVAL;
2491 ret = comm_client_request(mpc->info.request.cc,
2492 "get_restriction_mode",
2493 g_variant_new("(us)", uid, pkgid), &result);
2494 if (ret != PKGMGR_R_OK) {
2495 ERR("request failed: %d", ret);
2499 g_variant_get(result, "(ii)", &m, &ret);
2500 g_variant_unref(result);
2501 if (ret != PKGMGR_R_OK)
2509 API int pkgmgr_client_usr_get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode, uid_t uid)
2511 return __get_pkg_restriction_mode(pc, pkgid, mode, uid);
2514 API int pkgmgr_client_get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode)
2516 return pkgmgr_client_usr_get_pkg_restriction_mode(pc, pkgid, mode, _getuid());
2519 API int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode,
2523 int ret = PKGMGR_R_ECOMM;
2524 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2527 ERR("invalid parameter");
2528 return PKGMGR_R_EINVAL;
2531 ret = comm_client_request(mpc->info.request.cc, "set_restriction_mode",
2532 g_variant_new("(usi)", uid, "", mode), &result);
2533 if (ret != PKGMGR_R_OK) {
2534 ERR("request failed: %d", ret);
2538 g_variant_get(result, "(i)", &ret);
2539 g_variant_unref(result);
2544 API int pkgmgr_client_set_restriction_mode(pkgmgr_client *pc, int mode)
2546 return pkgmgr_client_usr_set_restriction_mode(pc, mode, _getuid());
2549 API int pkgmgr_client_usr_unset_restriction_mode(pkgmgr_client *pc, int mode,
2553 int ret = PKGMGR_R_ECOMM;
2554 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2557 ERR("invalid parameter");
2558 return PKGMGR_R_EINVAL;
2561 ret = comm_client_request(mpc->info.request.cc,
2562 "unset_restriction_mode",
2563 g_variant_new("(usi)", uid, "", mode), &result);
2564 if (ret != PKGMGR_R_OK) {
2565 ERR("request failed: %d", ret);
2569 g_variant_get(result, "(i)", &ret);
2570 g_variant_unref(result);
2575 API int pkgmgr_client_unset_restriction_mode(pkgmgr_client *pc, int mode)
2577 return pkgmgr_client_usr_unset_restriction_mode(pc, mode, _getuid());
2580 API int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc,
2581 int *mode, uid_t uid)
2584 int ret = PKGMGR_R_ECOMM;
2586 pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc;
2589 ERR("invalid parameter");
2590 return PKGMGR_R_EINVAL;
2593 ret = comm_client_request(mpc->info.request.cc,
2594 "get_restriction_mode",
2595 g_variant_new("(us)", uid, ""), &result);
2596 if (ret != PKGMGR_R_OK) {
2597 ERR("request failed: %d", ret);
2601 g_variant_get(result, "(ii)", &m, &ret);
2602 g_variant_unref(result);
2603 if (ret != PKGMGR_R_OK)
2611 API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc,
2614 return pkgmgr_client_usr_get_restriction_mode(pc, mode, _getuid());