[Android] Avoid dropping missing folders in JNI

Nicolas Pomepuy git at videolan.org
Mon May 15 12:09:55 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Mar 15 15:26:05 2023 +0100| [e475c0f91859dc0ae9525c300266f89371d62de5] | committer: Nicolas Pomepuy

Avoid dropping missing folders in JNI

Fixes #2859
Fixes #2858

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

 medialibrary/jni/medialibrary.cpp |  2 ++
 medialibrary/jni/utils.cpp        | 10 +++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index e56dff8606..7260363cc1 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -1857,6 +1857,8 @@ folders(JNIEnv* env, jobject thiz, jint type, jint sortingCriteria, jboolean des
         catch( const medialibrary::fs::errors::DeviceRemoved& )
         {
             // Ignore this folder since it's on a removed device.
+            auto item = convertFolderObject(env, &ml_fields, folder, 0);
+            env->SetObjectArrayElement(foldersRefs, ++index, item.get());
         }
     }
     return foldersRefs;
diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index 8913b13ee5..f9223dd545 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -130,7 +130,15 @@ utils::jni::object
 convertFolderObject(JNIEnv* env, fields *fields, medialibrary::FolderPtr const& folderPtr, int count)
 {
     auto name = vlcNewStringUTF(env, folderPtr->name().c_str());
-    auto mrl = vlcNewStringUTF(env, folderPtr->mrl().c_str());
+    utils::jni::string mrl;
+    try
+    {
+        mrl = vlcNewStringUTF(env, folderPtr->mrl().c_str());
+    }
+    catch( const medialibrary::fs::errors::DeviceRemoved& )
+    {
+        mrl = vlcNewStringUTF(env, "missing://");
+    }
     return utils::jni::object{ env, env->NewObject(fields->Folder.clazz, fields->Folder.initID,
                           (jlong) folderPtr->id(), name.get(), mrl.get(), (jint) count, (jboolean)folderPtr->isFavorite())
     };



More information about the Android mailing list