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 const char *__appid = NULL;
40 static const char *__pkgid = NULL;
42 SLPAPI int aul_app_is_running(const char *appid)
49 ret = __app_send_raw(AUL_UTIL_PID, APP_IS_RUNNING, (unsigned char*)appid,
58 SLPAPI int aul_app_get_running_app_info(aul_app_info_iter_fn enum_fn,
61 app_pkt_t *pkt = NULL;
62 char *saveptr1, *saveptr2;
67 memset(&info, 0, sizeof(info));
71 pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_RUNNING_INFO, NULL, 0);
76 for ( pkt_data = (char *)pkt->data; ; pkt_data = NULL) {
77 token = strtok_r(pkt_data, ";", &saveptr1);
80 info.pid = atoi(strtok_r(token, ":", &saveptr2));
81 info.appid = strtok_r(NULL, ":", &saveptr2);
82 info.app_path = strtok_r(NULL, ":", &saveptr2);
83 info.pkg_name = strdup(info.appid);
85 enum_fn(&info, user_param);
94 SLPAPI void aul_set_preinit_appid(const char *appid)
99 SLPAPI void aul_set_preinit_pkgid(const char *pkgid)
104 static int __get_info_bypid(int pid, char *appid, int len, int cmd)
107 app_info_from_db *menu_info;
109 result = __proc_get_appid_bypid(pid);
112 uid = __proc_get_usr_bypid(pid);
114 if ((menu_info = _get_app_info_from_db_by_appid_user(result, uid)) == NULL) {
118 if (cmd == APP_GET_APPID_BYPID)
119 snprintf(appid, len, "%s", _get_appid(menu_info));
121 snprintf(appid, len, "%s", _get_pkgid(menu_info));
125 _free_app_info_from_db(menu_info);
130 SLPAPI int aul_app_get_pkgname_bypid(int pid, char *pkgname, int len)
132 return aul_app_get_appid_bypid(pid, pkgname, len);
135 static int __get_appid_bypid(int pid, char *appid, int len)
139 result = __proc_get_appid_bypid(pid);
143 snprintf(appid, len, "%s", result);
149 SLPAPI int aul_app_get_appid_bypid_for_uid(int pid, char *appid, int len, uid_t uid)
155 if (pid != getpid()) {
156 pkt = __app_send_cmd_with_result_for_uid(AUL_UTIL_PID, uid,
157 APP_GET_APPID_BYPID, (unsigned char *)&pid,
161 if (pkt->cmd == APP_GET_INFO_ERROR) {
166 snprintf(appid, len, "%s", pkt->data);
171 snprintf(appid, len, "%s", __appid);
175 ret = __get_appid_bypid(pid, appid, len);
182 return __get_appid_bypid(pid, appid, len);
188 SLPAPI int aul_app_get_appid_bypid(int pid, char *appid, int len)
190 return aul_app_get_appid_bypid_for_uid(pid, appid, len, getuid());
193 SLPAPI int aul_app_get_pkgid_bypid_for_uid(int pid, char *pkgid, int len, uid_t uid)
195 app_pkt_t *pkt = NULL;
197 int cmd = APP_GET_PKGID_BYPID;
200 if (pid == cpid && __pkgid) {
201 snprintf(pkgid, len, "%s", __pkgid);
205 if (pid == cpid || getuid() == 0 || geteuid() == 0) {
206 if (__get_info_bypid(pid, pkgid, len, cmd) == 0) {
207 SECURE_LOGD("pkgid for %d is %s", pid, pkgid);
210 /* support app launched by shell script*/
216 _D("second change pgid = %d, pid = %d", pgid, pid);
217 if (__get_info_bypid(pgid, pkgid, len, cmd) == 0)
226 pkt = __app_send_cmd_with_result_for_uid(AUL_UTIL_PID, uid, cmd,
227 (unsigned char *)&pid, sizeof(pid));
231 if (pkt->cmd == APP_GET_INFO_ERROR) {
236 snprintf(pkgid, len, "%s", pkt->data);
241 SLPAPI int aul_app_get_pkgid_bypid(int pid, char *pkgid, int len)
243 return aul_app_get_pkgid_bypid_for_uid(pid, pkgid, len, getuid());