Send app2sd request 88/185488/2
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 31 Jul 2018 06:00:42 +0000 (15:00 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 31 Jul 2018 06:06:27 +0000 (15:06 +0900)
Before launching an application, the child process sends the request to
enable external storage if the application is installed in external
storage.

Change-Id: I956fad859c1fed16a26d734291b2ddb7d670673e
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
inc/key.h
inc/launchpad_common.h
src/launchpad.c
src/launchpad_common.c
src/launchpad_lib.c

index b75bc38..d3d2973 100644 (file)
--- a/inc/key.h
+++ b/inc/key.h
@@ -48,6 +48,7 @@ extern "C" {
 #define AUL_K_IS_GLOBAL                        "__AUL_IS_GLOBAL__"
 #define AUL_K_TEP_PATH                 "__AUL_TEP_PATH__"
 #define AUL_K_IS_INSTALLED             "__AUL_IS_INSTALLED__"
+#define AUL_K_INSTALLED_STORAGE                "__AUL_INSTALLED_STORAGE__"
 
 #ifdef __cplusplus
 }
index c43108a..f842b76 100644 (file)
@@ -127,6 +127,7 @@ int _setup_stdio(const char *ident);
 int _set_priority(int prio);
 int _wait_tep_mount(bundle *b);
 int _prepare_app_socket(void);
+int _enable_external_pkg(bundle *b, const char *pkgid, uid_t pkg_uid);
 
 #endif /* __LAUNCHPAD_COMMON_H__ */
 
index be32c28..869e510 100755 (executable)
@@ -943,6 +943,11 @@ static int __prepare_exec(const char *appid, const char *app_path,
        /* TODO : should be add to check permission in the kernel*/
        setsid();
 
+       ret = _enable_external_pkg(kb, menu_info->pkgid,
+                       menu_info->global ? GLOBAL_USER : getuid());
+       if (ret < 0)
+               return PAD_ERR_FAILED;
+
        if (menu_info->global)
                ret = trust_anchor_launch(menu_info->pkgid, GLOBAL_USER);
        else
index 5ed5b8b..f8a9a3b 100644 (file)
 #define TEP_INTERFACE_NAME             "org.tizen.system.deviced.Tzip"
 #define TEP_IS_MOUNTED_METHOD          "IsMounted"
 
+#define APP2SD_BUS_NAME                        "org.tizen.app2sd"
+#define APP2SD_OBJECT_PATH             "/org/tizen/app2sd"
+#define APP2SD_INTERFACE_NAME          "org.tizen.app2sd"
+#define APP2SD_ONDEMANDSETUPINIT_METHOD        "OndemandSetupInit"
+#define APP2SD_RETRY_MAX               5
+#define APP2SD_WAIT_USEC               (1000000 / 2) /* 0.5 sec */
+
 static int __read_proc(const char *path, char *buf, int size)
 {
        int fd;
@@ -934,7 +941,8 @@ int _set_priority(int prio)
        return r;
 }
 
-static int __is_tep_mount_done(const char *tep_path)
+static int __dbus_send_message(DBusMessage *callback(void *), void *user_data,
+               int timeout, int *result)
 {
        DBusError err;
        DBusConnection *conn;
@@ -953,25 +961,13 @@ static int __is_tep_mount_done(const char *tep_path)
                goto end;
        }
 
-       msg = dbus_message_new_method_call(TEP_BUS_NAME,
-                       TEP_OBJECT_PATH,
-                       TEP_INTERFACE_NAME,
-                       TEP_IS_MOUNTED_METHOD);
+       msg = callback(user_data);
        if (!msg) {
-               _E("Message is NULL");
-               ret = -1;
-               goto end;
-       }
-
-       dbus_message_iter_init_append(msg, &args);
-       r = dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &tep_path);
-       if (!r) {
-               _E("Out of memory");
-               ret = -1;
+               _E("Message is nullptr");
                goto end;
        }
 
-       r = dbus_connection_send_with_reply(conn, msg, &pending, 500);
+       r = dbus_connection_send_with_reply(conn, msg, &pending, timeout);
        if (!r || !pending) {
                _E("Failed to send message");
                ret = -1;
@@ -1000,10 +996,10 @@ static int __is_tep_mount_done(const char *tep_path)
                ret = -1;
        } else {
                dbus_message_iter_get_basic(&args, &i);
-               ret = i;
+               *result = i;
        }
 
-       _D("Result: %d", ret);
+       _D("Result: %d", *result);
 end:
        if (msg)
                dbus_message_unref(msg);
@@ -1019,6 +1015,46 @@ end:
        return ret;
 }
 
