app: Launch org.tizen.ode for encryption and get signal for mapper node from storaged 57/155857/2
authorpr.jung <pr.jung@samsung.com>
Mon, 16 Oct 2017 10:08:43 +0000 (19:08 +0900)
committerpr.jung <pr.jung@samsung.com>
Tue, 17 Oct 2017 08:44:50 +0000 (17:44 +0900)
- Launch org.tizen.ode for extended internal storage encryption
- Wait for mapper node mounted signal (DeviceChanged)

Change-Id: I592795cd7249114c2994ab22f5ed3e259e8b1bae
Signed-off-by: pr.jung <pr.jung@samsung.com>
apps/extended-sd/CMakeLists.txt
apps/extended-sd/include/extended-sd-main.h
apps/extended-sd/src/dbus-call.c
apps/extended-sd/src/es-internal-storage-page.c
apps/extended-sd/src/es-portable-storage-page.c
apps/extended-sd/src/extended-sd-main.c
packaging/storaged.spec

index c1b3a7e..9c8b6fa 100755 (executable)
@@ -24,6 +24,7 @@ pkg_check_modules(pkgs REQUIRED
        capi-system-system-settings
        efl-extension
        capi-appfw-app-control
+       storage
 )
 
 FIND_LIBRARY(LIB_M m)
index b89b062..406e79a 100644 (file)
@@ -6,6 +6,8 @@
 #include <system_settings.h>
 #include <efl_extension.h>
 #include <dlog.h>
+#include <storage.h>
+
 //#include <uxt_theme.h>
 //#include <uxt_theme_object.h>
 
 #define UNMOUNT_FORCE  1
 
 #define MYFILES_APP_ID "org.tizen.myfile"
