From b2c726efa8c2a785ee4bf5d99095b2e02db383a6 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Fri, 26 May 2023 18:59:57 +0600 Subject: [PATCH 1/2] 6584-Add_yahoo_account_support issue: https://gitlab.e.foundation/e/backlog/-/issues/6584 Add yahoo account support setup by accountManager --- app/core/src/main/AndroidManifest.xml | 6 +++ .../java/com/fsck/k9/OsAccountManagerUtil.kt | 8 ++- .../k9/oauth/OAuthConfigurationProvider.kt | 4 ++ .../fsck/k9/setup/AccountManagerConstants.kt | 1 + .../com/fsck/k9/setup/EeloAccountHelper.kt | 50 ++++++++++++++----- .../k9/backends/RealOAuth2TokenProvider.kt | 2 +- .../fsck/k9/account/AccountSyncReceiver.kt | 7 ++- .../k9/activity/setup/AccountSetupBasics.kt | 21 ++++++-- .../accountmanager/EeloAccountCreator.java | 17 ++++--- 9 files changed, 88 insertions(+), 28 deletions(-) diff --git a/app/core/src/main/AndroidManifest.xml b/app/core/src/main/AndroidManifest.xml index e4c26a20a1..a3ae99a7bb 100644 --- a/app/core/src/main/AndroidManifest.xml +++ b/app/core/src/main/AndroidManifest.xml @@ -2,6 +2,12 @@ + + diff --git a/app/core/src/main/java/com/fsck/k9/OsAccountManagerUtil.kt b/app/core/src/main/java/com/fsck/k9/OsAccountManagerUtil.kt index 9229ca2565..74da7102bc 100644 --- a/app/core/src/main/java/com/fsck/k9/OsAccountManagerUtil.kt +++ b/app/core/src/main/java/com/fsck/k9/OsAccountManagerUtil.kt @@ -44,6 +44,12 @@ object OsAccountManagerUtil { return syncEnable.getStatus() } + val yahooAccounts = accountManager.getAccountsByType(AccountManagerConstants.YAHOO_ACCOUNT_TYPE) + syncEnable = isSyncEnable(accountManager, yahooAccounts, email) + if (syncEnable.isAccountFound()) { + return syncEnable.getStatus() + } + return true } @@ -78,4 +84,4 @@ object OsAccountManagerUtil { fun isAccountFound() = this != ACCOUNT_NOT_FOUND } -} \ No newline at end of file +} diff --git a/app/core/src/main/java/com/fsck/k9/oauth/OAuthConfigurationProvider.kt b/app/core/src/main/java/com/fsck/k9/oauth/OAuthConfigurationProvider.kt index b9cd706090..0050931ab3 100644 --- a/app/core/src/main/java/com/fsck/k9/oauth/OAuthConfigurationProvider.kt +++ b/app/core/src/main/java/com/fsck/k9/oauth/OAuthConfigurationProvider.kt @@ -19,4 +19,8 @@ class OAuthConfigurationProvider( fun isGoogle(hostname: String): Boolean { return getConfiguration(hostname) == googleConfiguration } + + fun isYahoo(hostname: String): Boolean { + return hostname in listOf("imap.mail.yahoo.com", "smtp.mail.yahoo.com") + } } diff --git a/app/core/src/main/java/com/fsck/k9/setup/AccountManagerConstants.kt b/app/core/src/main/java/com/fsck/k9/setup/AccountManagerConstants.kt index b70aad6478..b6a3a50dbc 100644 --- a/app/core/src/main/java/com/fsck/k9/setup/AccountManagerConstants.kt +++ b/app/core/src/main/java/com/fsck/k9/setup/AccountManagerConstants.kt @@ -19,6 +19,7 @@ package com.fsck.k9.setup object AccountManagerConstants { const val EELO_ACCOUNT_TYPE = "e.foundation.webdav.eelo" const val GOOGLE_ACCOUNT_TYPE = "e.foundation.webdav.google" + const val YAHOO_ACCOUNT_TYPE = "e.foundation.webdav.yahoo" const val ACCOUNT_EMAIL_ADDRESS_KEY = "email_address" const val MAIL_CONTENT_AUTHORITY = "foundation.e.mail.provider.AppContentProvider" const val AUTH_TOKEN_TYPE = "oauth2-access-token" diff --git a/app/core/src/main/java/com/fsck/k9/setup/EeloAccountHelper.kt b/app/core/src/main/java/com/fsck/k9/setup/EeloAccountHelper.kt index 10b69fbe9e..dd419bf176 100644 --- a/app/core/src/main/java/com/fsck/k9/setup/EeloAccountHelper.kt +++ b/app/core/src/main/java/com/fsck/k9/setup/EeloAccountHelper.kt @@ -44,10 +44,30 @@ object EeloAccountHelper { } val osAccountManager = OsAccountManager.get(context) - val googleAccount = retrieveGoogleAccountFromAccountManager(osAccountManager, account.email) ?: return false + + val googleAccount = retrieveOpenIdAccountFromAccountManager(osAccountManager, AccountManagerConstants.GOOGLE_ACCOUNT_TYPE, account.email) + if (googleAccount != null) { + updateOAuthState(account, osAccountManager, googleAccount, accountManager) + return true + } + + val yahooAccount = retrieveOpenIdAccountFromAccountManager(osAccountManager, AccountManagerConstants.YAHOO_ACCOUNT_TYPE, account.email) + if (yahooAccount != null) { + updateOAuthState(account, osAccountManager, yahooAccount, accountManager) + return true + } + + return false + } + + private fun updateOAuthState( + account: Account, + osAccountManager: android.accounts.AccountManager, + googleAccount: android.accounts.Account?, + accountManager: AccountManager, + ) { account.oAuthState = osAccountManager.getUserData(googleAccount, AccountManagerConstants.KEY_AUTH_STATE) accountManager.saveAccount(account) - return true } // If token is updated by mail, also update the accountManager @@ -67,30 +87,36 @@ object EeloAccountHelper { accountManager.setUserData(account, AccountManagerConstants.KEY_AUTH_STATE, authState) } - fun retrieveGoogleAccountFromAccountManager(context: Context?, email: String?): OsAccount? { + fun retrieveOpenIdAccountFromAccountManager(context: Context?, email: String?): OsAccount? { if (context == null) { Timber.w("retrieve google accounts from accountManager failed, null context.") return null } val accountManager = OsAccountManager.get(context) - return retrieveGoogleAccountFromAccountManager(accountManager, email) + + val googleAccount = retrieveOpenIdAccountFromAccountManager(accountManager, AccountManagerConstants.GOOGLE_ACCOUNT_TYPE, email) + if (googleAccount != null) { + return googleAccount; + } + + return retrieveOpenIdAccountFromAccountManager(accountManager, AccountManagerConstants.YAHOO_ACCOUNT_TYPE, email) } - private fun retrieveGoogleAccountFromAccountManager(accountManager: OsAccountManager?, email: String?): OsAccount? { - if (accountManager == null || email == null || email.isEmpty()) { - Timber.w("retrieve google account from accountManager failed, invalid param") + private fun retrieveOpenIdAccountFromAccountManager(accountManager: OsAccountManager?, accountType: String, email: String?): OsAccount? { + if (accountManager == null || email.isNullOrEmpty()) { + Timber.w("retrieve $accountType account from accountManager failed, invalid param") return null } - val googleAccounts = accountManager.getAccountsByType(AccountManagerConstants.GOOGLE_ACCOUNT_TYPE) - for (googleAccount in googleAccounts) { - val emailId = accountManager.getUserData(googleAccount, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY) + val openIdAccounts = accountManager.getAccountsByType(accountType) + for (openIdAccount in openIdAccounts) { + val emailId = accountManager.getUserData(openIdAccount, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY) if (email.equals(emailId, ignoreCase = true)) { - return googleAccount + return openIdAccount } } return null } -} \ No newline at end of file +} diff --git a/app/k9mail/src/main/java/com/fsck/k9/backends/RealOAuth2TokenProvider.kt b/app/k9mail/src/main/java/com/fsck/k9/backends/RealOAuth2TokenProvider.kt index be4ac7f657..ed65f485a1 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/backends/RealOAuth2TokenProvider.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/backends/RealOAuth2TokenProvider.kt @@ -31,7 +31,7 @@ class RealOAuth2TokenProvider( ?: throw AuthenticationFailedException("Login required") } - val accountManagerAccount = EeloAccountHelper.retrieveGoogleAccountFromAccountManager(context, email) + val accountManagerAccount = EeloAccountHelper.retrieveOpenIdAccountFromAccountManager(context, email) val latch = CountDownLatch(1) var token: String? = null diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt b/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt index a1f9617c80..b50ceb4967 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt @@ -20,6 +20,8 @@ import android.accounts.AccountManager import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.os.Build +import androidx.annotation.RequiresApi import com.fsck.k9.Account import com.fsck.k9.Preferences import com.fsck.k9.activity.setup.accountmanager.EeloAccountCreator @@ -39,7 +41,7 @@ class AccountSyncReceiver : BroadcastReceiver(), KoinComponent { private const val ACCOUNT_CREATION_ACTION = "$ACTION_PREFIX.create" private const val ACCOUNT_REMOVAL_ACTION = "android.accounts.action.ACCOUNT_REMOVED" - private val ACCOUNT_TYPES = listOf(AccountManagerConstants.EELO_ACCOUNT_TYPE, AccountManagerConstants.GOOGLE_ACCOUNT_TYPE) + private val ACCOUNT_TYPES = listOf(AccountManagerConstants.EELO_ACCOUNT_TYPE, AccountManagerConstants.GOOGLE_ACCOUNT_TYPE, AccountManagerConstants.YAHOO_ACCOUNT_TYPE) } private val pushController: PushController by inject() @@ -58,6 +60,7 @@ class AccountSyncReceiver : BroadcastReceiver(), KoinComponent { } } + @RequiresApi(Build.VERSION_CODES.N) private fun createNewAccount(context: Context?) { pushController.init() context?.let { @@ -95,4 +98,4 @@ class AccountSyncReceiver : BroadcastReceiver(), KoinComponent { return null } -} \ No newline at end of file +} diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.kt index 5d528da898..bb3212014c 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.kt @@ -211,8 +211,7 @@ class AccountSetupBasics : K9Activity() { } private fun startOAuthFlow(connectionSettings: ConnectionSettings) { - if (oAuthConfigurationProvider.isGoogle(connectionSettings.incoming.host!!)) { - startGoogleOAuthFlow() + if (handleOpenIdAuthFlow(connectionSettings.incoming.host!!)) { return } @@ -222,12 +221,26 @@ class AccountSetupBasics : K9Activity() { startActivityForResult(intent, REQUEST_CODE_OAUTH) } - private fun startGoogleOAuthFlow() { + private fun handleOpenIdAuthFlow(hostname: String): Boolean { + if (oAuthConfigurationProvider.isGoogle(hostname)) { + startOpenIdOAuthFlow(AccountManagerConstants.GOOGLE_ACCOUNT_TYPE) + return true + } + + if (oAuthConfigurationProvider.isYahoo(hostname)) { + startOpenIdOAuthFlow(AccountManagerConstants.YAHOO_ACCOUNT_TYPE) + return true + } + + return false + } + + private fun startOpenIdOAuthFlow(accountType: String) { val osAccountManager = AccountManager.get(this) val options = Bundle() options.putString(AccountManagerConstants.OPEN_APP_PACKAGE_AFTER_AUTH, packageName) options.putString(AccountManagerConstants.OPEN_APP_ACTIVITY_AFTER_AUTH, MessageList::class.java.name) - osAccountManager.addAccount(AccountManagerConstants.GOOGLE_ACCOUNT_TYPE, null, null, options, this, null, null) + osAccountManager.addAccount(accountType, null, null, options, this, null, null) } private fun startPasswordFlow() { diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java index 7d550abfca..17e5920325 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java @@ -65,7 +65,8 @@ public class EeloAccountCreator { deleteIncompleteAccounts(accounts, accountRemover); loadEeloAccounts(context, accounts, accountManager, jobManager); - loadGoogleAccounts(context, accounts, accountManager, jobManager); + loadOpenIdAccounts(context, AccountManagerConstants.GOOGLE_ACCOUNT_TYPE, accounts, accountManager, jobManager); + loadOpenIdAccounts(context, AccountManagerConstants.YAHOO_ACCOUNT_TYPE, accounts, accountManager, jobManager); } catch (SecurityException e) { Timber.e(e, "Failed to load accounts from accountManager because of security violation"); } @@ -89,18 +90,18 @@ public class EeloAccountCreator { } @RequiresApi(api = VERSION_CODES.N) - private static void loadGoogleAccounts(@NonNull Context context, List accounts, + private static void loadOpenIdAccounts(@NonNull Context context, @NonNull String accountType, List accounts, @NonNull AccountManager accountManager, @NonNull K9JobManager jobManager) { - android.accounts.Account[] googleAccounts = - accountManager.getAccountsByType(AccountManagerConstants.GOOGLE_ACCOUNT_TYPE); - for (android.accounts.Account googleAccount : googleAccounts) { + android.accounts.Account[] openIdAccounts = + accountManager.getAccountsByType(accountType); + for (android.accounts.Account openIdAccount : openIdAccounts) { String emailId = - accountManager.getUserData(googleAccount, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY); + accountManager.getUserData(openIdAccount, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY); if (isInvalidEmail(emailId)) { continue; } - if (!isSyncable(googleAccount)) { + if (!isSyncable(openIdAccount)) { continue; } @@ -110,7 +111,7 @@ public class EeloAccountCreator { .findAny(); if (!existenceAccount.isPresent()) { - String authState = accountManager.getUserData(googleAccount, AccountManagerConstants.KEY_AUTH_STATE); + String authState = accountManager.getUserData(openIdAccount, AccountManagerConstants.KEY_AUTH_STATE); createAccount(context, emailId, "", authState); continue; } -- GitLab From fa44d63c8aba5f295d93d95746d4f450d2232423 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Mon, 29 May 2023 11:26:57 +0600 Subject: [PATCH 2/2] Refactor openId account support Simplify the openId accounts (google & yahoo for now) retrieval code, so less code duplication is needed. So in future, adding new openId account should be straight forward. --- .../java/com/fsck/k9/OsAccountManagerUtil.kt | 35 +++++++-------- .../k9/oauth/OAuthConfigurationProvider.kt | 4 -- .../fsck/k9/setup/AccountManagerConstants.kt | 11 +++++ .../com/fsck/k9/setup/EeloAccountHelper.kt | 44 +++++++++++-------- .../fsck/k9/account/AccountSyncReceiver.kt | 5 +-- .../k9/activity/setup/AccountSetupBasics.kt | 14 ++---- .../accountmanager/EeloAccountCreator.java | 4 +- 7 files changed, 61 insertions(+), 56 deletions(-) diff --git a/app/core/src/main/java/com/fsck/k9/OsAccountManagerUtil.kt b/app/core/src/main/java/com/fsck/k9/OsAccountManagerUtil.kt index 74da7102bc..3c2330118e 100644 --- a/app/core/src/main/java/com/fsck/k9/OsAccountManagerUtil.kt +++ b/app/core/src/main/java/com/fsck/k9/OsAccountManagerUtil.kt @@ -32,36 +32,35 @@ object OsAccountManagerUtil { fun isSyncEnable(context: Context, email: String): Boolean { val accountManager = AccountManager.get(context) - val murenaAccounts = accountManager.getAccountsByType(AccountManagerConstants.EELO_ACCOUNT_TYPE) - var syncEnable = isSyncEnable(accountManager, murenaAccounts, email) - if (syncEnable.isAccountFound()) { - return syncEnable.getStatus() - } - - val googleAccounts = accountManager.getAccountsByType(AccountManagerConstants.GOOGLE_ACCOUNT_TYPE) - syncEnable = isSyncEnable(accountManager, googleAccounts, email) - if (syncEnable.isAccountFound()) { - return syncEnable.getStatus() - } + var syncStatus = true - val yahooAccounts = accountManager.getAccountsByType(AccountManagerConstants.YAHOO_ACCOUNT_TYPE) - syncEnable = isSyncEnable(accountManager, yahooAccounts, email) - if (syncEnable.isAccountFound()) { - return syncEnable.getStatus() + AccountManagerConstants.ALL_ACCOUNT_TYPES.forEach { + val accounts = accountManager.getAccountsByType(it) + val syncEnable = isSyncEnable(accountManager, accounts, email) + if (syncEnable.isAccountFound()) { + syncStatus = syncEnable.getStatus() + return@forEach + } } - return true + return syncStatus } private fun isSyncEnable(accountManager: AccountManager, accounts: Array, email: String): Syncable { accounts.forEach { try { - val accountEmail: String = accountManager.getUserData(it, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY) + val accountEmail: String = + accountManager.getUserData(it, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY) if (accountEmail == email) { // if master sync disable, then account sync is disable return if (!ContentResolver.getMasterSyncAutomatically()) { Syncable.NOT_SYNCABLE - } else Syncable.getSyncable(ContentResolver.getSyncAutomatically(it, AccountManagerConstants.MAIL_CONTENT_AUTHORITY)) + } else Syncable.getSyncable( + ContentResolver.getSyncAutomatically( + it, + AccountManagerConstants.MAIL_CONTENT_AUTHORITY, + ), + ) } } catch (e: Throwable) { Timber.e(e) diff --git a/app/core/src/main/java/com/fsck/k9/oauth/OAuthConfigurationProvider.kt b/app/core/src/main/java/com/fsck/k9/oauth/OAuthConfigurationProvider.kt index 0050931ab3..b9cd706090 100644 --- a/app/core/src/main/java/com/fsck/k9/oauth/OAuthConfigurationProvider.kt +++ b/app/core/src/main/java/com/fsck/k9/oauth/OAuthConfigurationProvider.kt @@ -19,8 +19,4 @@ class OAuthConfigurationProvider( fun isGoogle(hostname: String): Boolean { return getConfiguration(hostname) == googleConfiguration } - - fun isYahoo(hostname: String): Boolean { - return hostname in listOf("imap.mail.yahoo.com", "smtp.mail.yahoo.com") - } } diff --git a/app/core/src/main/java/com/fsck/k9/setup/AccountManagerConstants.kt b/app/core/src/main/java/com/fsck/k9/setup/AccountManagerConstants.kt index b6a3a50dbc..2cb7c4bc01 100644 --- a/app/core/src/main/java/com/fsck/k9/setup/AccountManagerConstants.kt +++ b/app/core/src/main/java/com/fsck/k9/setup/AccountManagerConstants.kt @@ -29,4 +29,15 @@ object AccountManagerConstants { const val OPEN_APP_ACTIVITY_AFTER_AUTH = "open_app_activity_after_auth" const val IGNORE_ACCOUNT_SETUP = "ignore_account_setup" + + val OPENID_ACCOUNT_TYPES = listOf(GOOGLE_ACCOUNT_TYPE, YAHOO_ACCOUNT_TYPE) + val ALL_ACCOUNT_TYPES = listOf(EELO_ACCOUNT_TYPE, GOOGLE_ACCOUNT_TYPE, YAHOO_ACCOUNT_TYPE) + + fun getOpenIdAccountTypeByHostName(hostname: String): String? { + return when(hostname) { + in listOf("imap.gmail.com", "imap.googlemail.com", "smtp.gmail.com", "smtp.googlemail.com") -> GOOGLE_ACCOUNT_TYPE + in listOf("imap.mail.yahoo.com", "smtp.mail.yahoo.com") -> YAHOO_ACCOUNT_TYPE + else -> null + } + } } diff --git a/app/core/src/main/java/com/fsck/k9/setup/EeloAccountHelper.kt b/app/core/src/main/java/com/fsck/k9/setup/EeloAccountHelper.kt index dd419bf176..e273661fcd 100644 --- a/app/core/src/main/java/com/fsck/k9/setup/EeloAccountHelper.kt +++ b/app/core/src/main/java/com/fsck/k9/setup/EeloAccountHelper.kt @@ -16,13 +16,13 @@ package com.fsck.k9.setup -import android.accounts.Account as OsAccount -import android.accounts.AccountManager as OsAccountManager import android.content.Context import com.fsck.k9.Account import com.fsck.k9.mail.AuthType import com.fsck.k9.preferences.AccountManager import timber.log.Timber +import android.accounts.Account as OsAccount +import android.accounts.AccountManager as OsAccountManager object EeloAccountHelper { @@ -45,19 +45,17 @@ object EeloAccountHelper { val osAccountManager = OsAccountManager.get(context) - val googleAccount = retrieveOpenIdAccountFromAccountManager(osAccountManager, AccountManagerConstants.GOOGLE_ACCOUNT_TYPE, account.email) - if (googleAccount != null) { - updateOAuthState(account, osAccountManager, googleAccount, accountManager) - return true - } - - val yahooAccount = retrieveOpenIdAccountFromAccountManager(osAccountManager, AccountManagerConstants.YAHOO_ACCOUNT_TYPE, account.email) - if (yahooAccount != null) { - updateOAuthState(account, osAccountManager, yahooAccount, accountManager) - return true + var result = false + AccountManagerConstants.OPENID_ACCOUNT_TYPES.forEach { + val openIdAccount = retrieveOpenIdAccountFromAccountManager(osAccountManager, it, account.email) + if (openIdAccount != null) { + updateOAuthState(account, osAccountManager, openIdAccount, accountManager) + result = true + return@forEach + } } - return false + return result } private fun updateOAuthState( @@ -75,7 +73,7 @@ object EeloAccountHelper { context: Context?, account: OsAccount?, authState: String?, - accessToken: String? + accessToken: String?, ) { if (context == null || account == null || authState == null || accessToken == null) { Timber.w("updating account for accountManager failed, invalid param.") @@ -95,15 +93,23 @@ object EeloAccountHelper { val accountManager = OsAccountManager.get(context) - val googleAccount = retrieveOpenIdAccountFromAccountManager(accountManager, AccountManagerConstants.GOOGLE_ACCOUNT_TYPE, email) - if (googleAccount != null) { - return googleAccount; + var resultAccount: OsAccount? = null + + AccountManagerConstants.OPENID_ACCOUNT_TYPES.forEach { + resultAccount = retrieveOpenIdAccountFromAccountManager(accountManager, it, email) + if (resultAccount != null) { + return@forEach + } } - return retrieveOpenIdAccountFromAccountManager(accountManager, AccountManagerConstants.YAHOO_ACCOUNT_TYPE, email) + return resultAccount } - private fun retrieveOpenIdAccountFromAccountManager(accountManager: OsAccountManager?, accountType: String, email: String?): OsAccount? { + private fun retrieveOpenIdAccountFromAccountManager( + accountManager: OsAccountManager?, + accountType: String, + email: String?, + ): OsAccount? { if (accountManager == null || email.isNullOrEmpty()) { Timber.w("retrieve $accountType account from accountManager failed, invalid param") return null diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt b/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt index b50ceb4967..f34820adb7 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt @@ -31,7 +31,6 @@ import com.fsck.k9.setup.AccountManagerConstants import java.util.concurrent.Executors import org.koin.core.component.KoinComponent import org.koin.core.component.inject -import timber.log.Timber class AccountSyncReceiver : BroadcastReceiver(), KoinComponent { @@ -41,7 +40,6 @@ class AccountSyncReceiver : BroadcastReceiver(), KoinComponent { private const val ACCOUNT_CREATION_ACTION = "$ACTION_PREFIX.create" private const val ACCOUNT_REMOVAL_ACTION = "android.accounts.action.ACCOUNT_REMOVED" - private val ACCOUNT_TYPES = listOf(AccountManagerConstants.EELO_ACCOUNT_TYPE, AccountManagerConstants.GOOGLE_ACCOUNT_TYPE, AccountManagerConstants.YAHOO_ACCOUNT_TYPE) } private val pushController: PushController by inject() @@ -49,6 +47,7 @@ class AccountSyncReceiver : BroadcastReceiver(), KoinComponent { private val accountRemover: BackgroundAccountRemover by inject() private val jobManager: K9JobManager by inject() + @RequiresApi(Build.VERSION_CODES.N) override fun onReceive(context: Context?, intent: Intent?) { if (intent == null) { return @@ -84,7 +83,7 @@ class AccountSyncReceiver : BroadcastReceiver(), KoinComponent { private fun getAccount(intent: Intent) : Account? { val accountType = intent.extras?.getString(AccountManager.KEY_ACCOUNT_TYPE) - if (!ACCOUNT_TYPES.contains(accountType)) { + if (!AccountManagerConstants.ALL_ACCOUNT_TYPES.contains(accountType)) { return null } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.kt index bb3212014c..97a18c9241 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.kt @@ -137,6 +137,7 @@ class AccountSetupBasics : K9Activity() { advancedOptionsContainer.isVisible = false nextButton.setOnClickListener { attemptAutoSetupUsingOnlyEmailAddress() } } + UiState.PASSWORD_FLOW -> { passwordLayout.isVisible = true advancedOptionsContainer.isVisible = true @@ -222,17 +223,10 @@ class AccountSetupBasics : K9Activity() { } private fun handleOpenIdAuthFlow(hostname: String): Boolean { - if (oAuthConfigurationProvider.isGoogle(hostname)) { - startOpenIdOAuthFlow(AccountManagerConstants.GOOGLE_ACCOUNT_TYPE) - return true - } - - if (oAuthConfigurationProvider.isYahoo(hostname)) { - startOpenIdOAuthFlow(AccountManagerConstants.YAHOO_ACCOUNT_TYPE) - return true - } + val accountType = AccountManagerConstants.getOpenIdAccountTypeByHostName(hostname) ?: return false - return false + startOpenIdOAuthFlow(accountType) + return true } private fun startOpenIdOAuthFlow(accountType: String) { diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java index 17e5920325..4cc9cd0077 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java @@ -65,8 +65,8 @@ public class EeloAccountCreator { deleteIncompleteAccounts(accounts, accountRemover); loadEeloAccounts(context, accounts, accountManager, jobManager); - loadOpenIdAccounts(context, AccountManagerConstants.GOOGLE_ACCOUNT_TYPE, accounts, accountManager, jobManager); - loadOpenIdAccounts(context, AccountManagerConstants.YAHOO_ACCOUNT_TYPE, accounts, accountManager, jobManager); + + AccountManagerConstants.INSTANCE.getOPENID_ACCOUNT_TYPES().forEach(accountType -> loadOpenIdAccounts(context, accountType, accounts, accountManager, jobManager)); } catch (SecurityException e) { Timber.e(e, "Failed to load accounts from accountManager because of security violation"); } -- GitLab