Add IdleRefreshTimeoutProvider
This commit is contained in:
parent
145eba5e2e
commit
aa9f6eaefa
5 changed files with 19 additions and 10 deletions
|
@ -6,6 +6,7 @@ import com.fsck.k9.mail.AuthenticationFailedException
|
|||
import com.fsck.k9.mail.MessagingException
|
||||
import com.fsck.k9.mail.power.PowerManager
|
||||
import com.fsck.k9.mail.store.imap.IdleRefreshManager
|
||||
import com.fsck.k9.mail.store.imap.IdleRefreshTimeoutProvider
|
||||
import com.fsck.k9.mail.store.imap.IdleRefreshTimer
|
||||
import com.fsck.k9.mail.store.imap.ImapStore
|
||||
import java.io.IOException
|
||||
|
@ -88,8 +89,10 @@ internal class ImapBackendPusher(
|
|||
}
|
||||
|
||||
private fun createImapFolderPusher(folderServerId: String): ImapFolderPusher {
|
||||
// TODO: use value from account settings
|
||||
val idleRefreshTimeoutMs = 15 * 60 * 1000L
|
||||
val idleRefreshTimeoutProvider = object : IdleRefreshTimeoutProvider {
|
||||
// TODO: use value from account settings
|
||||
override val idleRefreshTimeoutMs = 15 * 60 * 1000L
|
||||
}
|
||||
return ImapFolderPusher(
|
||||
imapStore,
|
||||
powerManager,
|
||||
|
@ -97,7 +100,7 @@ internal class ImapBackendPusher(
|
|||
this,
|
||||
accountName,
|
||||
folderServerId,
|
||||
idleRefreshTimeoutMs
|
||||
idleRefreshTimeoutProvider
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.fsck.k9.backend.imap
|
|||
|
||||
import com.fsck.k9.mail.power.PowerManager
|
||||
import com.fsck.k9.mail.store.imap.IdleRefreshManager
|
||||
import com.fsck.k9.mail.store.imap.IdleRefreshTimeoutProvider
|
||||
import com.fsck.k9.mail.store.imap.IdleResult
|
||||
import com.fsck.k9.mail.store.imap.ImapFolderIdler
|
||||
import com.fsck.k9.mail.store.imap.ImapStore
|
||||
|
@ -18,7 +19,7 @@ class ImapFolderPusher(
|
|||
private val callback: ImapPusherCallback,
|
||||
private val accountName: String,
|
||||
private val folderServerId: String,
|
||||
private val idleRefreshTimeoutMs: Long
|
||||
private val idleRefreshTimeoutProvider: IdleRefreshTimeoutProvider
|
||||
) {
|
||||
@Volatile
|
||||
private var folderIdler: ImapFolderIdler? = null
|
||||
|
@ -56,7 +57,7 @@ class ImapFolderPusher(
|
|||
wakeLock,
|
||||
imapStore,
|
||||
folderServerId,
|
||||
idleRefreshTimeoutMs
|
||||
idleRefreshTimeoutProvider
|
||||
).also {
|
||||
folderIdler = it
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package com.fsck.k9.mail.store.imap
|
||||
|
||||
interface IdleRefreshTimeoutProvider {
|
||||
val idleRefreshTimeoutMs: Long
|
||||
}
|
|
@ -20,7 +20,7 @@ interface ImapFolderIdler {
|
|||
wakeLock: WakeLock,
|
||||
imapStore: ImapStore,
|
||||
folderServerId: String,
|
||||
idleRefreshTimeoutMs: Long
|
||||
idleRefreshTimeoutProvider: IdleRefreshTimeoutProvider
|
||||
): ImapFolderIdler {
|
||||
return RealImapFolderIdler(
|
||||
idleRefreshManager,
|
||||
|
@ -28,7 +28,7 @@ interface ImapFolderIdler {
|
|||
imapStore,
|
||||
connectionProvider,
|
||||
folderServerId,
|
||||
idleRefreshTimeoutMs
|
||||
idleRefreshTimeoutProvider
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ internal class RealImapFolderIdler(
|
|||
private val imapStore: ImapStore,
|
||||
private val connectionProvider: ImapConnectionProvider,
|
||||
private val folderServerId: String,
|
||||
private val idleRefreshTimeoutMs: Long
|
||||
private val idleRefreshTimeoutProvider: IdleRefreshTimeoutProvider
|
||||
) : ImapFolderIdler {
|
||||
private val logTag = "ImapFolderIdler[$folderServerId]"
|
||||
|
||||
|
@ -89,7 +89,7 @@ internal class RealImapFolderIdler(
|
|||
val expectSleeping = !connection.isDataAvailable() && !stopIdle
|
||||
|
||||
idleRefreshTimer = if (expectSleeping) {
|
||||
idleRefreshManager.startTimer(idleRefreshTimeoutMs) { idleRefresh() }
|
||||
idleRefreshManager.startTimer(idleRefreshTimeoutProvider.idleRefreshTimeoutMs) { idleRefresh() }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ internal class RealImapFolderIdler(
|
|||
}
|
||||
|
||||
private fun ImapConnection.setSocketIdleReadTimeout() {
|
||||
setSocketReadTimeout((idleRefreshTimeoutMs + SOCKET_EXTRA_TIMEOUT_MS).toInt())
|
||||
setSocketReadTimeout((idleRefreshTimeoutProvider.idleRefreshTimeoutMs + SOCKET_EXTRA_TIMEOUT_MS).toInt())
|
||||
}
|
||||
|
||||
private val ImapResponse.isRelevant: Boolean
|
||||
|
|
Loading…
Reference in a new issue