VishnuSanal / DialogMusicPlayer

A simple and minimal music player dialog :)
https://vishnusanal.github.io/posts/story-of-dialogmusicplayer/
GNU General Public License v3.0
83 stars 5 forks source link

`ForegroundServiceStartNotAllowedException` crash #42

Open shuvashish76 opened 1 year ago

shuvashish76 commented 1 year ago

Describe the bug App crashes when play a music from another music player e.g BlackHole/VLC while DMP playing.

To Reproduce Steps to reproduce the behavior:

  1. Play a music from FM > DMP
  2. While DMP playing the music, open BH & play a music.
  3. See error

Crash logs

FATAL EXCEPTION: main
Process: phone.vishnu.dialogmusicplayer, PID: 4109
android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service phone.vishnu.dialogmusicplayer/.MediaPlaybackService
    at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
    at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
    at android.os.Parcel.readParcelable(Parcel.java:3334)
    at android.os.Parcel.createExceptionOrNull(Parcel.java:2421)
    at android.os.Parcel.createException(Parcel.java:2410)
    at android.os.Parcel.readException(Parcel.java:2393)
    at android.os.Parcel.readException(Parcel.java:2335)
    at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7637)
    at android.app.Service.startForeground(Service.java:733)
    at phone.vishnu.dialogmusicplayer.MediaPlaybackService$a.c(SourceFile:29)
    at android.support.v4.media.session.MediaSessionCompat$a$b.onPause(SourceFile:13)
    at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1622)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loopOnce(Looper.java:238)
    at android.os.Looper.loop(Looper.java:357)
    at android.app.ActivityThread.main(ActivityThread.java:8090)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026)
Caused by: android.os.RemoteException: Remote stack trace:
    at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:1881)
    at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1394)
    at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:12280)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3473)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2602)

Smartphone (please complete the following information):

VishnuSanal commented 1 year ago

@shuvashish76 have you enabled battery restrictions/some other types of background restrictions on your device when this crash occurred? 🤔

PS: I found this, but just wanted to confirm.

shuvashish76 commented 1 year ago

Everything set to default. I'm not sure.

matterharz commented 1 year ago

This can be solved, at least in my case, by switching the app's battery settings to "Unrestricted" (or whatever it's called in the OS and language you use). Used to be "Optimized".

OnePlus 5t, LineageOS 19.1, v2.1.0