[Android] Avoid double entries for external devices

Geoffrey Métais git at videolan.org
Wed Apr 15 11:08:11 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Apr 14 11:46:55 2015 +0200| [6fb95fd8a9c77dddb9906b7a454371196bcaf99e] | committer: Geoffrey Métais

Avoid double entries for external devices

Get rid of the first occurence, because the second will be the mounptoint exposed in userland.
Fixes sdcard/usbdrive browsing in nVidia Shield tablet and LG G3.

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=6fb95fd8a9c77dddb9906b7a454371196bcaf99e
---

 vlc-android/src/org/videolan/vlc/util/AndroidDevices.java |    9 ++++++---
 vlc-android/src/org/videolan/vlc/util/Strings.java        |   10 +++++++++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
index 003c2e0..bcdfa79 100644
--- a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
+++ b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
@@ -37,7 +37,6 @@ import android.annotation.TargetApi;
 import android.content.Context;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
-import android.os.Build;
 import android.os.Build.VERSION;
 import android.os.Build.VERSION_CODES;
 import android.os.Environment;
@@ -123,12 +122,16 @@ public class AndroidDevices {
                 String type = tokens.nextToken();
 
                 // skip if already in list or if type/mountpoint is blacklisted
-                if (list.contains(mountpoint) || typeBL.contains(type) || Strings.StartsWith(mountBL, mountpoint))
+                if (list.contains(mountpoint) || typeBL.contains(type) || Strings.startsWith(mountBL, mountpoint))
                     continue;
 
                 // check that device is in whitelist, and either type or mountpoint is in a whitelist
-                if (Strings.StartsWith(deviceWL, device) && (typeWL.contains(type) || Strings.StartsWith(mountWL, mountpoint)))
+                if (Strings.startsWith(deviceWL, device) && (typeWL.contains(type) || Strings.startsWith(mountWL, mountpoint))) {
+                    int position = Strings.containsName(list, Strings.getName(mountpoint));
+                    if (position > -1)
+                        list.remove(position);
                     list.add(mountpoint);
+                }
             }
         }
         catch (FileNotFoundException e) {}
diff --git a/vlc-android/src/org/videolan/vlc/util/Strings.java b/vlc-android/src/org/videolan/vlc/util/Strings.java
index f8460fd..ccee272 100644
--- a/vlc-android/src/org/videolan/vlc/util/Strings.java
+++ b/vlc-android/src/org/videolan/vlc/util/Strings.java
@@ -24,6 +24,7 @@ import org.videolan.vlc.MediaWrapper;
 
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
+import java.util.List;
 import java.util.Locale;
 
 public class Strings {
@@ -35,13 +36,20 @@ public class Strings {
         return s;
     }
 
-    static boolean StartsWith(String[] array, String text) {
+    static boolean startsWith(String[] array, String text) {
         for (String item : array)
             if (text.startsWith(item))
                 return true;
         return false;
     }
 
+    static int containsName(List<String> array, String text) {
+        for (int i = array.size()-1 ; i >= 0 ; --i)
+            if (array.get(i).endsWith(text))
+                return i;
+        return -1;
+    }
+
     /**
      * Convert time to a string
      * @param millis e.g.time/length from file



More information about the Android mailing list