seedvault-app / seedvault

A backup application for the Android Open Source Project.
1.31k stars 75 forks source link

System crashes us on Android 15 if foreground service runs for too long #795

Open grote opened 3 weeks ago

grote commented 3 weeks ago
--------- beginning of crash
10-23 17:27:05.674 16081 16081 E AndroidRuntime: FATAL EXCEPTION: main
10-23 17:27:05.674 16081 16081 E AndroidRuntime: Process: com.stevesoltys.seedvault, PID: 16081
10-23 17:27:05.674 16081 16081 E AndroidRuntime: android.app.RemoteServiceException$ForegroundServiceDidNotStopInTimeException: A foreground service of type dataSync did not stop within its timeout: ComponentInfo{com.stevesoltys.seedvault/androidx.work.impl.foreground.SystemForegroundService}
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at android.app.ActivityThread.generateForegroundServiceDidNotStopInTimeException(ActivityThread.java:2280)
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2242)
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2557)
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:107)
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:232)
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:317)
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:8705)
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
10-23 17:27:05.674 16081 16081 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
grote commented 1 week ago

Some related docs: https://developer.android.com/about/versions/15/changes/foreground-service-types

If the timeout period is reached, the system calls the service's Service.onTimeout(int, int) method. At this time, the service has a few seconds to call [Service.stopSelf()](https://developer.android.com/reference/android/app/Service#stopSelf()). If the service does not call Service.stopSelf(), an ANR will occur with this error message: "A foreground service of did not stop within its timeout: ".

However, our workers automatically use androidx.work.impl.foreground.SystemForegroundService, so we can't fix this ourselves. Maybe there's a WorkManager bug for this upstream.