[Android] Set all mediabrowser calls in mutex lock

Geoffrey Métais git at videolan.org
Mon Jan 7 10:18:29 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan  7 10:17:51 2019 +0100| [73445b4c9744b98141781d55f05327c46bc99074] | committer: Geoffrey Métais

Set all mediabrowser calls in mutex lock

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

 vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt    | 2 +-
 vlc-android/src/org/videolan/vlc/providers/FilePickerProvider.kt | 9 ++++++++-
 vlc-android/src/org/videolan/vlc/providers/NetworkProvider.kt    | 8 +++++++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index 0c7cb0626..16a048a84 100644
--- a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -52,7 +52,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
 
     override val coroutineContext = Dispatchers.Main.immediate
 
-    private val mutex= Mutex()
+    protected val mutex= Mutex()
     protected var mediabrowser: MediaBrowser? = null
 
     private val foldersContentMap = androidx.collection.SimpleArrayMap<MediaLibraryItem, MutableList<MediaLibraryItem>>()
diff --git a/vlc-android/src/org/videolan/vlc/providers/FilePickerProvider.kt b/vlc-android/src/org/videolan/vlc/providers/FilePickerProvider.kt
index 172106b6f..5e891e111 100644
--- a/vlc-android/src/org/videolan/vlc/providers/FilePickerProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/FilePickerProvider.kt
@@ -21,6 +21,9 @@
 package org.videolan.vlc.providers
 
 import android.content.Context
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.sync.withLock
 import org.videolan.libvlc.util.MediaBrowser
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.MediaWrapper
@@ -35,7 +38,11 @@ class FilePickerProvider(context: Context, dataset: LiveDataset<MediaLibraryItem
 
     override fun initBrowser() {
         super.initBrowser()
-        mediabrowser?.setIgnoreFileTypes("db,nfo,ini,jpg,jpeg,ljpg,gif,png,pgm,pgmyuv,pbm,pam,tga,bmp,pnm,xpm,xcf,pcx,tif,tiff,lbm,sfv")
+        launch(Dispatchers.IO) {
+            mutex.withLock {
+                mediabrowser?.setIgnoreFileTypes("db,nfo,ini,jpg,jpeg,ljpg,gif,png,pgm,pgmyuv,pbm,pam,tga,bmp,pnm,xpm,xcf,pcx,tif,tiff,lbm,sfv")
+            }
+        }
     }
 
     override fun addMedia(media: MediaLibraryItem) {
diff --git a/vlc-android/src/org/videolan/vlc/providers/NetworkProvider.kt b/vlc-android/src/org/videolan/vlc/providers/NetworkProvider.kt
index 01a1cdf63..0456ebfb8 100644
--- a/vlc-android/src/org/videolan/vlc/providers/NetworkProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/NetworkProvider.kt
@@ -22,7 +22,9 @@ package org.videolan.vlc.providers
 
 import android.content.Context
 import androidx.lifecycle.Observer
+import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.launch
+import kotlinx.coroutines.sync.withLock
 import org.videolan.medialibrary.media.DummyItem
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.MediaWrapper
@@ -61,7 +63,11 @@ class NetworkProvider(context: Context, dataset: LiveDataset<MediaLibraryItem>,
     }
 
     override fun stop(): Unit? {
-        if (url == null) mediabrowser?.changeEventListener(null)
+        launch(Dispatchers.IO) {
+            if (url == null) mutex.withLock {
+                mediabrowser?.changeEventListener(null)
+            }
+        }
         return super.stop()
     }
 



More information about the Android mailing list