[Android] Prevent sending empty strings to Medialibrary
Geoffrey Métais
git at videolan.org
Wed May 24 12:32:10 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed May 24 12:31:12 2017 +0200| [b65afe5b1ca74fd222aa5cd6140cd883ed16ba9c] | committer: Geoffrey Métais
Prevent sending empty strings to Medialibrary
> https://code.videolan.org/videolan/vlc-android/commit/b65afe5b1ca74fd222aa5cd6140cd883ed16ba9c
---
medialibrary/src/org/videolan/medialibrary/Medialibrary.java | 9 +++++----
vlc-android/src/org/videolan/vlc/MediaParsingService.java | 8 ++++++--
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 25c63965e..3ce3d4221 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -7,6 +7,7 @@ import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
+import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
@@ -81,7 +82,7 @@ public class Medialibrary {
nativeStart();
}
- public void banFolder(String path) {
+ public void banFolder(@NonNull String path) {
if (mIsInitiated && new File(path).exists())
nativeBanFolder(Tools.encodeVLCMrl(path));
}
@@ -90,16 +91,16 @@ public class Medialibrary {
return mIsInitiated ? nativeDevices() : new String[0];
}
- public boolean addDevice(String uuid, String path, boolean removable, boolean notify) {
+ public boolean addDevice(@NonNull String uuid, @NonNull String path, boolean removable, boolean notify) {
return nativeAddDevice(uuid, Tools.encodeVLCMrl(path), removable, notify);
}
- public void discover(String path) {
+ public void discover(@NonNull String path) {
if (mIsInitiated)
nativeDiscover(Tools.encodeVLCMrl(path));
}
- public void removeFolder(String path) {
+ public void removeFolder(@NonNull String path) {
if (mIsInitiated)
nativeRemoveEntryPoint(Tools.encodeVLCMrl(path));
}
diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index 2a8e18ceb..ca7838b06 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -150,6 +150,8 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
private void discoverStorage(final String path) {
if (BuildConfig.DEBUG) Log.d(TAG, "discoverStorage: "+path);
+ if (TextUtils.isEmpty(path))
+ return;
mThreadPool.execute(new Runnable() {
@Override
public void run() {
@@ -180,8 +182,8 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
for (String storagePath : AndroidDevices.getExternalStorageDirectories()) {
if (path.startsWith(storagePath)) {
String uuid = FileUtils.getFileNameFromPath(path);
- if (TextUtils.isEmpty(uuid))
- uuid = "root";
+ if (TextUtils.isEmpty(path) || TextUtils.isEmpty(uuid))
+ return;
mMedialibrary.addDevice(uuid, path, true, true);
for (String folder : Medialibrary.getBlackList())
mMedialibrary.banFolder(path + folder);
@@ -214,6 +216,8 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
for (String device : devices) {
boolean isMainStorage = TextUtils.equals(device, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
String uuid = FileUtils.getFileNameFromPath(device);
+ if (TextUtils.isEmpty(device) || TextUtils.isEmpty(uuid))
+ continue;
boolean isNew = mMedialibrary.addDevice(isMainStorage ? "main-storage" : uuid, device, !isMainStorage, false);
boolean isIgnored = sharedPreferences.getBoolean("ignore_"+ uuid, false);
if (!isMainStorage && isNew && !isIgnored) {
More information about the Android
mailing list