Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e0626160 authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

5293-Fix_crash_on_non_gmail_domained_google_account_add

issue: https://gitlab.e.foundation/e/backlog/-/issues/5293

Fix app crash on startup when multiple accounts are configured
parent 625b926e
Loading
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -3,20 +3,22 @@ package com.fsck.k9.backend
import com.fsck.k9.Account
import com.fsck.k9.backend.api.Backend
import com.fsck.k9.mail.ServerSettings
import java.lang.Exception
import java.util.concurrent.CopyOnWriteArraySet
import timber.log.Timber

class BackendManager(private val backendFactories: Map<String, BackendFactory>) {
    private val backendCache = mutableMapOf<String, BackendContainer>()
    private val listeners = CopyOnWriteArraySet<BackendChangedListener>()

    fun getBackend(account: Account): Backend {
    fun getBackend(account: Account): Backend? {
        val newBackend = synchronized(backendCache) {
            val container = backendCache[account.uuid]
            if (container != null && isBackendStillValid(container, account)) {
                return container.backend
            }

            createBackend(account).also { backend ->
            createBackend(account)?.also { backend ->
                backendCache[account.uuid] = BackendContainer(
                    backend,
                    account.incomingServerSettings,
@@ -43,10 +45,15 @@ class BackendManager(private val backendFactories: Map<String, BackendFactory>)
        notifyListeners(account)
    }

    private fun createBackend(account: Account): Backend {
    private fun createBackend(account: Account): Backend? {
        return try {
            val serverType = account.incomingServerSettings.type
            val backendFactory = backendFactories[serverType] ?: error("Unsupported account type")
        return backendFactory.createBackend(account)
            backendFactory.createBackend(account)
        } catch (e: Exception) {
            Timber.e(e)
            null
        }
    }

    fun addListener(listener: BackendChangedListener) {
+2 −2
Original line number Diff line number Diff line
@@ -63,8 +63,8 @@ internal class AccountPushController(

    private fun startBackendPusher() {
        val backend = backendManager.getBackend(account)
        backendPusher = backend.createPusher(backendPusherCallback).also { backendPusher ->
            backendPusher.start()
        backendPusher = backend?.createPusher(backendPusherCallback).also { backendPusher ->
            backendPusher?.start()
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ class PushController internal constructor(

    private fun getPushAccounts(): List<Account> {
        return preferences.accounts.filter { account ->
            account.folderPushMode != FolderMode.NONE && backendManager.getBackend(account).isPushCapable
            account.folderPushMode != FolderMode.NONE && backendManager.getBackend(account)?.isPushCapable ?: false
        }
    }
    private fun setPushNotificationState(notificationState: PushNotificationState) {