novoda / download-manager

A library that handles long-running downloads, handling the network interactions and retrying downloads automatically after failures
Apache License 2.0
483 stars 63 forks source link

TargetSDK 31+ cause Fatal Exception: android.app.ForegroundServiceStartNotAllowedException #535

Closed kaan-celen closed 1 month ago

kaan-celen commented 1 year ago

Hey Dear Novoda,

We are using 2.3.4 version of this library and we update our targetSDK version to 31 recently. After that we start to receive following crash on Android 12+ devices. Can you help us or do you consider to update the library?

Fatal Exception: android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.kaancelen.example/o.cpA
       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:3346)
       at android.os.Parcel.createExceptionOrNull(Parcel.java:2433)
       at android.os.Parcel.createException(Parcel.java:2422)
       at android.os.Parcel.readException(Parcel.java:2405)
       at android.os.Parcel.readException(Parcel.java:2347)
       at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:8094)
       at android.app.Service.startForeground(Service.java:733)
       at com.novoda.downloadmanager.LiteDownloadService.start(LiteDownloadService.java:33)
       at com.novoda.downloadmanager.ServiceNotificationDispatcher.updatePersistentNotification(ServiceNotificationDispatcher.java:77)
       at com.novoda.downloadmanager.ServiceNotificationDispatcher.lambda$executeUpdateNotification$0$ServiceNotificationDispatcher(ServiceNotificationDispatcher.java:43)
       at com.novoda.downloadmanager.-$$Lambda$ServiceNotificationDispatcher$fdgBcDem2IRXi-wTA35AnYZVZcI.performAction(-.java:5077)
       at com.novoda.downloadmanager.Wait$ThenPerform.thenPerform(Wait.java:47)
       at com.novoda.downloadmanager.ServiceNotificationDispatcher.updateNotification(ServiceNotificationDispatcher.java:32)
       at com.novoda.downloadmanager.DownloadBatchStatusNotificationDispatcher.updateNotification(DownloadBatchStatusNotificationDispatcher.java:44)
       at com.novoda.downloadmanager.LiteDownloadManagerDownloader.lambda$null$1$LiteDownloadManagerDownloader(LiteDownloadManagerDownloader.java:131)
       at com.novoda.downloadmanager.-$$Lambda$LiteDownloadManagerDownloader$SKCM32-pYCABujU_3QcgQXLNLvs.run(-.java:3032)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8669)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
kaan-celen commented 1 year ago

Some related links =>

https://developer.android.com/guide/components/foreground-services https://developer.android.com/guide/components/foreground-services#background-start-restriction-exemptions

shweta-gupt commented 1 year ago

Hi Novoda,

We are using version 2.3.4 in our project. Now we have supported targetSDKVersion 31. Recently we started facing crash on Android 12 devices.

When we checked the code of Novoda , the 2.3.4 version is supporting targetSdkVersion 28. Can you please provide us some info about the update of this library?

Below are the logs of Firebase crash.

Fatal Exception: android.app.ForegroundServiceStartNotAllowedException Service.startForeground() not allowed due to mAllowStartForeground false: service com.erinstutland.video/com.novoda.downloadmanager.LiteDownloadService

android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:54) android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:50) android.os.Parcel.readParcelable (Parcel.java:3333) android.os.Parcel.createExceptionOrNull (Parcel.java:2420) android.os.Parcel.createException (Parcel.java:2409) android.os.Parcel.readException (Parcel.java:2392) android.os.Parcel.readException (Parcel.java:2334) android.app.IActivityManager$Stub$Proxy.setServiceForeground (IActivityManager.java:7096) android.app.Service.startForeground (Service.java:733) com.novoda.downloadmanager.LiteDownloadService.start (LiteDownloadService.java:33) com.novoda.downloadmanager.ServiceNotificationDispatcher.updatePersistentNotification (ServiceNotificationDispatcher.java:77) com.novoda.downloadmanager.ServiceNotificationDispatcher.lambda$executeUpdateNotification$0$ServiceNotificationDispatcher (ServiceNotificationDispatcher.java:43) com.novoda.downloadmanager.-$$Lambda$ServiceNotificationDispatcher$fUaXwJTqIk-dL4KG2RhDgF7MGBQ.performAction (Unknown Source:4) com.novoda.downloadmanager.Wait$ThenPerform.thenPerform (Wait.java:47) com.novoda.downloadmanager.ServiceNotificationDispatcher.updateNotification (ServiceNotificationDispatcher.java:32) com.novoda.downloadmanager.DownloadBatchStatusNotificationDispatcher.updateNotification (DownloadBatchStatusNotificationDispatcher.java:44) com.novoda.downloadmanager.LiteDownloadManagerDownloader.lambda$null$1$LiteDownloadManagerDownloader (LiteDownloadManagerDownloader.java:131) com.novoda.downloadmanager.-$$Lambda$LiteDownloadManagerDownloader$vjc4bI8B-wekJeUeMWHYG2tvRq8.run (Unknown Source:8) android.os.Handler.handleCallback (Handler.java:938) android.os.Handler.dispatchMessage (Handler.java:99) android.os.Looper.loopOnce (Looper.java:201) android.os.Looper.loop (Looper.java:288) android.app.ActivityThread.main (ActivityThread.java:7843) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)

kaan-celen commented 1 month ago

I fork it, fix the issue then release 2.3.5 on github. FYI https://github.com/kaan-celen/download-manager @shweta-gupt