[Android] Sanity check on Uri retrieval

Geoffrey Métais git at videolan.org
Wed Mar 13 11:11:25 CET 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar  7 09:54:26 2019 +0100| [cf485c7a7992e1ef8053a7eb998a65502fdd4d7c] | committer: Geoffrey Métais

Sanity check on Uri retrieval

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

 vlc-android/src/org/videolan/vlc/media/MediaUtils.kt | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt b/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
index e7bed6216..3630911fe 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
+++ b/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
@@ -280,13 +280,16 @@ object MediaUtils : CoroutineScope {
 
     fun getMediaTitle(mediaWrapper: MediaWrapper) = mediaWrapper.title ?: FileUtils.getFileNameFromPath(mediaWrapper.location)!!
 
-    fun getContentMediaUri(data: Uri): Uri {
+    fun getContentMediaUri(data: Uri)= try {
         VLCApplication.getAppContext().contentResolver.query(data,
                 arrayOf(MediaStore.Video.Media.DATA), null, null, null)?.use {
             val columnIndex = it.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)
-            if (it.moveToFirst()) return AndroidUtil.PathToUri(it.getString(columnIndex)) ?: data
+            if (it.moveToFirst()) AndroidUtil.PathToUri(it.getString(columnIndex)) ?: data else data
         }
-        return data
+    } catch (e: SecurityException) {
+        data
+    } catch (e: IllegalArgumentException) {
+        data
     }
 
     private fun getMediaString(ctx: Context?, id: Int): String {



More information about the Android mailing list