2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/types.h>
22 #include <systemd/sd-login.h>
24 #include <pkgmgr_installer.h>
25 #include <tzplatform_config.h>
27 #include "pkgmgr-server.h"
29 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
31 static int __get_uid_list(uid_t target_uid, uid_t **uids)
35 if (target_uid != GLOBAL_USER) {
36 *uids = malloc(sizeof(uid_t));
41 (*uids)[0] = target_uid;
44 n = sd_get_uids(uids);
46 ERR("cannot get login user list");
54 static void __free_uid_list(uid_t *uids)
59 void _send_app_signal(uid_t uid, const char *req_id,
60 const char *pkgid, const char *appid,
61 const char *key, const char *val, int req_type)
68 pi = pkgmgr_installer_new();
70 DBG("Failure in creating the pkgmgr_installer object");
74 if (pkgmgr_installer_set_uid(pi, uid))
78 case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID:
79 case REQUEST_TYPE_ENABLE_APP:
80 if (pkgmgr_installer_set_request_type(pi,
81 PKGMGR_REQ_ENABLE_APP))
84 case REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID:
85 case REQUEST_TYPE_DISABLE_APP:
86 if (pkgmgr_installer_set_request_type(pi,
87 PKGMGR_REQ_DISABLE_APP))
90 case REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN:
91 if (pkgmgr_installer_set_request_type(pi,
92 PKGMGR_REQ_ENABLE_APP_SPLASH_SCREEN))
95 case REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN:
96 if (pkgmgr_installer_set_request_type(pi,
97 PKGMGR_REQ_DISABLE_APP_SPLASH_SCREEN))
101 DBG("Unsupported req_type[%d]", req_type);
105 if (pkgmgr_installer_set_session_id(pi, req_id))
107 pkgmgr_installer_send_app_signal(pi, "app", pkgid, appid, key, val);
108 n = __get_uid_list(uid, &uids);
109 for (i = 0; i < n; i++)
110 pkgmgr_installer_send_app_signal_for_uid(pi, uids[i], "app",
111 pkgid, appid, key, val);
114 __free_uid_list(uids);
115 pkgmgr_installer_free(pi);
120 void _send_fail_signal(struct backend_job *job)
123 pkgmgr_installer *pi;
128 pi = pkgmgr_installer_new();
130 ERR("Failure in creating the pkgmgr_installer object");
133 pkgmgr_installer_set_session_id(pi, job->req_id);
134 switch (job->req_type) {
135 case REQUEST_TYPE_INSTALL:
136 case REQUEST_TYPE_MOUNT_INSTALL:
137 case REQUEST_TYPE_REINSTALL:
138 req_type = PKGMGR_REQ_INSTALL;
140 case REQUEST_TYPE_UNINSTALL:
141 req_type = PKGMGR_REQ_UNINSTALL;
143 case REQUEST_TYPE_MOVE:
144 req_type = PKGMGR_REQ_MOVE;
146 case REQUEST_TYPE_GETSIZE:
147 req_type = PKGMGR_REQ_GETSIZE;
150 req_type = PKGMGR_REQ_INVALID;
153 pkgmgr_installer_set_request_type(pi, req_type);
154 pkgmgr_installer_send_signal(pi, job->backend_type, job->pkgid,
156 n = __get_uid_list(job->target_uid, &uids);
157 for (i = 0; i < n; i++)
158 pkgmgr_installer_send_signal_for_uid(pi, uids[i],
159 job->backend_type, job->pkgid, "end", "fail");
161 __free_uid_list(uids);
162 pkgmgr_installer_free(pi);