From aa9f6eaefaa10e2159995994dcd7b3b6f746c940 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 23 Jun 2021 14:02:07 +0200 Subject: [PATCH] Add IdleRefreshTimeoutProvider --- .../java/com/fsck/k9/backend/imap/ImapBackendPusher.kt | 9 ++++++--- .../java/com/fsck/k9/backend/imap/ImapFolderPusher.kt | 5 +++-- .../k9/mail/store/imap/IdleRefreshTimeoutProvider.kt | 5 +++++ .../java/com/fsck/k9/mail/store/imap/ImapFolderIdler.kt | 4 ++-- .../com/fsck/k9/mail/store/imap/RealImapFolderIdler.kt | 6 +++--- 5 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/IdleRefreshTimeoutProvider.kt diff --git a/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapBackendPusher.kt b/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapBackendPusher.kt index af2978b85..3d11c6a68 100644 --- a/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapBackendPusher.kt +++ b/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapBackendPusher.kt @@ -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 ) } diff --git a/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapFolderPusher.kt b/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapFolderPusher.kt index 4c172fbae..19e284909 100644 --- a/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapFolderPusher.kt +++ b/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapFolderPusher.kt @@ -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 } diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/IdleRefreshTimeoutProvider.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/IdleRefreshTimeoutProvider.kt new file mode 100644 index 000000000..6ad88acf6 --- /dev/null +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/IdleRefreshTimeoutProvider.kt @@ -0,0 +1,5 @@ +package com.fsck.k9.mail.store.imap + +interface IdleRefreshTimeoutProvider { + val idleRefreshTimeoutMs: Long +} diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapFolderIdler.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapFolderIdler.kt index 36492b326..2642e956d 100644 --- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapFolderIdler.kt +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapFolderIdler.kt @@ -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 ) } } diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolderIdler.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolderIdler.kt index 9fcdedc4d..1cc7356ee 100644 --- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolderIdler.kt +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolderIdler.kt @@ -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