[Android] Check ML is OK on all JNI calls

Geoffrey Métais git at videolan.org
Tue Jul 4 16:43:25 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul  4 16:26:58 2017 +0200| [6d3c3439614d482707fe4fd7c4ed2af5b2d585f2] | committer: Geoffrey Métais

Check ML is OK on all JNI calls

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

 .../src/org/videolan/medialibrary/Medialibrary.java    |  2 +-
 .../src/org/videolan/medialibrary/media/Album.java     |  2 +-
 .../src/org/videolan/medialibrary/media/Artist.java    |  4 ++--
 .../src/org/videolan/medialibrary/media/DummyItem.java |  2 +-
 .../src/org/videolan/medialibrary/media/Genre.java     |  6 +++---
 .../src/org/videolan/medialibrary/media/Playlist.java  | 18 ++++++++++--------
 6 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 3229a5147..c840c6619 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -47,7 +47,7 @@ public class Medialibrary {
     public static final String ACTION_IDLE = "action_idle";
     public static final String STATE_IDLE = "state_idle";
 
-    private static final MediaWrapper[] EMPTY_COLLECTION = {};
+    public static final MediaWrapper[] EMPTY_COLLECTION = {};
     public static final String VLC_MEDIA_DB_NAME = "/vlc_media.db";
     public static final String THUMBS_FOLDER_NAME = "/thumbs";
 
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Album.java b/medialibrary/src/org/videolan/medialibrary/media/Album.java
index f6ea5f378..c0b1e732f 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Album.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Album.java
@@ -55,7 +55,7 @@ public class Album extends MediaLibraryItem {
     }
 
     public MediaWrapper[] getTracks(Medialibrary ml) {
-        return nativeGetTracksFromAlbum(ml, mId);
+        return ml != null && ml.isInitiated() ? nativeGetTracksFromAlbum(ml, mId) : Medialibrary.EMPTY_COLLECTION;
     }
 
     @Override
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Artist.java b/medialibrary/src/org/videolan/medialibrary/media/Artist.java
index 3f4458a72..ba02fff88 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Artist.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Artist.java
@@ -40,11 +40,11 @@ public class Artist extends MediaLibraryItem {
     }
 
     public Album[] getAlbums(Medialibrary ml) {
-        return nativeGetAlbumsFromArtist(ml, mId);
+        return ml != null && ml.isInitiated() ? nativeGetAlbumsFromArtist(ml, mId) : new Album[0];
     }
 
     public MediaWrapper[] getTracks(Medialibrary ml) {
-        return nativeGetMediaFromArtist(ml, mId);
+        return ml != null && ml.isInitiated() ? nativeGetMediaFromArtist(ml, mId) : Medialibrary.EMPTY_COLLECTION;
     }
 
     @Override
diff --git a/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java b/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java
index c3faf432d..b4c237a4a 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java
@@ -14,7 +14,7 @@ public class DummyItem extends MediaLibraryItem {
 
     @Override
     public MediaWrapper[] getTracks(Medialibrary ml) {
-        return new MediaWrapper[0];
+        return Medialibrary.EMPTY_COLLECTION;
     }
 
     @Override
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Genre.java b/medialibrary/src/org/videolan/medialibrary/media/Genre.java
index 1fdfc416b..87e484a03 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Genre.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Genre.java
@@ -12,15 +12,15 @@ public class Genre extends MediaLibraryItem {
     }
 
     public Album[] getAlbums(Medialibrary ml) {
-       return nativeGetAlbumsFromGenre(ml, mId);
+       return ml != null && ml.isInitiated() ? nativeGetAlbumsFromGenre(ml, mId) : new Album[0];
     }
 
     public Artist[] getArtists(Medialibrary ml) {
-        return nativeGetArtistsFromGenre(ml, mId);
+        return ml != null && ml.isInitiated() ? nativeGetArtistsFromGenre(ml, mId) : new Artist[0];
     }
 
     public MediaWrapper[] getTracks(Medialibrary ml) {
-        return nativeGetTracksFromGenre(ml, mId);
+        return ml != null && ml.isInitiated() ? nativeGetTracksFromGenre(ml, mId) : Medialibrary.EMPTY_COLLECTION;
     }
 
     @Override
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Playlist.java b/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
index 050d02478..783f2ef09 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
@@ -18,7 +18,7 @@ public class Playlist extends MediaLibraryItem {
     }
 
     public MediaWrapper[] getTracks(Medialibrary ml) {
-        return nativeGetTracksFromPlaylist(ml, mId);
+        return ml != null && ml.isInitiated() ? nativeGetTracksFromPlaylist(ml, mId) : Medialibrary.EMPTY_COLLECTION;
     }
 
     @Override
@@ -27,34 +27,36 @@ public class Playlist extends MediaLibraryItem {
     }
 
     public boolean append(Medialibrary ml, long mediaId) {
-        return nativePlaylistAppend(ml, mId, mediaId);
+        return ml != null && ml.isInitiated() && nativePlaylistAppend(ml, mId, mediaId);
     }
 
     public boolean append(Medialibrary ml, long[] mediaIds) {
-        return nativePlaylistAppendGroup(ml, mId, mediaIds);
+        return ml != null && ml.isInitiated() && nativePlaylistAppendGroup(ml, mId, mediaIds);
     }
 
     public boolean append(Medialibrary ml, List<Long> mediaIds) {
+        if (ml == null || !ml.isInitiated())
+            return false;
         long[] ids = new long[mediaIds.size()];
         for (int i = 0; i < ids.length; ++i)
-            ids[i] = mediaIds.get(i).longValue();
+            ids[i] = mediaIds.get(i);
         return nativePlaylistAppendGroup(ml, mId, ids);
     }
 
     public boolean add(Medialibrary ml, long mediaId, int position) {
-        return nativePlaylistAdd(ml, mId, mediaId, position);
+        return ml != null && ml.isInitiated() && nativePlaylistAdd(ml, mId, mediaId, position);
     }
 
     public boolean move(Medialibrary ml, long mediaId, int position) {
-        return nativePlaylistMove(ml, mId, mediaId, position);
+        return ml != null && ml.isInitiated() && nativePlaylistMove(ml, mId, mediaId, position);
     }
 
     public boolean remove(Medialibrary ml, long mediaId) {
-        return nativePlaylistRemove(ml, mId, mediaId);
+        return ml != null && ml.isInitiated() && nativePlaylistRemove(ml, mId, mediaId);
     }
 
     public boolean delete(Medialibrary ml) {
-        return nativePlaylistDelete(ml, mId);
+        return ml != null && ml.isInitiated() && nativePlaylistDelete(ml, mId);
     }
 
     public static Parcelable.Creator<Playlist> CREATOR



More information about the Android mailing list