Commit 9345b7b0 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Store External public directory path

parent e9acd0c5
......@@ -81,7 +81,7 @@ public class MediaLibrary {
FOLDER_BLACKLIST = new HashSet<String>();
for (String item : folder_blacklist)
FOLDER_BLACKLIST.add(android.os.Environment.getExternalStorageDirectory().getPath() + item);
FOLDER_BLACKLIST.add(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + item);
}
private MediaLibrary() {
......
......@@ -30,6 +30,7 @@ import java.io.StringWriter;
import java.io.Writer;
import java.lang.Thread.UncaughtExceptionHandler;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Logcat;
import org.videolan.vlc.util.Util;
......@@ -69,9 +70,8 @@ public class VLCCrashHandler implements UncaughtExceptionHandler {
// Save the log on SD card if available
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
String sdcardPath = Environment.getExternalStorageDirectory().getPath();
writeLog(stacktrace, sdcardPath + "/vlc_crash");
writeLogcat(sdcardPath + "/vlc_logcat");
writeLog(stacktrace, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/vlc_crash");
writeLogcat(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/vlc_logcat");
}
defaultUEH.uncaughtException(thread, ex);
......
......@@ -37,6 +37,7 @@ import android.support.v4.app.NotificationCompat;
import android.text.format.DateFormat;
import org.videolan.vlc.R;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Logcat;
import org.videolan.vlc.util.Util;
......@@ -170,7 +171,7 @@ public class DebugLogService extends Service implements Logcat.Callback, Runnabl
public void run() {
final CharSequence timestamp = DateFormat.format(
"yyyyMMdd_kkmmss", System.currentTimeMillis());
final String filename = Environment.getExternalStorageDirectory().getPath() + "/vlc_logcat_" + timestamp + ".log";
final String filename = AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/vlc_logcat_" + timestamp + ".log";
boolean saved = true;
FileOutputStream fos = null;
OutputStreamWriter output = null;
......
......@@ -123,9 +123,9 @@ public class AudioUtil {
if (LibVlcUtil.isFroyoOrLater() && AndroidDevices.hasExternalStorage() && context.getExternalCacheDir() != null)
CACHE_DIR = context.getExternalCacheDir().getPath();
else
CACHE_DIR = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + BuildConfig.APPLICATION_ID + "/cache";
CACHE_DIR = AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/Android/data/" + BuildConfig.APPLICATION_ID + "/cache";
} catch (Exception e) { // catch NPE thrown by getExternalCacheDir()
CACHE_DIR = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + BuildConfig.APPLICATION_ID + "/cache";
CACHE_DIR = AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/Android/data/" + BuildConfig.APPLICATION_ID + "/cache";
}
ART_DIR = CACHE_DIR + "/art/";
COVER_DIR = CACHE_DIR + "/covers/";
......
......@@ -22,7 +22,6 @@
*/
package org.videolan.vlc.gui.browser;
import android.os.Environment;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
......@@ -38,6 +37,7 @@ import org.videolan.vlc.MediaDatabase;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.audio.MediaComparators;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.CustomDirectories;
import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.Util;
......@@ -157,7 +157,7 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
private void onBindStorageViewHolder(final RecyclerView.ViewHolder holder, int position) {
final MediaViewHolder vh = (MediaViewHolder) holder;
final Storage storage = (Storage) getItem(position);
boolean isPublicStorage = TextUtils.equals(storage.getPath(), Environment.getExternalStorageDirectory().getPath());
boolean isPublicStorage = TextUtils.equals(storage.getPath(), AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
boolean hasContextMenu = !isPublicStorage && mCustomDirsLocation.contains(storage.getPath());
vh.title.setText(isPublicStorage ? holder.itemView.getContext().getString(R.string.internal_memory) : storage.getName());
vh.icon.setVisibility(View.GONE);
......
......@@ -53,7 +53,7 @@ public class FileBrowserFragment extends BaseBrowserFragment {
public FileBrowserFragment() {
super();
ROOT = Environment.getExternalStorageDirectory().getPath();
ROOT = AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY;
}
@Override
......
......@@ -69,6 +69,7 @@ import org.videolan.vlc.gui.SecondaryActivity;
import org.videolan.vlc.gui.browser.MediaBrowserFragment;
import org.videolan.vlc.interfaces.ISortable;
import org.videolan.vlc.interfaces.IVideoBrowser;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance;
import org.videolan.vlc.util.VLCRunnable;
......@@ -374,7 +375,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
hasInfo = true;
menu.findItem(R.id.video_list_info).setVisible(hasInfo);
menu.findItem(R.id.video_list_delete).setVisible(!LibVlcUtil.isLolliPopOrLater() ||
mediaWrapper.getLocation().startsWith("file://" + Environment.getExternalStorageDirectory().getPath()));
mediaWrapper.getLocation().startsWith("file://" + AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY));
}
@Override
......
......@@ -2058,7 +2058,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
} else if (item.getItemId() == R.id.video_menu_subtitles_picker) {
Intent intent = new Intent("org.openintents.action.PICK_FILE");
File file = new File(android.os.Environment.getExternalStorageDirectory().getPath());
File file = new File(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
intent.setData(Uri.fromFile(file));
// Set fancy title and button (optional)
......@@ -2653,13 +2653,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
Log.i(TAG, "Getting file " + filename + " from content:// URI");
is = getContentResolver().openInputStream(data);
os = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() + "/Download/" + filename);
os = new FileOutputStream(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/Download/" + filename);
byte[] buffer = new byte[1024];
int bytesRead = 0;
while((bytesRead = is.read(buffer)) >= 0) {
os.write(buffer, 0, bytesRead);
}
mLocation = LibVLC.PathToURI(Environment.getExternalStorageDirectory().getPath() + "/Download/" + filename);
mLocation = LibVLC.PathToURI(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/Download/" + filename);
}
} catch (Exception e) {
Log.e(TAG, "Couldn't download file from mail URI");
......
......@@ -48,6 +48,7 @@ import java.util.StringTokenizer;
public class AndroidDevices {
public final static String TAG = "VLC/Util/AndroidDevices";
public final static String EXTERNAL_PUBLIC_DIRECTORY = Environment.getExternalStorageDirectory().getPath();
final static boolean hasNavBar;
final static boolean hasTsp;
......@@ -95,7 +96,7 @@ public class AndroidDevices {
public static ArrayList<String> getStorageDirectories() {
BufferedReader bufReader = null;
ArrayList<String> list = new ArrayList<String>();
list.add(Environment.getExternalStorageDirectory().getPath());
list.add(EXTERNAL_PUBLIC_DIRECTORY);
List<String> typeWL = Arrays.asList("vfat", "exfat", "sdcardfs", "fuse", "ntfs", "fat32", "ext3", "ext4", "esdfs");
List<String> typeBL = Arrays.asList("tmpfs");
......@@ -186,11 +187,4 @@ public class AndroidDevices {
return networkEnabled;
}
public static String getStorageTitle(String path){
if (TextUtils.equals(Environment.getExternalStorageDirectory().getPath(), path))
return VLCApplication.getAppContext().getString(R.string.internal_memory);
else
return Strings.getName(path);
}
}
......@@ -30,7 +30,6 @@ import android.content.pm.ResolveInfo;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils.TruncateAt;
import android.util.DisplayMetrics;
......@@ -348,7 +347,7 @@ public class Util {
path = path.substring(7);
if (!path.startsWith("/"))
return false;
if (path.startsWith(Environment.getExternalStorageDirectory().getPath()))
if (path.startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY))
return true;
if (LibVlcUtil.isLolliPopOrLater())
return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment