[Android] FileUtils: Sanity checks

Geoffrey Métais git at videolan.org
Tue Oct 1 14:44:45 CEST 2019


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Sep 26 10:21:01 2019 +0200| [67c8079bd7f52d1f0e0887ae7bbba998c36b3eab] | committer: Geoffrey Métais

FileUtils: Sanity checks

(cherry picked from commit 244bc7e2cd503b0815365d2bdbf78b05e1153159)

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

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

diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.kt b/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
index f159fd1f7..2d6e52233 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
@@ -232,7 +232,6 @@ object FileUtils {
                 return docFile.delete()
             } catch (ignored: Exception) {
             }
-
         return false
     }
 
@@ -325,11 +324,10 @@ object FileUtils {
     @WorkerThread
     fun findFile(uri: Uri): DocumentFile? {
         uri.path?.let { path ->
-            val storage = getMediaStorage(uri)
-            val treePref = Settings.getInstance(VLCApplication.appContext).getString("tree_uri_" + storage!!, null)
-                    ?: return null
+            val context = (VLCApplication.appContext as Context?) ?: return null
+            val treePref = getMediaStorage(uri)?.let { Settings.getInstance(context).getString("tree_uri_$it", null) } ?: return null
             val treeUri = Uri.parse(treePref)
-            var documentFile = DocumentFile.fromTreeUri(VLCApplication.appContext, treeUri)
+            var documentFile = DocumentFile.fromTreeUri(context, treeUri)
             val parts = path.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
             for (i in 3 until parts.size) {
                 if (documentFile != null)
@@ -340,7 +338,6 @@ object FileUtils {
             return documentFile
         }
         return null
-
     }
 
     @WorkerThread



More information about the Android mailing list