From f7067d9fddff013cfbadbbbb8df9f9c92d89c2b7 Mon Sep 17 00:00:00 2001 From: "bhutani.92" Date: Wed, 12 Oct 2016 13:03:51 +0530 Subject: [PATCH] Fixing SD Card removal issues Change-Id: I53e5b755dc2f4d8e738eb4bbdea01ce4b360805c Signed-off-by: bhutani.92 --- inc/mp-common-defs.h | 66 ++++++++++++++++++++++++++--- music-chooser/src/mc-common.c | 6 +-- src/common/include/mp-info-define.h | 3 -- src/common/include/mp-util.h | 1 + src/common/mp-app.c | 18 +++++--- src/common/mp-play.c | 5 --- src/common/mp-util.c | 45 ++++++++++++++------ src/core/mp-playlist-mgr.c | 5 ++- src/include/music.h | 2 +- src/view/mp-detail-view.c | 20 +++++++-- src/widget/mp-folder-list.c | 32 ++++++++++++-- 11 files changed, 158 insertions(+), 45 deletions(-) diff --git a/inc/mp-common-defs.h b/inc/mp-common-defs.h index ddc52d1..e11004d 100755 --- a/inc/mp-common-defs.h +++ b/inc/mp-common-defs.h @@ -18,6 +18,10 @@ #ifndef __MP_COMMON_DEFS_H__ #define __MP_COMMON_DEFS_H__ +#include +#include +#include "mp-player-debug.h" + #define MP_B_PATH "path" #define MP_MM_KEY "multimedia_key" #define MP_PLAY_RECENT "play_recent" @@ -59,7 +63,10 @@ #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, \ diff --git a/music-chooser/src/mc-common.c b/music-chooser/src/mc-common.c index 441e21d..9cb76c3 100755 --- a/music-chooser/src/mc-common.c +++ b/music-chooser/src/mc-common.c @@ -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; } diff --git a/src/common/include/mp-info-define.h b/src/common/include/mp-info-define.h index 42e9542..49c9b9d 100755 --- a/src/common/include/mp-info-define.h +++ b/src/common/include/mp-info-define.h @@ -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 diff --git a/src/common/include/mp-util.h b/src/common/include/mp-util.h index 29e5f3c..82dc0ec 100755 --- a/src/common/include/mp-util.h +++ b/src/common/include/mp-util.h @@ -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); diff --git a/src/common/mp-app.c b/src/common/mp-app.c index 32d2e4f..2e3b2e7 100755 --- a/src/common/mp-app.c +++ b/src/common/mp-app.c @@ -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; } diff --git a/src/common/mp-play.c b/src/common/mp-play.c index d8c73f3..b19bca6 100755 --- a/src/common/mp-play.c +++ b/src/common/mp-play.c @@ -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) { diff --git a/src/common/mp-util.c b/src/common/mp-util.c index 43822d9..98d6b6f 100755 --- a/src/common/mp-util.c +++ b/src/common/mp-util.c @@ -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; diff --git a/src/core/mp-playlist-mgr.c b/src/core/mp-playlist-mgr.c index 3e3c629..3261c99 100755 --- a/src/core/mp-playlist-mgr.c +++ b/src/core/mp-playlist-mgr.c @@ -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; diff --git a/src/include/music.h b/src/include/music.h index 87e4a30..2dba00d 100755 --- a/src/include/music.h +++ b/src/include/music.h @@ -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; }; diff --git a/src/view/mp-detail-view.c b/src/view/mp-detail-view.c index bd5d8d2..5136824 100755 --- a/src/view/mp-detail-view.c +++ b/src/view/mp-detail-view.c @@ -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); } } diff --git a/src/widget/mp-folder-list.c b/src/widget/mp-folder-list.c index 8a3a0a5..88ec915 100755 --- a/src/widget/mp-folder-list.c +++ b/src/widget/mp-folder-list.c @@ -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); -- 2.34.1