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"
32 typedef struct _internal_param_t {
33 aul_app_info_iter_fn enum_fn;
37 static int __get_pkginfo(const char *dname, const char *cmdline, void *priv);
38 static int __get_pkgname_bypid(int pid, char *pkgname, int len);
41 SLPAPI int aul_app_is_running(const char *pkgname)
53 ail_ret = ail_package_get_appinfo(pkgname, &handle);
54 if (ail_ret != AIL_ERROR_OK) {
55 _E("ail_package_get_appinfo with %s failed", pkgname);
59 ail_ret = ail_appinfo_get_str(handle, AIL_PROP_EXEC_STR, &apppath);
60 if (ail_ret != AIL_ERROR_OK) {
61 _E("ail_appinfo_get_str failed");
68 /*truncate apppath if it includes default bundles */
69 while (apppath[i] != 0) {
70 if (apppath[i] == ' ' || apppath[i] == '\t') {
77 if (__proc_iter_cmdline(NULL, apppath) > 0)
83 if (ail_package_destroy_appinfo(handle) != AIL_ERROR_OK)
84 _E("ail_destroy_rs failed");
88 static int __get_pkginfo(const char *dname, const char *cmdline, void *priv)
91 app_info_from_db *menu_info;
94 p = (internal_param_t *) priv;
95 if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL)
98 info.pid = atoi(dname);
99 info.pkg_name = _get_pkgname(menu_info);
100 info.app_path = _get_app_path(menu_info);
101 _D("get pkginfo - %d %s", info.pid, info.app_path);
102 p->enum_fn(&info, p->user_param);
106 if (menu_info != NULL)
107 _free_app_info_from_db(menu_info);
111 SLPAPI int aul_app_get_running_app_info(aul_app_info_iter_fn enum_fn,
114 internal_param_t param;
119 param.enum_fn = enum_fn;
120 param.user_param = user_param;
122 __proc_iter_cmdline(__get_pkginfo, ¶m);
127 static int __get_pkgname_bypid(int pid, char *pkgname, int len)
130 app_info_from_db *menu_info;
132 cmdline = __proc_get_cmdline_bypid(pid);
136 if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL) {
140 snprintf(pkgname, len, "%s", _get_pkgname(menu_info));
143 _free_app_info_from_db(menu_info);
148 SLPAPI int aul_app_get_pkgname_bypid(int pid, char *pkgname, int len)
155 if (__get_pkgname_bypid(pid, pkgname, len) == 0) {
156 _D("Pkg name for %d is %s", pid, pkgname);
159 /* support app launched by shell script*/
165 _D("second change pgid = %d, pid = %d", pgid, pid);
166 if (__get_pkgname_bypid(pgid, pkgname, len) == 0)