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_client_debug.h"
42 #include "pkgmgr_client_internal.h"
44 /* API export macro */
46 #define API __attribute__ ((visibility("default")))
49 #define PKG_TMP_PATH tzplatform_mkpath(TZ_USER_APP, "tmp")
51 #define BINSH_NAME "/bin/sh"
54 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
55 #define REGULAR_USER 5000
57 static inline uid_t _getuid(void)
61 if (uid < REGULAR_USER)
67 static int _get_request_id()
69 static int internal_req_id = 1;
71 return internal_req_id++;
74 static struct cb_info *__create_event_cb_info(struct pkgmgr_client_t *client,
75 pkgmgr_handler event_cb, void *data, const char *req_key)
77 struct cb_info *cb_info;
79 cb_info = calloc(1, sizeof(struct cb_info));
80 if (cb_info == NULL) {
84 cb_info->client = client;
85 cb_info->event_cb = event_cb;
87 cb_info->req_id = _get_request_id();
88 if (req_key != NULL) {
89 cb_info->req_key = strdup(req_key);
90 if (cb_info->req_key == NULL) {
100 static struct cb_info *__create_app_event_cb_info(
101 struct pkgmgr_client_t *client, pkgmgr_app_handler app_event_cb,
102 void *data, const char *req_key)
104 struct cb_info *cb_info;
106 cb_info = calloc(1, sizeof(struct cb_info));
107 if (cb_info == NULL) {
108 ERR("out of memory");
111 cb_info->client = client;
112 cb_info->app_event_cb = app_event_cb;
113 cb_info->data = data;
114 cb_info->req_id = _get_request_id();
115 if (req_key != NULL) {
116 cb_info->req_key = strdup(req_key);
117 if (cb_info->req_key == NULL) {
118 ERR("out of memory");
127 static struct cb_info *__create_size_info_cb_info(
128 struct pkgmgr_client_t *client,
129 pkgmgr_pkg_size_info_receive_cb size_info_cb,
130 void *data, const char *req_key)
132 struct cb_info *cb_info;
134 cb_info = calloc(1, sizeof(struct cb_info));
135 if (cb_info == NULL) {
136 ERR("out of memory");
139 cb_info->client = client;
140 cb_info->size_info_cb = size_info_cb;
141 cb_info->data = data;
142 cb_info->req_id = _get_request_id();
143 if (req_key != NULL) {
144 cb_info->req_key = strdup(req_key);
145 if (cb_info->req_key == NULL) {
146 ERR("out of memory");
155 static void __free_cb_info(struct cb_info *cb_info)
157 free(cb_info->req_key);
161 static int __sync_process(const char *req_key)
164 char info_file[PKG_STRING_LEN_MAX] = {'\0', };
168 char buf[PKG_STRING_LEN_MAX] = {0, };
170 snprintf(info_file, PKG_STRING_LEN_MAX, "%s/%s", PKG_SIZE_INFO_PATH, req_key);
174 if (access(info_file, F_OK) == 0) {
175 fp = fopen(info_file, "r");
177 DBG("file is not generated yet.... wait\n");
178 usleep(100 * 1000); /* 100ms sleep*/
182 if (fgets(buf, PKG_STRING_LEN_MAX, fp) == NULL) {
183 ERR("failed to read info file");
189 DBG("info_file file is generated, result = %s. \n", buf);
194 DBG("file is not generated yet.... wait\n");
195 usleep(100 * 1000); /* 100ms sleep*/
197 if (check_cnt > 6000) { /* 60s * 10 time over*/
198 ERR("wait time over!!\n");
203 ret = remove(info_file);
205 ERR("file is can not remove[%s, %d]\n", info_file, ret);
210 static int __get_size_process(pkgmgr_client *pc, const char *pkgid, uid_t uid,
211 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
215 int ret = PKGMGR_R_ECOMM;
216 char *req_key = NULL;
217 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
219 if (pc == NULL || pkgid == NULL) {
220 ERR("invalid parameter");
221 return PKGMGR_R_EINVAL;
224 if (client->pc_type != PC_REQUEST) {
225 ERR("client->pc_type is not PC_REQUEST");
226 return PKGMGR_R_EINVAL;
229 ret = pkgmgr_client_connection_send_request(client, "getsize",
230 g_variant_new("(usi)", uid, pkgid, get_type), &result);
231 if (ret != PKGMGR_R_OK) {
232 ERR("request failed: %d", ret);
236 g_variant_get(result, "(i&s)", &ret, &req_key);
237 if (req_key == NULL) {
238 g_variant_unref(result);
239 return PKGMGR_R_ECOMM;
241 if (ret != PKGMGR_R_OK) {
242 g_variant_unref(result);
246 ret = __sync_process(req_key);
248 ERR("get size failed, ret=%d\n", ret);
250 g_variant_unref(result);
255 static int __move_pkg_process(pkgmgr_client *pc, const char *pkgid,
256 const char *pkg_type, uid_t uid, pkgmgr_move_type move_type,
257 pkgmgr_handler event_cb, void *data)
261 ret = pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, event_cb, data, uid);
263 ERR("move request failed");
270 static int __check_app_process(pkgmgr_request_service_type service_type,
271 pkgmgr_client *pc, const char *pkgid, uid_t uid, void *data)
274 int ret = PKGMGR_R_ECOMM;
275 pkgmgrinfo_pkginfo_h handle;
277 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
279 retvm_if(client->pc_type != PC_REQUEST, PKGMGR_R_EINVAL, "client->pc_type is not PC_REQUEST\n");
281 if (uid != GLOBAL_USER)
282 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
284 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
285 retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgrinfo_pkginfo_get_pkginfo failed");
287 if (service_type == PM_REQUEST_KILL_APP)
288 ret = pkgmgr_client_connection_send_request(client, "kill",
289 g_variant_new("(us)", uid, pkgid), &result);
290 else if (service_type == PM_REQUEST_CHECK_APP)
291 ret = pkgmgr_client_connection_send_request(client, "check",
292 g_variant_new("(us)", uid, pkgid), &result);
293 if (ret != PKGMGR_R_OK) {
294 ERR("request failed: %d", ret);
298 g_variant_get(result, "(ii)", &ret, &pid);
299 g_variant_unref(result);
300 if (ret != PKGMGR_R_OK) {
301 ERR("request failed, ret=%d", ret);
307 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
313 static int __request_size_info(pkgmgr_client *pc, uid_t uid)
316 int ret = PKGMGR_R_ECOMM;
317 // char *req_key = NULL;
318 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
321 ERR("invalid parameter");
322 return PKGMGR_R_EINVAL;
325 if (client->pc_type != PC_REQUEST) {
326 ERR("client->pc_type is not PC_REQUEST");
327 return PKGMGR_R_EINVAL;
330 ret = pkgmgr_client_connection_send_request(client, "getsize",
331 g_variant_new("(usi)", uid, "size_info",
332 PM_GET_SIZE_INFO), &result);
333 if (ret != PKGMGR_R_OK) {
334 ERR("request failed: %d", ret);
339 g_variant_get(result, "(i&s)", &ret, &req_key);
340 if (req_key == NULL) {
341 g_variant_unref(result);
342 return PKGMGR_R_ECOMM;
346 g_variant_unref(result);
351 API pkgmgr_client *pkgmgr_client_new(pkgmgr_client_type pc_type)
353 struct pkgmgr_client_t *client;
355 if (pc_type == PC_BROADCAST) {
356 ERR("broadcast type is not supported");
360 if (pc_type != PC_REQUEST && pc_type != PC_LISTENING) {
361 ERR("invalid parameter");
365 client = calloc(1, sizeof(struct pkgmgr_client_t));
366 if (client == NULL) {
367 ERR("out of memory");
371 client->pc_type = pc_type;
372 client->status_type = PKGMGR_CLIENT_STATUS_ALL;
374 if (pkgmgr_client_connection_connect(client))
377 return (pkgmgr_client *)client;
380 API int pkgmgr_client_free(pkgmgr_client *pc)
382 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
385 ERR("invalid argument");
386 return PKGMGR_R_EINVAL;
389 pkgmgr_client_remove_listen_status(client);
390 pkgmgr_client_connection_disconnect(client);
391 if (client->tep_path)
392 free(client->tep_path);
398 static char *__get_type_from_path(const char *pkg_path)
401 char mimetype[255] = { '\0', };
402 char extlist[256] = { '\0', };
405 ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype));
407 ERR("_get_mime_from_file() failed - error code[%d]\n", ret);
411 ret = _get_mime_extension(mimetype, extlist, sizeof(extlist));
413 ERR("_get_mime_extension() failed - error code[%d]\n", ret);
417 if (strlen(extlist) == 0)
420 if (strchr(extlist, ','))
421 extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0';
423 pkg_type = strchr(extlist, '.') + 1;
424 return strdup(pkg_type);
427 API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, const char *tep_path,
430 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *) pc;
432 if (pc == NULL || tep_path == NULL) {
433 ERR("invalied parameter");
434 return PKGMGR_R_EINVAL;
437 if (client->tep_path)
438 free(client->tep_path);
440 client->tep_path = strdup(tep_path);
441 client->tep_move = tep_move;
446 API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type,
447 const char *descriptor_path, const char *pkg_path,
448 const char *optional_data, pkgmgr_mode mode,
449 pkgmgr_handler event_cb, void *data, uid_t uid)
452 int ret = PKGMGR_R_ECOMM;
453 char *req_key = NULL;
454 GVariantBuilder *builder = NULL;
455 GVariant *args = NULL;
456 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
457 char *pkgtype = NULL;
458 struct cb_info *cb_info;
460 if (pc == NULL || pkg_path == NULL) {
461 ERR("invalid parameter");
462 return PKGMGR_R_EINVAL;
465 if (client->pc_type != PC_REQUEST) {
466 ERR("client type is not PC_REQUEST");
467 return PKGMGR_R_EINVAL;
470 if (access(pkg_path, F_OK) != 0) {
471 ERR("failed to access: %s", pkg_path);
472 return PKGMGR_R_EINVAL;
475 if (client->tep_path != NULL && access(client->tep_path, F_OK) != 0) {
476 ERR("failed to access: %s", client->tep_path);
477 return PKGMGR_R_EINVAL;
481 pkgtype = strdup(pkg_type);
483 /* build arguments */
484 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
485 if (client->tep_path) {
486 g_variant_builder_add(builder, "s", "-e");
487 g_variant_builder_add(builder, "s", client->tep_path);
488 g_variant_builder_add(builder, "s", "-M");
489 /* TODO: revise tep_move */
490 g_variant_builder_add(builder, "s",
491 client->tep_move ? "tep_move" : "tep_copy");
494 args = g_variant_new("as", builder);
495 g_variant_builder_unref(builder);
497 ret = pkgmgr_client_connection_send_request(client, "install",
498 g_variant_new("(uss@as)", uid, pkgtype ? pkgtype : "",
501 if (ret != PKGMGR_R_OK) {
502 ERR("request failed: %d", ret);
506 g_variant_get(result, "(i&s)", &ret, &req_key);
507 if (req_key == NULL) {
508 g_variant_unref(result);
509 return PKGMGR_R_ECOMM;
511 if (ret != PKGMGR_R_OK) {
512 g_variant_unref(result);
516 cb_info = __create_event_cb_info(client, event_cb, data, req_key);
517 if (cb_info == NULL) {
518 g_variant_unref(result);
519 return PKGMGR_R_ENOMEM;
521 g_variant_unref(result);
522 ret = pkgmgr_client_connection_set_callback(client, cb_info);
523 if (ret != PKGMGR_R_OK) {
524 __free_cb_info(cb_info);
527 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
529 return cb_info->req_id;
532 API int pkgmgr_client_install(pkgmgr_client *pc, const char *pkg_type,
533 const char *descriptor_path, const char *pkg_path,
534 const char *optional_data, pkgmgr_mode mode,
535 pkgmgr_handler event_cb, void *data)
537 return pkgmgr_client_usr_install(pc, pkg_type, descriptor_path,
538 pkg_path, optional_data, mode, event_cb, data,
542 API int pkgmgr_client_reinstall(pkgmgr_client *pc, const char *pkg_type,
543 const char *pkgid, const char *optional_data, pkgmgr_mode mode,
544 pkgmgr_handler event_cb, void *data)
546 return pkgmgr_client_usr_reinstall(pc, pkg_type, pkgid, optional_data,
547 mode, event_cb, data, _getuid());
550 API int pkgmgr_client_usr_reinstall(pkgmgr_client *pc, const char *pkg_type,
551 const char *pkgid, const char *optional_data, pkgmgr_mode mode,
552 pkgmgr_handler event_cb, void *data, uid_t uid)
555 int ret = PKGMGR_R_ECOMM;
556 char *req_key = NULL;
557 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
558 struct cb_info *cb_info;
560 if (pc == NULL || pkgid == NULL) {
561 ERR("invalid parameter");
562 return PKGMGR_R_EINVAL;
565 if (client->pc_type != PC_REQUEST) {
566 ERR("client->pc_type is not PC_REQUEST");
567 return PKGMGR_R_EINVAL;
570 ret = pkgmgr_client_connection_send_request(client, "reinstall",
571 g_variant_new("(us)", uid, pkgid), &result);
572 if (ret != PKGMGR_R_OK) {
573 ERR("request failed: %d", ret);
577 g_variant_get(result, "(i&s)", &ret, &req_key);
578 if (req_key == NULL) {
579 g_variant_unref(result);
580 return PKGMGR_R_ECOMM;
582 if (ret != PKGMGR_R_OK) {
583 g_variant_unref(result);
587 cb_info = __create_event_cb_info(client, event_cb, data, req_key);
588 if (cb_info == NULL) {
589 g_variant_unref(result);
590 return PKGMGR_R_ENOMEM;
592 g_variant_unref(result);
593 ret = pkgmgr_client_connection_set_callback(client, cb_info);
594 if (ret != PKGMGR_R_OK) {
595 __free_cb_info(cb_info);
598 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
600 return cb_info->req_id;
603 API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type,
604 const char *descriptor_path, const char *pkg_path,
605 const char *optional_data, pkgmgr_mode mode,
606 pkgmgr_handler event_cb, void *data, uid_t uid)
609 int ret = PKGMGR_R_ECOMM;
610 char *req_key = NULL;
611 GVariantBuilder *builder = NULL;
612 GVariant *args = NULL;
613 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
614 char *pkgtype = NULL;
615 struct cb_info *cb_info;
617 if (pc == NULL || pkg_path == NULL) {
618 ERR("invalid parameter");
619 return PKGMGR_R_EINVAL;
622 if (client->pc_type != PC_REQUEST) {
623 ERR("client->pc_type is not PC_REQUEST");
624 return PKGMGR_R_EINVAL;
627 if (access(pkg_path, F_OK) != 0) {
628 ERR("failed to access: %s", pkg_path);
629 return PKGMGR_R_EINVAL;
632 if (client->tep_path != NULL && access(client->tep_path, F_OK) != 0) {
633 ERR("failed to access: %s", client->tep_path);
634 return PKGMGR_R_EINVAL;
638 pkgtype = strdup(pkg_type);
640 /* build arguments */
641 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
642 if (client->tep_path) {
643 g_variant_builder_add(builder, "s", "-e");
644 g_variant_builder_add(builder, "s", client->tep_path);
645 g_variant_builder_add(builder, "s", "-M");
646 /* TODO: revise tep_move */
647 g_variant_builder_add(builder, "s",
648 client->tep_move ? "tep_move" : "tep_copy");
651 args = g_variant_new("as", builder);
652 g_variant_builder_unref(builder);
654 ret = pkgmgr_client_connection_send_request(client, "mount_install",
655 g_variant_new("(uss@as)", uid, pkgtype ? pkgtype : "",
658 if (ret != PKGMGR_R_OK) {
659 ERR("request failed: %d", ret);
663 g_variant_get(result, "(i&s)", &ret, &req_key);
664 if (req_key == NULL) {
665 g_variant_unref(result);
666 return PKGMGR_R_ECOMM;
668 if (ret != PKGMGR_R_OK) {
669 g_variant_unref(result);
673 cb_info = __create_event_cb_info(client, event_cb, data, req_key);
674 if (cb_info == NULL) {
675 g_variant_unref(result);
676 return PKGMGR_R_ENOMEM;
678 g_variant_unref(result);
679 ret = pkgmgr_client_connection_set_callback(client, cb_info);
680 if (ret != PKGMGR_R_OK) {
681 __free_cb_info(cb_info);
684 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
686 return cb_info->req_id;
689 API int pkgmgr_client_mount_install(pkgmgr_client *pc, const char *pkg_type,
690 const char *descriptor_path, const char *pkg_path,
691 const char *optional_data, pkgmgr_mode mode,
692 pkgmgr_handler event_cb, void *data)
694 return pkgmgr_client_usr_mount_install(pc, pkg_type, descriptor_path,
695 pkg_path, optional_data, mode, event_cb, data,
699 API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
700 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
703 return pkgmgr_client_usr_uninstall(pc, pkg_type, pkgid, mode, event_cb,
707 API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type,
708 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
709 void *data, uid_t uid)
712 int ret = PKGMGR_R_ECOMM;
713 char *req_key = NULL;
714 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
715 struct cb_info *cb_info;
717 if (pc == NULL || pkgid == NULL) {
718 ERR("invalid parameter");
719 return PKGMGR_R_EINVAL;
722 if (client->pc_type != PC_REQUEST) {
723 ERR("client->pc_type is not PC_REQUEST");
724 return PKGMGR_R_EINVAL;
727 ret = pkgmgr_client_connection_send_request(client, "uninstall",
728 g_variant_new("(us)", uid, pkgid), &result);
729 if (ret != PKGMGR_R_OK) {
730 ERR("request failed: %d", ret);
734 g_variant_get(result, "(i&s)", &ret, &req_key);
735 if (req_key == NULL) {
736 g_variant_unref(result);
737 return PKGMGR_R_ECOMM;
739 if (ret != PKGMGR_R_OK) {
740 g_variant_unref(result);
744 cb_info = __create_event_cb_info(client, event_cb, data, req_key);
745 if (cb_info == NULL) {
746 g_variant_unref(result);
747 return PKGMGR_R_ENOMEM;
749 g_variant_unref(result);
750 ret = pkgmgr_client_connection_set_callback(client, cb_info);
751 if (ret != PKGMGR_R_OK) {
752 __free_cb_info(cb_info);
755 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
757 return cb_info->req_id;
760 API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
761 const char *pkgid, pkgmgr_move_type move_type,
762 pkgmgr_handler event_cb, void *data)
764 return pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type,
765 event_cb, data, _getuid());
767 API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type,
768 const char *pkgid, pkgmgr_move_type move_type,
769 pkgmgr_handler event_cb, void *data, uid_t uid)
772 int ret = PKGMGR_R_ECOMM;
773 char *req_key = NULL;
774 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
775 struct cb_info *cb_info;
777 if (pc == NULL || pkgid == NULL) {
778 ERR("invalid parameter");
779 return PKGMGR_R_EINVAL;
782 if ((move_type < PM_MOVE_TO_INTERNAL) ||
783 (move_type > PM_MOVE_TO_SDCARD))
784 return PKGMGR_R_EINVAL;
786 if (client->pc_type != PC_REQUEST) {
787 ERR("client->pc_type is not PC_REQUEST");
788 return PKGMGR_R_EINVAL;
791 ret = pkgmgr_client_connection_send_request(client, "move",
792 g_variant_new("(usi)", uid, pkgid, move_type), &result);
793 if (ret != PKGMGR_R_OK) {
794 ERR("request failed: %d", ret);
798 g_variant_get(result, "(i&s)", &ret, &req_key);
799 if (req_key == NULL) {
800 g_variant_unref(result);
801 return PKGMGR_R_ECOMM;
803 if (ret != PKGMGR_R_OK) {
804 g_variant_unref(result);
808 cb_info = __create_event_cb_info(client, event_cb, data, req_key);
809 if (cb_info == NULL) {
810 g_variant_unref(result);
811 return PKGMGR_R_ERROR;
813 g_variant_unref(result);
814 ret = pkgmgr_client_connection_set_callback(client, cb_info);
815 if (ret != PKGMGR_R_OK) {
816 __free_cb_info(cb_info);
819 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
821 return cb_info->req_id;
824 API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type,
825 const char *pkgid, uid_t uid)
828 int ret = PKGMGR_R_ECOMM;
829 GVariantBuilder *builder;
830 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
832 if (pc == NULL || pkgid == NULL) {
833 ERR("invalid parameter");
834 return PKGMGR_R_EINVAL;
837 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
838 g_variant_builder_add(builder, "s", pkgid);
840 ret = pkgmgr_client_connection_send_request(client, "enable_pkgs",
841 g_variant_new("(uas)", uid, builder), &result);
842 g_variant_builder_unref(builder);
843 if (ret != PKGMGR_R_OK) {
844 ERR("request failed: %d", ret);
848 g_variant_get(result, "(is)", &ret, NULL);
849 g_variant_unref(result);
854 API int pkgmgr_client_activate(pkgmgr_client *pc, const char *pkg_type,
857 return pkgmgr_client_usr_activate(pc, pkg_type, pkgid, _getuid());
860 API int pkgmgr_client_usr_activate_packages(pkgmgr_client *pc,
861 const char *pkg_type, const char **pkgids, int n_pkgs,
862 pkgmgr_handler event_cb, void *data, uid_t uid)
865 GVariantBuilder *builder;
866 int ret = PKGMGR_R_ECOMM;
867 char *req_key = NULL;
868 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
869 struct cb_info *cb_info;
872 if (pc == NULL || pkgids == NULL || n_pkgs < 1) {
873 ERR("invalid parameter");
874 return PKGMGR_R_EINVAL;
877 if (client->pc_type != PC_REQUEST) {
878 ERR("client type is not PC_REQUEST");
879 return PKGMGR_R_EINVAL;
882 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
883 for (i = 0; i < n_pkgs; i++)
884 g_variant_builder_add(builder, "s", pkgids[i]);
886 ret = pkgmgr_client_connection_send_request(client, "enable_pkgs",
887 g_variant_new("(uas)", uid, builder), &result);
888 g_variant_builder_unref(builder);
889 if (ret != PKGMGR_R_OK) {
890 ERR("request failed: %d", ret);
894 g_variant_get(result, "(i&s)", &ret, &req_key);
895 if (req_key == NULL) {
896 g_variant_unref(result);
897 return PKGMGR_R_ECOMM;
899 if (ret != PKGMGR_R_OK) {
900 g_variant_unref(result);
904 cb_info = __create_event_cb_info(client, event_cb, data, req_key);
905 if (cb_info == NULL) {
906 g_variant_unref(result);
907 return PKGMGR_R_ERROR;
909 g_variant_unref(result);
910 ret = pkgmgr_client_connection_set_callback(client, cb_info);
911 if (ret != PKGMGR_R_OK) {
912 __free_cb_info(cb_info);
915 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
917 return cb_info->req_id;
920 API int pkgmgr_client_activate_packages(pkgmgr_client *pc,
921 const char *pkg_type, const char **pkgids, int n_pkgs,
922 pkgmgr_handler event_cb, void *data)
924 return pkgmgr_client_usr_activate_packages(pc, pkg_type,
925 pkgids, n_pkgs, event_cb, data, _getuid());
928 API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type,
929 const char *pkgid, uid_t uid)
932 GVariantBuilder *builder;
933 int ret = PKGMGR_R_ECOMM;
934 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
936 if (pc == NULL || pkgid == NULL) {
937 ERR("invalid parameter");
938 return PKGMGR_R_EINVAL;
941 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
942 g_variant_builder_add(builder, "s", pkgid);
944 ret = pkgmgr_client_connection_send_request(client, "disable_pkgs",
945 g_variant_new("(uas)", uid, builder), &result);
946 g_variant_builder_unref(builder);
947 if (ret != PKGMGR_R_OK) {
948 ERR("request failed: %d", ret);
952 g_variant_get(result, "(is)", &ret, NULL);
953 g_variant_unref(result);
958 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
961 return pkgmgr_client_usr_deactivate(pc, pkg_type, pkgid, _getuid());
964 API int pkgmgr_client_usr_deactivate_packages(pkgmgr_client *pc,
965 const char *pkg_type, const char **pkgids, int n_pkgs,
966 pkgmgr_handler event_cb, void *data, uid_t uid)
969 GVariantBuilder *builder;
970 int ret = PKGMGR_R_ECOMM;
971 char *req_key = NULL;
972 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
973 struct cb_info *cb_info;
976 if (pc == NULL || pkgids == NULL || n_pkgs < 1) {
977 ERR("invalid parameter");
978 return PKGMGR_R_EINVAL;
981 if (client->pc_type != PC_REQUEST) {
982 ERR("client type is not PC_REQUEST");
983 return PKGMGR_R_EINVAL;
986 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
987 for (i = 0; i < n_pkgs; i++)
988 g_variant_builder_add(builder, "s", pkgids[i]);
990 ret = pkgmgr_client_connection_send_request(client, "disable_pkgs",
991 g_variant_new("(uas)", uid, builder), &result);
992 g_variant_builder_unref(builder);
993 if (ret != PKGMGR_R_OK) {
994 ERR("request failed: %d", ret);
998 g_variant_get(result, "(i&s)", &ret, &req_key);
999 if (req_key == NULL) {
1000 g_variant_unref(result);
1001 return PKGMGR_R_ECOMM;
1003 if (ret != PKGMGR_R_OK) {
1004 g_variant_unref(result);
1008 cb_info = __create_event_cb_info(client, event_cb, data, req_key);
1009 if (cb_info == NULL) {
1010 g_variant_unref(result);
1011 return PKGMGR_R_ERROR;
1013 g_variant_unref(result);
1014 ret = pkgmgr_client_connection_set_callback(client, cb_info);
1015 if (ret != PKGMGR_R_OK) {
1016 __free_cb_info(cb_info);
1019 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
1021 return cb_info->req_id;
1024 API int pkgmgr_client_deactivate_packages(pkgmgr_client *pc,
1025 const char *pkg_type, const char **pkgids, int n_pkgs,
1026 pkgmgr_handler event_cb, void *data)
1028 return pkgmgr_client_usr_deactivate_packages(pc, pkg_type,
1029 pkgids, n_pkgs, event_cb, data, _getuid());
1032 API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid,
1033 pkgmgr_app_handler app_event_cb, uid_t uid)
1036 int ret = PKGMGR_R_ECOMM;
1037 char *req_key = NULL;
1038 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1039 struct cb_info *cb_info;
1041 if (pc == NULL || appid == NULL) {
1042 ERR("invalid parameter");
1043 return PKGMGR_R_EINVAL;
1046 ret = pkgmgr_client_connection_send_request(client, "enable_app",
1047 g_variant_new("(us)", uid, appid), &result);
1048 if (ret != PKGMGR_R_OK) {
1049 ERR("request failed: %d", ret);
1053 g_variant_get(result, "(i&s)", &ret, &req_key);
1054 if (req_key == NULL) {
1055 g_variant_unref(result);
1056 return PKGMGR_R_ECOMM;
1058 if (ret != PKGMGR_R_OK) {
1059 g_variant_unref(result);
1063 cb_info = __create_app_event_cb_info(client, app_event_cb, NULL,
1065 if (cb_info == NULL) {
1066 g_variant_unref(result);
1067 return PKGMGR_R_ENOMEM;
1069 g_variant_unref(result);
1070 ret = pkgmgr_client_connection_set_callback(client, cb_info);
1071 if (ret != PKGMGR_R_OK) {
1072 __free_cb_info(cb_info);
1075 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
1080 API int pkgmgr_client_activate_app(pkgmgr_client *pc, const char *appid,
1081 pkgmgr_app_handler app_event_cb)
1083 return pkgmgr_client_usr_activate_app(pc, appid, app_event_cb,
1087 API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc,
1088 const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid)
1091 int ret = PKGMGR_R_ECOMM;
1092 char *req_key = NULL;
1093 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1094 struct cb_info *cb_info;
1096 if (pc == NULL || appid == NULL) {
1097 ERR("invalid parameter");
1098 return PKGMGR_R_EINVAL;
1101 ret = pkgmgr_client_connection_send_request(client,
1102 "enable_global_app_for_uid",
1103 g_variant_new("(us)", uid, appid), &result);
1104 if (ret != PKGMGR_R_OK) {
1105 ERR("request failed: %d", ret);
1109 g_variant_get(result, "(i&s)", &ret, &req_key);
1110 if (req_key == NULL) {
1111 g_variant_unref(result);
1112 return PKGMGR_R_ECOMM;
1114 if (ret != PKGMGR_R_OK) {
1115 g_variant_unref(result);
1119 cb_info = __create_app_event_cb_info(client, app_event_cb, NULL,
1121 if (cb_info == NULL) {
1122 g_variant_unref(result);
1123 return PKGMGR_R_ENOMEM;
1125 g_variant_unref(result);
1126 ret = pkgmgr_client_connection_set_callback(client, cb_info);
1127 if (ret != PKGMGR_R_OK) {
1128 __free_cb_info(cb_info);
1131 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
1136 API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid,
1137 pkgmgr_app_handler app_event_cb, uid_t uid)
1140 int ret = PKGMGR_R_ECOMM;
1141 char *req_key = NULL;
1142 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1143 struct cb_info *cb_info;
1145 if (pc == NULL || appid == NULL) {
1146 ERR("invalid parameter");
1147 return PKGMGR_R_EINVAL;
1150 ret = pkgmgr_client_connection_send_request(client, "disable_app",
1151 g_variant_new("(us)", uid, appid), &result);
1152 if (ret != PKGMGR_R_OK) {
1153 ERR("request failed: %d", ret);
1157 g_variant_get(result, "(i&s)", &ret, &req_key);
1158 if (req_key == NULL) {
1159 g_variant_unref(result);
1160 return PKGMGR_R_ECOMM;
1162 if (ret != PKGMGR_R_OK) {
1163 g_variant_unref(result);
1167 cb_info = __create_app_event_cb_info(client, app_event_cb, NULL,
1169 if (cb_info == NULL) {
1170 g_variant_unref(result);
1171 return PKGMGR_R_ENOMEM;
1173 g_variant_unref(result);
1174 ret = pkgmgr_client_connection_set_callback(client, cb_info);
1175 if (ret != PKGMGR_R_OK) {
1176 __free_cb_info(cb_info);
1179 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
1184 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid,
1185 pkgmgr_app_handler app_event_cb)
1187 return pkgmgr_client_usr_deactivate_app(pc, appid, app_event_cb,
1191 API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc,
1192 const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid)
1195 int ret = PKGMGR_R_ECOMM;
1196 char *req_key = NULL;
1197 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1198 struct cb_info *cb_info;
1200 if (pc == NULL || appid == NULL) {
1201 ERR("invalid parameter");
1202 return PKGMGR_R_EINVAL;
1205 ret = pkgmgr_client_connection_send_request(client,
1206 "disable_global_app_for_uid",
1207 g_variant_new("(us)", uid, appid), &result);
1208 if (ret != PKGMGR_R_OK) {
1209 ERR("request failed: %d", ret);
1213 g_variant_get(result, "(i&s)", &ret, &req_key);
1214 if (req_key == NULL) {
1215 g_variant_unref(result);
1216 return PKGMGR_R_ECOMM;
1218 if (ret != PKGMGR_R_OK) {
1219 g_variant_unref(result);
1223 cb_info = __create_app_event_cb_info(client, app_event_cb, NULL,
1225 if (cb_info == NULL) {
1226 g_variant_unref(result);
1227 return PKGMGR_R_ENOMEM;
1229 g_variant_unref(result);
1230 ret = pkgmgr_client_connection_set_callback(client, cb_info);
1231 if (ret != PKGMGR_R_OK) {
1232 __free_cb_info(cb_info);
1235 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
1240 API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc,
1241 const char *pkg_type, const char *appid, pkgmgr_mode mode,
1246 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1248 if (pc == NULL || appid == NULL) {
1249 ERR("invalid parameter");
1250 return PKGMGR_R_EINVAL;
1253 if (client->pc_type != PC_REQUEST) {
1254 ERR("client->pc_type is not PC_REQUEST");
1255 return PKGMGR_R_EINVAL;
1258 ret = pkgmgr_client_connection_send_request(client, "cleardata",
1259 g_variant_new("(us)", uid, appid), &result);
1260 if (ret == PKGMGR_R_OK) {
1261 ERR("request failed: %d", ret);
1265 g_variant_get(result, "(i)", &ret);
1266 g_variant_unref(result);
1271 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
1272 const char *appid, pkgmgr_mode mode)
1274 return pkgmgr_client_usr_clear_user_data(pc, pkg_type, appid, mode,
1278 API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type)
1280 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1283 ERR("invalid parameter");
1284 return PKGMGR_R_EINVAL;
1287 client->status_type = status_type;
1292 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
1296 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1297 struct cb_info *cb_info;
1299 if (pc == NULL || event_cb == NULL) {
1300 ERR("invalid parameter");
1301 return PKGMGR_R_EINVAL;
1304 if (client->pc_type != PC_LISTENING) {
1305 ERR("client->pc_type is not PC_LISTENING");
1306 return PKGMGR_R_EINVAL;
1309 cb_info = __create_event_cb_info(client, event_cb, data, NULL);
1310 if (cb_info == NULL)
1311 return PKGMGR_R_ENOMEM;
1312 cb_info->status_type = client->status_type;
1313 ret = pkgmgr_client_connection_set_callback(client, cb_info);
1314 if (ret != PKGMGR_R_OK) {
1315 __free_cb_info(cb_info);
1318 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
1320 return cb_info->req_id;
1323 API int pkgmgr_client_listen_app_status(pkgmgr_client *pc,
1324 pkgmgr_app_handler app_event_cb, void *data)
1327 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1328 struct cb_info *cb_info;
1330 if (pc == NULL || app_event_cb == NULL) {
1331 ERR("invalid parameter");
1332 return PKGMGR_R_EINVAL;
1335 if (client->pc_type != PC_LISTENING) {
1336 ERR("client->pc_type is not PC_LISTENING");
1337 return PKGMGR_R_EINVAL;
1340 cb_info = __create_app_event_cb_info(client, app_event_cb, data, NULL);
1341 if (cb_info == NULL)
1342 return PKGMGR_R_ENOMEM;
1343 cb_info->status_type = client->status_type;
1344 ret = pkgmgr_client_connection_set_callback(client, cb_info);
1345 if (ret != PKGMGR_R_OK) {
1346 __free_cb_info(cb_info);
1349 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
1351 return cb_info->req_id;
1354 API int pkgmgr_client_remove_listen_status(pkgmgr_client *pc)
1356 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1359 struct cb_info *cb_info;
1362 ERR("invalid parameter");
1363 return PKGMGR_R_EINVAL;
1366 /* unset all callback */
1367 tmp = client->cb_info_list;
1368 while (tmp != NULL) {
1370 cb_info = (struct cb_info *)tmp->data;
1371 pkgmgr_client_connection_unset_callback(pc, cb_info);
1372 client->cb_info_list = g_list_delete_link(client->cb_info_list,
1374 __free_cb_info(cb_info);
1381 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
1382 const char *pkgid, const char *key, const char *val)
1384 /* client cannot broadcast signal */
1388 /* TODO: deprecate(or remove) */
1389 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type,
1390 int service_mode, pkgmgr_client *pc, const char *pkg_type,
1391 const char *pkgid, const char *custom_info,
1392 pkgmgr_handler event_cb, void *data)
1394 return pkgmgr_client_usr_request_service(service_type, service_mode,
1395 pc, pkg_type, pkgid, _getuid(), custom_info, event_cb,
1399 API int pkgmgr_client_usr_request_service(
1400 pkgmgr_request_service_type service_type, int service_mode,
1401 pkgmgr_client *pc, const char *pkg_type, const char *pkgid,
1402 uid_t uid, const char *custom_info, pkgmgr_handler event_cb,
1407 /* Check for NULL value of service type */
1408 retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
1409 retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n");
1411 switch (service_type) {
1412 case PM_REQUEST_MOVE:
1413 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1414 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1415 tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1417 ret = __move_pkg_process(pc, pkgid, pkg_type, uid, (pkgmgr_move_type)service_mode, event_cb, data);
1420 case PM_REQUEST_GET_SIZE:
1421 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1422 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1423 tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode >= PM_GET_MAX), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
1425 ret = __get_size_process(pc, pkgid, uid, (pkgmgr_getsize_type)service_mode, event_cb, data);
1428 case PM_REQUEST_KILL_APP:
1429 case PM_REQUEST_CHECK_APP:
1430 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
1431 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
1433 ret = __check_app_process(service_type, pc, pkgid, uid, data);
1435 ERR("__check_app_process fail \n");
1442 ERR("Wrong Request\n");
1453 API int pkgmgr_client_usr_request_size_info(uid_t uid)
1456 struct pkgmgr_client *client;
1458 client = pkgmgr_client_new(PC_REQUEST);
1459 if (client == NULL) {
1460 ERR("out of memory");
1461 return PKGMGR_R_ENOMEM;
1464 ret = __request_size_info(client, uid);
1466 ERR("__request_size_info fail");
1468 pkgmgr_client_free(client);
1472 API int pkgmgr_client_request_size_info(void)
1474 /* get all package size (data, total) */
1475 return pkgmgr_client_usr_request_size_info(_getuid());
1478 API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid)
1482 struct pkgmgr_client_t *client;
1484 if (pkgid == NULL) {
1485 ERR("invalid parameter");
1486 return PKGMGR_R_EINVAL;
1489 client = pkgmgr_client_new(PC_REQUEST);
1490 if (client == NULL) {
1491 ERR("out of memory");
1492 return PKGMGR_R_ENOMEM;
1495 ret = pkgmgr_client_connection_send_request(client, "clearcache",
1496 g_variant_new("(us)", uid, pkgid), &result);
1497 if (ret != PKGMGR_R_OK) {
1498 ERR("request failed: %d", ret);
1502 g_variant_get(result, "(i)", &ret);
1503 g_variant_unref(result);
1508 API int pkgmgr_client_clear_cache_dir(const char *pkgid)
1510 return pkgmgr_client_usr_clear_cache_dir(pkgid, _getuid());
1513 API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid)
1515 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, uid);
1518 API int pkgmgr_client_clear_all_cache_dir(void)
1520 return pkgmgr_client_usr_clear_cache_dir(
1521 PKG_CLEAR_ALL_CACHE, getuid());
1524 API int pkgmgr_client_get_size(pkgmgr_client *pc, const char *pkgid,
1525 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
1528 return pkgmgr_client_usr_get_size(pc, pkgid, get_type, event_cb, data,
1532 /* TODO: deprecate(or remove) */
1533 API int pkgmgr_client_usr_get_size(pkgmgr_client *pc, const char *pkgid,
1534 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
1535 void *data, uid_t uid)
1538 int ret = PKGMGR_R_ECOMM;
1539 char *req_key = NULL;
1540 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1541 struct cb_info *cb_info;
1543 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
1544 ERR("invalid parameter");
1545 return PKGMGR_R_EINVAL;
1548 if (client->pc_type != PC_REQUEST) {
1549 ERR("client->pc_type is not PC_REQUEST");
1550 return PKGMGR_R_EINVAL;
1554 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
1555 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
1557 get_type = PM_GET_PKG_SIZE_INFO;
1559 ret = pkgmgr_client_connection_send_request(client, "getsize",
1560 g_variant_new("(usi)", uid, pkgid, get_type), &result);
1561 if (ret != PKGMGR_R_OK) {
1562 ERR("request failed: %d", ret);
1566 g_variant_get(result, "(i&s)", &ret, &req_key);
1567 if (req_key == NULL) {
1568 g_variant_unref(result);
1569 return PKGMGR_R_ECOMM;
1571 if (ret != PKGMGR_R_OK) {
1572 g_variant_unref(result);
1576 cb_info = __create_event_cb_info(client, event_cb, data, req_key);
1577 if (cb_info == NULL) {
1578 g_variant_unref(result);
1579 return PKGMGR_R_ENOMEM;
1581 g_variant_unref(result);
1582 ret = pkgmgr_client_connection_set_callback(client, cb_info);
1583 if (ret != PKGMGR_R_OK) {
1584 __free_cb_info(cb_info);
1587 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
1592 API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc,
1593 const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb,
1594 void *user_data, uid_t uid)
1597 int ret = PKGMGR_R_ECOMM;
1598 char *req_key = NULL;
1600 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1601 struct cb_info *cb_info;
1603 if (pc == NULL || pkgid == NULL || event_cb == NULL) {
1604 ERR("invalid parameter");
1605 return PKGMGR_R_EINVAL;
1608 if (client->pc_type != PC_REQUEST) {
1609 ERR("client->pc_type is not PC_REQUEST");
1610 return PKGMGR_R_EINVAL;
1613 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
1614 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
1616 get_type = PM_GET_PKG_SIZE_INFO;
1618 ret = pkgmgr_client_connection_send_request(client, "getsize",
1619 g_variant_new("(usi)", uid, pkgid, get_type), &result);
1620 if (ret != PKGMGR_R_OK) {
1621 ERR("request failed: %d", ret);
1625 g_variant_get(result, "(i&s)", &ret, &req_key);
1626 if (req_key == NULL) {
1627 g_variant_unref(result);
1628 return PKGMGR_R_ECOMM;
1630 if (ret != PKGMGR_R_OK) {
1631 g_variant_unref(result);
1635 cb_info = __create_size_info_cb_info(client, event_cb, user_data,
1637 if (cb_info == NULL) {
1638 g_variant_unref(result);
1639 return PKGMGR_R_ENOMEM;
1641 g_variant_unref(result);
1642 ret = pkgmgr_client_connection_set_callback(client, cb_info);
1643 if (ret != PKGMGR_R_OK) {
1644 __free_cb_info(cb_info);
1647 client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
1652 API int pkgmgr_client_get_package_size_info(pkgmgr_client *pc,
1653 const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb,
1656 return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb,
1657 user_data, _getuid());
1660 API int pkgmgr_client_usr_get_total_package_size_info(pkgmgr_client *pc,
1661 pkgmgr_total_pkg_size_info_receive_cb event_cb,
1662 void *user_data, uid_t uid)
1663 { /* total package size info */
1664 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL,
1665 (pkgmgr_pkg_size_info_receive_cb)event_cb,
1669 API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc,
1670 pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data)
1672 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL,
1673 (pkgmgr_pkg_size_info_receive_cb)event_cb,
1674 user_data, _getuid());
1677 API int pkgmgr_client_generate_license_request(pkgmgr_client *pc,
1678 const char *resp_data, char **req_data, char **license_url)
1684 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1686 if (pc == NULL || resp_data == NULL || req_data == NULL ||
1687 license_url == NULL) {
1688 ERR("invalid parameter");
1689 return PKGMGR_R_EINVAL;
1692 if (client->pc_type != PC_REQUEST) {
1693 ERR("client->pc_type is not PC_REQUEST");
1694 return PKGMGR_R_EINVAL;
1697 ret = pkgmgr_client_connection_send_request(client,
1698 "generate_license_request",
1699 g_variant_new("(s)", resp_data), &result);
1700 if (ret != PKGMGR_R_OK) {
1701 ERR("request failed: %d", ret);
1705 g_variant_get(result, "(i&s&s)", &ret, &data, &url);
1706 if (ret != PKGMGR_R_OK) {
1707 ERR("generate_license_request failed: %d", ret);
1708 g_variant_unref(result);
1712 *req_data = strdup(data);
1713 *license_url = strdup(url);
1715 g_variant_unref(result);
1720 API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data)
1724 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1726 if (pc == NULL || resp_data == NULL) {
1727 ERR("invalid parameter");
1728 return PKGMGR_R_EINVAL;
1731 if (client->pc_type != PC_REQUEST) {
1732 ERR("client->pc_type is not PC_REQUEST");
1733 return PKGMGR_R_EINVAL;
1736 ret = pkgmgr_client_connection_send_request(client, "register_license",
1737 g_variant_new("(s)", resp_data), &result);
1738 if (ret != PKGMGR_R_OK) {
1739 ERR("request failed: %d", ret);
1743 g_variant_get(result, "(i)", &ret);
1744 g_variant_unref(result);
1745 if (ret != PKGMGR_R_OK)
1746 ERR("register license failed: %d", ret);
1751 API int pkgmgr_client_decrypt_package(pkgmgr_client *pc,
1752 const char *drm_file_path, const char *decrypted_file_path)
1756 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1758 if (pc == NULL || drm_file_path == NULL ||
1759 decrypted_file_path == NULL) {
1760 ERR("invalid parameter");
1761 return PKGMGR_R_EINVAL;
1764 if (client->pc_type != PC_REQUEST) {
1765 ERR("client->pc_type is not PC_REQUEST");
1766 return PKGMGR_R_EINVAL;
1769 ret = pkgmgr_client_connection_send_request(client, "decrypt_package",
1770 g_variant_new("(ss)", drm_file_path,
1771 decrypted_file_path), &result);
1772 if (ret != PKGMGR_R_OK) {
1773 ERR("request failed: %d", ret);
1777 g_variant_get(result, "(i)", &ret);
1778 g_variant_unref(result);
1779 if (ret != PKGMGR_R_OK)
1780 ERR("decrypt_package failed: %d", ret);
1785 API int pkgmgr_client_enable_splash_screen(pkgmgr_client *pc, const char *appid)
1787 return pkgmgr_client_usr_enable_splash_screen(pc, appid, _getuid());
1790 API int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc,
1791 const char *appid, uid_t uid)
1795 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1797 if (pc == NULL || appid == NULL) {
1798 ERR("Invalid parameter");
1799 return PKGMGR_R_EINVAL;
1802 ret = pkgmgr_client_connection_send_request(client,
1803 "enable_app_splash_screen",
1804 g_variant_new("(us)", uid, appid), &result);
1805 if (ret != PKGMGR_R_OK) {
1806 ERR("request failed: %d", ret);
1810 g_variant_get(result, "(i)", &ret);
1811 g_variant_unref(result);
1812 if (ret != PKGMGR_R_OK)
1813 ERR("enable splash screen failed: %d", ret);
1818 API int pkgmgr_client_disable_splash_screen(pkgmgr_client *pc,
1821 return pkgmgr_client_usr_disable_splash_screen(pc, appid,
1825 API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc,
1826 const char *appid, uid_t uid)
1830 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1832 if (pc == NULL || appid == NULL) {
1833 ERR("Invalid parameter");
1834 return PKGMGR_R_EINVAL;
1837 ret = pkgmgr_client_connection_send_request(client,
1838 "disable_app_splash_screen",
1839 g_variant_new("(us)", uid, appid), &result);
1840 if (ret != PKGMGR_R_OK) {
1841 ERR("request failed: %d", ret);
1845 g_variant_get(result, "(i)", &ret);
1846 g_variant_unref(result);
1847 if (ret != PKGMGR_R_OK)
1848 ERR("disable splash screen failed: %d", ret);
1853 static int __set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid,
1854 int mode, uid_t uid)
1857 int ret = PKGMGR_R_ECOMM;
1858 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1860 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) {
1861 ERR("invalid parameter");
1862 return PKGMGR_R_EINVAL;
1865 ret = pkgmgr_client_connection_send_request(client,
1866 "set_restriction_mode",
1867 g_variant_new("(usi)", uid, pkgid, mode), &result);
1868 if (ret != PKGMGR_R_OK) {
1869 ERR("request failed: %d", ret);
1873 g_variant_get(result, "(i)", &ret);
1874 g_variant_unref(result);
1879 API int pkgmgr_client_usr_set_pkg_restriction_mode(pkgmgr_client *pc,
1880 const char *pkgid, int mode, uid_t uid)
1882 return __set_pkg_restriction_mode(pc, pkgid, mode, uid);
1885 API int pkgmgr_client_set_pkg_restriction_mode(pkgmgr_client *pc,
1886 const char *pkgid, int mode)
1888 return pkgmgr_client_usr_set_pkg_restriction_mode(pc, pkgid, mode,
1892 static int __unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid,
1893 int mode, uid_t uid)
1896 int ret = PKGMGR_R_ECOMM;
1897 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1899 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) {
1900 ERR("invalid parameter");
1901 return PKGMGR_R_EINVAL;
1904 ret = pkgmgr_client_connection_send_request(client,
1905 "unset_restriction_mode",
1906 g_variant_new("(usi)", uid, pkgid, mode), &result);
1907 if (ret != PKGMGR_R_OK) {
1908 ERR("request failed: %d", ret);
1912 g_variant_get(result, "(i)", &ret);
1913 g_variant_unref(result);
1919 API int pkgmgr_client_usr_unset_pkg_restriction_mode(pkgmgr_client *pc,
1920 const char *pkgid, int mode, uid_t uid)
1922 return __unset_pkg_restriction_mode(pc, pkgid, mode, uid);
1925 API int pkgmgr_client_unset_pkg_restriction_mode(pkgmgr_client *pc,
1926 const char *pkgid, int mode)
1928 return pkgmgr_client_usr_unset_pkg_restriction_mode(pc, pkgid, mode,
1932 static int __get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid,
1933 int *mode, uid_t uid)
1936 int ret = PKGMGR_R_ECOMM;
1938 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1940 if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0) {
1941 ERR("invalid parameter");
1942 return PKGMGR_R_EINVAL;
1945 ret = pkgmgr_client_connection_send_request(client,
1946 "get_restriction_mode",
1947 g_variant_new("(us)", uid, pkgid), &result);
1948 if (ret != PKGMGR_R_OK) {
1949 ERR("request failed: %d", ret);
1953 g_variant_get(result, "(ii)", &m, &ret);
1954 g_variant_unref(result);
1955 if (ret != PKGMGR_R_OK)
1963 API int pkgmgr_client_usr_get_pkg_restriction_mode(pkgmgr_client *pc,
1964 const char *pkgid, int *mode, uid_t uid)
1966 return __get_pkg_restriction_mode(pc, pkgid, mode, uid);
1969 API int pkgmgr_client_get_pkg_restriction_mode(pkgmgr_client *pc,
1970 const char *pkgid, int *mode)
1972 return pkgmgr_client_usr_get_pkg_restriction_mode(pc, pkgid, mode,
1976 API int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode,
1980 int ret = PKGMGR_R_ECOMM;
1981 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
1984 ERR("invalid parameter");
1985 return PKGMGR_R_EINVAL;
1988 ret = pkgmgr_client_connection_send_request(client,
1989 "set_restriction_mode",
1990 g_variant_new("(usi)", uid, "", mode), &result);
1991 if (ret != PKGMGR_R_OK) {
1992 ERR("request failed: %d", ret);
1996 g_variant_get(result, "(i)", &ret);
1997 g_variant_unref(result);
2002 API int pkgmgr_client_set_restriction_mode(pkgmgr_client *pc, int mode)
2004 return pkgmgr_client_usr_set_restriction_mode(pc, mode, _getuid());
2007 API int pkgmgr_client_usr_unset_restriction_mode(pkgmgr_client *pc, int mode,
2011 int ret = PKGMGR_R_ECOMM;
2012 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
2015 ERR("invalid parameter");
2016 return PKGMGR_R_EINVAL;
2019 ret = pkgmgr_client_connection_send_request(client,
2020 "unset_restriction_mode",
2021 g_variant_new("(usi)", uid, "", mode), &result);
2022 if (ret != PKGMGR_R_OK) {
2023 ERR("request failed: %d", ret);
2027 g_variant_get(result, "(i)", &ret);
2028 g_variant_unref(result);
2033 API int pkgmgr_client_unset_restriction_mode(pkgmgr_client *pc, int mode)
2035 return pkgmgr_client_usr_unset_restriction_mode(pc, mode, _getuid());
2038 API int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc,
2039 int *mode, uid_t uid)
2042 int ret = PKGMGR_R_ECOMM;
2044 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
2047 ERR("invalid parameter");
2048 return PKGMGR_R_EINVAL;
2051 ret = pkgmgr_client_connection_send_request(client,
2052 "get_restriction_mode",
2053 g_variant_new("(us)", uid, ""), &result);
2054 if (ret != PKGMGR_R_OK) {
2055 ERR("request failed: %d", ret);
2059 g_variant_get(result, "(ii)", &m, &ret);
2060 g_variant_unref(result);
2061 if (ret != PKGMGR_R_OK)
2069 API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc, int *mode)
2071 return pkgmgr_client_usr_get_restriction_mode(pc, mode, _getuid());
2074 API pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path)
2077 pkg_plugin_set *plugin_set;
2078 package_manager_pkg_detail_info_t *info;
2081 if (pkg_path == NULL) {
2082 ERR("invalid parameter");
2086 pkg_type = __get_type_from_path(pkg_path);
2087 if (pkg_type == NULL) {
2088 ERR("cannot get pkg type");
2092 plugin_set = _package_manager_load_library(pkg_type);
2093 if (plugin_set == NULL) {
2094 ERR("failed to load library for %s", pkg_type);
2099 info = calloc(1, sizeof(package_manager_pkg_detail_info_t));
2101 ERR("out of memory");
2106 ret = plugin_set->get_pkg_detail_info_from_package(pkg_path, info);
2108 ERR("get_pkg_detail_info_from_package failed");
2116 return (pkgmgr_info *)info;
2119 API int pkgmgr_client_free_pkginfo(pkgmgr_info *info)
2121 package_manager_pkg_detail_info_t *pkg_info =
2122 (package_manager_pkg_detail_info_t *)info;
2125 ERR("invalid parameter");
2126 return PKGMGR_R_EINVAL;
2129 free(pkg_info->icon_buf);
2135 API int pkgmgr_client_usr_set_app_label(pkgmgr_client *pc, char *appid,
2136 char *label, uid_t uid)
2140 struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
2142 if (pc == NULL || appid == NULL || label == NULL) {
2143 ERR("Invalid parameter");
2144 return PKGMGR_R_EINVAL;
2147 ret = pkgmgr_client_connection_send_request(client,
2149 g_variant_new("(uss)", uid, appid, label), &result);
2150 if (ret != PKGMGR_R_OK) {
2151 ERR("Request failed: %d", ret);
2155 g_variant_get(result, "(i)", &ret);
2156 g_variant_unref(result);
2161 API int pkgmgr_client_set_app_label(pkgmgr_client *pc, char *appid, char *label)
2163 return pkgmgr_client_usr_set_app_label(pc, appid, label, _getuid());