[Android] Implement the ML banned folder listing

Nicolas Pomepuy git at videolan.org
Thu Feb 24 10:58:19 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jan 13 10:09:48 2022 +0100| [22df541c413778c50cc4220e6fb5d500c735ff3a] | committer: Nicolas Pomepuy

Implement the ML banned folder listing

> https://code.videolan.org/videolan/vlc-android/commit/22df541c413778c50cc4220e6fb5d500c735ff3a
---

 medialibrary/jni/AndroidMediaLibrary.cpp           |  6 +++++
 medialibrary/jni/AndroidMediaLibrary.h             |  1 +
 medialibrary/jni/medialibrary.cpp                  | 29 ++++++++++++++++++++++
 .../videolan/medialibrary/MedialibraryImpl.java    |  5 ++++
 .../medialibrary/interfaces/Medialibrary.java      |  1 +
 .../medialibrary/stubs/StubMedialibrary.java       |  4 +++
 6 files changed, 46 insertions(+)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 5b5e3c999..c804778c2 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -110,6 +110,12 @@ AndroidMediaLibrary::unbanFolder(const std::string& path)
     p_ml->unbanFolder(path);
 }
 
+std::vector<medialibrary::FolderPtr>
+AndroidMediaLibrary::bannedEntryPoints()
+{
+    return p_ml->bannedEntryPoints()->all();
+}
+
 void
 AndroidMediaLibrary::discover(const std::string& libraryPath)
 {
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 32f36a7cf..2511fa8e1 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -40,6 +40,7 @@ public:
     bool removeDevice(const std::string& uuid, const std::string& path);
     void banFolder(const std::string& path);
     void unbanFolder(const std::string& path);
+    std::vector<medialibrary::FolderPtr> bannedEntryPoints();
     void discover(const std::string&);
     bool setDiscoverNetworkEnabled(bool enabled);
     void removeEntryPoint(const std::string& entryPoint);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index e2f84427c..7065240b4 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -93,6 +93,34 @@ unbanFolder(JNIEnv* env, jobject thiz, jstring folderPath)
     env->ReleaseStringUTFChars(folderPath, path);
 }
 
+jobjectArray
+bannedFolders(JNIEnv* env, jobject thiz)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    std::vector<medialibrary::FolderPtr> folders = aml->bannedEntryPoints();
+
+
+    std::vector<std::string> mrls;
+    mrls.reserve(folders.size());
+    for(medialibrary::FolderPtr& folder : folders) {
+        try
+        {
+            mrls.push_back( std::move( folder->mrl() ) );
+        }
+        catch ( const medialibrary::fs::errors::DeviceRemoved& )
+        {
+            // Just ignore, the device isn't available anymore
+        }
+    }
+    jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(mrls.size(), env->FindClass("java/lang/String"), NULL);
+    int index = -1;
+    for( const std::string& m : mrls ) {
+        auto mrl = vlcNewStringUTF(env, m.c_str());
+        env->SetObjectArrayElement(mediaRefs, ++index, mrl.get());
+    }
+    return mediaRefs;
+}
+
 void
 addDevice(JNIEnv* env, jobject thiz, jstring uuid, jstring storagePath, jboolean removable)
 {
@@ -2008,6 +2036,7 @@ static JNINativeMethod methods[] = {
     {"nativeRemoveDevice", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)removeDevice },
     {"nativeBanFolder", "(Ljava/lang/String;)V", (void*)banFolder },
     {"nativeUnbanFolder", "(Ljava/lang/String;)V", (void*)unbanFolder },
+    {"nativeBannedFolders", "()[Ljava/lang/String;", (void*)bannedFolders },
     {"nativeLastMediaPlayed", "()[Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)lastMediaPLayed },
     {"nativeLastStreamsPlayed", "()[Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)lastStreamsPlayed },
     {"nativeAddToHistory", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)addToHistory },
diff --git a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
index a679844c6..8eb8b0c4b 100644
--- a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
@@ -114,6 +114,10 @@ public class MedialibraryImpl extends Medialibrary {
             nativeUnbanFolder(Tools.encodeVLCMrl(path));
     }
 
+    public String[] bannedFolders() {
+        return mIsInitiated ? nativeBannedFolders() : new String[0];
+    }
+
     public String[] getDevices() {
         return mIsInitiated ? nativeDevices() : new String[0];
     }
@@ -602,6 +606,7 @@ public class MedialibraryImpl extends Medialibrary {
     private native boolean nativeClearDatabase(boolean keepPlaylist);
     private native void nativeBanFolder(String path);
     private native void nativeUnbanFolder(String path);
+    private native String[] nativeBannedFolders();
     private native void nativeAddDevice(String uuid, String path, boolean removable);
     private native boolean nativeIsDeviceKnown(String uuid, String path, boolean removable);
     private native boolean nativeDeleteRemovableDevices();
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
index 1abf4c072..0ba96655c 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
@@ -701,6 +701,7 @@ abstract public class Medialibrary {
     abstract public void start();
     abstract public void banFolder(@NonNull String path);
     abstract public void unbanFolder(@NonNull String path);
+    abstract public String[] bannedFolders();
     abstract public String[] getDevices();
     abstract public void addDevice(@NonNull String uuid, @NonNull String path, boolean removable);
     abstract public boolean isDeviceKnown(@NonNull String uuid, @NonNull String path, boolean removable);
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
index b4aacadd6..c4ebaff1f 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
@@ -56,6 +56,10 @@ public class StubMedialibrary extends Medialibrary {
         dt.mBannedFolders.remove(path);
     }
 
+    public String[] bannedFolders() {
+        return new String[0];
+    }
+
     public String[] getDevices() {
         return new String[0];
     }



More information about the Android mailing list