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