Fixing SD Card removal issues 16/91916/4
authorbhutani.92 <bhutani.92@samsung.com>
Wed, 12 Oct 2016 07:33:51 +0000 (13:03 +0530)
committerbhutani.92 <bhutani.92@samsung.com>
Thu, 13 Oct 2016 10:55:22 +0000 (16:25 +0530)
Change-Id: I53e5b755dc2f4d8e738eb4bbdea01ce4b360805c
Signed-off-by: bhutani.92 <bhutani.92@samsung.com>
inc/mp-common-defs.h
music-chooser/src/mc-common.c
src/common/include/mp-info-define.h
src/common/include/mp-util.h
src/common/mp-app.c
src/common/mp-play.c
src/common/mp-util.c
src/core/mp-playlist-mgr.c
src/include/music.h
src/view/mp-detail-view.c
src/widget/mp-folder-list.c

index ddc52d14d2fc0059138ac8e5f7bc650a7a2db215..e11004de2ff9c34ca2b16e8de2261bb3cf3f4d5a 100755 (executable)
 #ifndef __MP_COMMON_DEFS_H__
 #define __MP_COMMON_DEFS_H__
 
+#include <storage/storage.h>
+#include <glib.h>
+#include "mp-player-debug.h"
+
 #define MP_B_PATH "path"
 #define MP_MM_KEY "multimedia_key"
 #define MP_PLAY_RECENT "play_recent"
 #define MC_SHOW_VAL            "show"
 #define MC_HIDE_VAL            "hide"
 
-
+typedef enum {
+       DEVICE,
+       MMC
+}storage_mode_e;
 
 //1 Do not change default thumbnail path. it's shared by other apps
 #define DEFAULT_THUMBNAIL                              "default_album_art_120.png"
