vanilla-music / vanilla

Vanilla Music Player for Android
GNU General Public License v3.0
1.19k stars 296 forks source link

App crashes on resuming #1086

Closed opusforlife2 closed 5 months ago

opusforlife2 commented 3 years ago

Steps to reproduce the issue

Play some music in Vanilla. Then pause it/let it be paused by another media app. Do something else for a while. Come back to Vanilla. Crash.

This behavious is not consistent, though. Sometimes it crashes, but other times it resumes just fine. Probably, a longer period away from the app would make it more likely to encounter a crash.

Logs

FATAL EXCEPTION: main
Process: ch.blinkenlights.android.vanilla, PID: 5232
java.lang.IllegalStateException: Not allowed to start service Intent { cmp=ch.blinkenlights.android.vanilla/.PlaybackService }: app is in background uid UidRecord{2ffc8d1 u0a175 LAST bg:+6m21s338ms idle change:cached procs:1 seq(0,0,0)}
    at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1616)
    at android.app.ContextImpl.startService(ContextImpl.java:1571)
    at android.content.ContextWrapper.startService(ContextWrapper.java:669)
    at ch.blinkenlights.android.vanilla.r.onStart(Unknown Source:20)
    at ch.blinkenlights.android.vanilla.FullPlaybackActivity.onStart(Unknown Source:0)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1432)
    at android.app.Activity.performStart(Activity.java:7847)
    at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3294)
    at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
    at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:940)
adrian-bl commented 3 years ago

Interesting: Since Android 8.0, apps are only allowed to create services while the app is in foreground (or: create a foreground service (-> notification)): https://developer.android.com/about/versions/oreo/background

It's pretty strange that this happens while FullPlaybackActivity.onStart() is called since the app is about to come into the foreground.

Did you have this issue since forever or did it only start recently?

opusforlife2 commented 3 years ago

I think it might have started in this or the previous version. I'm not sure, sorry.

adrian-bl commented 3 years ago

I tried to reproduce this today on an Android 10 device, but was unable to:

I tried to:

-> No crash, tried about 20 times :-/

How consistent can you reproduce the issue? Maybe we could catch the exception and fire off a worker thread which would try to create the activity once the app is fully launched.

opusforlife2 commented 3 years ago

It's not consistent, as I've said. I've speculated on what might trigger it, but I can't reproduce it at will.

I can install a debug APK to test solutions out, if you want.

opusforlife2 commented 3 years ago

Got the crash again. One line is slightly different this time:

java.lang.IllegalStateException: Not allowed to start service Intent { cmp=ch.blinkenlights.android.vanilla/.PlaybackService }: app is in background uid UidRecord{a02f111 u0a175 CAC  bg:+12m39s511ms idle change:cached procs:1 seq(0,0,0)}

Edit: Another:

java.lang.IllegalStateException: Not allowed to start service Intent { cmp=ch.blinkenlights.android.vanilla/.PlaybackService }: app is in background uid UidRecord{f00b293 u0a175 TPSL bg:+2m37s516ms idle change:cached procs:1 seq(0,0,0)}
opusforlife2 commented 3 years ago

Another thing I noticed:

opusforlife2 commented 3 years ago

This time I encountered the crash when my car Bluetooth connected and the phone tried to resume playing audio in Vanilla (since it was the last used media app). The error message was the same, so I didn't bother keeping the crash log.

opusforlife2 commented 3 years ago

Got a pretty quick crash this time. The time between going away from Vanilla and coming back must have been less than a minute.

It's the same crash as all the ones above.

opusforlife2 commented 5 months ago

Closing as I haven't encountered this for a long time.