[Android] Match new Medialibrary API

Geoffrey Métais git at videolan.org
Mon Dec 3 10:36:39 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Dec  3 10:22:10 2018 +0100| [32a50a3b0cae3ca677a61ded264cff6ae5133620] | committer: Geoffrey Métais

Match new Medialibrary API

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

 medialibrary/jni/AndroidMediaLibrary.cpp                     | 6 +++---
 medialibrary/jni/AndroidMediaLibrary.h                       | 2 +-
 medialibrary/jni/medialibrary.cpp                            | 8 +++++---
 medialibrary/src/org/videolan/medialibrary/Medialibrary.java | 6 +++---
 vlc-android/src/org/videolan/vlc/ExternalMonitor.java        | 4 ++--
 vlc-android/src/org/videolan/vlc/MediaParsingService.kt      | 5 ++++-
 6 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 67fcc5ccb..6ddca9829 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -64,7 +64,7 @@ bool
 AndroidMediaLibrary::addDevice(const std::string& uuid, const std::string& path, bool removable)
 {
     p_lister->addDevice(uuid, path, removable);
-    return p_DeviceListerCb != nullptr && (m_started ? p_DeviceListerCb->onDevicePlugged(uuid, path) : !p_DeviceListerCb->isDeviceKnown(uuid));
+    return p_DeviceListerCb != nullptr && (m_started ? p_DeviceListerCb->onDeviceMounted(uuid, path) : !p_DeviceListerCb->isDeviceKnown(uuid));
 }
 
 std::vector<std::tuple<std::string, std::string, bool>>
@@ -74,11 +74,11 @@ AndroidMediaLibrary::devices()
 }
 
 bool
-AndroidMediaLibrary::removeDevice(const std::string& uuid)
+AndroidMediaLibrary::removeDevice(const std::string& uuid, const std::string& path)
 {
     bool removed = p_lister->removeDevice(uuid);
     if (removed && p_DeviceListerCb != nullptr)
-        p_DeviceListerCb->onDeviceUnplugged(uuid);
+        p_DeviceListerCb->onDeviceUnmounted(uuid, path);
     return removed;
 }
 
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 2ff193ec0..24578e2c0 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -33,7 +33,7 @@ public:
     void start();
     bool addDevice(const std::string& uuid, const std::string& path, bool removable);
     std::vector<std::tuple<std::string, std::string, bool>> devices();
-    bool removeDevice(const std::string& uuid);
+    bool removeDevice(const std::string& uuid, const std::string& path);
     void banFolder(const std::string& path);
     void unbanFolder(const std::string& path);
     void discover(const std::string&);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 9e1acbc44..a70327479 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -134,12 +134,14 @@ entryPoints(JNIEnv* env, jobject thiz)
 }
 
 jboolean
-removeDevice(JNIEnv* env, jobject thiz, jstring uuid)
+removeDevice(JNIEnv* env, jobject thiz, jstring uuid, jstring storagePath)
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
     const char *uuidChar = env->GetStringUTFChars(uuid, JNI_FALSE);
-    jboolean removed = aml->removeDevice(uuidChar);
+    const char *path = env->GetStringUTFChars(storagePath, JNI_FALSE);
+    jboolean removed = aml->removeDevice(uuidChar, path);
     env->ReleaseStringUTFChars(uuid, uuidChar);
+    env->ReleaseStringUTFChars(storagePath, path);
     return removed;
 }
 
@@ -1677,7 +1679,7 @@ static JNINativeMethod methods[] = {
     {"nativeDiscover", "(Ljava/lang/String;)V", (void*)discover },
     {"nativeRemoveEntryPoint", "(Ljava/lang/String;)V", (void*)removeEntryPoint },
     {"nativeEntryPoints", "()[Ljava/lang/String;", (void*)entryPoints },
-    {"nativeRemoveDevice", "(Ljava/lang/String;)Z", (void*)removeDevice },
+    {"nativeRemoveDevice", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)removeDevice },
     {"nativeBanFolder", "(Ljava/lang/String;)V", (void*)banFolder },
     {"nativeUnbanFolder", "(Ljava/lang/String;)V", (void*)unbanFolder },
     {"nativeLastMediaPlayed", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)lastMediaPLayed },
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index ed38599bd..df7a9a507 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -168,8 +168,8 @@ public class Medialibrary {
         return nativeEntryPoints();
     }
 
-    public boolean removeDevice(String uuid) {
-        return mIsInitiated && !TextUtils.isEmpty(uuid) && nativeRemoveDevice(Tools.encodeVLCMrl(uuid));
+    public boolean removeDevice(String uuid, String path) {
+        return mIsInitiated && !TextUtils.isEmpty(uuid) && !TextUtils.isEmpty(path) && nativeRemoveDevice(Tools.encodeVLCMrl(uuid), Tools.encodeVLCMrl(path));
     }
 
     @Override
@@ -906,7 +906,7 @@ public class Medialibrary {
     private native void nativeDiscover(String path);
     private native void nativeRemoveEntryPoint(String path);
     private native String[] nativeEntryPoints();
-    private native boolean nativeRemoveDevice(String uuid);
+    private native boolean nativeRemoveDevice(String uuid, String path);
     private native MediaWrapper[] nativeLastMediaPlayed();
     private native MediaWrapper[] nativeLastStreamsPlayed();
     private native  boolean nativeAddToHistory(String mrl, String title);
diff --git a/vlc-android/src/org/videolan/vlc/ExternalMonitor.java b/vlc-android/src/org/videolan/vlc/ExternalMonitor.java
index 5da9721fc..8ff35c617 100644
--- a/vlc-android/src/org/videolan/vlc/ExternalMonitor.java
+++ b/vlc-android/src/org/videolan/vlc/ExternalMonitor.java
@@ -174,9 +174,9 @@ public class ExternalMonitor extends BroadcastReceiver implements LifecycleObser
         public void handleMessage(Message msg) {
             final Context appCtx = VLCApplication.getAppContext();
             final String uuid = ((Uri) msg.obj).getLastPathSegment();
+            final String path = ((Uri) msg.obj).getPath();
             switch (msg.what) {
                 case ACTION_MEDIA_MOUNTED:
-                    final String path = ((Uri) msg.obj).getPath();
                     removeMessages(ACTION_MEDIA_UNMOUNTED);
                     if (!TextUtils.isEmpty(uuid)
                             && !Settings.INSTANCE.getInstance(appCtx).getBoolean("ignore_" + uuid, false)) {
@@ -188,7 +188,7 @@ public class ExternalMonitor extends BroadcastReceiver implements LifecycleObser
                     }
                     break;
                 case ACTION_MEDIA_UNMOUNTED:
-                    VLCApplication.getMLInstance().removeDevice(uuid);
+                    VLCApplication.getMLInstance().removeDevice(uuid, path);
                     MediaParsingService.Companion.getStarted().setValue(false);
                     break;
             }
diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index b7fd177e9..de06b3c72 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -262,7 +262,10 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
             val isIgnored = sharedPreferences.getBoolean("ignore_$uuid", false)
             if (!isIgnored && isNew) showStorageNotification(device)
         }
-        withContext(Dispatchers.IO) { for (device in missingDevices) medialibrary.removeDevice(FileUtils.getFileNameFromPath(device)) }
+        withContext(Dispatchers.IO) { for (device in missingDevices) {
+            val uri = Uri.parse(device)
+            medialibrary.removeDevice(uri.lastPathSegment, uri.path)
+        } }
         serviceLock = false
         exitCommand()
     }



More information about the Android mailing list