summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiwoong Im <jiwoong.im@samsung.com>2015-09-03 21:36:56 +0900
committerJiwoong Im <jiwoong.im@samsung.com>2015-09-03 21:36:56 +0900
commit29214aa36e0147a6623f829ffea9e7e669584177 (patch)
tree3418ee75bcdebce450c9dde31c63450c4075b46d
parent40543a8ec4e66516c4543c81432566a9da59c28d (diff)
downloadaul-1-29214aa36e0147a6623f829ffea9e7e669584177.tar.gz
aul-1-29214aa36e0147a6623f829ffea9e7e669584177.tar.bz2
aul-1-29214aa36e0147a6623f829ffea9e7e669584177.zip
merge aul_app_get_pkgid_bypid() api from tizen_2.4 Change-Id: I463ae4f777e32bcc961c0bae9929dff9e0a05f19 Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
-rw-r--r--am_daemon/amd_request.c5
-rw-r--r--am_daemon/amd_status.c90
-rw-r--r--include/app_sock.h5
-rw-r--r--include/menu_db_util.h5
-rw-r--r--src/pkginfo.c68
-rw-r--r--test/aul_test.c25
6 files changed, 179 insertions, 19 deletions
diff --git a/am_daemon/amd_request.c b/am_daemon/amd_request.c
index 738427b4..614161d3 100644
--- a/am_daemon/amd_request.c
+++ b/am_daemon/amd_request.c
@@ -523,6 +523,11 @@ static gboolean __request_handler(gpointer data)
ret = _status_get_appid_bypid(clifd, pid);
_D("APP_GET_APPID_BYPID : %d : %d", pid, ret);
break;
+ case APP_GET_PKGID_BYPID:
+ memcpy(&pid, pkt->data, sizeof(int));
+ ret = _status_get_pkgid_bypid(clifd, pid);
+ _D("APP_GET_PKGID_BYPID : %d : %d", pid, ret);
+ break;
case APP_KEY_RESERVE:
// support for key events has been removed (sdx-20140813)
__send_result_to_client(clifd, 0);
diff --git a/am_daemon/amd_status.c b/am_daemon/amd_status.c
index e4c9a96b..11dfc446 100644
--- a/am_daemon/amd_status.c
+++ b/am_daemon/amd_status.c
@@ -394,12 +394,12 @@ int _status_get_appid_bypid(int fd, int pid)
int pgid;
char appid[MAX_PACKAGE_STR_SIZE] = {0, };
- cmd = APP_GET_APPID_BYPID_ERROR;
+ cmd = APP_GET_INFO_ERROR;
if (__get_appid_bypid(pid, appid, MAX_PACKAGE_STR_SIZE) == 0) {
SECURE_LOGD("appid for %d is %s", pid, appid);
len = strlen(appid);
- cmd = APP_GET_APPID_BYPID_OK;
+ cmd = APP_GET_INFO_OK;
goto out;
}
/* support app launched by shell script*/
@@ -413,7 +413,7 @@ int _status_get_appid_bypid(int fd, int pid)
_D("second change pgid = %d, pid = %d", pgid, pid);
if (__get_appid_bypid(pgid, appid, MAX_PACKAGE_STR_SIZE) == 0) {
len = strlen(appid);
- cmd = APP_GET_APPID_BYPID_OK;
+ cmd = APP_GET_INFO_OK;
}
out:
@@ -441,3 +441,87 @@ int _status_get_appid_bypid(int fd, int pid)
return 0;
}
+
+static int __get_pkgid_bypid(int pid, char *pkgid, int len)
+{
+ char *cmdline;
+ app_info_from_db *menu_info;
+ uid_t uid;
+ cmdline = __proc_get_cmdline_bypid(pid);
+ if (cmdline == NULL)
+ return -1;
+
+ uid = __proc_get_usr_bypid(pid);
+ if (uid == -1) {
+ free(cmdline);
+ return -1;
+ }
+
+ if ((menu_info = _get_app_info_from_db_by_apppath_user(cmdline,uid)) == NULL) {
+ free(cmdline);
+ return -1;
+ } else {
+ snprintf(pkgid, len, "%s", _get_pkgid(menu_info));
+ }
+
+ free(cmdline);
+ _free_app_info_from_db(menu_info);
+
+ return 0;
+}
+
+int _status_get_pkgid_bypid(int fd, int pid)
+{
+ app_pkt_t *pkt = NULL;
+ int cmd;
+ int len = 0;
+ int pgid;
+ char pkgid[MAX_PACKAGE_STR_SIZE] = {0, };
+
+ cmd = APP_GET_INFO_ERROR;
+
+ if (__get_pkgid_bypid(pid, pkgid, MAX_PACKAGE_STR_SIZE) == 0) {
+ SECURE_LOGD("pkgid for %d is %s", pid, pkgid);
+ len = strlen(pkgid);
+ cmd = APP_GET_INFO_OK;
+ goto out;
+ }
+ /* support app launched by shell script*/
+ _D("second chance");
+ pgid = getpgid(pid);
+ if (pgid <= 1) {
+ close(fd);
+ return 0;
+ }
+
+ _D("second change pgid = %d, pid = %d", pgid, pid);
+ if (__get_pkgid_bypid(pgid, pkgid, MAX_PACKAGE_STR_SIZE) == 0) {
+ len = strlen(pkgid);
+ cmd = APP_GET_INFO_OK;
+ }
+
+ out:
+ pkt = (app_pkt_t *)malloc(AUL_PKT_HEADER_SIZE + len);
+ if (!pkt) {
+ _E("malloc fail");
+ close(fd);
+ return 0;
+ }
+ pkt->cmd = cmd;
+ pkt->len = len;
+ memcpy(pkt->data, pkgid, len);
+
+ if ((len = send(fd, pkt, pkt->len + AUL_PKT_HEADER_SIZE, 0)) !=
+ pkt->len + AUL_PKT_HEADER_SIZE) {
+ if (errno == EPIPE)
+ _E("send failed due to EPIPE.\n");
+ _E("send fail to client");
+ }
+
+ if (pkt)
+ free(pkt);
+
+ close(fd);
+
+ return 0;
+}
diff --git a/include/app_sock.h b/include/app_sock.h
index 620cb905..33b024b5 100644
--- a/include/app_sock.h
+++ b/include/app_sock.h
@@ -44,8 +44,9 @@ enum app_cmd {
APP_RUNNING_INFO_RESULT,
APP_IS_RUNNING,
APP_GET_APPID_BYPID,
- APP_GET_APPID_BYPID_OK,
- APP_GET_APPID_BYPID_ERROR,
+ APP_GET_PKGID_BYPID,
+ APP_GET_INFO_OK,
+ APP_GET_INFO_ERROR,
APP_KEY_EVENT,
APP_KEY_RESERVE,
APP_KEY_RELEASE,
diff --git a/include/menu_db_util.h b/include/menu_db_util.h
index fbba0060..888d8074 100644
--- a/include/menu_db_util.h
+++ b/include/menu_db_util.h
@@ -60,6 +60,11 @@ static inline char *_get_appid(app_info_from_db *menu_info)
return menu_info ? menu_info->appid : NULL;
}
+static inline char *_get_pkgid(app_info_from_db *menu_info)
+{
+ return menu_info ? menu_info->pkg_id : NULL;
+}
+
static inline char *_get_app_path(app_info_from_db *menu_info)
{
int i = 0;
diff --git a/src/pkginfo.c b/src/pkginfo.c
index 52769b55..7e048d16 100644
--- a/src/pkginfo.c
+++ b/src/pkginfo.c
@@ -36,8 +36,6 @@ typedef struct _internal_param_t {
void *user_param;
} internal_param_t;
-static int __get_appid_bypid(int pid, char *appid, int len);
-
SLPAPI int aul_app_is_running(const char *appid)
{
int ret = 0;
@@ -89,7 +87,7 @@ SLPAPI int aul_app_get_running_app_info(aul_app_info_iter_fn enum_fn,
return AUL_R_OK;
}
-static int __get_appid_bypid(int pid, char *appid, int len)
+static int __get_info_bypid(int pid, char *appid, int len, int cmd)
{
char *cmdline;
app_info_from_db *menu_info;
@@ -102,8 +100,12 @@ static int __get_appid_bypid(int pid, char *appid, int len)
if ((menu_info = _get_app_info_from_db_by_apppath_user(cmdline,uid)) == NULL) {
free(cmdline);
return -1;
- } else
- snprintf(appid, len, "%s", _get_appid(menu_info));
+ } else {
+ if (cmd == APP_GET_APPID_BYPID)
+ snprintf(appid, len, "%s", _get_appid(menu_info));
+ else
+ snprintf(appid, len, "%s", _get_pkgid(menu_info));
+ }
free(cmdline);
_free_app_info_from_db(menu_info);
@@ -120,9 +122,10 @@ SLPAPI int aul_app_get_appid_bypid(int pid, char *appid, int len)
{
app_pkt_t *pkt = NULL;
int pgid;
+ int cmd = APP_GET_APPID_BYPID;
- if(pid == getpid() || getuid()==0 || geteuid()==0) {
- if (__get_appid_bypid(pid, appid, len) == 0) {
+ if (pid == getpid() || getuid()==0 || geteuid()==0) {
+ if (__get_info_bypid(pid, appid, len, cmd) == 0) {
SECURE_LOGD("appid for %d is %s", pid, appid);
return AUL_R_OK;
}
@@ -133,7 +136,7 @@ SLPAPI int aul_app_get_appid_bypid(int pid, char *appid, int len)
return AUL_R_ERROR;
_D("second change pgid = %d, pid = %d", pgid, pid);
- if (__get_appid_bypid(pgid, appid, len) == 0)
+ if (__get_info_bypid(pgid, appid, len, cmd) == 0)
return AUL_R_OK;
return AUL_R_ERROR;
@@ -142,11 +145,12 @@ SLPAPI int aul_app_get_appid_bypid(int pid, char *appid, int len)
if (appid == NULL)
return AUL_R_EINVAL;
- pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GET_APPID_BYPID, (unsigned char *)&pid, sizeof(pid));
+ pkt = __app_send_cmd_with_result(AUL_UTIL_PID, cmd,
+ (unsigned char *)&pid, sizeof(pid));
- if(pkt == NULL)
+ if (pkt == NULL)
return AUL_R_ERROR;
- if(pkt->cmd == APP_GET_APPID_BYPID_ERROR) {
+ if (pkt->cmd == APP_GET_INFO_ERROR) {
free(pkt);
return AUL_R_ERROR;
}
@@ -155,3 +159,45 @@ SLPAPI int aul_app_get_appid_bypid(int pid, char *appid, int len)
free(pkt);
return AUL_R_OK;
}
+
+SLPAPI int aul_app_get_pkgid_bypid(int pid, char *pkgid, int len)
+{
+ app_pkt_t *pkt = NULL;
+ int pgid;
+ int cmd = APP_GET_PKGID_BYPID;
+
+ if (pid == getpid() || getuid()==0 || geteuid()==0) {
+ if (__get_info_bypid(pid, pkgid, len, cmd) == 0) {
+ SECURE_LOGD("pkgid for %d is %s", pid, pkgid);
+ return AUL_R_OK;
+ }
+ /* support app launched by shell script*/
+
+ pgid = getpgid(pid);
+ if (pgid <= 1)
+ return AUL_R_ERROR;
+
+ _D("second change pgid = %d, pid = %d", pgid, pid);
+ if (__get_info_bypid(pgid, pkgid, len, cmd) == 0)
+ return AUL_R_OK;
+
+ return AUL_R_ERROR;
+ }
+
+ if (pkgid == NULL)
+ return AUL_R_EINVAL;
+
+ pkt = __app_send_cmd_with_result(AUL_UTIL_PID, cmd,
+ (unsigned char *)&pid, sizeof(pid));
+
+ if (pkt == NULL)
+ return AUL_R_ERROR;
+ if (pkt->cmd == APP_GET_INFO_ERROR) {
+ free(pkt);
+ return AUL_R_ERROR;
+ }
+
+ snprintf(pkgid, len, "%s", pkt->data);
+ free(pkt);
+ return AUL_R_OK;
+}
diff --git a/test/aul_test.c b/test/aul_test.c
index f43eb015..f12b5d1b 100644
--- a/test/aul_test.c
+++ b/test/aul_test.c
@@ -266,7 +266,7 @@ int get_allpkg_test()
return aul_app_get_running_app_info(iterfunc, NULL);
}
-int get_pkgpid_test()
+int get_app_bypid_test()
{
int pid = 0;
static int num = 0;
@@ -283,6 +283,23 @@ int get_pkgpid_test()
return 0;
}
+int get_pkg_bypid_test()
+{
+ int pid = 0;
+ static int num = 0;
+ char buf[MAX_LOCAL_BUFSZ];
+
+ printf("[aul_app_get_pkgid_bypid %d test] \n", num++);
+ pid = atoi(gargv[2]);
+
+ if (aul_app_get_pkgid_bypid(pid, buf, sizeof(buf)) < 0)
+ printf("no such pkg by %d\n", pid);
+ else
+ printf("pkgname = %s, pid = %d\n", buf, pid);
+
+ return 0;
+}
+
int open_file_test()
{
static int num = 0;
@@ -549,8 +566,10 @@ static test_func_t test_func[] = {
"[usage] is_run <pkgname>"},
{"getallpkg", get_allpkg_test, "aul_app_get_running_app_info test",
"[usage] getallpkg all"},
- {"getpkgpid", get_pkgpid_test, "aul_app_get_appid_bypid test",
- "[usage] getpkgpid <pid>"},
+ {"get_app_bypid", get_app_bypid_test, "aul_app_get_appid_bypid test",
+ "[usage] get_app_bypid <pid>"},
+ {"get_pkg_bypid", get_pkg_bypid_test, "aul_app_get_pkgid_bypid test",
+ "[usage] get_pkg_bypid <pid>"},
{"open_file", open_file_test, "aul_open_file test",
"[usage] open_file <filename>"},