@@ -118,11 +125,58 @@ typedef enum {
 
 #define FACTORY_MUSIC "/opt/usr/media/Sounds/Over the horizon.mp3"
 
-#define MP_PHONE_ROOT_PATH        "/opt/usr/media"
-#define MP_MMC_ROOT_PATH               "/opt/storage/sdcard"
-
-#define CONTROLLER_REW_SOURCE "control_previous"
-#define CONTROLLER_FF_SOURCE "control_next"
+static int device_id = -1;
+static int mmc_id = -1;
+
+static void mp_lower_string(char *str) {
+       int i = 0;
+       while(str[i] != '\0') {
+               if (str[i] >= 'A' && str[i] <= 'Z') {
+                       str[i] = str[i] + 32;
+               }
+       i++;
+       }
+}
+
+static bool __mp_get_all_supported_storage_cb(int storageId, storage_type_e type, storage_state_e state, const char *path, void *userData)
+{
+       char *temp_path = g_strdup(path);
+       mp_lower_string(temp_path);
+       if (type == STORAGE_TYPE_EXTERNAL && strstr(temp_path, "sdcard")) {
+               mmc_id = storageId;
+       }
+       if (type == STORAGE_TYPE_INTERNAL) {
+               device_id = storageId;
+       }
+       if (temp_path) {
+               g_free(temp_path);
+       }
+       return true;
+}
+
+static inline char *Get_Root_Path(int storage_type, storage_mode_e smode)
+{
+       char *path = NULL;
+       int error_code = storage_foreach_device_supported(__mp_get_all_supported_storage_cb, NULL);
+       if (error_code != STORAGE_ERROR_NONE) {
+               ERROR_TRACE("failed to get storage Id");
+               return NULL;
+       }
+       if (smode == DEVICE && device_id != -1) {
+               storage_get_root_directory(device_id, &path);
+       } else if (smode == MMC && mmc_id != -1) {
+               storage_get_root_directory(mmc_id, &path);
+       } else {
+               ERROR_TRACE("Invalid storage Id");
+               return NULL;
+       }
+       return path;
+}
+
+#define MP_PHONE_ROOT_PATH             Get_Root_Path(STORAGE_TYPE_INTERNAL, DEVICE);
+#define MP_MMC_ROOT_PATH               Get_Root_Path(STORAGE_TYPE_EXTERNAL, MMC)
+#define CONTROLLER_REW_SOURCE  "control_previous"
+#define CONTROLLER_FF_SOURCE   "control_next"
 
 #define PLAY_TIME_ARGS(t) \
         (((int)(t)) / 60) % 60, \
index 441e21d767dc36a676c748999683322c8f54bd10..9cb76c378359f5ecac156b4bd2a2801335144862 100755 (executable)
@@ -29,8 +29,8 @@
 
 #define MC_FILE_PREFIX "file://"
 
-static int externalStorageId = -1;
 bool detail_view = false;
+static external_mmc_id = -1;
 
 static Eina_Bool
 _back_cb(void *data, Elm_Object_Item *it)
@@ -190,7 +190,7 @@ bool mc_is_call_connected(void)
 bool mc_get_supported_storages_callback(int storageId, storage_type_e type, storage_state_e state, const char *path, void *userData)
 {
        if (type == STORAGE_TYPE_EXTERNAL) {
-               externalStorageId = storageId;
+               external_mmc_id = storageId;
                return false;
        }
        return true;
@@ -201,7 +201,7 @@ bool mc_is_mmc_removed(void)
        int error = storage_foreach_device_supported(mc_get_supported_storages_callback, NULL);
        if (error == STORAGE_ERROR_NONE) {
                storage_state_e state;
-               storage_get_state(externalStorageId, &state);
+               storage_get_state(external_mmc_id, &state);
                if (state == STORAGE_STATE_REMOVED) {
                        return true;
                }
index 42e95420de7d4ea0a56de72c584fa1b8bf72d02c..49c9b9d7fcc8183fa7aee078e34e7a0334163e26 100755 (executable)
@@ -47,9 +47,6 @@
 #define TITLE_H 90
 #define START_Y_POSITION       94
 
-#define MP_PHONE_ROOT_PATH        "/opt/usr/media"
-#define MP_MMC_ROOT_PATH               "/opt/storage/sdcard"
-
 #ifndef FALSE
 #define FALSE  0
 #endif
index 29e5f3c1ce95aa274906675993e10fd338976a7e..82dc0ec502369c1641f877d4075c3d9cd8e9674f 100755 (executable)
@@ -56,6 +56,7 @@ enum {
 #define PREF_SOUND_PLAYER_LAUNCH "preference/org.tizen.sound-player/launch_state"
 #define PREF_MUSIC_PLAYER_LAUNCH "preference/org.tizen.music-player/launch_state"
 
+void mp_to_lower(char *str);
 int mp_setting_get_nowplaying_id(void);
 bool                   mp_util_is_streaming(const char *uri);
 bool                    mp_util_text_multiline_check(Evas_Object *obj,const char*text, const char*textstyle, int text_width, int text_height);
index 32d2e4fc5c2940d429083e4ad3487a13c702afd8..2e3b2e71943fde1b1c840cbbe6745e76d6a9c4e2 100755 (executable)
@@ -176,6 +176,8 @@ _mp_app_noti_key_changed_cb(const char *key, void *data)
 
 }
 
+static bool __mp_get_supported_storage_cb();
+
 void
 _mp_app_storage_state_changed_cb(int storage_id, storage_state_e state, void *user_data)
 {
@@ -183,6 +185,7 @@ _mp_app_storage_state_changed_cb(int storage_id, storage_state_e state, void *us
 
        struct appdata *ad = (struct appdata *)user_data;
        MP_CHECK(ad);
+       char *path = NULL;
        ad->is_sdcard_removed = true;
        if (state == STORAGE_STATE_REMOVED) {
                mp_view_mgr_post_event(GET_VIEW_MGR, MP_MMC_REMOVED);
@@ -190,10 +193,13 @@ _mp_app_storage_state_changed_cb(int storage_id, storage_state_e state, void *us
                mp_common_force_close_delete();
 #endif
        } else if (state == STORAGE_STATE_UNMOUNTABLE) {
-               if (strstr(ad->current_track_info->uri, MP_MMC_ROOT_PATH)
-                       == ad->current_track_info->uri) {
+               char *mmc_path = MP_MMC_ROOT_PATH;
+               if (mmc_path && ad->current_track_info && ad->current_track_info->uri && (strstr(ad->current_track_info->uri, mmc_path)
+                       == ad->current_track_info->uri)) {
+                       IF_FREE(mmc_path);
                        mp_play_next_and_updateview(ad);
                } else {
+                       IF_FREE(mmc_path);
                        mp_view_mgr_post_event(GET_VIEW_MGR, MP_MMC_REMOVED);
 #ifndef MP_SOUND_PLAYER
                        mp_common_force_close_delete();
@@ -433,7 +439,7 @@ bool mp_app_get_supported_storages_callback(int storageId, storage_type_e type,
 {
        if (type == STORAGE_TYPE_EXTERNAL) {
                struct appdata *ad = (struct appdata *)userData;
-               ad->externalStorageId = storageId;
+               ad->mmc_id = storageId;
                return false;
        }
        return true;
@@ -448,7 +454,7 @@ mp_app_noti_init(void *data)
        int error = storage_foreach_device_supported(mp_app_get_supported_storages_callback, ad);
        if (error == STORAGE_ERROR_NONE) {
                storage_state_e state;
-               storage_get_state(ad->externalStorageId, &state);
+               storage_get_state(ad->mmc_id, &state);
        }
        ad->idle_unlocked = false;
        bool res = TRUE;
@@ -470,7 +476,7 @@ mp_app_noti_init(void *data)
        free(path);
        ecore_file_monitor_add(now_playing_id, mp_app_now_playing_id_changed_cb, ad);
 
-       if (storage_set_state_changed_cb(ad->externalStorageId, _mp_app_storage_state_changed_cb, ad) < 0) {
+       if (storage_set_state_changed_cb(ad->mmc_id, _mp_app_storage_state_changed_cb, ad) < 0) {
                ERROR_TRACE("Fail to register storage state changed callback");
                res = FALSE;
        }
@@ -523,7 +529,7 @@ mp_app_noti_ignore(void *data)
                return FALSE;
        }
 
-       if (storage_unset_state_changed_cb(ad->externalStorageId, _mp_app_storage_state_changed_cb) != STORAGE_ERROR_NONE) {
+       if (storage_unset_state_changed_cb(ad->mmc_id, _mp_app_storage_state_changed_cb) != STORAGE_ERROR_NONE) {
                ERROR_TRACE("Error when ignore callback");
                return FALSE;
        }
index d8c73f3282627a9d4457f2283a26485b12a2492b..b19bca66a88abc6183bf4a18776ac72cc147ffdf 100755 (executable)
@@ -507,7 +507,6 @@ mp_play_start(void *data)
        ad->music_length = mp_player_mgr_get_duration() / 1000.0;
        ad->player_state = PLAY_STATE_PLAYING;
 
-
        if (!ad->noti) {
                DEBUG_TRACE("notification create");
 
@@ -572,10 +571,6 @@ mp_play_start(void *data)
        if (mp_view_mgr_count_view(GET_VIEW_MGR) == 0) {
                mp_common_create_initial_view(ad, NULL, NULL);
                evas_object_show(ad->win_main);
-               elm_win_iconified_set(ad->win_main, EINA_TRUE);
-               elm_win_lower(ad->win_main);
-               ad->app_is_foreground = false;
-               ad->is_focus_out = true;
        }
 
        if (ad->create_view_on_play) {
index 43822d9a64f62259d48763292af681c74379ad39..98d6b6f41ab9b1b79d9ca8c0f34ee4d8081b0ef4 100755 (executable)
@@ -49,8 +49,8 @@
 bool track_deleted = false;
 #define SINGLE_BYTE_MAX 0x7F
 #define PATH_MAX 4096
-static int externalStorageId = -1;
-static int internalStorageId = -1;
+static int external_mmc_id = -1;
+static int internal_device_id = -1;
 
 struct index_s {
        const char *index;
@@ -539,9 +539,16 @@ int
 mp_util_file_is_in_phone_memory(const char *path)
 {
        MP_CHECK_VAL(path, 0);
-       if (!strncmp(MP_PHONE_ROOT_PATH, path, strlen(MP_PHONE_ROOT_PATH))) {
+       int phone_len = 0;
+       char *phone_path = MP_PHONE_ROOT_PATH;
+       if (phone_path) {
+               phone_len = strlen(phone_path);
+       }
+       if (!strncmp(phone_path, path, strlen(phone_path))) {
+               IF_FREE(phone_path);
                return 1;
        } else {
+               IF_FREE(phone_path);
                return 0;
        }
 }
@@ -625,6 +632,16 @@ mp_util_is_streaming(const char *uri)
        }
 }
 
+void mp_to_lower(char *str) {
+       int i = 0;
+       while(str[i] != '\0') {
+               if (str[i] >= 'A' && str[i] <= 'Z') {
+                       str[i] = str[i] + 32;
+               }
+       i++;
+       }
+}
+
 bool
 mp_check_file_exist(const char *path)
 {
@@ -634,10 +651,14 @@ mp_check_file_exist(const char *path)
 
        bool mmc_removed = mp_util_is_mmc_removed();
 
-       if (mmc_removed && strstr(path, MP_MMC_ROOT_PATH) == path) {
+       char *temp_path = g_strdup(path);
+       mp_to_lower(temp_path);
+       if (mmc_removed && strstr(temp_path, "sdcard") == path) {
+               IF_G_FREE(temp_path);
                return false;
        }
 
+       IF_G_FREE(temp_path);
        if (strstr(path, MP_FILE_PREFIX)) {
                if (!g_file_test(path + strlen(MP_FILE_PREFIX), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
                        ERROR_TRACE("file not exist: %s", path);
@@ -2120,7 +2141,7 @@ void mp_util_item_domain_translatable_part_text_set(Elm_Object_Item *item, const
 bool mp_util_get_supported_storages_callback(int storageId, storage_type_e type, storage_state_e state, const char *path, void *userData)
 {
        if (type == STORAGE_TYPE_EXTERNAL) {
-               externalStorageId = storageId;
+               external_mmc_id = storageId;
                return false;
        }
        return true;
@@ -2131,7 +2152,7 @@ bool mp_util_is_mmc_removed(void)
        int error = storage_foreach_device_supported(mp_util_get_supported_storages_callback, NULL);
        if (error == STORAGE_ERROR_NONE) {
                storage_state_e state;
-               storage_get_state(externalStorageId, &state);
+               storage_get_state(external_mmc_id, &state);
                if (state == STORAGE_STATE_REMOVED || state == STORAGE_STATE_UNMOUNTABLE) {
                        return true;
                }
@@ -2530,10 +2551,10 @@ mp_util_media_is_uhqa(const char *media_id)
 static bool __mp_get_all_supported_storageids_cb(int storageId, storage_type_e type, storage_state_e state, const char *path, void *userData)
 {
        if (type == STORAGE_TYPE_EXTERNAL) {
-               externalStorageId = storageId;
+               external_mmc_id = storageId;
        }
        if (type == STORAGE_TYPE_INTERNAL) {
-               internalStorageId = storageId;
+               internal_device_id = storageId;
        }
 
        return true;
@@ -2546,10 +2567,10 @@ char *mp_get_media_directory(storage_type_e storage_type) {
                ERROR_TRACE("Failed to get Storage Id");
                return NULL;
        }
-       if (storage_type == STORAGE_TYPE_INTERNAL && internalStorageId != -1) {
-               storage_get_root_directory(internalStorageId, &path);
-       } else if (storage_type == STORAGE_TYPE_EXTERNAL && externalStorageId != -1) {
-               storage_get_root_directory(externalStorageId, &path);
+       if (storage_type == STORAGE_TYPE_INTERNAL && internal_device_id != -1) {
+               storage_get_root_directory(internal_device_id, &path);
+       } else if (storage_type == STORAGE_TYPE_EXTERNAL && external_mmc_id != -1) {
+               storage_get_root_directory(external_mmc_id, &path);
        } else {
                ERROR_TRACE("Invalid Storage Id");
                return NULL;
index 3e3c6295b7a8ff7555ffbe2586f046a5644eab5e..3261c99b3e48437937270bbc00917e97dbc1f918 100755 (executable)
@@ -941,7 +941,9 @@ void mp_playlist_mgr_check_existance_and_refresh(mp_plst_mgr *playlist_mgr, bool
                if (item) {
                        if (item->uri && item->track_type == MP_TRACK_URI && !mp_util_is_streaming(item->uri)) {
                                SECURE_DEBUG("uri = %s", item->uri);
-                               if (!mp_file_exists(item->uri) || (mmc_removed && strstr(item->uri, MP_MMC_ROOT_PATH) == item->uri)) {
+                               char *temp_uri = g_strdup(item->uri);
+                               mp_to_lower(temp_uri);
+                               if (!mp_file_exists(item->uri) || (mmc_removed && strstr(temp_uri, "sdcard") == item->uri)) {
                                        SECURE_DEBUG("removed uri = %s", item->uri);
                                        mp_playlist_mgr_item_remove_item(playlist_mgr, item);
                                        if (current_removed && cur == item) {
@@ -949,6 +951,7 @@ void mp_playlist_mgr_check_existance_and_refresh(mp_plst_mgr *playlist_mgr, bool
                                                *current_removed = true;
                                        }
                                }
+                               IF_G_FREE(temp_uri);
                        }
                }
                list = list->next;
index 87e4a3035ed9b1da049e95680d25422a1f8410c6..2dba00d48502b99181a7e9d0d918f27c04fbf300 100755 (executable)
@@ -490,7 +490,7 @@ struct appdata
        Ecore_Timer *app_control_check_timer;
 
        bool prepare_by_init; //to indicate if player created and prepared to ready state  in init idler
-       int externalStorageId;
+       int mmc_id;
        app_event_low_battery_status_e low_battery_status;
 };
 
index bd5d8d2471a3851a8dc8ca09679f2ae12164f065..51368249f456e7e80773397eb82ddf8a38a6a92c 100755 (executable)
@@ -51,17 +51,29 @@ _mp_detail_view_get_location_info_from_file_path(char *file_path)
        mp_retvm_if(!file_path, NULL, "File path is null...");
 
        int prefix_pos;
-       if (!strncmp(file_path, MP_PHONE_ROOT_PATH, strlen(MP_PHONE_ROOT_PATH))) {
-               prefix_pos = strlen(MP_PHONE_ROOT_PATH);
+       int phone_len = 0;
+       int mmc_len = 0;
+       char *phone_path = MP_PHONE_ROOT_PATH;
+       char *mmc_path = MP_MMC_ROOT_PATH;
+       if (!strncmp(file_path, phone_path, phone_len)) {
+               prefix_pos = phone_len;
+               IF_FREE(phone_path);
+               IF_FREE(mmc_path);
                return g_strdup_printf("Device memory%s", file_path + prefix_pos);
-       } else if (!strncmp(file_path, MP_MMC_ROOT_PATH, strlen(MP_MMC_ROOT_PATH))) {
-               prefix_pos = strlen(MP_MMC_ROOT_PATH);
+       } else if (!strncmp(file_path, mmc_path, mmc_len)) {
+               prefix_pos = mmc_len;
+               IF_FREE(phone_path);
+               IF_FREE(mmc_path);
                return g_strdup_printf("SD card%s", file_path + prefix_pos);
        } else if (!strncmp(file_path, "/mnt/mmc", strlen("/mnt/mmc"))) {
                prefix_pos = strlen("/mnt/mmc");
+               IF_FREE(phone_path);
+               IF_FREE(mmc_path);
                return g_strdup_printf("Memory%s", file_path + prefix_pos);
        } else {
                WARN_TRACE("Unable to get proper location...");
+               IF_FREE(phone_path);
+               IF_FREE(mmc_path);
                return strdup(file_path);
        }
 }
index 8a3a0a566a6afc5b8f4295680a045f63166ca193..88ec9152049f2f8d7344144e5d8312303f9aef47 100755 (executable)
@@ -179,14 +179,26 @@ _mp_folder_list_icon_get(void *data, Evas_Object * obj, const char *part)
                mp_retvm_if((ret != 0), NULL, "Fail to get value");
                if (folder) {
                        const char *icon_path = NULL;
-                       if (g_strstr_len(folder, strlen(MP_PHONE_ROOT_PATH), MP_PHONE_ROOT_PATH)) {
+                       int phone_len = 0;
+                       int mmc_len = 0;
+                       char *phone_path = MP_PHONE_ROOT_PATH;
+                       char *mmc_path = MP_MMC_ROOT_PATH;
+                       if (phone_path) {
+                               phone_len = strlen(phone_path);
+                       }
+                       if (mmc_path) {
+                               mmc_len = strlen(mmc_path);
+                       }
+                       if (g_strstr_len(folder, phone_len, phone_path)) {
                                icon_path = MP_ICON_STORAGE_PHONE;
-                       } else if (g_strstr_len(folder, strlen(MP_MMC_ROOT_PATH), MP_MMC_ROOT_PATH)) {
+                       } else if (g_strstr_len(folder, mmc_len, mmc_path)) {
                                icon_path = MP_ICON_STORAGE_MEMORY;
                        } else {
                                icon_path = MP_ICON_STORAGE_EXTERNAL;
                        }
 
+                       IF_FREE(phone_path);
+                       IF_FREE(mmc_path);
                        storage_icon = elm_icon_add(obj);
                        MP_CHECK_NULL(storage_icon);
                        elm_image_file_set(storage_icon, IMAGE_EDJ_NAME, icon_path);
@@ -218,14 +230,26 @@ _mp_folder_list_icon_get(void *data, Evas_Object * obj, const char *part)
                mp_retvm_if((ret != 0), NULL, "Fail to get value");
                if (folder) {
                        const char *icon_path = NULL;
-                       if (g_strstr_len(folder, strlen(MP_PHONE_ROOT_PATH), MP_PHONE_ROOT_PATH)) {
+                       int phone_len = 0;
+                       int mmc_len = 0;
+                       char *phone_path = MP_PHONE_ROOT_PATH;
+                       char *mmc_path = MP_MMC_ROOT_PATH;
+                       if (phone_path) {
+                               phone_len = strlen(phone_path);
+                       }
+                       if (mmc_path) {
+                               mmc_len = strlen(mmc_path);
+                       }
+                       if (g_strstr_len(folder, phone_len, phone_path)) {
                                icon_path = MP_ICON_STORAGE_PHONE;
-                       } else if (g_strstr_len(folder, strlen(MP_MMC_ROOT_PATH), MP_MMC_ROOT_PATH)) {
+                       } else if (g_strstr_len(folder, mmc_len, mmc_path)) {
                                icon_path = MP_ICON_STORAGE_MEMORY;
                        } else {
                                icon_path = MP_ICON_STORAGE_EXTERNAL;
                        }
 
+                       IF_FREE(phone_path);
+                       IF_FREE(mmc_path);
                        icon = elm_icon_add(obj);
                        MP_CHECK_NULL(icon);
                        elm_image_file_set(icon, IMAGE_EDJ_NAME, icon_path);