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.
29 #include <sys/types.h>
32 #include <sys/types.h>
40 #include <pkgmgr-info.h>
41 #include <pkgmgr/pkgmgr_parser_db.h>
42 #include <tzplatform_config.h>
43 #include <drm-tizen-apps.h>
44 #ifdef TIZEN_FEATURE_CSR
45 #include <csr-content-screening.h>
48 #include "pkgmgr_installer.h"
49 #include "pkgmgr-server.h"
51 #include "package-manager.h"
54 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
58 #define EXT_STORAGE_GROUP 10001
59 #define EXT_STORAGE_APPDATA_GROUP 10002
60 #define MEDIA_STORAGE_GROUP 10502
61 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
76 8 bit value to represent maximum 8 backends.
77 Each bit position corresponds to a queue slot which
78 is dynamically determined.
80 static char backend_busy = 0;
81 extern int num_of_backends;
83 struct signal_info_t {
88 static int pipe_sig[2];
89 static GIOChannel *pipe_io;
90 static guint pipe_wid;
91 static GHashTable *backend_info_table;
92 static GMainLoop *mainloop = NULL;
94 static int __check_backend_status_for_exit(void);
95 static int __check_queue_status_for_exit(void);
96 static int __is_backend_busy(int position);
97 static void __set_backend_busy(int position);
98 static void __set_backend_free(int position);
99 static void sighandler(int signo);
101 gboolean exit_server(void *data);
103 /* To check whether a particular backend is free/busy */
104 static int __is_backend_busy(int position)
106 return backend_busy & (1 << position);
108 /* To set a particular backend as busy */
109 static void __set_backend_busy(int position)
111 backend_busy = backend_busy | (1 << position);
113 /* To set a particular backend as free */
114 static void __set_backend_free(int position)
116 backend_busy = backend_busy & ~(1 << position);
119 static gboolean pipe_io_handler(GIOChannel *io, GIOCondition cond,
125 struct signal_info_t info;
126 struct backend_job *job;
128 s = g_io_channel_read_chars(io, (gchar *)&info,
129 sizeof(struct signal_info_t), &len, &err);
130 if (s != G_IO_STATUS_NORMAL) {
131 ERR("Signal pipe read failed: %s", err->message);
136 job = (struct backend_job *)g_hash_table_lookup(backend_info_table,
137 (gconstpointer)info.pid);
139 ERR("Unknown child exit");
143 __set_backend_free(job->backend_slot);
144 if (WIFSIGNALED(info.status)) {
145 _send_fail_signal(job);
146 DBG("backend[%s] exit with signal[%d]", job->backend_type,
147 WTERMSIG(info.status));
148 } else if (WEXITSTATUS(info.status)) {
149 DBG("backend[%s] exit with error", job->backend_type);
151 DBG("backend[%s] exit", job->backend_type);
154 g_hash_table_remove(backend_info_table, (gconstpointer)info.pid);
155 g_idle_add(queue_job, NULL);
160 static int __init_backend_info(void)
162 backend_info_table = g_hash_table_new_full(g_direct_hash,
163 g_direct_equal, NULL,
164 (GDestroyNotify)_free_backend_job);
166 if (pipe(pipe_sig)) {
167 ERR("create pipe failed");
171 pipe_io = g_io_channel_unix_new(pipe_sig[0]);
172 g_io_channel_set_encoding(pipe_io, NULL, NULL);
173 g_io_channel_set_buffered(pipe_io, FALSE);
174 pipe_wid = g_io_add_watch(pipe_io, G_IO_IN, pipe_io_handler, NULL);
179 static void __fini_backend_info(void)
181 g_source_remove(pipe_wid);
182 g_io_channel_unref(pipe_io);
186 /*Free backend info */
187 g_hash_table_destroy(backend_info_table);
190 static void sighandler(int signo)
192 struct signal_info_t info;
193 char buf[1024] = {0, };
195 info.pid = waitpid(-1, &info.status, WNOHANG);
196 if (write(pipe_sig[1], &info, sizeof(struct signal_info_t)) < 0)
197 ERR("failed to write result: %s",
198 strerror_r(errno, buf, sizeof(buf)));
201 static int __register_signal_handler(void)
203 static int sig_reg = 0;
204 struct sigaction act;
209 act.sa_handler = sighandler;
210 sigemptyset(&act.sa_mask);
211 act.sa_flags = SA_NOCLDSTOP;
212 if (sigaction(SIGCHLD, &act, NULL) < 0) {
213 ERR("signal: SIGCHLD failed");
217 g_timeout_add_seconds(2, exit_server, NULL);
223 static int __check_backend_status_for_exit(void)
226 for (i = 0; i < num_of_backends; i++) {
227 if (__is_backend_busy(i))
233 static int __check_queue_status_for_exit(void)
236 for (i = 0; i < num_of_backends; i++) {
237 if (_is_queue_empty(i) == 0)
243 gboolean exit_server(void *data)
245 DBG("exit_server Start");
246 if (__check_backend_status_for_exit() &&
247 __check_queue_status_for_exit()) {
248 g_main_loop_quit(mainloop);
254 #ifdef TIZEN_FEATURE_CSR
255 static int __check_csr(const char *path)
257 csr_cs_context_h context = NULL;
258 csr_cs_malware_h detected = NULL;
261 ret = csr_cs_context_create(&context);
262 if (ret != CSR_ERROR_NONE) {
263 ERR("Failed to create csr context");
268 ret = csr_cs_scan_file(context, path, &detected);
269 DBG("CSR result[%d]", ret);
271 csr_cs_context_destroy(context);
272 if (detected != NULL) {
273 ERR("CSR Denied[%s] Installation", path);
282 static int __kill_app(char *appid, uid_t uid)
288 is_running = aul_app_is_running_for_uid(appid, uid);
289 /* app is not running */
293 pid = aul_app_get_pid_for_uid(appid, uid);
297 ret = aul_terminate_pid_for_uid(pid, uid);
298 if (ret != AUL_R_OK) {
299 ERR("failed to terminate app(%d)", appid);
306 static int __check_app(char *appid, uid_t uid)
311 is_running = aul_app_is_running_for_uid(appid, uid);
315 pid = aul_app_get_pid_for_uid(appid, uid);
320 static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
326 pkgcmd_data *pdata = (pkgcmd_data *)user_data;
328 if (handle == NULL) {
329 perror("appinfo handle is NULL\n");
332 ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
334 perror("Failed to get app exec path\n");
337 ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
339 perror("Failed to get appid\n");
342 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
344 perror("Failed to get pkgid\n");
348 if (strcmp(pdata->cmd, "kill") == 0) {
349 pdata->pid = __check_app(appid, pdata->uid);
351 ret = __kill_app(appid, pdata->uid);
352 } else if (strcmp(pdata->cmd, "check") == 0) {
353 pdata->pid = __check_app(appid, pdata->uid);
359 void free_user_context(user_ctx* ctx)
366 /* env variable ends by NULL element */
376 int set_environement(user_ctx *ctx)
387 if (ctx->uid != APPFW_UID) {
388 if (setuid(ctx->uid)) {
389 ERR("setuid failed: %d", errno);
393 if (setgid(ctx->gid)) {
394 ERR("setgid failed: %d", errno);
399 n = getgroups(0, NULL);
401 ERR("Failed to get the number of supplementary group IDs");
405 groups = (gid_t *)calloc(1, sizeof(gid_t) * (n + 3));
406 if (groups == NULL) {
407 ERR("out of memory");
411 n = getgroups(n, groups);
413 ERR("Failed to get list of supplementary group IDs");
418 groups[n++] = EXT_STORAGE_GROUP;
419 groups[n++] = EXT_STORAGE_APPDATA_GROUP;
420 groups[n++] = MEDIA_STORAGE_GROUP;
422 if (setgroups(n, groups) < 0) {
423 ERR("setgroups failed: %d", errno);
430 /* env variable ends by NULL element */
432 if (putenv(env[i]) != 0)
439 user_ctx *get_user_context(uid_t uid)
441 /* we can use getpwnam because this is used only after a
442 * fork and just before an execv
443 * No concurrencial call can corrupt the data
444 * returned by getpwuid
446 user_ctx *context_res;
448 char buf[1024] = {0, };
449 struct passwd pwd, *result;
454 ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &result);
455 if (ret != 0 || result == NULL)
459 context_res = (user_ctx *)malloc(sizeof(user_ctx));
464 env = (char **)malloc(3 * sizeof(char *));
469 /* Build environment context */
470 len = snprintf(NULL, 0, "HOME=%s", pwd.pw_dir);
471 env[0] = (char *)malloc((len + 1) * sizeof(char));
472 if (env[0] == NULL) {
476 snprintf(env[0], len + 1, "HOME=%s", pwd.pw_dir);
477 len = snprintf(NULL, 0, "USER=%s", pwd.pw_name);
478 env[1] = (char *)malloc((len + 1) * sizeof(char));
479 if (env[1] == NULL) {
483 snprintf(env[1], len + 1, "USER=%s", pwd.pw_name);
491 /* env variable ends by NULL element */
492 while (env && env[i]) {
499 context_res->env = env;
500 context_res->uid = uid;
501 context_res->gid = pwd.pw_gid;
506 static char **__generate_argv(const char *args)
508 /* Create args vector
509 * req_id + pkgid + args
511 * vector size = # of args +
512 *(req_id + pkgid + NULL termination = 3)
513 * Last value must be NULL for execv.
521 ret_parse = g_shell_parse_argv(args, &argcp, &argvp, &gerr);
522 if (FALSE == ret_parse) {
523 DBG("Failed to split args: %s", args);
524 DBG("messsage: %s", gerr->message);
529 for (i = 0; i < argcp; i++)
530 DBG(">>>>>> argsv[%d]=%s", i, argvp[i]);
535 void __set_environment(gpointer user_data)
537 user_ctx *ctx = (user_ctx *)user_data;
539 if (set_environement(ctx))
540 DBG("Failed to set env for the user : %d", ctx->uid);
543 static int __fork_and_exec_with_args(char **argv, uid_t uid)
545 user_ctx* user_context;
546 GError *error = NULL;
550 user_context = get_user_context(uid);
552 DBG("Failed to getenv");
556 ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
557 __set_environment, (gpointer)user_context, &pid,
560 ERR("Failed to excute backend: %s", error->message);
564 free_user_context(user_context);
569 static int __change_job_info(struct backend_job *job, uid_t uid,
574 pkgmgrinfo_appinfo_h handle = NULL;
576 switch (job->req_type) {
577 case REQUEST_TYPE_DISABLE_APP:
578 case REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID:
579 case REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN:
580 case REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN:
581 ret = pkgmgrinfo_appinfo_get_usr_appinfo(job->pkgid, uid,
584 case REQUEST_TYPE_ENABLE_APP:
585 case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID:
586 ret = pkgmgrinfo_appinfo_get_usr_disabled_appinfo(job->pkgid,
590 return PMINFO_R_ERROR;
593 if (ret != PMINFO_R_OK)
594 return PMINFO_R_ERROR;
596 ret = pkgmgrinfo_appinfo_is_global(handle, is_global);
597 if (ret != PMINFO_R_OK)
600 if ((job->req_type == REQUEST_TYPE_DISABLE_APP ||
601 job->req_type == REQUEST_TYPE_ENABLE_APP) &&
603 ret = PMINFO_R_ERROR;
605 } else if ((job->req_type == REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID ||
607 REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID) &&
609 ret = PMINFO_R_ERROR;
613 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
614 if (ret != PMINFO_R_OK)
618 job->appid = strdup(job->pkgid);
620 job->pkgid = strdup(pkgid);
623 pkgmgrinfo_appinfo_destroy_appinfo(handle);
628 static int __process_install(struct backend_job *job)
632 char args[MAX_PKG_ARGS_LEN];
635 backend_cmd = job->backend_path;
636 if (backend_cmd == NULL)
639 snprintf(args, sizeof(args), "%s -k %s -i %s -u %d %s", backend_cmd,
640 job->req_id, job->pkgid, (int)job->uid, job->args);
642 argv = __generate_argv(args);
644 pid = __fork_and_exec_with_args(argv, APPFW_UID);
650 static int __process_mount_install(struct backend_job *job)
654 char args[MAX_PKG_ARGS_LEN];
657 backend_cmd = job->backend_path;
658 if (backend_cmd == NULL)
661 snprintf(args, sizeof(args), "%s -k %s -w %s -u %d %s", backend_cmd,
662 job->req_id, job->pkgid, (int)job->uid, job->args);
664 argv = __generate_argv(args);
666 pid = __fork_and_exec_with_args(argv, APPFW_UID);
672 static int __process_reinstall(struct backend_job *job)
676 char args[MAX_PKG_ARGS_LEN];
679 backend_cmd = job->backend_path;
680 if (backend_cmd == NULL)
683 snprintf(args, sizeof(args), "%s -k %s -r %s -u %d", backend_cmd,
684 job->req_id, job->pkgid, (int)job->uid);
685 argv = __generate_argv(args);
687 pid = __fork_and_exec_with_args(argv, APPFW_UID);
694 static int __process_uninstall(struct backend_job *job)
698 char args[MAX_PKG_ARGS_LEN];
701 backend_cmd = job->backend_path;
702 if (backend_cmd == NULL)
705 snprintf(args, sizeof(args), "%s -k %s -d %s -u %d", backend_cmd,
706 job->req_id, job->pkgid, (int)job->uid);
707 argv = __generate_argv(args);
709 pid = __fork_and_exec_with_args(argv, APPFW_UID);
716 static int __process_move(struct backend_job *job)
720 char args[MAX_PKG_ARGS_LEN];
723 backend_cmd = job->backend_path;
724 if (backend_cmd == NULL)
727 snprintf(args, sizeof(args), "%s -k %s -m %s -u %d -t %s", backend_cmd,
728 job->req_id, job->pkgid, (int)job->uid, job->args);
729 argv = __generate_argv(args);
731 pid = __fork_and_exec_with_args(argv, APPFW_UID);
738 static int __process_enable_pkg(struct backend_job *job)
742 char args[MAX_PKG_ARGS_LEN];
745 backend_cmd = job->backend_path;
746 if (backend_cmd == NULL)
749 snprintf(args, sizeof(args), "%s -k %s -u %d -A %s", backend_cmd,
750 job->req_id, (int)job->uid, job->pkgid);
751 argv = __generate_argv(args);
753 pid = __fork_and_exec_with_args(argv, APPFW_UID);
760 static int __process_disable_pkg(struct backend_job *job)
764 char args[MAX_PKG_ARGS_LEN];
767 backend_cmd = job->backend_path;
768 if (backend_cmd == NULL)
771 snprintf(args, sizeof(args), "%s -k %s -u %d -D %s", backend_cmd,
772 job->req_id, (int)job->uid, job->pkgid);
773 argv = __generate_argv(args);
775 pid = __fork_and_exec_with_args(argv, APPFW_UID);
782 static int __process_enable_app(struct backend_job *job)
785 bool is_global = false;
787 /* get actual pkgid and replace it to appid which is currently stored
790 ret = __change_job_info(job, job->uid, &is_global);
791 if (ret != PMINFO_R_OK || strlen(job->appid) == 0) {
792 _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
793 PKGMGR_INSTALLER_START_KEY_STR,
794 PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR,
796 _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
797 PKGMGR_INSTALLER_END_KEY_STR,
798 PKGMGR_INSTALLER_FAIL_EVENT_STR,
803 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
804 PKGMGR_INSTALLER_START_KEY_STR,
805 PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, job->req_type);
807 ret = pkgmgr_parser_update_app_disable_info_in_usr_db(job->appid,
809 if (ret != PMINFO_R_OK)
810 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
811 PKGMGR_INSTALLER_END_KEY_STR,
812 PKGMGR_INSTALLER_FAIL_EVENT_STR,
815 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
816 PKGMGR_INSTALLER_END_KEY_STR,
817 PKGMGR_INSTALLER_OK_EVENT_STR,
823 static int __process_disable_app(struct backend_job *job)
826 bool is_global = false;
828 /* get actual pkgid and replace it to appid which is currently stored
831 ret = __change_job_info(job, job->uid, &is_global);
832 if (ret != PMINFO_R_OK || strlen(job->appid) == 0) {
833 _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
834 PKGMGR_INSTALLER_START_KEY_STR,
835 PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR,
837 _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
838 PKGMGR_INSTALLER_END_KEY_STR,
839 PKGMGR_INSTALLER_FAIL_EVENT_STR,
844 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
845 PKGMGR_INSTALLER_START_KEY_STR,
846 PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, job->req_type);
848 ret = __kill_app(job->appid, job->uid);
850 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
851 PKGMGR_INSTALLER_END_KEY_STR,
852 PKGMGR_INSTALLER_FAIL_EVENT_STR,
856 ret = pkgmgr_parser_update_app_disable_info_in_usr_db(job->appid,
858 if (ret != PMINFO_R_OK)
859 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
860 PKGMGR_INSTALLER_END_KEY_STR,
861 PKGMGR_INSTALLER_FAIL_EVENT_STR,
864 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
865 PKGMGR_INSTALLER_END_KEY_STR,
866 PKGMGR_INSTALLER_OK_EVENT_STR,
872 static int __process_enable_global_app_for_uid(struct backend_job *job)
875 bool is_global = true;
877 /* get actual pkgid and replace it to appid which is currently stored
880 ret = __change_job_info(job, job->uid, &is_global);
881 if (ret != PMINFO_R_OK || strlen(job->appid) == 0) {
882 _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
883 PKGMGR_INSTALLER_START_KEY_STR,
884 PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID,
886 _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
887 PKGMGR_INSTALLER_END_KEY_STR,
888 PKGMGR_INSTALLER_FAIL_EVENT_STR,
893 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
894 PKGMGR_INSTALLER_START_KEY_STR,
895 PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID,
898 ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(
899 job->appid, job->uid, 0);
900 if (ret != PMINFO_R_OK)
901 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
902 PKGMGR_INSTALLER_END_KEY_STR,
903 PKGMGR_INSTALLER_FAIL_EVENT_STR,
906 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
907 PKGMGR_INSTALLER_END_KEY_STR,
908 PKGMGR_INSTALLER_OK_EVENT_STR,
914 static int __process_disable_global_app_for_uid(struct backend_job *job)
917 bool is_global = true;
919 /* get actual pkgid and replace it to appid which is currently stored
922 ret = __change_job_info(job, GLOBAL_USER, &is_global);
923 if (ret != PMINFO_R_OK || strlen(job->appid) == 0) {
924 _send_app_signal(job->uid, job->req_id,
925 job->pkgid, job->pkgid,
926 PKGMGR_INSTALLER_START_KEY_STR,
927 PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID,
929 _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid,
930 PKGMGR_INSTALLER_END_KEY_STR,
931 PKGMGR_INSTALLER_FAIL_EVENT_STR,
936 _send_app_signal(job->uid, job->req_id,
937 job->pkgid, job->appid,
938 PKGMGR_INSTALLER_START_KEY_STR,
939 PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID,
942 ret = __kill_app(job->appid, job->uid);
943 ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(
944 job->appid, job->uid, 1);
946 if (ret != PMINFO_R_OK)
947 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
948 PKGMGR_INSTALLER_END_KEY_STR,
949 PKGMGR_INSTALLER_FAIL_EVENT_STR,
952 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
953 PKGMGR_INSTALLER_END_KEY_STR,
954 PKGMGR_INSTALLER_OK_EVENT_STR,
960 static int __process_getsize(struct backend_job *job)
962 static const char *backend_cmd = "/usr/bin/pkg_getsize";
964 char args[MAX_PKG_ARGS_LEN];
967 snprintf(args, sizeof(args), "%s %s %s -k %s", backend_cmd, job->pkgid,
968 job->args, job->req_id);
969 argv = __generate_argv(args);
970 pid = __fork_and_exec_with_args(argv, job->uid);
977 static int __process_cleardata(struct backend_job *job)
981 char args[MAX_PKG_ARGS_LEN];
984 backend_cmd = job->backend_path;
985 if (backend_cmd == NULL)
988 /* TODO: set movetype */
989 snprintf(args, sizeof(args), "%s -k %s -c %s -u %d", backend_cmd,
990 job->req_id, job->pkgid, (int)job->uid);
991 argv = __generate_argv(args);
993 pid = __fork_and_exec_with_args(argv, APPFW_UID);
1000 static int __process_clearcache(struct backend_job *job)
1002 static const char *backend_cmd = "/usr/bin/pkg_clearcache";
1004 char args[MAX_PKG_ARGS_LEN];
1007 snprintf(args, sizeof(args), "%s %s", backend_cmd, job->pkgid);
1008 argv = __generate_argv(args);
1009 pid = __fork_and_exec_with_args(argv, job->uid);
1016 static int __process_kill(struct backend_job *job)
1019 pkgmgrinfo_pkginfo_h handle;
1022 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(job->pkgid, job->uid,
1025 ERR("Failed to get handle");
1026 _return_value_to_caller(job->req_id,
1027 g_variant_new("(ii)", PKGMGR_R_ERROR, 0));
1031 pdata = calloc(1, sizeof(pkgcmd_data));
1032 if (pdata == NULL) {
1033 ERR("memory alloc failed");
1034 _return_value_to_caller(job->req_id,
1035 g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
1038 pdata->cmd = strdup("kill");
1039 if (pdata->cmd == NULL) {
1040 ERR("out of memory");
1041 _return_value_to_caller(job->req_id,
1042 g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
1046 pdata->uid = job->uid;
1047 ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP,
1048 __pkgcmd_app_cb, pdata, job->uid);
1050 _return_value_to_caller(job->req_id,
1051 g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid));
1055 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1057 ERR("pkgmgrinfo_appinfo_get_list() failed");
1064 static int __process_check(struct backend_job *job)
1067 pkgmgrinfo_pkginfo_h handle;
1070 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(job->pkgid, job->uid,
1073 ERR("Failed to get handle");
1074 _return_value_to_caller(job->req_id,
1075 g_variant_new("(ii)", PKGMGR_R_ERROR, 0));
1079 pdata = calloc(1, sizeof(pkgcmd_data));
1080 if (pdata == NULL) {
1081 ERR("memory alloc failed");
1082 _return_value_to_caller(job->req_id,
1083 g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
1086 pdata->cmd = strdup("check");
1087 if (pdata->cmd == NULL) {
1088 ERR("out of memory");
1089 _return_value_to_caller(job->req_id,
1090 g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
1094 pdata->uid = job->uid;
1095 ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP,
1096 __pkgcmd_app_cb, pdata, job->uid);
1098 _return_value_to_caller(job->req_id,
1099 g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid));
1103 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1105 ERR("pkgmgrinfo_appinfo_get_list() failed");
1112 static int __process_generate_license_request(struct backend_job *job)
1116 char req_data[MAX_PKG_ARGS_LEN];
1117 unsigned int req_data_len;
1118 char license_url[MAX_PKG_ARGS_LEN];
1119 unsigned int license_url_len;
1121 resp_data = job->args;
1122 req_data_len = sizeof(req_data);
1123 license_url_len = sizeof(license_url);
1125 ret = drm_tizen_generate_license_request(resp_data, strlen(resp_data),
1126 req_data, &req_data_len, license_url, &license_url_len);
1127 if (ret != TADC_SUCCESS) {
1128 ERR("drm_tizen_generate_license_request failed: %d", ret);
1129 _return_value_to_caller(job->req_id, g_variant_new("(iss)",
1130 PKGMGR_R_ESYSTEM, "", ""));
1134 _return_value_to_caller(job->req_id,
1135 g_variant_new("(iss)", PKGMGR_R_OK, req_data,
1141 static int __process_register_license(struct backend_job *job)
1146 resp_data = job->args;
1148 ret = drm_tizen_register_license(resp_data, strlen(resp_data));
1149 if (ret != TADC_SUCCESS) {
1150 ERR("drm_tizen_register_license failed: %d", ret);
1151 _return_value_to_caller(job->req_id,
1152 g_variant_new("(i)", PKGMGR_R_ESYSTEM));
1156 _return_value_to_caller(job->req_id,
1157 g_variant_new("(i)", PKGMGR_R_OK));
1162 static int __process_decrypt_package(struct backend_job *job)
1165 char *drm_file_path;
1166 char *decrypted_file_path;
1168 drm_file_path = job->pkgid;
1169 decrypted_file_path = job->args;
1171 /* TODO: check ownership of decrypted file */
1172 ret = drm_tizen_decrypt_package(drm_file_path, strlen(drm_file_path),
1173 decrypted_file_path, strlen(decrypted_file_path));
1174 if (ret != TADC_SUCCESS) {
1175 ERR("drm_tizen_register_license failed: %d", ret);
1176 _return_value_to_caller(job->req_id,
1177 g_variant_new("(i)", PKGMGR_R_ESYSTEM));
1181 _return_value_to_caller(job->req_id,
1182 g_variant_new("(i)", PKGMGR_R_OK));
1187 static int __process_update_app_splash_screen(struct backend_job *job, int flag)
1190 bool is_global = false;
1193 ret = __change_job_info(job, job->uid, &is_global);
1194 if (ret != PMINFO_R_OK || strlen(job->appid) == 0)
1197 val = flag ? PKGMGR_INSTALLER_APP_ENABLE_SPLASH_SCREEN_EVENT_STR :
1198 PKGMGR_INSTALLER_APP_DISABLE_SPLASH_SCREEN_EVENT_STR;
1199 _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid,
1200 PKGMGR_INSTALLER_START_KEY_STR, val, job->req_type);
1203 ret = pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(job->appid, job->uid, flag);
1205 ret = pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(
1206 job->appid, job->uid, flag);
1207 if (ret != PMINFO_R_OK)
1208 _send_app_signal(job->uid, job->req_id, job->pkgid,
1209 job->appid, PKGMGR_INSTALLER_END_KEY_STR,
1210 PKGMGR_INSTALLER_FAIL_EVENT_STR,
1213 _send_app_signal(job->uid, job->req_id, job->pkgid,
1214 job->appid, PKGMGR_INSTALLER_END_KEY_STR,
1215 PKGMGR_INSTALLER_OK_EVENT_STR,
1221 static int __process_set_restriction_mode(struct backend_job *job)
1226 mode = atoi(job->args);
1227 ret = _set_restriction_mode(job->uid, job->pkgid, mode);
1229 _return_value_to_caller(job->req_id,
1230 g_variant_new("(i)", ret));
1235 static int __process_unset_restriction_mode(struct backend_job *job)
1240 mode = atoi(job->args);
1241 ret = _unset_restriction_mode(job->uid, job->pkgid, mode);
1243 _return_value_to_caller(job->req_id,
1244 g_variant_new("(i)", ret));
1249 static int __process_get_restriction_mode(struct backend_job *job)
1254 ret = _get_restriction_mode(job->uid, job->pkgid, &mode);
1256 _return_value_to_caller(job->req_id,
1257 g_variant_new("(ii)", mode, ret));
1262 gboolean queue_job(void *data)
1264 struct backend_job *job = NULL;
1268 /* Pop a job from queue */
1269 for (x = 0; x < num_of_backends; x++) {
1270 if (__is_backend_busy(x))
1273 job = _pop_queue(x);
1278 /* all backend messages queue are empty or busy */
1279 if (x == num_of_backends || job == NULL) {
1284 /* set current backend job */
1285 DBG("handle request type [%d]", job->req_type);
1287 #ifdef TIZEN_FEATURE_CSR
1288 if (job->req_type == REQUEST_TYPE_INSTALL ||
1289 job->req_type == REQUEST_TYPE_MOUNT_INSTALL ||
1290 job->req_type == REQUEST_TYPE_REINSTALL) {
1291 ret = __check_csr(job->pkgid);
1294 _send_fail_signal(job);
1295 _free_backend_job(job);
1301 switch (job->req_type) {
1302 case REQUEST_TYPE_INSTALL:
1303 __set_backend_busy(x);
1304 ret = __process_install(job);
1305 g_hash_table_insert(backend_info_table, (gpointer)ret,
1308 case REQUEST_TYPE_MOUNT_INSTALL:
1309 __set_backend_busy(x);
1310 ret = __process_mount_install(job);
1311 g_hash_table_insert(backend_info_table, (gpointer)ret,
1314 case REQUEST_TYPE_REINSTALL:
1315 __set_backend_busy(x);
1316 ret = __process_reinstall(job);
1317 g_hash_table_insert(backend_info_table, (gpointer)ret,
1320 case REQUEST_TYPE_UNINSTALL:
1321 __set_backend_busy(x);
1322 ret = __process_uninstall(job);
1323 g_hash_table_insert(backend_info_table, (gpointer)ret,
1326 case REQUEST_TYPE_MOVE:
1327 __set_backend_busy(x);
1328 ret = __process_move(job);
1329 g_hash_table_insert(backend_info_table, (gpointer)ret,
1332 case REQUEST_TYPE_ENABLE_PKG:
1333 __set_backend_busy(x);
1334 ret = __process_enable_pkg(job);
1335 g_hash_table_insert(backend_info_table, (gpointer)ret,
1338 case REQUEST_TYPE_DISABLE_PKG:
1339 __set_backend_busy(x);
1340 ret = __process_disable_pkg(job);
1341 g_hash_table_insert(backend_info_table, (gpointer)ret,
1344 case REQUEST_TYPE_ENABLE_APP:
1345 ret = __process_enable_app(job);
1347 case REQUEST_TYPE_DISABLE_APP:
1348 ret = __process_disable_app(job);
1350 case REQUEST_TYPE_GETSIZE:
1351 __set_backend_busy(x);
1352 ret = __process_getsize(job);
1354 case REQUEST_TYPE_CLEARDATA:
1355 __set_backend_busy(x);
1356 ret = __process_cleardata(job);
1358 case REQUEST_TYPE_CLEARCACHE:
1359 __set_backend_busy(x);
1360 ret = __process_clearcache(job);
1361 _free_backend_job(job);
1363 case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID:
1364 ret = __process_enable_global_app_for_uid(job);
1365 _free_backend_job(job);
1367 case REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID:
1368 ret = __process_disable_global_app_for_uid(job);
1369 _free_backend_job(job);
1371 case REQUEST_TYPE_KILL:
1372 ret = __process_kill(job);
1373 _free_backend_job(job);
1375 case REQUEST_TYPE_CHECK:
1376 ret = __process_check(job);
1377 _free_backend_job(job);
1379 case REQUEST_TYPE_GENERATE_LICENSE_REQUEST:
1380 ret = __process_generate_license_request(job);
1381 _free_backend_job(job);
1383 case REQUEST_TYPE_REGISTER_LICENSE:
1384 ret = __process_register_license(job);
1385 _free_backend_job(job);
1387 case REQUEST_TYPE_DECRYPT_PACKAGE:
1388 ret = __process_decrypt_package(job);
1389 _free_backend_job(job);
1391 case REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN:
1392 ret = __process_update_app_splash_screen(job, 1);
1393 _free_backend_job(job);
1395 case REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN:
1396 ret = __process_update_app_splash_screen(job, 0);
1397 _free_backend_job(job);
1399 case REQUEST_TYPE_SET_RESTRICTION_MODE:
1400 ret = __process_set_restriction_mode(job);
1401 _free_backend_job(job);
1403 case REQUEST_TYPE_UNSET_RESTRICTION_MODE:
1404 ret = __process_unset_restriction_mode(job);
1405 _free_backend_job(job);
1407 case REQUEST_TYPE_GET_RESTRICTION_MODE:
1408 ret = __process_get_restriction_mode(job);
1409 _free_backend_job(job);
1419 int main(int argc, char *argv[])
1423 DBG("server start");
1425 r = _init_backend_queue();
1427 DBG("Queue Initialization Failed");
1431 r = __init_backend_info();
1433 DBG("backend info init failed");
1437 r = _init_request_handler();
1439 ERR("dbus init failed");
1443 if (__register_signal_handler()) {
1444 ERR("failed to register signal handler");
1448 #if !GLIB_CHECK_VERSION(2, 35, 0)
1451 mainloop = g_main_loop_new(NULL, FALSE);
1453 ERR("g_main_loop_new failed");
1457 DBG("Main loop is created.");
1459 g_main_loop_run(mainloop);
1461 DBG("Quit main loop.");
1462 _fini_request_handler();
1463 __fini_backend_info();
1464 _fini_backend_queue();
1466 DBG("package manager server terminated.");