<div dir="ltr">LGTM<br></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 6, 2015 at 1:30 PM Thomas Guillem <<a href="mailto:thomas@gllm.fr">thomas@gllm.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
.../src/org/videolan/vlc/MediaDatabase.java | 283 ++++++++++++---------<br>
.../vlc/gui/video/VideoPlayerActivity.java | 13 +-<br>
vlc-android/src/org/videolan/vlc/util/Util.java | 2 +-<br>
3 files changed, 168 insertions(+), 130 deletions(-)<br>
<br>
diff --git a/vlc-android/src/org/videolan/vlc/MediaDatabase.java b/vlc-android/src/org/videolan/vlc/MediaDatabase.java<br>
index b5cc3de..082bbe1 100644<br>
--- a/vlc-android/src/org/videolan/vlc/MediaDatabase.java<br>
+++ b/vlc-android/src/org/videolan/vlc/MediaDatabase.java<br>
@@ -362,9 +362,11 @@ public class MediaDatabase {<br>
new String[] { PLAYLIST_NAME },<br>
null, null, null, null, null);<br>
<br>
- while(c.moveToNext())<br>
- playlists.add(c.getString(c.getColumnIndex(PLAYLIST_NAME)));<br>
- c.close();<br>
+ if (c != null) {<br>
+ while (c.moveToNext())<br>
+ playlists.add(c.getString(c.getColumnIndex(PLAYLIST_NAME)));<br>
+ c.close();<br>
+ }<br>
return playlists.toArray(new String[playlists.size()]);<br>
}<br>
<br>
@@ -413,9 +415,12 @@ public class MediaDatabase {<br>
Cursor c = mDb.query(PLAYLIST_TABLE_NAME,<br>
new String[] { PLAYLIST_NAME }, PLAYLIST_NAME + "= ?",<br>
new String[] { name }, null, null, "1");<br>
- int count = c.getCount();<br>
- c.close();<br>
- return (count > 0);<br>
+ if (c != null) {<br>
+ final int count = c.getCount();<br>
+ c.close();<br>
+ return (count > 0);<br>
+ } else<br>
+ return false;<br>
}<br>
<br>
/**<br>
@@ -436,14 +441,18 @@ public class MediaDatabase {<br>
new String[] { playlistName }, null, null,<br>
PLAYLIST_MEDIA_ORDER + " ASC");<br>
<br>
- int count = c.getCount();<br>
- String ret[] = new String[count]; int i = 0;<br>
- while(c.moveToNext()) {<br>
- ret[i] = c.getString(c.getColumnIndex(PLAYLIST_MEDIA_MEDIALOCATION));<br>
- i++;<br>
- }<br>
- c.close();<br>
- return ret;<br>
+ if (c != null) {<br>
+ int count = c.getCount();<br>
+ String ret[] = new String[count];<br>
+ int i = 0;<br>
+ while (c.moveToNext()) {<br>
+ ret[i] = c.getString(c.getColumnIndex(PLAYLIST_MEDIA_MEDIALOCATION));<br>
+ i++;<br>
+ }<br>
+ c.close();<br>
+ return ret;<br>
+ } else<br>
+ return null;<br>
}<br>
<br>
/**<br>
@@ -492,15 +501,17 @@ public class MediaDatabase {<br>
new String[] { playlistName, String.valueOf(position) },<br>
null, null,<br>
PLAYLIST_MEDIA_ORDER + " ASC");<br>
- while(c.moveToNext()) {<br>
- ContentValues cv = new ContentValues();<br>
- int ii = c.getInt(c.getColumnIndex(PLAYLIST_MEDIA_ORDER)) + factor;<br>
- Log.d(TAG, "ii = " + ii);<br>
- cv.put(PLAYLIST_MEDIA_ORDER, ii /* i */);<br>
- mDb.update(PLAYLIST_MEDIA_TABLE_NAME, cv, PLAYLIST_MEDIA_ID + "=?",<br>
- new String[] { c.getString(c.getColumnIndex(PLAYLIST_MEDIA_ID)) });<br>
+ if (c != null) {<br>
+ while (c.moveToNext()) {<br>
+ ContentValues cv = new ContentValues();<br>
+ int ii = c.getInt(c.getColumnIndex(PLAYLIST_MEDIA_ORDER)) + factor;<br>
+ Log.d(TAG, "ii = " + ii);<br>
+ cv.put(PLAYLIST_MEDIA_ORDER, ii /* i */);<br>
+ mDb.update(PLAYLIST_MEDIA_TABLE_NAME, cv, PLAYLIST_MEDIA_ID + "=?",<br>
+ new String[]{c.getString(c.getColumnIndex(PLAYLIST_MEDIA_ID))});<br>
+ }<br>
+ c.close();<br>
}<br>
- c.close();<br>
}<br>
<br>
/**<br>
@@ -595,9 +606,12 @@ public class MediaDatabase {<br>
MEDIA_LOCATION + "=?",<br>
new String[] { uri.toString() },<br>
null, null, null);<br>
- boolean exists = cursor.moveToFirst();<br>
- cursor.close();<br>
- return exists;<br>
+ if (cursor != null) {<br>
+ final boolean exists = cursor.moveToFirst();<br>
+ cursor.close();<br>
+ return exists;<br>
+ } else<br>
+ return false;<br>
} catch (Exception e) {<br>
Log.e(TAG, "Query failed");<br>
return false;<br>
@@ -618,14 +632,16 @@ public class MediaDatabase {<br>
MEDIA_TABLE_NAME,<br>
new String[] { MEDIA_LOCATION },<br>
null, null, null, null, null);<br>
- cursor.moveToFirst();<br>
- if (!cursor.isAfterLast()) {<br>
- do {<br>
- File file = new File(cursor.getString(0));<br>
- files.add(file);<br>
- } while (cursor.moveToNext());<br>
+ if (cursor != null) {<br>
+ cursor.moveToFirst();<br>
+ if (!cursor.isAfterLast()) {<br>
+ do {<br>
+ File file = new File(cursor.getString(0));<br>
+ files.add(file);<br>
+ } while (cursor.moveToNext());<br>
+ }<br>
+ cursor.close();<br>
}<br>
- cursor.close();<br>
<br>
return files;<br>
}<br>
@@ -640,12 +656,14 @@ public class MediaDatabase {<br>
<br>
ArrayList<String> mediaList = new ArrayList<String>();<br>
Cursor cursor = queryMedia(filter);<br>
- if (cursor.moveToFirst()){<br>
- do {<br>
- mediaList.add(cursor.getString(0));<br>
- } while (cursor.moveToNext());<br>
+ if (cursor != null) {<br>
+ if (cursor.moveToFirst()) {<br>
+ do {<br>
+ mediaList.add(cursor.getString(0));<br>
+ } while (cursor.moveToNext());<br>
+ }<br>
+ cursor.close();<br>
}<br>
- cursor.close();<br>
return mediaList;<br>
}<br>
<br>
@@ -681,36 +699,39 @@ public class MediaDatabase {<br>
CHUNK_SIZE,<br>
chunk_count * CHUNK_SIZE), null);<br>
<br>
- if (cursor.moveToFirst()) {<br>
- try {<br>
- do {<br>
- final Uri uri = AndroidUtil.LocationToUri(cursor.getString(0));<br>
- MediaWrapper media = new MediaWrapper(uri,<br>
- cursor.getLong(1), // MEDIA_TIME<br>
- cursor.getLong(2), // MEDIA_LENGTH<br>
- cursor.getInt(3), // MEDIA_TYPE<br>
- null, // MEDIA_PICTURE<br>
- cursor.getString(4), // MEDIA_TITLE<br>
- cursor.getString(5), // MEDIA_ARTIST<br>
- cursor.getString(6), // MEDIA_GENRE<br>
- cursor.getString(7), // MEDIA_ALBUM<br>
- cursor.getString(8), // MEDIA_ALBUMARTIST<br>
- cursor.getInt(9), // MEDIA_WIDTH<br>
- cursor.getInt(10), // MEDIA_HEIGHT<br>
- cursor.getString(11), // MEDIA_ARTWORKURL<br>
- cursor.getInt(12), // MEDIA_AUDIOTRACK<br>
- cursor.getInt(13), // MEDIA_SPUTRACK<br>
- cursor.getInt(14), // MEDIA_TRACKNUMBER<br>
- cursor.getInt(15), // MEDIA_DISCNUMBER<br>
- cursor.getLong(16)); // MEDIA_LAST_MODIFIED<br>
- medias.put(media.getUri().toString(), media);<br>
+ if (cursor != null) {<br>
+ if (cursor.moveToFirst()) {<br>
+ try {<br>
+ do {<br>
+ final Uri uri = AndroidUtil.LocationToUri(cursor.getString(0));<br>
+ MediaWrapper media = new MediaWrapper(uri,<br>
+ cursor.getLong(1), // MEDIA_TIME<br>
+ cursor.getLong(2), // MEDIA_LENGTH<br>
+ cursor.getInt(3), // MEDIA_TYPE<br>
+ null, // MEDIA_PICTURE<br>
+ cursor.getString(4), // MEDIA_TITLE<br>
+ cursor.getString(5), // MEDIA_ARTIST<br>
+ cursor.getString(6), // MEDIA_GENRE<br>
+ cursor.getString(7), // MEDIA_ALBUM<br>
+ cursor.getString(8), // MEDIA_ALBUMARTIST<br>
+ cursor.getInt(9), // MEDIA_WIDTH<br>
+ cursor.getInt(10), // MEDIA_HEIGHT<br>
+ cursor.getString(11), // MEDIA_ARTWORKURL<br>
+ cursor.getInt(12), // MEDIA_AUDIOTRACK<br>
+ cursor.getInt(13), // MEDIA_SPUTRACK<br>
+ cursor.getInt(14), // MEDIA_TRACKNUMBER<br>
+ cursor.getInt(15), // MEDIA_DISCNUMBER<br>
+ cursor.getLong(16)); // MEDIA_LAST_MODIFIED<br>
+ medias.put(media.getUri().toString(), media);<br>
+<br>
+ count++;<br>
+ } while (cursor.moveToNext());<br>
+ } catch (IllegalStateException e) {<br>
+ } //Google bug causing IllegalStateException, see <a href="https://code.google.com/p/android/issues/detail?id=32472" rel="noreferrer" target="_blank">https://code.google.com/p/android/issues/detail?id=32472</a><br>
+ }<br>
<br>
- count++;<br>
- } while (cursor.moveToNext());<br>
- } catch (IllegalStateException e) {} //Google bug causing IllegalStateException, see <a href="https://code.google.com/p/android/issues/detail?id=32472" rel="noreferrer" target="_blank">https://code.google.com/p/android/issues/detail?id=32472</a><br>
+ cursor.close();<br>
}<br>
-<br>
- cursor.close();<br>
chunk_count++;<br>
} while (count == CHUNK_SIZE);<br>
<br>
@@ -736,16 +757,18 @@ public class MediaDatabase {<br>
CHUNK_SIZE,<br>
chunk_count * CHUNK_SIZE), null);<br>
<br>
- if (cursor.moveToFirst()) {<br>
- do {<br>
- String location = cursor.getString(0);<br>
- long time = cursor.getLong(1);<br>
- times.put(location, time);<br>
- count++;<br>
- } while (cursor.moveToNext());<br>
- }<br>
+ if (cursor != null) {<br>
+ if (cursor.moveToFirst()) {<br>
+ do {<br>
+ String location = cursor.getString(0);<br>
+ long time = cursor.getLong(1);<br>
+ times.put(location, time);<br>
+ count++;<br>
+ } while (cursor.moveToNext());<br>
+ }<br>
<br>
- cursor.close();<br>
+ cursor.close();<br>
+ }<br>
chunk_count++;<br>
} while (count == CHUNK_SIZE);<br>
<br>
@@ -785,27 +808,29 @@ public class MediaDatabase {<br>
// java.lang.IllegalArgumentException: the bind value at index 1 is null<br>
return null;<br>
}<br>
- if (cursor.moveToFirst()) {<br>
- media = new MediaWrapper(uri,<br>
- cursor.getLong(0),<br>
- cursor.getLong(1),<br>
- cursor.getInt(2),<br>
- null, // lazy loading, see getPicture()<br>
- cursor.getString(3),<br>
- cursor.getString(4),<br>
- cursor.getString(5),<br>
- cursor.getString(6),<br>
- cursor.getString(7),<br>
- cursor.getInt(8),<br>
- cursor.getInt(9),<br>
- cursor.getString(10),<br>
- cursor.getInt(11),<br>
- cursor.getInt(12),<br>
- cursor.getInt(13),<br>
- cursor.getInt(14),<br>
- cursor.getLong(15));<br>
+ if (cursor != null) {<br>
+ if (cursor.moveToFirst()) {<br>
+ media = new MediaWrapper(uri,<br>
+ cursor.getLong(0),<br>
+ cursor.getLong(1),<br>
+ cursor.getInt(2),<br>
+ null, // lazy loading, see getPicture()<br>
+ cursor.getString(3),<br>
+ cursor.getString(4),<br>
+ cursor.getString(5),<br>
+ cursor.getString(6),<br>
+ cursor.getString(7),<br>
+ cursor.getInt(8),<br>
+ cursor.getInt(9),<br>
+ cursor.getString(10),<br>
+ cursor.getInt(11),<br>
+ cursor.getInt(12),<br>
+ cursor.getInt(13),<br>
+ cursor.getInt(14),<br>
+ cursor.getLong(15));<br>
+ }<br>
+ cursor.close();<br>
}<br>
- cursor.close();<br>
return media;<br>
}<br>
<br>
@@ -821,19 +846,21 @@ public class MediaDatabase {<br>
MEDIA_LOCATION + "=?",<br>
new String[] { uri.toString() },<br>
null, null, null);<br>
- if (cursor.moveToFirst()) {<br>
- blob = cursor.getBlob(0);<br>
- if (blob != null && blob.length > 1 && blob.length < 500000) {<br>
- try {<br>
- picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);<br>
- } catch(OutOfMemoryError e) {<br>
- picture = null;<br>
- } finally {<br>
- blob = null;<br>
+ if (cursor != null) {<br>
+ if (cursor.moveToFirst()) {<br>
+ blob = cursor.getBlob(0);<br>
+ if (blob != null && blob.length > 1 && blob.length < 500000) {<br>
+ try {<br>
+ picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);<br>
+ } catch (OutOfMemoryError e) {<br>
+ picture = null;<br>
+ } finally {<br>
+ blob = null;<br>
+ }<br>
}<br>
}<br>
+ cursor.close();<br>
}<br>
- cursor.close();<br>
return picture;<br>
}<br>
<br>
@@ -951,14 +978,16 @@ public class MediaDatabase {<br>
DIR_TABLE_NAME,<br>
new String[] { DIR_ROW_PATH },<br>
null, null, null, null, null);<br>
- cursor.moveToFirst();<br>
- if (!cursor.isAfterLast()) {<br>
- do {<br>
- File dir = new File(cursor.getString(0));<br>
- paths.add(dir);<br>
- } while (cursor.moveToNext());<br>
+ if (cursor != null) {<br>
+ cursor.moveToFirst();<br>
+ if (!cursor.isAfterLast()) {<br>
+ do {<br>
+ File dir = new File(cursor.getString(0));<br>
+ paths.add(dir);<br>
+ } while (cursor.moveToNext());<br>
+ }<br>
+ cursor.close();<br>
}<br>
- cursor.close();<br>
<br>
return paths;<br>
}<br>
@@ -1030,10 +1059,12 @@ public class MediaDatabase {<br>
MRL_DATE + " DESC",<br>
MRL_TABLE_SIZE);<br>
<br>
- while (cursor.moveToNext()) {<br>
- history.add(cursor.getString(0));<br>
+ if (cursor != null) {<br>
+ while (cursor.moveToNext()) {<br>
+ history.add(cursor.getString(0));<br>
+ }<br>
+ cursor.close();<br>
}<br>
- cursor.close();<br>
<br>
return history;<br>
}<br>
@@ -1060,9 +1091,12 @@ public class MediaDatabase {<br>
NETWORK_FAV_URI + "=?",<br>
new String[] { uri.toString() },<br>
null, null, null);<br>
- boolean exists = cursor.moveToFirst();<br>
- cursor.close();<br>
- return exists;<br>
+ if (cursor != null) {<br>
+ final boolean exists = cursor.moveToFirst();<br>
+ cursor.close();<br>
+ return exists;<br>
+ } else<br>
+ return false;<br>
}<br>
<br>
public synchronized ArrayList<MediaWrapper> getAllNetworkFav() {<br>
@@ -1072,14 +1106,15 @@ public class MediaDatabase {<br>
Cursor cursor = mDb.query(NETWORK_FAV_TABLE_NAME,<br>
new String[] { NETWORK_FAV_URI , NETWORK_FAV_TITLE},<br>
null, null, null, null, null);<br>
-<br>
- while (cursor.moveToNext()) {<br>
- mw = new MediaWrapper(Uri.parse(cursor.getString(0)));<br>
- mw.setTitle(Uri.decode(cursor.getString(1)));<br>
- mw.setType(MediaWrapper.TYPE_DIR);<br>
- favs.add(mw);<br>
+ if (cursor != null) {<br>
+ while (cursor.moveToNext()) {<br>
+ mw = new MediaWrapper(Uri.parse(cursor.getString(0)));<br>
+ mw.setTitle(Uri.decode(cursor.getString(1)));<br>
+ mw.setType(MediaWrapper.TYPE_DIR);<br>
+ favs.add(mw);<br>
+ }<br>
+ cursor.close();<br>
}<br>
- cursor.close();<br>
<br>
return favs;<br>
}<br>
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java<br>
index a1f26a0..0bcfc30 100644<br>
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java<br>
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java<br>
@@ -117,6 +117,7 @@ import org.videolan.vlc.widget.OnRepeatListener;<br>
<br>
import java.io.ByteArrayInputStream;<br>
import java.io.ByteArrayOutputStream;<br>
+import java.io.FileInputStream;<br>
import java.io.FileNotFoundException;<br>
import java.io.FileOutputStream;<br>
import java.io.IOException;<br>
@@ -2506,11 +2507,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C<br>
<br>
Cursor returnCursor =<br>
getContentResolver().query(data, null, null, null, null);<br>
- if (returnCursor != null && returnCursor.getCount() > 0) {<br>
- int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);<br>
- if (nameIndex > -1) {<br>
- returnCursor.moveToFirst();<br>
- title = returnCursor.getString(nameIndex);<br>
+ if (returnCursor != null) {<br>
+ if (returnCursor.getCount() > 0) {<br>
+ int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);<br>
+ if (nameIndex > -1) {<br>
+ returnCursor.moveToFirst();<br>
+ title = returnCursor.getString(nameIndex);<br>
+ }<br>
}<br>
returnCursor.close();<br>
}<br>
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java<br>
index 8bee66e..26694a6 100644<br>
--- a/vlc-android/src/org/videolan/vlc/util/Util.java<br>
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java<br>
@@ -358,7 +358,7 @@ public class Util {<br>
return false;<br>
}<br>
} else {<br>
- return false;<br>
+ return false;<br>
}<br>
}<br>
<br>
--<br>
2.1.4<br>
<br>
_______________________________________________<br>
Android mailing list<br>
<a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
</blockquote></div>