下载代码优化
This commit is contained in:
@@ -474,6 +474,26 @@ object CacheBook {
|
||||
updateSummary()
|
||||
}
|
||||
|
||||
fun shutdownPreservingPaused() {
|
||||
isPaused = false
|
||||
val toRemove = ArrayList<String>()
|
||||
cacheBookMap.forEach { (bookUrl, model) ->
|
||||
val keep = synchronized(model) {
|
||||
model.isPaused() || model.pausedIndices().isNotEmpty()
|
||||
}
|
||||
if (keep) return@forEach
|
||||
toRemove.add(bookUrl)
|
||||
model.stop()
|
||||
}
|
||||
toRemove.forEach { cacheBookMap.remove(it) }
|
||||
successDownloadCount.set(0)
|
||||
pendingRemoveRequests.values.forEach { it.complete(false) }
|
||||
pendingRemoveRequests.clear()
|
||||
clearPendingAdmissions()
|
||||
stateStore.clearRuntimeState()
|
||||
updateSummary()
|
||||
}
|
||||
|
||||
fun setWorkingState(value: Boolean) {
|
||||
coordinator.setWorkingState(value)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ class CacheBookService : BaseService() {
|
||||
private const val DIAGNOSTICS_LOG_INTERVAL_MILLIS = 5_000L
|
||||
private const val MAX_IDLE_SPIN_MS = 60_000L
|
||||
|
||||
@Volatile
|
||||
var isRun = false
|
||||
private set
|
||||
}
|
||||
@@ -183,9 +184,9 @@ class CacheBookService : BaseService() {
|
||||
admissionIdleWaiters.values.flatten().forEach { it.complete(Unit) }
|
||||
admissionIdleWaiters.clear()
|
||||
}
|
||||
CacheBook.close(clearFailureState = false)
|
||||
serviceCommandScope.cancel()
|
||||
CacheBook.shutdownPreservingPaused()
|
||||
super.onDestroy()
|
||||
serviceCommandScope.cancel()
|
||||
}
|
||||
|
||||
private fun reconstructRequestFromIntent(intent: Intent): CacheDownloadRequest? {
|
||||
|
||||
Reference in New Issue
Block a user