+#define SECURITY_APP_ID        "org.tizen.ode"
+#define VIEWTYPE_KEY   "viewtype"
+#define DEVPATH_KEY    "dev_path"
+#define ENCRYPT_EXTENSION "ENCRYPT_EXTENSION"
+#define MAPPING_NODE_KEY "mapping_node"
 
 typedef enum {
        USE_AS_PORTABLE_STORAGE = 0,
@@ -82,4 +89,6 @@ void apply_theme_extension();
 Evas_Object* create_image(Evas_Object* parent, char* image_path);
 void load_font_color_table();
 
+void mapper_device_cb(int id, storage_dev_e dev, storage_state_e state, const char *fstype, const char *fsuuid, const char *mount_point, bool primary, int flags, void *user_data);
+
 #endif /* __EXTENDED_SD_MAIN_H__ */
index c13e210..01360d7 100644 (file)
@@ -43,7 +43,6 @@ struct proxy_node {
 static GList *proxy_pool;
 static pthread_mutex_t dmutex = PTHREAD_MUTEX_INITIALIZER;
 static int bus_init;
-static guint signal_id = 0;
 
 static int g_dbus_error_to_errno(int code)
 {
@@ -408,96 +407,4 @@ int dbus_method_async_with_reply(const char *dest, const char *path,
        pthread_mutex_unlock(&dmutex);
 
        return 0;
-}
-
-static GDBusConnection *get_dbus_connection(void)
-{
-       GError *err = NULL;
-       static GDBusConnection *conn;
-
-       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-       if (!conn) {
-               if (err)
-                       _D("Fail to get dbus connection: %s", err->message);
-               else
-                       _D("Fail to get dbus connection");
-               return NULL;
-       }
-
-       return conn;
-}
-
-static void storage_signal_callback(GDBusConnection *conn,
-               const gchar *sender,
-               const gchar *path,
-               const gchar *iface,
-               const gchar *signal,
-               GVariant *params,
-               gpointer user_data)
-{
-       size_t iface_len, signal_len;
-       appdata_s *ad = (appdata_s *)user_data;
-       int id;
-
-       if (!params || !sender || !path || !iface || !signal)
-               return;
-
-       iface_len = strlen(iface) + 1;
-       signal_len = strlen(signal) + 1;
-
-       if (strncmp(iface, STORAGED_INTERFACE_BLOCK_MANAGER, iface_len))
-               return;
-
-       if (strncmp(signal, "DeviceRemoved", signal_len))
-               return;
-
-       g_variant_get(params, "(issssssisibii)", NULL, NULL, NULL, NULL,
-                       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &id);
-       if (id == ad->storage_id) {
-               DMSG("Storage is removed");
-               ui_app_exit();
-       }
-}
-
-int register_signal_handler(appdata_s *ad)
-{
-       GDBusConnection *conn;
-
-       conn = get_dbus_connection();
-       if (!conn) {
-               _E("Failed to get dbus connection");
-               return -EPERM;
-       }
-
-       signal_id = g_dbus_connection_signal_subscribe(conn,
-                       NULL,
-                       STORAGED_INTERFACE_BLOCK_MANAGER,
-                       NULL,
-                       NULL,
-                       NULL,
-                       G_DBUS_SIGNAL_FLAGS_NONE,
-                       storage_signal_callback,
-                       ad,
-                       NULL);
-       if (signal_id == 0) {
-               _E("Failed to subscrive bus signal");
-               return -EPERM;
-       }
-
-       return 0;
-}
-
-int unregister_signal_handler()
-{
-       GDBusConnection *conn;
-
-       conn = get_dbus_connection();
-       if (!conn) {
-               _E("Failed to get dbus connection");
-               return -EPERM;
-       }
-
-       g_dbus_connection_signal_unsubscribe(conn, signal_id);
-
-       return 0;
-}
+}
\ No newline at end of file
index 5ebc14c..0be6fd9 100644 (file)
@@ -43,42 +43,36 @@ static Evas_Object* create_page_3(appdata_s* ad);
 static Evas_Object* create_page_4(appdata_s* ad);
 static Evas_Object* create_page_5(appdata_s* ad);
 
-static void
-format_done(void *data, GVariant *result, GError *err)
+void
+mapper_device_cb(int id, storage_dev_e dev, storage_state_e state,
+               const char *fstype, const char *fsuuide, const char *mount_point,
+               bool primary, int flags, void *user_data)
 {
-       appdata_s* ad = (appdata_s*)data;
-       char str_id[32];
-       char *arr[2];
-       int ret;
-
        FUNC_BEGIN();
+       appdata_s* ad = (appdata_s*)user_data;
+
        ret_if(ad == NULL);
-       ret_if(result == NULL);
 
-       g_variant_get(result, "(i)", &ret);
-       if (ret < 0) {
-               DMSG("Failed to format sd card as portable storage: %d", ret);
+       //TODO This supports only one extended internal storage and one sdcard slot.
+       // What if sdcard #1 is setting on extended internal storage,
+       // and another sdcard #2 is inserted and then #1 is removed?
+       if (dev != STORAGE_DEV_EXTENDED_INTERNAL) {
+               DMSG("Not mapper device");
                return;
        }
 
-       snprintf(str_id, sizeof(str_id), "%d", ad->storage_id);
-       arr[0] = str_id;
-       arr[1] = "ExtendedInternalSD";
-
-       ret = dbus_method_sync(STORAGED_BUS_NAME,
-                       STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "Mount", "is", arr);
-       if (ret < 0) {
-               DMSG("Failed to mount sd card as extended internal storage: %d", ret);
+       // Do not deal with STORAGE_STATE_UNMOUNTABLE. Because of Format operation also emits signals with STORAGE_STATE_UNMOUNTABLE.
+       if (state == STORAGE_STATE_REMOVED) {
+               DMSG("Storage is removed");
+               ui_app_exit();
+       } else if (state == STORAGE_STATE_UNMOUNTABLE)
                return;
-       }
 
        Evas_Object* page_content = elm_object_part_content_unset(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content");
        EVAS_OBJECT_DEL(page_content);
        page_content = create_page_5(ad);
        elm_object_part_content_set(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content", page_content);
 
-
-       g_variant_unref(result);
        FUNC_END();
 }
 
@@ -87,10 +81,8 @@ encryption_format(void *data)
 {
        FUNC_BEGIN();
 
+       app_control_h app_control = NULL;
        appdata_s* ad = (appdata_s*)data;
-       char str_id[32];
-       char str_option[32];
-       char *arr[3];
        int ret;
 
        ret_if(ad == NULL);
@@ -100,22 +92,26 @@ encryption_format(void *data)
        page_content = create_page_4(ad);
        elm_object_part_content_set(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content", page_content);
 
-       snprintf(str_id, sizeof(str_id), "%d", ad->storage_id);
-       arr[0] = str_id;
-       snprintf(str_option, sizeof(str_option), "%d", UNMOUNT_FORCE);
-       arr[1] = str_option;
-       arr[2] = "ext4";
-       ret = dbus_method_async_with_reply(STORAGED_BUS_NAME,
-                       STORAGED_PATH_BLOCK_MANAGER,
-                       STORAGED_INTERFACE_BLOCK_MANAGER,
-                       "FormatwithType",
-                       "iis",
-                       arr,
-                       format_done,
-                       120000,  // ms
-                       ad);
-       if (ret < 0)
-               DMSG("Failed to format", ret);
+       ret = app_control_create(&app_control);
+       if (ret != APP_CONTROL_ERROR_NONE)
+               return;
+
+       app_control_add_extra_data(app_control, VIEWTYPE_KEY, ENCRYPT_EXTENSION);
+       app_control_add_extra_data(app_control, DEVPATH_KEY, "/dev/mmcblk1");
+       app_control_add_extra_data(app_control, MAPPING_NODE_KEY, "extendedsd");
+       ret = app_control_set_app_id(app_control, SECURITY_APP_ID);
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               app_control_destroy(app_control);
+               return;
+       }
+
+       app_control_set_launch_mode(app_control, APP_CONTROL_LAUNCH_MODE_GROUP);
+
+       ret = app_control_send_launch_request(app_control, NULL, ad);
+       if (ret != APP_CONTROL_ERROR_NONE)
+               DMSG_ERR("app_control_send_launch_request() is failed err = %d", ret);
+
+       app_control_destroy(app_control);
 
        FUNC_END();
 }
@@ -210,6 +206,9 @@ _move_files_button_click_cb(void *data, Evas_Object* obj, void *event_info)
        }
 
        ret = app_control_send_launch_request(app_control, NULL, NULL);
+       if (ret != APP_CONTROL_ERROR_NONE)
+               DMSG_ERR("app_control_send_launch_request() is failed err = %d", ret);
+
        app_control_destroy(app_control);
 
        FUNC_END();
index 41a3141..0947fca 100644 (file)
@@ -128,6 +128,9 @@ _move_button_click_cb(void *data, Evas_Object* obj, void *event_info)
        }
 
        ret = app_control_send_launch_request(app_control, NULL, NULL);
+       if (ret != APP_CONTROL_ERROR_NONE)
+               DMSG_ERR("app_control_send_launch_request() is failed err = %d", ret);
+
        app_control_destroy(app_control);
 
        FUNC_END();
index d4065ea..e91db75 100644 (file)
@@ -72,6 +72,23 @@ app_create(void *data)
 }
 
 static void
+storage_removed_cb(int id, storage_state_e state, void *user_data)
+{
+       FUNC_BEGIN();
+
+       appdata_s *ad = (appdata_s *)user_data;
+
+       ret_if(ad == NULL);
+
+       if (id == ad->storage_id) {
+               DMSG("Storage is removed");
+               ui_app_exit();
+       }
+
+       FUNC_END();
+}
+
+static void
 app_control(app_control_h app_control, void *data)
 {
        /* Handle the launch request. */
@@ -82,20 +99,25 @@ app_control(app_control_h app_control, void *data)
        char *arr[1];
        int int_id;
        int ret;
-
        char *type = NULL;
        int len;
 
+       ret_if(ad == NULL);
+
        app_control_get_extra_data(app_control, POPUP_SDCARD_ID, &id);
        if (!id) {
                ad->storage_id = -1;
                DMSG("No sdcard id");
-               //temp
-       ad->storage_id = 1;
                return;
        }
        ad->storage_id = atoi(id);
-       register_signal_handler(ad);
+
+       ret = storage_set_state_changed_cb(ad->storage_id, storage_removed_cb, ad);
+       if (ret != STORAGE_ERROR_NONE) {
+               DMSG_ERR("Failed to register signal handler");
+               ui_app_exit();
+       }
+       ret = storage_set_changed_cb(STORAGE_TYPE_EXTENDED_INTERNAL, mapper_device_cb, ad);
 
        len = strlen(SETUP_EXTENDED) + 1;
        app_control_get_extra_data(app_control, SDCARD_SETUP_TYPE, &type);
@@ -146,10 +168,11 @@ app_terminate(void *data)
 {
        FUNC_BEGIN();
 
-       unregister_signal_handler();
        appdata_s* ad = (appdata_s*)data;
        ret_if(ad == NULL);
 
+       storage_unset_state_changed_cb(ad->storage_id, storage_removed_cb);
+
        FUNC_END();
 }
 
index 0ec0776..4b5f39a 100644 (file)
@@ -35,6 +35,7 @@ BuildRequires:        pkgconfig(capi-appfw-preference)
 BuildRequires: pkgconfig(capi-appfw-app-control)
 BuildRequires: pkgconfig(capi-system-system-settings)
 BuildRequires: pkgconfig(efl-extension)
+BuildRequires: pkgconfig(storage)
 
 #For /usr/bin/msgfmt
 BuildRequires: gettext-tools