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 "menu_db_util.h"
30 #include "simple_util.h"
34 typedef struct _internal_param_t {
35 aul_app_info_iter_fn enum_fn;
39 static int __get_pkgname_bypid(int pid, char *pkgname, int len);
41 SLPAPI int aul_app_is_running(const char *appid)
48 ret = __app_send_raw(AUL_UTIL_PID, APP_IS_RUNNING, (unsigned char*)appid, strlen(appid));
53 SLPAPI int aul_app_get_running_app_info(aul_app_info_iter_fn enum_fn,
56 app_pkt_t *pkt = NULL;
57 char *saveptr1, *saveptr2;
65 pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_RUNNING_INFO);
70 for( pkt_data = (char *)pkt->data; ; pkt_data = NULL) {
71 token = strtok_r(pkt_data, ";", &saveptr1);
74 info.pid = atoi(strtok_r(token, ":", &saveptr2));
75 info.appid = strtok_r(NULL, ":", &saveptr2);
76 info.app_path = strtok_r(NULL, ":", &saveptr2);
77 info.pkg_name = strdup(info.appid);
79 enum_fn(&info, user_param);
88 static int __get_pkgname_bypid(int pid, char *pkgname, int len)
91 app_info_from_db *menu_info;
93 cmdline = __proc_get_cmdline_bypid(pid);
97 if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL) {
101 snprintf(pkgname, len, "%s", _get_pkgname(menu_info));
104 _free_app_info_from_db(menu_info);
109 SLPAPI int aul_app_get_pkgname_bypid(int pid, char *pkgname, int len)
111 return aul_app_get_appid_bypid(pid, pkgname, len);
114 SLPAPI int aul_app_get_appid_bypid(int pid, char *appid, int len)
121 if (__get_pkgname_bypid(pid, appid, len) == 0) {
122 _D("appid for %d is %s", pid, appid);
125 /* support app launched by shell script*/
131 _D("second change pgid = %d, pid = %d", pgid, pid);
132 if (__get_pkgname_bypid(pgid, appid, len) == 0)