[Android] Implement ML API update for addDevice

Geoffrey Métais git at videolan.org
Fri Apr 14 17:29:06 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 13 16:47:54 2017 +0200| [778ca49fbd8eca7d194614b57614d2c5795de803] | committer: Geoffrey Métais

Implement ML API update for addDevice

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

 medialibrary/jni/AndroidMediaLibrary.cpp                     | 5 ++---
 medialibrary/jni/AndroidMediaLibrary.h                       | 2 +-
 medialibrary/jni/medialibrary.cpp                            | 8 +++++---
 medialibrary/src/org/videolan/medialibrary/Medialibrary.java | 6 +++---
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 6f730dd..cb293c9 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -61,12 +61,11 @@ AndroidMediaLibrary::initML(const std::string& dbPath, const std::string& thumbs
     return p_ml->initialize(dbPath, thumbsPath, this);
 }
 
-void
+bool
 AndroidMediaLibrary::addDevice(const std::string& uuid, const std::string& path, bool removable)
 {
     p_lister->addDevice(uuid, path, removable);
-    if (p_DeviceListerCb != nullptr)
-        p_DeviceListerCb->onDevicePlugged(uuid, path);
+    return p_DeviceListerCb != nullptr && p_DeviceListerCb->onDevicePlugged(uuid, path);
 }
 
 std::vector<std::tuple<std::string, std::string, bool>>
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 33f892b..a01e2ca 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -29,7 +29,7 @@ public:
     ~AndroidMediaLibrary();
 
     bool initML(const std::string& dbPath, const std::string& thumbsPath);
-    void addDevice(const std::string& uuid, const std::string& path, bool removable);
+    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);
     void banFolder(const std::string& path);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 1e78a56..e1eab2d 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -57,14 +57,16 @@ banFolder(JNIEnv* env, jobject thiz, jstring folderPath)
     env->ReleaseStringUTFChars(folderPath, path);
 }
 
-void addDevice(JNIEnv* env, jobject thiz, jstring uuid, jstring storagePath, jboolean removable)
+jboolean
+addDevice(JNIEnv* env, jobject thiz, jstring uuid, jstring storagePath, jboolean removable)
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
     const char *uuidChar = env->GetStringUTFChars(uuid, JNI_FALSE);
     const char *path = env->GetStringUTFChars(storagePath, JNI_FALSE);
-    aml->addDevice(uuidChar, path, removable);
+    jboolean isNew = aml->addDevice(uuidChar, path, removable);
     env->ReleaseStringUTFChars(uuid, uuidChar);
     env->ReleaseStringUTFChars(storagePath, path);
+    return isNew;
 }
 
 jobjectArray
@@ -742,7 +744,7 @@ static JNINativeMethod methods[] = {
     {"nativeSetup", "()V", (void*)setup },
     {"nativeInit", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)init },
     {"nativeRelease", "()V", (void*)release },
-    {"nativeAddDevice", "(Ljava/lang/String;Ljava/lang/String;Z)V", (void*)addDevice },
+    {"nativeAddDevice", "(Ljava/lang/String;Ljava/lang/String;Z)Z", (void*)addDevice },
     {"nativeDevices", "()[Ljava/lang/String;", (void*)devices },
     {"nativeDiscover", "(Ljava/lang/String;)V", (void*)discover },
     {"nativeRemoveEntryPoint", "(Ljava/lang/String;)V", (void*)removeEntryPoint },
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 42fd8f8..0d775ce 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -83,8 +83,8 @@ public class Medialibrary {
         return mIsInitiated ? nativeDevices() : new String[0];
     }
 
-    public void addDevice(String uuid, String path, boolean removable) {
-        nativeAddDevice(uuid, Tools.encodeVLCMrl(path), removable);
+    public boolean addDevice(String uuid, String path, boolean removable) {
+        return nativeAddDevice(uuid, Tools.encodeVLCMrl(path), removable);
     }
 
     public void discover(String path) {
@@ -538,7 +538,7 @@ public class Medialibrary {
     private native boolean nativeInit(String dbPath, String thumbsPath);
     private native void nativeRelease();
     private native void nativeBanFolder(String path);
-    private native void nativeAddDevice(String uuid, String path, boolean removable);
+    private native boolean nativeAddDevice(String uuid, String path, boolean removable);
     private native String[] nativeDevices();
     private native void nativeDiscover(String path);
     private native void nativeRemoveEntryPoint(String path);



More information about the Android mailing list