Skip to content
Snippets Groups Projects
Commit 32e7f82d authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Services: Force foreground sooner

May help reduce RemoteServiceException occurences
parent 53fe49ab
No related branches found
No related tags found
1 merge request!531Services: Force foreground sooner
Pipeline #15495 passed with stage
in 5 minutes and 4 seconds
......@@ -122,6 +122,7 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
dispatcher.onServicePreSuperOnCreate()
super.onCreate()
NotificationHelper.createNotificationChannels(applicationContext)
if (AndroidUtil.isOOrLater) forceForeground()
medialibrary = Medialibrary.getInstance()
medialibrary.addDeviceDiscoveryCb(this@MediaParsingService)
val filter = IntentFilter()
......
......@@ -477,6 +477,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
updateHasWidget()
if (!this::mediaSession.isInitialized) initMediaSession()
forceForeground()
val filter = IntentFilter().apply {
priority = Integer.MAX_VALUE
......@@ -523,7 +524,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (AndroidUtil.isOOrLater && !isForeground) forceForeground()
forceForeground()
dispatcher.onServicePreSuperOnStart()
setupScope()
when (intent?.action) {
......@@ -587,6 +588,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
@TargetApi(Build.VERSION_CODES.O)
private fun forceForeground() {
if (!AndroidUtil.isOOrLater || isForeground) return
val ctx = this@PlaybackService
val stopped = PlayerController.playbackState == PlaybackStateCompat.STATE_STOPPED
val notification = if (this::notification.isInitialized && !stopped) notification
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment