Fix the bug in recieving files after interting mmc card 73/74973/1 accepted/tizen/common/20160617.121549 accepted/tizen/ivi/20160617.083953 accepted/tizen/mobile/20160617.083943 accepted/tizen/tv/20160617.083809 accepted/tizen/wearable/20160617.084013 submit/tizen/20160617.011759
authorDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 16 Jun 2016 07:42:42 +0000 (16:42 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 16 Jun 2016 07:42:42 +0000 (16:42 +0900)
Change-Id: Icaa5f25e3d67f2111622380519d1c307e274d6dd
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-share/include/bt-share-common.h
bt-share/include/bt-share-noti-handler.h
bt-share/src/bt-share-common.c
bt-share/src/bt-share-noti-handler.c
bt-share/src/obex-event-handler.c

index fa90dab..74961d6 100644 (file)
@@ -30,6 +30,26 @@ extern "C" {
 #define BT_SHARE_FAIL -1
 #define BT_SHARE_ERROR_NONE 0
 
+#define BT_DEFAULT_MEM_PHONE 0
+#define BT_DEFAULT_MEM_MMC 1
+
+#define STORAGE_PATH_LEN_MAX 255
+
+#define BT_DOWNLOAD_DEFAULT_PHONE_FOLDER "/opt/home/owner/content/Downloads"
+#define BT_DOWNLOAD_DEFAULT_MMC_FOLDER "/opt/media/SDCardA1"
+#define BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER "/opt/home/owner/content/Downloads"
+//#define BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER tzplatform_getenv(TZ_USER_CONTENT)
+
+/*
+#define BT_FTP_FOLDER tzplatform_mkpath(TZ_SYS_SHARE, "bt-ftp")
+*/
+
+#define BT_DOWNLOAD_PHONE_ROOT "/opt/home/owner/content/"
+#define BT_DOWNLOAD_MMC_ROOT "/opt/media/SDCardA1"
+#define BT_FTP_FOLDER "/opt/share/bt-ftp"
+#define BT_FTP_FOLDER_PHONE "/opt/share/bt-ftp/Media/"
+#define BT_FTP_FOLDER_MMC "/opt/share/bt-ftp/SD_External/"
+
 //#define BT_TMP_DIR "/opt/home/owner/content/Downloads/.bluetooth/"
 #define BT_TMP_DIR "/opt/home/owner/content/Downloads/"
 #define BT_TMP_FILE BT_TMP_DIR"bluetooth_content_share"
@@ -60,6 +80,7 @@ int _bt_set_transfer_indicator(gboolean state);
 char *_bt_share_create_transfer_file(char *text);
 void _bt_remove_tmp_file(char *file_path);
 void _bt_remove_vcf_file(char *file_path);
+char *_bt_share_get_storage_path(int storage_type);
 
 #ifdef __cplusplus
 }
index 1d3c0b2..560e473 100644 (file)
 extern "C" {
 #endif
 
-#define STORAGE_PATH_LEN_MAX 255
-#define BT_DEFAULT_MEM_PHONE 0
-#define BT_DEFAULT_MEM_MMC 1
-
-#define BT_DOWNLOAD_DEFAULT_PHONE_FOLDER "/opt/usr/media/Downloads"
-#define BT_DOWNLOAD_DEFAULT_MMC_FOLDER "/opt/storage/sdcard/Downloads"
-#define BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER "/opt/home/owner/content/Downloads"
-//#define BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER tzplatform_getenv(TZ_USER_CONTENT)
-
-/*
-#define BT_FTP_FOLDER tzplatform_mkpath(TZ_SYS_SHARE, "bt-ftp")
-*/
-
-#define BT_DOWNLOAD_PHONE_ROOT "/opt/usr/media"
-#define BT_DOWNLOAD_MMC_ROOT "/opt/storage/sdcard"
-#define BT_FTP_FOLDER "/opt/share/bt-ftp"
-#define BT_FTP_FOLDER_PHONE "/opt/share/bt-ftp/Media/"
-#define BT_FTP_FOLDER_MMC "/opt/share/bt-ftp/SD_External/"
-
 void _bt_init_vconf_notification(void *data);
 void _bt_deinit_vconf_notification(void);
 #ifdef __cplusplus
index c762d93..1041c7a 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/types.h>
 #include <sys/xattr.h>
 #include <linux/xattr.h>
+#include <storage.h>
 
 #include "vconf-keys.h"
 #include "applog.h"
@@ -247,3 +248,45 @@ fail:
        return NULL;
 }
 
+static bool __bt_get_storage_id(int sid, storage_type_e type, storage_state_e state,
+               const char *path, void *user_data)
+{
+       int *storage_id = (int *)user_data;
+
+       if (type == STORAGE_TYPE_EXTERNAL && state == STORAGE_STATE_MOUNTED) {
+               *storage_id = sid;
+               return false;
+       }
+       return true;
+}
+
+char *_bt_share_get_storage_path(int storage_type)
+{
+       int ret = 0;
+       int storage_id = 0;
+       char *path = NULL;
+
+       DBG("storage type: %d", storage_type);
+
+       if (storage_type == BT_DEFAULT_MEM_MMC) {
+               if (storage_foreach_device_supported(__bt_get_storage_id,
+                                               &storage_id) == STORAGE_ERROR_NONE) {
+                       DBG("storage_id = %d", storage_id);
+
+                       ret = storage_get_root_directory(storage_id, &path);
+
+                       if (ret != STORAGE_ERROR_NONE)
+                               DBG("Fail to get the download path: %d", ret);
+               }
+
+               if (path == NULL) {
+                       DBG("Fail to get the download path. So use media folder");
+                       path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
+               }
+       } else {
+               path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
+       }
+
+       return path;
+}
+
index 5b8c994..5d3df44 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "applog.h"
 #include "bluetooth-api.h"
+#include "bt-share-common.h"
 #include "bt-share-noti-handler.h"
 #include "bt-share-main.h"
 #include "obex-event-handler.h"
@@ -35,7 +36,6 @@
 
 static void __bt_default_memory_changed_cb(keynode_t *node, void *data)
 {
-       int ret;
        int default_memory = 0;
        char *root_path = NULL;
        char *download_path = NULL;
@@ -51,22 +51,14 @@ static void __bt_default_memory_changed_cb(keynode_t *node, void *data)
                default_memory = vconf_keynode_get_int(node);
 
                if (default_memory == BT_DEFAULT_MEM_MMC) /* MMC */ {
-                       ret = storage_get_directory(STORAGE_TYPE_EXTERNAL,
-                                               STORAGE_DIRECTORY_DOWNLOADS, &download_path);
-
-                       if (ret != STORAGE_ERROR_NONE)
-                               DBG("Fail to get the download path: %d", ret);
-
-                       ret = storage_get_root_directory(STORAGE_TYPE_EXTERNAL, &root_path);
-
-                       if (ret != STORAGE_ERROR_NONE)
-                               DBG("Fail to get the root path: %d", ret);
+                       download_path = _bt_share_get_storage_path(default_memory);
+                       root_path = _bt_share_get_storage_path(default_memory);
 
                        if (download_path == NULL)
-                               download_path = g_strdup(BT_DOWNLOAD_DEFAULT_MMC_FOLDER);
+                               download_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
 
                        if (root_path == NULL)
-                               root_path = g_strdup(BT_DOWNLOAD_DEFAULT_MMC_FOLDER);
+                               root_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
 
                } else {
                        download_path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
index fde3f89..c377993 100644 (file)
@@ -691,7 +691,6 @@ void _bt_share_event_handler(int event, bluetooth_event_param_t *param,
 void _bt_get_default_storage(char *storage)
 {
        int val = BT_DEFAULT_MEM_PHONE;
-       int ret = 0;
        char *path = NULL;
 
        if (vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
@@ -700,18 +699,10 @@ void _bt_get_default_storage(char *storage)
                val = BT_DEFAULT_MEM_PHONE;
        }
 
-       if (val == BT_DEFAULT_MEM_MMC) {
-               ret = storage_get_directory(STORAGE_TYPE_EXTERNAL,
-                                       STORAGE_DIRECTORY_DOWNLOADS, &path);
-
-       if (ret != STORAGE_ERROR_NONE)
-               DBG("Fail to get the download path: %d", ret);
+       path = _bt_share_get_storage_path(val);
 
        if (path == NULL)
-               path = g_strdup(BT_DOWNLOAD_DEFAULT_MMC_FOLDER);
-       } else {
                path = g_strdup(BT_DOWNLOAD_DEFAULT_MEDIA_FOLDER);
-       }
 
        g_strlcpy(storage, path, STORAGE_PATH_LEN_MAX);
        g_free(path);
@@ -770,15 +761,21 @@ static int __bt_get_available_int_memory(double *dAvail)
        return r;
 }
 
-static gboolean __bt_get_available_ext_memory(unsigned long long *available_mem_size)
+static int __bt_get_available_ext_memory(double *dAvail)
 {
-       struct statfs fs = {0, };
-       if (statfs(BT_DOWNLOAD_MMC_ROOT, &fs) != 0) {
-               *available_mem_size = 0;
-               return FALSE;
+       struct statvfs s;
+       int r;
+
+       r = storage_get_internal_memory_size(&s);
+       if (r < 0)
+               ERR("ret : %d", r);
+       else {
+               INFO("total : %lf, avail : %lf",
+               (double)s.f_frsize*s.f_blocks, (double)s.f_bsize*s.f_bavail);
+               *dAvail = (double)s.f_bsize*s.f_bavail;
        }
-       *available_mem_size = ((unsigned long long)fs.f_bavail) * ((unsigned long long)fs.f_bsize);
-       return TRUE;
+
+       return r;
 }
 
 static gchar *__bt_get_unique_file_name(char *storage_path, char *filename)
@@ -870,9 +867,7 @@ static void __bt_obex_file_push_auth(bt_obex_server_authorize_into_t *server_aut
        DBG("+");
 
        int val = -1;
-       gboolean ret = FALSE;
-       unsigned long long available_ext_mem_size = 0;
-       double available_int_mem_size = 0;
+       double available_mem_size = 0;
 
        if (vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT,
                                (void *)&val)) {
@@ -883,27 +878,25 @@ static void __bt_obex_file_push_auth(bt_obex_server_authorize_into_t *server_aut
        INFO("File Length = %ld", server_auth_info->length);
 
        if (val == BT_DEFAULT_MEM_MMC) {
-               ret = __bt_get_available_ext_memory(&available_ext_mem_size);
-               if (ret == FALSE) {
+               if (__bt_get_available_ext_memory(&available_mem_size) < 0) {
                        ERR("Unable to get available memory size");
                        goto reject;
                }
-
-               INFO("available_ext_mem_size =%llu", available_ext_mem_size);
-               if (available_ext_mem_size < server_auth_info->length) {
+               INFO("available_ext_mem_size =%llu", available_mem_size);
+               if (available_mem_size < server_auth_info->length) {
                        g_timeout_add(BT_APP_POPUP_LAUNCH_TIMEOUT,
                                (GSourceFunc)_bt_app_popup_memoryfull,
                                NULL);
                        goto reject;
                }
        } else {
-               if (__bt_get_available_int_memory(&available_int_mem_size) < 0) {
+               if (__bt_get_available_int_memory(&available_mem_size) < 0) {
                        ERR("Unable to get available memory size");
                        goto reject;
                }
 
-               INFO("available_int_mem_size =%lf", available_ext_mem_size);
-               if (available_int_mem_size < server_auth_info->length) {
+               INFO("available_int_mem_size =%lf", available_mem_size);
+               if (available_mem_size < server_auth_info->length) {
                        g_timeout_add(BT_APP_POPUP_LAUNCH_TIMEOUT,
                                (GSourceFunc)_bt_app_popup_memoryfull,
                                NULL);