[Android] Medialibrary parsing: prevent early service exit

Geoffrey Métais git at videolan.org
Thu Jul 18 16:07:00 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jul 18 15:57:21 2019 +0200| [2cd3e6136fd9cbb53ce30a2f027063124e2f39b7] | committer: Geoffrey Métais

Medialibrary parsing: prevent early service exit

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

 vlc-android/src/org/videolan/vlc/MediaParsingService.kt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 223ef34e8..d125aa8e4 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -78,6 +78,8 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
 
     @Volatile
     private var serviceLock = false
+    @Volatile
+    private var discoverTriggered = false
     internal val sb = StringBuilder()
 
     private val notificationActor by lazy {
@@ -159,6 +161,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
             exitCommand()
             return
         }
+        discoverTriggered = true
         actions.offer(DiscoverStorage(path))
     }
 
@@ -313,6 +316,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
 
     override fun onDiscoveryStarted(entryPoint: String) {
         if (BuildConfig.DEBUG) Log.v(TAG, "onDiscoveryStarted: $entryPoint")
+        discoverTriggered = false
     }
 
     override fun onDiscoveryProgress(entryPoint: String) {
@@ -343,7 +347,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
     }
 
     private fun exitCommand() = launch {
-        if (!medialibrary.isWorking && !serviceLock) {
+        if (!medialibrary.isWorking && !serviceLock && !discoverTriggered) {
             lastNotificationTime = 0L
             stopSelf()
         }



More information about the Android mailing list