summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2016-01-20 14:22:45 +0900
committerHwankyu Jhun <h.jhun@samsung.com>2016-01-20 14:57:27 +0900
commit6c47b5e3967bf9f1a035535beef0050818f3b9ce (patch)
tree35b796760a1c133f353ec57aef5043856466c8a9
parent1c874b24fe2930f8e56e739bb7ad679bb81be463 (diff)
downloadaul-1-6c47b5e3967bf9f1a035535beef0050818f3b9ce.tar.gz
aul-1-6c47b5e3967bf9f1a035535beef0050818f3b9ce.tar.bz2
aul-1-6c47b5e3967bf9f1a035535beef0050818f3b9ce.zip
Support quick launch without AMDfor/drafts/tizen
- Add "-f" option on app_launcher tool Change-Id: I2e41e089d8f24733c64f621f4f5a747093afceac Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r--include/aul_cmd.h2
-rw-r--r--include/aul_sock.h5
-rw-r--r--include/launch.h2
-rw-r--r--include/menu_db_util.h42
-rw-r--r--src/aul_sock.c46
-rw-r--r--src/launch.c59
-rw-r--r--tool/app_launcher.c89
7 files changed, 227 insertions, 18 deletions
diff --git a/include/aul_cmd.h b/include/aul_cmd.h
index a789fd3f..fd6185f7 100644
--- a/include/aul_cmd.h
+++ b/include/aul_cmd.h
@@ -73,6 +73,8 @@ enum app_cmd {
APP_COM_LEAVE,
APP_COM_MESSAGE,
+ APP_REGISTER_PID,
+
/* for special purpose */
AMD_RELOAD_APPINFO,
/* reserved for AMD Agent */
diff --git a/include/aul_sock.h b/include/aul_sock.h
index 86b2ca24..9ef41531 100644
--- a/include/aul_sock.h
+++ b/include/aul_sock.h
@@ -80,3 +80,8 @@ app_pkt_t *aul_sock_send_raw_with_pkt_reply(int pid, uid_t uid, int cmd, unsigne
* This API is only for Appfw internally.
*/
app_pkt_t *aul_sock_recv_pkt(int fd, int *clifd, struct ucred *cr);
+
+/*
+ * This API is only for Appfw internally.
+ */
+int aul_sock_create_launchpad_client(const char *pad_type, uid_t uid);
diff --git a/include/launch.h b/include/launch.h
index 6e809c64..ddcace4a 100644
--- a/include/launch.h
+++ b/include/launch.h
@@ -24,11 +24,13 @@ int aul_register_init_callback(
int aul_is_initialized();
int aul_sock_handler(int fd);
int aul_make_bundle_from_argv(int argc, char **argv, bundle **kb);
+int aul_app_register_pid(const char *appid, int pid);
int app_start(bundle *kb);
int app_send_cmd(int pid, int cmd, bundle *kb);
int app_send_cmd_for_uid(int pid, uid_t uid, int cmd, bundle *kb);
int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb);
+int app_send_cmd_to_launchpad(const char *pad_type, uid_t uid, int cmd, bundle *kb);
int app_request_to_launchpad(int cmd, const char *pkgname, bundle *kb);
int app_request_to_launchpad_for_uid(int cmd, const char *pkgname, bundle *kb, uid_t uid);
diff --git a/include/menu_db_util.h b/include/menu_db_util.h
index 383c9489..c00c6ab5 100644
--- a/include/menu_db_util.h
+++ b/include/menu_db_util.h
@@ -45,8 +45,8 @@ typedef struct {
char *app_path; /* exec */
char *original_app_path; /* exec */
char *pkg_type; /* x_slp_packagetype */
- char *hwacc; /* hwacceleration */
char *pkg_id;
+ char *component_type;
} app_info_from_db;
static inline char *_get_appid(app_info_from_db *menu_info)
@@ -98,21 +98,22 @@ static inline char *_get_original_app_path(app_info_from_db *menu_info)
static inline void _free_app_info_from_db(app_info_from_db *menu_info)
{
- if (menu_info != NULL) {
- if (menu_info->appid != NULL)
- free(menu_info->appid);
- if (menu_info->app_path != NULL)
- free(menu_info->app_path);
- if (menu_info->original_app_path != NULL)
- free(menu_info->original_app_path);
- if (menu_info->pkg_type != NULL)
- free(menu_info->pkg_type);
- if (menu_info->hwacc != NULL)
- free(menu_info->hwacc);
- if (menu_info->pkg_id != NULL)
- free(menu_info->pkg_id);
- free(menu_info);
- }
+ if (menu_info == NULL)
+ return;
+
+ if (menu_info->appid != NULL)
+ free(menu_info->appid);
+ if (menu_info->app_path != NULL)
+ free(menu_info->app_path);
+ if (menu_info->original_app_path != NULL)
+ free(menu_info->original_app_path);
+ if (menu_info->pkg_type != NULL)
+ free(menu_info->pkg_type);
+ if (menu_info->pkg_id != NULL)
+ free(menu_info->pkg_id);
+ if (menu_info->component_type != NULL)
+ free(menu_info->component_type);
+ free(menu_info);
}
static inline app_info_from_db *_get_app_info_from_db_by_pkgname(
@@ -123,6 +124,8 @@ static inline app_info_from_db *_get_app_info_from_db_by_pkgname(
int ret = PMINFO_R_OK;
char *exec = NULL;
char *apptype = NULL;
+ char *component_type = NULL;
+
menu_info = calloc(1, sizeof(app_info_from_db));
if (menu_info == NULL)
@@ -163,6 +166,13 @@ static inline app_info_from_db *_get_app_info_from_db_by_pkgname(
if (apptype)
menu_info->pkg_type = strdup(apptype);
+ ret = pkgmgrinfo_appinfo_get_component_type(handle, &component_type);
+ if (ret != PMINFO_R_OK)
+ _E("failed to get component type");
+
+ if (component_type)
+ menu_info->component_type = strdup(component_type);
+
ret = pkgmgrinfo_appinfo_destroy_appinfo(handle);
if (ret != PMINFO_R_OK)
_E("pkgmgrinfo_appinfo_destroy_appinfo failed");
diff --git a/src/aul_sock.c b/src/aul_sock.c
index cda52059..7039e7f6 100644
--- a/src/aul_sock.c
+++ b/src/aul_sock.c
@@ -662,3 +662,49 @@ retry_recv:
return res;
}
+
+int aul_sock_create_launchpad_client(const char *pad_type, uid_t uid)
+{
+ int fd = -1;
+ struct sockaddr_un saddr = { 0, };
+ int retry = 1;
+ int ret = -1;
+
+ fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ /* support above version 2.6.27*/
+ if (fd < 0) {
+ if (errno == EINVAL) {
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ _E("second chance - socket create error");
+ return -1;
+ }
+ } else {
+ _E("socket error");
+ return -1;
+ }
+ }
+
+ saddr.sun_family = AF_UNIX;
+ snprintf(saddr.sun_path, sizeof(saddr.sun_path),
+ "/run/user/%d/%s", uid, pad_type);
+retry_con:
+ ret = __connect_client_sock(fd, (struct sockaddr *)&saddr,
+ sizeof(saddr), 100 * 1000);
+ if (ret < -1) {
+ _E("maybe peer not launched or peer daed\n");
+ if (retry > 0) {
+ usleep(100 * 1000);
+ retry--;
+ goto retry_con;
+ }
+ }
+ if (ret < 0) {
+ close(fd);
+ return -1;
+ }
+
+ __set_sock_option(fd, 1);
+
+ return fd;
+}
diff --git a/src/launch.c b/src/launch.c
index 3e2d8eb6..d9f0697d 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -257,6 +257,48 @@ API int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb)
return res;
}
+API int app_send_cmd_to_launchpad(const char *pad_type, uid_t uid, int cmd, bundle *kb)
+{
+ int fd;
+ int datalen;
+ bundle_raw *kb_data;
+ int len;
+ int res;
+
+ fd = aul_sock_create_launchpad_client(pad_type, uid);
+ if (fd < 0)
+ return -1;
+
+ bundle_encode(kb, &kb_data, &datalen);
+ res = aul_sock_send_raw_async_with_fd(fd, cmd,
+ kb_data, datalen, AUL_SOCK_NONE);
+ if (res < 0) {
+ free(kb_data);
+ close(fd);
+ return res;
+ }
+
+retry_recv:
+ len = recv(fd, &res, sizeof(int), 0);
+ if (len == -1) {
+ if (errno == EAGAIN) {
+ _E("recv timeout: %s", strerror(errno));
+ res = -EAGAIN;
+ } else if (errno == EINTR) {
+ _D("recv: %s", strerror(errno));
+ goto retry_recv;
+ } else {
+ _E("recv error: %s", strerror(errno));
+ res = -ECOMM;
+ }
+ }
+
+ free(kb_data);
+ close(fd);
+
+ return res;
+}
+
static void __clear_internal_key(bundle *kb)
{
bundle_del(kb, AUL_K_CALLER_PID);
@@ -930,4 +972,21 @@ API int aul_remove_loader(int loader_id)
return ret;
}
+API int aul_app_register_pid(const char *appid, int pid)
+{
+ char buf[MAX_PID_STR_BUFSZ];
+ int ret;
+ bundle *b;
+ if (!appid || pid <= 0)
+ return AUL_R_EINVAL;
+
+ b = bundle_create();
+ bundle_add_str(b, AUL_K_APPID, appid);
+ snprintf(buf, sizeof(buf), "%d", pid);
+ bundle_add_str(b, AUL_K_PID, buf);
+ ret = app_send_cmd(AUL_UTIL_PID, APP_REGISTER_PID, b);
+ bundle_free(b);
+
+ return ret;
+}
diff --git a/tool/app_launcher.c b/tool/app_launcher.c
index 4032afc1..927d132e 100644
--- a/tool/app_launcher.c
+++ b/tool/app_launcher.c
@@ -33,6 +33,13 @@
#include <bundle_internal.h>
#include "aul.h"
+#include "aul_svc.h"
+#include "launch.h"
+#include "menu_db_util.h"
+
+#define LAUNCHPAD_PROCESS_POOL_SOCK ".launchpad-process-pool-sock"
+#define APP_TYPE_UI "uiapp"
+#define APP_TYPE_SERVICE "svcapp"
static GMainLoop *mainloop = NULL;
@@ -106,6 +113,68 @@ static gboolean run_func(void *data)
return FALSE;
}
+static int __set_appinfo_for_launchpad(bundle *kb, const char *appid)
+{
+ app_info_from_db *menu_info;
+
+ if (kb == NULL)
+ return -1;
+
+ menu_info = _get_app_info_from_db_by_pkgname(appid);
+ if (menu_info == NULL)
+ return -1;
+
+ if (strcmp(menu_info->component_type, APP_TYPE_SERVICE) != 0
+ && strcmp(menu_info->component_type, APP_TYPE_UI) != 0) {
+ _free_app_info_from_db(menu_info);
+ return -1;
+ }
+
+ bundle_add(kb, AUL_K_APPID, appid);
+ bundle_add(kb, AUL_K_HWACC, "NOT_USE");
+ bundle_add(kb, AUL_K_EXEC, menu_info->app_path);
+ bundle_add(kb, AUL_K_PACKAGETYPE, menu_info->pkg_type);
+ bundle_add(kb, AUL_K_PKGID, menu_info->pkg_id);
+ bundle_add(kb, AUL_K_INTERNAL_POOL, "false");
+ bundle_add(kb, AUL_K_COMP_TYPE, menu_info->component_type);
+
+ aul_svc_set_loader_id(kb, PAD_LOADER_ID_DIRECT);
+
+ _free_app_info_from_db(menu_info);
+
+ return 0;
+}
+
+static gboolean fast_run_func(void *data)
+{
+ int pid;
+ bundle *kb;
+ struct launch_arg *launch_arg_data = (struct launch_arg *)data;
+
+ kb = _create_internal_bundle(launch_arg_data);
+ if (kb == NULL)
+ kb = bundle_create();
+
+ if (__set_appinfo_for_launchpad(kb, launch_arg_data->appid) < 0) {
+ printf("failed to set appinfo\n");
+ bundle_free(kb);
+ return FALSE;
+ }
+
+ pid = app_send_cmd_to_launchpad(LAUNCHPAD_PROCESS_POOL_SOCK, getuid(),
+ 0, kb);
+ if (pid > 0) {
+ printf("... successfully launched pid = %d\n", pid);
+ aul_app_register_pid(launch_arg_data->appid, pid);
+ } else {
+ printf("... launch failed\n");
+ }
+
+ g_main_loop_quit(mainloop);
+
+ return FALSE;
+}
+
static void print_usage(char *program)
{
printf("Usage : %s [ OPTIONS... ] [ ARGS... ]\n", program);
@@ -118,6 +187,7 @@ static void print_usage(char *program)
" -t [tizen application ID] --terminate Terminate widget with tizen application ID\n"
" -r [tizen application ID] --is-running Check whether application is running by tizen application ID,\n"
" If widget is running, 0(zero) will be returned.\n"
+ " -f [tizen application ID] --fast-start Fast launch app with tizen application ID\n"
" -d --debug Activate debug mode\n"
);
}
@@ -231,6 +301,7 @@ int main(int argc, char **argv)
{ "kill", required_argument, 0, 'k' },
{ "terminate", required_argument, 0, 't' },
{ "is-running", required_argument, 0, 'r' },
+ { "fast-launch", required_argument, 0, 'f' },
{ "debug", no_argument, 0, 'd' },
{ 0, 0, 0, 0 }
};
@@ -239,7 +310,7 @@ int main(int argc, char **argv)
do {
next_opt = getopt_long(argc,
argv,
- "hlSs:k:t:r:d",
+ "hlSs:k:t:r:f:d",
long_options,
&opt_idx);
@@ -276,6 +347,7 @@ int main(int argc, char **argv)
case 'k':
case 't':
case 'r':
+ case 'f':
if (strlen(optarg) > 255) {
print_usage(argv[0]);
return -1;
@@ -304,7 +376,7 @@ int main(int argc, char **argv)
args.argc = argc - optind;
args.argv = &argv[optind];
}
- if ((op == 's') || (op == 'k') || (op == 'r')) {
+ if ((op == 's') || (op == 'k') || (op == 'r') || (op == 'f')) {
if (is_app_installed(args.appid) <= 0) {
printf("The app with ID: %s is not avaible "
"for the user %d \n",
@@ -354,6 +426,19 @@ int main(int argc, char **argv)
printf("result: %s\n", "not running");
return 1;
}
+ } else if (op == 'f') {
+ if (strlen(args.appid) <= 0) {
+ printf("result: failed\n");
+ return -1;
+ }
+ aul_launch_init(NULL, NULL);
+ g_idle_add(fast_run_func, args.appid);
+ mainloop = g_main_loop_new(NULL, FALSE);
+ if (!mainloop) {
+ printf("failed to create glib main loop\n");
+ exit(EXIT_FAILURE);
+ }
+ g_main_loop_run(mainloop);
}
return 0;