kiwix / kiwix-android

Kiwix for Android
https://android.kiwix.org
GNU General Public License v3.0
826 stars 443 forks source link

Download notification disappearing #3882

Open kelson42 opened 1 month ago

kelson42 commented 1 month ago

I have no clear reproduction steps, but downloading large files at some point make the download notification disappearing.

MohitMaliFtechiz commented 1 month ago

@kelson42 Can you please provide some addtional information so that the problem can be narrowed down?

kelson42 commented 1 month ago

Android 13, only one download at a time. It disappear I believe after a while if I don't use the device and never reapoear... but downloads continues (I see it in the library).

MohitMaliFtechiz commented 1 month ago

@kelson42 I have tested this issue with different large zim files, and left the phone until the files were not downloading, and monitored the behavior but the notification was visible all the time. The notification only disappeared when I killed the application(closed from the background list), and again visible when I reopened the application. Apart from this, the notification is triggering from the fetch lib with the downloadProgress see the below method of fetch lib.

https://github.com/tonyofrancis/Fetch/blob/c450f681035ed47d2bd6e5e2b7cf4b921665e669/fetch2/src/main/java/com/tonyodev/fetch2/fetch/ListenerCoordinator.kt#L413

override fun progress(download: Download, etaInMilliSeconds: Long, downloadedBytesPerSecond: Long) {
            synchronized(lock) {
                fetchNotificationHandler.post {
                    synchronized(lock) {
                        for (fetchNotificationManager in fetchNotificationManagerList) {
                            if (fetchNotificationManager.postDownloadUpdate(download)) break
                        }
                    }
                }
                fetchListenerMap.values.forEach {
                    val iterator = it.iterator()
                    while (iterator.hasNext()) {
                        val fetchListener = iterator.next().get()
                        if (fetchListener == null) {
                            iterator.remove()
                        } else {
                            uiHandler.post {
                                fetchListener.onProgress(download, etaInMilliSeconds, downloadedBytesPerSecond)
                            }
                        }
                    }
                }
                if (fetchGroupListenerMap.isNotEmpty()) {
                    val groupId = download.group
                    val fetchGroup = groupInfoProvider.getGroupReplace(groupId, download, Reason.DOWNLOAD_PROGRESS_CHANGED)
                    fetchGroupListenerMap.values.forEach {
                        val iterator = it.iterator()
                        while (iterator.hasNext()) {
                            val fetchListener = iterator.next().get()
                            if (fetchListener == null) {
                                iterator.remove()
                            } else {
                                fetchListener.onProgress(groupId, download, etaInMilliSeconds, downloadedBytesPerSecond, fetchGroup)
                            }
                        }
                    }
                } else {
                    groupInfoProvider.postGroupReplace(download.group, download, Reason.DOWNLOAD_PROGRESS_CHANGED)
                }
                val downloadObserverSet = downloadsObserverMap[download.id]
                downloadObserverSet?.forEach {
                    val observer = it.get()
                    if (observer != null) {
                        uiHandler.post {
                            observer.onChanged(download, Reason.DOWNLOAD_PROGRESS_CHANGED)
                        }
                    }
                }
            }
        }

In the above code, notification and downloadProgress are triggering via this method.

This code triggers the notification

for (fetchNotificationManager in fetchNotificationManagerList) {
      if (fetchNotificationManager.postDownloadUpdate(download)) break
}

As you mentioned downloads continue so this method is running as it is publishing the download progress via below method, and we are handling this progress and showing it in LocalLibrary.

fetchListener.onProgress(download, etaInMilliSeconds, downloadedBytesPerSecond)

So the postDownloadUpdate method is not calling which updates the notification, somehow the fetchNotificationManager listener was removed. The removal and adding of the fetchNotificationManager listener is internal to fetch. The notification disappears after 10 seconds if it is not updated(To handle the app killing scenarios).

kelson42 commented 5 days ago

I will retest once #3940 is merged