[Android] Await app foreground to start MediaParsingService

Geoffrey Métais git at videolan.org
Mon Jan 27 15:59:57 CET 2020


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan 27 15:57:31 2020 +0100| [e4847ee365801ea12875360def254f751cc28173] | committer: Geoffrey Métais

Await app foreground to start MediaParsingService

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

 .../vlc-android/src/org/videolan/vlc/StartActivity.kt    | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/StartActivity.kt b/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
index a97e5ebb5..97749e44b 100644
--- a/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
@@ -42,10 +42,7 @@ import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.medialibrary.MLServiceLocator
 import org.videolan.resources.*
 import org.videolan.resources.util.startMedialibrary
-import org.videolan.tools.BETA_WELCOME
-import org.videolan.tools.Settings
-import org.videolan.tools.awaitAppIsForegroung
-import org.videolan.tools.getContextWithLocale
+import org.videolan.tools.*
 import org.videolan.vlc.gui.BetaWelcomeActivity
 import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getStoragePermission
 import org.videolan.vlc.gui.onboarding.ONBOARDING_DONE_KEY
@@ -191,8 +188,15 @@ class StartActivity : FragmentActivity() {
         // cf https://github.com/Kotlin/kotlinx.coroutines/issues/878
         if (!onboarding || !firstRun) {
             Thread {
-                this at StartActivity.startMedialibrary(firstRun, upgrade, true)
-                if (onboarding)  settings.edit().putBoolean(ONBOARDING_DONE_KEY, true).apply()
+                AppScope.launch {
+                    // workaround for a Android 9 bug
+                    // https://issuetracker.google.com/issues/113122354
+                    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.P && !awaitAppIsForegroung()) {
+                        return at launch
+                    }
+                    this at StartActivity.startMedialibrary(firstRun, upgrade, true)
+                    if (onboarding)  settings.edit().putBoolean(ONBOARDING_DONE_KEY, true).apply()
+                }
             }.start()
             val intent = Intent().apply { setClassName(applicationContext, if (tv) "org.videolan.television.ui.MainTvActivity" else "org.videolan.vlc.gui.MainActivity") }
                     .putExtra(EXTRA_FIRST_RUN, firstRun)



More information about the Android mailing list