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>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
29 #include "amd_config.h"
30 #include "amd_status.h"
31 #include "amd_appinfo.h"
33 #include "simple_util.h"
35 #include "menu_db_util.h"
37 GSList *app_status_info_list = NULL;
39 struct appinfomgr *_saf = NULL;
41 int _status_add_app_info_list(char *appid, char *app_path, int pid)
44 app_status_info_t *info_t = NULL;
46 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
48 info_t = (app_status_info_t *)iter->data;
49 if(pid == info_t->pid) {
54 info_t = malloc(sizeof(app_status_info_t));
55 strncpy(info_t->appid, appid, MAX_PACKAGE_STR_SIZE-1);
56 strncpy(info_t->app_path, app_path, MAX_PACKAGE_APP_PATH_SIZE-1);
57 info_t->status = STATUS_LAUNCHING;
59 app_status_info_list = g_slist_append(app_status_info_list, info_t);
61 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
63 info_t = (app_status_info_t *)iter->data;
65 _D("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
71 static Eina_Bool __app_terminate_timer_cb(void *data)
78 ret = kill(pid, SIGKILL);
80 _E("send SIGKILL: %s", strerror(errno));
82 return ECORE_CALLBACK_CANCEL;
85 int _status_update_app_info_list(int pid, int status)
88 app_status_info_t *info_t = NULL;
90 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
92 info_t = (app_status_info_t *)iter->data;
93 if(pid == info_t->pid) {
94 info_t->status = status;
95 if(status == STATUS_DYING) {
96 ecore_timer_add(2, __app_terminate_timer_cb, info_t->pid);
102 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
104 info_t = (app_status_info_t *)iter->data;
106 _D("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
112 int _status_remove_app_info_list(int pid)
115 app_status_info_t *info_t = NULL;
117 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
119 info_t = (app_status_info_t *)iter->data;
120 if(pid == info_t->pid) {
121 app_status_info_list = g_slist_remove(app_status_info_list, info_t);
127 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
129 info_t = (app_status_info_t *)iter->data;
131 _D("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
137 int _status_get_app_info_status(int pid)
140 app_status_info_t *info_t = NULL;
142 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
144 info_t = (app_status_info_t *)iter->data;
145 if(pid == info_t->pid) {
146 return info_t->status;
152 int _status_app_is_running(char *appid)
155 app_status_info_t *info_t = NULL;
157 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
159 info_t = (app_status_info_t *)iter->data;
160 if( strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE) == 0 ) {
167 int _status_send_running_appinfo(int fd)
170 app_status_info_t *info_t = NULL;
171 app_pkt_t *pkt = NULL;
173 char tmp_pid[MAX_PID_STR_BUFSZ];
175 pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
181 memset(pkt, 0, AUL_SOCK_MAXBUFF);
183 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
185 info_t = (app_status_info_t *)iter->data;
186 snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", info_t->pid);
187 strncat((char *)pkt->data, tmp_pid, MAX_PID_STR_BUFSZ);
188 strncat((char *)pkt->data, ":", 1);
189 strncat((char *)pkt->data, info_t->appid, MAX_PACKAGE_STR_SIZE);
190 strncat((char *)pkt->data, ":", 1);
191 strncat((char *)pkt->data, info_t->app_path, MAX_PACKAGE_APP_PATH_SIZE);
192 strncat((char *)pkt->data, ";", 1);
195 pkt->cmd = APP_RUNNING_INFO_RESULT;
196 pkt->len = strlen((char *)pkt->data) + 1;
198 if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
200 _E("send failed due to EPIPE.\n");
201 _E("send fail to client");
212 int _status_app_is_running_v2(char *appid)
214 char *apppath = NULL;
217 const struct appinfo *ai;
222 ai = appinfo_find(_saf, appid);
227 apppath = strdup(appinfo_get_value(ai, AIT_EXEC));
229 /*truncate apppath if it includes default bundles */
230 while (apppath[i] != 0) {
231 if (apppath[i] == ' ' || apppath[i] == '\t') {
238 ret = __proc_iter_cmdline(NULL, apppath);
245 static int __get_pkginfo(const char *dname, const char *cmdline, void *priv)
247 app_info_from_db *menu_info;
250 r_info = (char *)priv;
252 if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL)
255 strncat(r_info, dname, 8);
256 strncat(r_info, ":", 1);
257 strncat(r_info, _get_pkgname(menu_info), MAX_PACKAGE_STR_SIZE);
258 strncat(r_info, ":", 1);
259 strncat(r_info, _get_app_path(menu_info), MAX_PACKAGE_APP_PATH_SIZE);
260 strncat(r_info, ";", 1);
264 if (menu_info != NULL)
265 _free_app_info_from_db(menu_info);
269 int _status_send_running_appinfo_v2(int fd)
271 app_pkt_t *pkt = NULL;
274 pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
281 memset(pkt, 0, AUL_SOCK_MAXBUFF);
283 __proc_iter_cmdline(__get_pkginfo, pkt->data);
285 pkt->cmd = APP_RUNNING_INFO_RESULT;
286 pkt->len = strlen((char *)pkt->data) + 1;
288 if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
290 _E("send failed due to EPIPE.\n");
291 _E("send fail to client");
302 static int __get_pkgname_bypid(int pid, char *pkgname, int len)
305 app_info_from_db *menu_info;
307 cmdline = __proc_get_cmdline_bypid(pid);
311 if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL) {
315 snprintf(pkgname, len, "%s", _get_pkgname(menu_info));
319 _free_app_info_from_db(menu_info);
324 int _status_get_appid_bypid(int fd, int pid)
326 app_pkt_t *pkt = NULL;
330 pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
337 memset(pkt, 0, AUL_SOCK_MAXBUFF);
339 pkt->cmd = APP_GET_APPID_BYPID_ERROR;
341 if (__get_pkgname_bypid(pid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0) {
342 _D("appid for %d is %s", pid, pkt->data);
343 pkt->cmd = APP_GET_APPID_BYPID_OK;
346 /* support app launched by shell script*/
352 _D("second change pgid = %d, pid = %d", pgid, pid);
353 if (__get_pkgname_bypid(pgid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0)
354 pkt->cmd = APP_GET_APPID_BYPID_OK;
357 pkt->len = strlen((char *)pkt->data) + 1;
359 if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
361 _E("send failed due to EPIPE.\n");
362 _E("send fail to client");
374 int _status_init(struct amdmgr* amd)