+static DBusMessage *__create_tep_mount_message(void *user_data)
+{
+       DBusMessage *message;
+       DBusMessageIter args;
+       dbus_bool_t r;
+       const char *tep_path = (const char *)user_data;
+
+       message = dbus_message_new_method_call(TEP_BUS_NAME,
+                       TEP_OBJECT_PATH,
+                       TEP_INTERFACE_NAME,
+                       TEP_IS_MOUNTED_METHOD);
+       if (!message) {
+               _E("Message is nullptr");
+               return NULL;
+       }
+
+       dbus_message_iter_init_append(message, &args);
+       r = dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &tep_path);
+       if (!r) {
+               _E("Out of memory");
+               dbus_message_unref(message);
+               return NULL;
+       }
+
+       return message;
+}
+
+static int __is_tep_mount_done(const char *tep_path)
+{
+       int result = -1;
+       int ret;
+
+       ret = __dbus_send_message(__create_tep_mount_message,
+                       (void *)tep_path, 500, &result);
+       if (ret != 0)
+               _E("Failed to send message");
+
+       return result;
+}
+
 static int __check_tep_mount(const char *tep_path)
 {
        int r;
@@ -1138,3 +1174,79 @@ int _prepare_app_socket(void)
 
        return 0;
 }
+
+struct package_info_s {
+       const char *id;
+       uid_t uid;
+};
+
+static DBusMessage *__create_app2sd_message(void *user_data)
+{
+       struct package_info_s *pkg_info = (struct package_info_s *)user_data;
+       DBusMessage *message;
+       DBusMessageIter args;
+       dbus_bool_t r;
+
+       _D("[__APP2SD__] package(%s), uid(%u)", pkg_info->id, pkg_info->uid);
+
+       message = dbus_message_new_method_call(APP2SD_BUS_NAME,
+                       APP2SD_OBJECT_PATH,
+                       APP2SD_INTERFACE_NAME,
+                       APP2SD_ONDEMANDSETUPINIT_METHOD);
+       if (!message) {
+               _E("Message is nullptr");
+               return NULL;
+       }
+
+       dbus_message_iter_init_append(message, &args);
+       r = dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
+                       &pkg_info->id);
+       if (!r) {
+               _E("Failed to append pkgid");
+               dbus_message_unref(message);
+               return NULL;
+       }
+
+       r = dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32,
+                       &pkg_info->uid);
+       if (!r) {
+               _E("Failed to append uid");
+               dbus_message_unref(message);
+               return NULL;
+       }
+
+       return message;
+}
+
+int _enable_external_pkg(bundle *b, const char *pkgid, uid_t pkg_uid)
+{
+       const char *installed_storage;
+       int retry_cnt = 0;
+       int result = -1;
+       int ret;
+       struct package_info_s pkg_info = {
+               .id = pkgid,
+               .uid = pkg_uid
+       };
+
+       installed_storage = bundle_get_val(b, AUL_K_INSTALLED_STORAGE);
+       if (!installed_storage || strcmp(installed_storage, "external") != 0)
+               return 0;
+
+       do {
+               ret = __dbus_send_message(__create_app2sd_message,
+                               &pkg_info, G_MAXINT, &result);
+               if (ret != 0) {
+                       _E("Failed to send message");
+                       retry_cnt++;
+                       usleep(APP2SD_WAIT_USEC);
+                       continue;
+               }
+
+               break;
+       } while (retry_cnt <= APP2SD_RETRY_MAX);
+
+       _D("[__APP2SD__] result(%d)", result);
+
+       return result;
+}
index 6c225de..70161c0 100644 (file)
@@ -65,6 +65,10 @@ static int __prepare_exec(const char *appid, const char *app_path,
 
        __preexec_run(pkg_type, appid, app_path);
 
+       ret = _enable_external_pkg(kb, pkgid, global ? GLOBAL_USER : getuid());
+       if (ret < 0)
+               return -1;
+
        /* SET PRIVILEGES*/
        SECURE_LOGD("[candidata] appid : %s / pkg_type : %s / app_path : %s",
                appid, pkg_type, app_path);