capi-system-system-settings
efl-extension
capi-appfw-app-control
+ storage
)
FIND_LIBRARY(LIB_M m)
#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,
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__ */
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)
{
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
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();
}
{
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);
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();
}
}
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();
}
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();
}
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. */
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);
{
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();
}
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