[Android] SAF: stop saving files opened through SAF

Duncan McNamara git at videolan.org
Fri May 6 08:23:37 UTC 2022


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Thu Apr 21 15:37:40 2022 +0200| [b20f10772331abbde87bf46eed18ee951fae8a2b] | committer: Nicolas Pomepuy

SAF: stop saving files opened through SAF

Because these files can't be reopened through the app, they should not
be saved and displayed in history.

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

 .../vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt  | 10 ++++++----
 .../vlc-android/src/org/videolan/vlc/util/Browserutils.kt      |  1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index b09989664..2a13b83cb 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -512,7 +512,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     fun saveMediaMeta() = launch(start = CoroutineStart.UNDISPATCHED) {
         val titleIdx = player.getTitleIdx()
         val currentMedia = getCurrentMedia() ?: return at launch
-        if (currentMedia.uri.scheme == "fd") return at launch
+        if (currentMedia.uri.scheme.isSchemeFD()) return at launch
         //Save progress
         val time = player.mediaplayer.time
         val length = player.getLength()
@@ -590,13 +590,15 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     @Synchronized
     fun saveCurrentMedia(forceVideo:Boolean = false) {
         val media = getCurrentMedia() ?: return
+        if (media.uri.scheme.isSchemeFD()) return
         val isAudio = isAudioList() || forceVideo
         settings.putSingle(if (isAudio) KEY_CURRENT_AUDIO else KEY_CURRENT_MEDIA, media.location)
         settings.putSingle(KEY_CURRENT_MEDIA_RESUME, media.location)
     }
 
     suspend fun saveMediaList(forceVideo:Boolean = false) {
-        if (getCurrentMedia() === null) return
+        val currentMedia = getCurrentMedia() ?: return
+        if (currentMedia.uri.scheme.isSchemeFD()) return
         val locations = StringBuilder()
         val isAudio = isAudioList() || forceVideo
         withContext(Dispatchers.Default) {
@@ -740,7 +742,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                             type = MediaWrapper.TYPE_STREAM
                             entryUrl = mrl
                             medialibrary.getMedia(mrl)?.run { if (id > 0) medialibrary.removeExternalMedia(id) }
-                        } else if (uri.scheme != "fd") {
+                        } else if (!uri.scheme.isSchemeFD()) {
                             medialibrary.addToHistory(mrl, title)
                         }
                     }
@@ -1032,7 +1034,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     }
 
     private suspend fun savePlaycount(mw: MediaWrapper) {
-        if (settings.getBoolean(PLAYBACK_HISTORY, true)) withContext(Dispatchers.IO) {
+        if (settings.getBoolean(PLAYBACK_HISTORY, true) && !mw.uri.scheme.isSchemeFD()) withContext(Dispatchers.IO) {
             var id = mw.id
             if (id == 0L) {
                 var internalMedia = medialibrary.findMedia(mw)
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt b/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
index d92abe99d..0eb6bb11c 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
@@ -55,6 +55,7 @@ fun String?.isSchemeFile() = when(this) {
 fun Uri.isOTG() = this.path?.startsWith("/mnt") == true
 fun Uri.isSD() = this.path != null && this.path?.startsWith("/storage") == true && this.path?.startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY) == false
 fun String?.isSchemeSMB() = this == "smb"
+fun String?.isSchemeFD() = this == "fd"
 
 fun String?.isSchemeDistant() = !this.isSchemeFile()
 



More information about the Android mailing list