Check wakelock is held in download service

This commit is contained in:
Koitharu
2020-05-20 19:04:31 +03:00
parent 260ff32cd1
commit 7d147b3c37

View File

@@ -76,7 +76,7 @@ class DownloadService : BaseService() {
private fun downloadManga(manga: Manga, chaptersIds: Set<Long>?, startId: Int): Job {
return launch(Dispatchers.IO) {
mutex.lock()
wakeLock.acquire(TimeUnit.MINUTES.toMillis(20))
wakeLock.acquire(TimeUnit.HOURS.toMillis(1))
withContext(Dispatchers.Main) {
notification.fillFrom(manga)
notification.setCancelId(startId)
@@ -167,7 +167,9 @@ class DownloadService : BaseService() {
notification.dismiss()
stopSelf(startId)
}
wakeLock.release()
if (wakeLock.isHeld) {
wakeLock.release()
}
mutex.unlock()
}
}