[Android] Prevent SecurityException
Geoffrey Métais
git at videolan.org
Tue Oct 10 19:37:21 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Oct 10 19:36:48 2017 +0200| [9b0e87efa4c4e0db50b3c47117fcc9df83c17f80] | committer: Geoffrey Métais
Prevent SecurityException
> https://code.videolan.org/videolan/vlc-android/commit/9b0e87efa4c4e0db50b3c47117fcc9df83c17f80
---
.../src/org/videolan/vlc/PlaybackService.java | 25 ++++++++++++++--------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 1ef1dba4f..8a37e813c 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -2073,16 +2073,23 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
}
private void retrieveMediaTitle(MediaWrapper mw) {
- final Cursor returnCursor = getContentResolver().query(mw.getUri(), null, null, null, null);
- if (returnCursor == null)
- return;
- final int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
- if (nameIndex > -1 && returnCursor.getCount() > 0) {
- returnCursor.moveToFirst();
- if (!returnCursor.isNull(nameIndex))
- mw.setTitle(returnCursor.getString(nameIndex));
+ Cursor cursor = null;
+ try {
+ cursor = getContentResolver().query(mw.getUri(), null, null, null, null);
+ if (cursor == null)
+ return;
+ final int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
+ if (nameIndex > -1 && cursor.getCount() > 0) {
+ cursor.moveToFirst();
+ if (!cursor.isNull(nameIndex))
+ mw.setTitle(cursor.getString(nameIndex));
+ }
+ } catch (SecurityException e) { // We may not have storage access permission yet
+ Log.w(TAG, "retrieveMediaTitle: fail to resolve file from "+mw.getUri(), e);
+ } finally {
+ if (cursor != null && !cursor.isClosed())
+ cursor.close();
}
- Util.close(returnCursor);
}
/**
More information about the Android
mailing list