[Android] Set services foreground only when needed

Geoffrey Métais git at videolan.org
Thu Jun 28 17:17:46 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jun 28 17:06:27 2018 +0200| [b7bf16c9adf1bbcb54489d8aa6d18b57f51befbb] | committer: Geoffrey Métais

Set services foreground only when needed

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

 vlc-android/src/org/videolan/vlc/MediaParsingService.kt | 2 +-
 vlc-android/src/org/videolan/vlc/PlaybackService.kt     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index c1d5fd9dc..7af4557f8 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -143,7 +143,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb {
             // Set 1s delay before displaying scan icon
             // Except for Android 8+ which expects startForeground immediately
 
-        if (AndroidUtil.isOOrLater) forceForeground()
+        if (AndroidUtil.isOOrLater && lastNotificationTime == 0L) forceForeground()
         else if (lastNotificationTime <= 0L) notificationActor.offer(UPDATE_NOTIFICATION_TIME)
         when (intent.action) {
             Constants.ACTION_INIT -> {
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index f091e1d1c..426aecad6 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -498,7 +498,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
     }
 
     override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
-        if (AndroidUtil.isOOrLater && !VLCApplication.isForeground()) forceForeground()
+        if (AndroidUtil.isOOrLater && !isForeground && !VLCApplication.isForeground()) forceForeground()
         when (intent?.action) {
             Intent.ACTION_MEDIA_BUTTON -> {
                 if (AndroidDevices.hasTsp || AndroidDevices.hasPlayServices) MediaButtonReceiver.handleIntent(mediaSession, intent)



More information about the Android mailing list