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.
27 #include <pkgmgr-info.h>
30 #include "menu_db_util.h"
31 #include "simple_util.h"
35 #define METADATA_LEGACY_LIFECYCLE "http://developer.samsung.com/tizen/metadata/legacylifecycle"
37 static char *__appid = NULL;
38 static int __aul_support_legacy_lifecycle = -1;
40 static int __get_pkgname_bypid(int pid, char *pkgname, int len);
42 SLPAPI int aul_app_is_running(const char *appid)
49 ret = __app_send_raw(AUL_UTIL_PID, APP_IS_RUNNING, (unsigned char*)appid, strlen(appid));
57 SLPAPI int aul_app_get_running_app_info(aul_app_info_iter_fn iter_fn,
60 return aul_get_running_app_info_from_memory(iter_fn, user_param);
63 SLPAPI int aul_get_running_app_info_from_proc(aul_app_info_iter_fn iter_fn,
66 app_pkt_t *pkt = NULL;
67 char *saveptr1, *saveptr2;
72 memset(&info, 0, sizeof(info));
76 pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_RUNNING_INFO, NULL, 0);
81 for( pkt_data = (char *)pkt->data; ; pkt_data = NULL) {
82 token = strtok_r(pkt_data, ";", &saveptr1);
85 info.pid = atoi(strtok_r(token, ":", &saveptr2));
86 info.appid = strtok_r(NULL, ":", &saveptr2);
87 info.app_path = strtok_r(NULL, ":", &saveptr2);
88 info.pkg_name = strdup(info.appid);
90 iter_fn(&info, user_param);
99 SLPAPI int aul_get_running_app_info_from_memory(aul_app_info_iter_fn iter_fn,
102 app_pkt_t *pkt = NULL;
103 char *saveptr1, *saveptr2;
108 memset(&info, 0, sizeof(info));
112 pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_RUNNING_INFO_MEMORY, NULL, 0);
117 for( pkt_data = (char *)pkt->data; ; pkt_data = NULL) {
118 token = strtok_r(pkt_data, ";", &saveptr1);
121 info.pid = atoi(strtok_r(token, ":", &saveptr2));
122 info.appid = strtok_r(NULL, ":", &saveptr2);
123 info.app_path = strtok_r(NULL, ":", &saveptr2);
124 info.pkg_name = strdup(info.appid);
126 iter_fn(&info, user_param);
135 SLPAPI void aul_set_preinit_appid(const char *appid)
140 static char* __aul_get_preinit_appid(void)
145 static int __get_pkgname_bypid(int pid, char *pkgname, int len)
148 app_info_from_db *menu_info;
150 cmdline = __proc_get_cmdline_bypid(pid);
154 if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL) {
158 snprintf(pkgname, len, "%s", _get_pkgname(menu_info));
161 _free_app_info_from_db(menu_info);
166 SLPAPI int aul_app_get_pkgname_bypid(int pid, char *pkgname, int len)
168 return aul_app_get_appid_bypid(pid, pkgname, len);
171 SLPAPI int aul_app_get_appid_bypid(int pid, char *appid, int len)
173 app_pkt_t *pkt = NULL;
176 if (pid == getpid()) {
177 char *preinit_appid = __aul_get_preinit_appid();
179 if (preinit_appid != NULL)
181 #ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP
182 if(strncmp(preinit_appid, "org.tizen.phone", MAX_PACKAGE_STR_SIZE) == 0) {
183 snprintf(appid, len > MAX_PACKAGE_STR_SIZE ? MAX_PACKAGE_STR_SIZE : len, "%s", "org.tizen.contacts");
186 snprintf(appid, len > MAX_PACKAGE_STR_SIZE ? MAX_PACKAGE_STR_SIZE : len, "%s", preinit_appid);
187 #ifdef _APPFW_FEATURE_CONTACT_PHONE_AS_ONE_APP
194 if (pid == getpid() || getuid()==0 || geteuid()==0) {
195 if (__get_pkgname_bypid(pid, appid, len) == 0) {
196 SECURE_LOGD("appid for %d is %s", pid, appid);
199 /* support app launched by shell script*/
205 _D("second change pgid = %d, pid = %d", pgid, pid);
206 if (__get_pkgname_bypid(pgid, appid, len) == 0)
215 pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GET_APPID_BYPID, (unsigned char *)&pid, sizeof(pid));
219 if(pkt->cmd == APP_GET_INFO_ERROR) {
224 snprintf(appid, len, "%s", pkt->data);
229 static int __get_pkgid_bypid(int pid, char *pkgid, int len)
232 app_info_from_db *menu_info;
234 cmdline = __proc_get_cmdline_bypid(pid);
238 if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL) {
242 snprintf(pkgid, len, "%s", _get_pkgid(menu_info));
245 _free_app_info_from_db(menu_info);
250 SLPAPI int aul_app_get_pkgid_bypid(int pid, char *pkgid, int len)
252 app_pkt_t *pkt = NULL;
255 if(pid == getpid() || getuid()==0 || geteuid()==0) {
256 if (__get_pkgid_bypid(pid, pkgid, len) == 0) {
257 SECURE_LOGD("appid for %d is %s", pid, pkgid);
260 /* support app launched by shell script*/
266 _D("second change pgid = %d, pid = %d", pgid, pid);
267 if (__get_pkgid_bypid(pgid, pkgid, len) == 0)
276 pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GET_APPID_BYPID, (unsigned char *)&pid, sizeof(pid));
280 if(pkt->cmd == APP_GET_INFO_ERROR) {
285 snprintf(pkgid, len, "%s", pkt->data);
290 SLPAPI int aul_get_support_legacy_lifecycle(void)
292 if (__aul_support_legacy_lifecycle != -1)
293 return __aul_support_legacy_lifecycle;
296 pkgmgrinfo_appinfo_h handle = NULL;
297 char *metadata_value = NULL;
299 ret = pkgmgrinfo_appinfo_get_appinfo(__appid, &handle);
300 if (ret != PMINFO_R_OK)
303 ret = pkgmgrinfo_appinfo_get_metadata_value(handle, METADATA_LEGACY_LIFECYCLE, &metadata_value);
304 if (ret != PMINFO_R_OK) {
305 __aul_support_legacy_lifecycle = 0;
307 __aul_support_legacy_lifecycle = 1;
310 pkgmgrinfo_appinfo_destroy_appinfo(handle);
312 return __aul_support_legacy_lifecycle;