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

Commit 8056a495 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊 Committed by Nishith Khanna
Browse files

Fix crash for openid

parent f2a818f2
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -697,9 +697,17 @@ public class MessagingController implements MessagingControllerRegistry, Messagi

        for (android.accounts.Account deviceAccount : eeloAccounts) {
            String hostUrl = accountManager.getUserData(deviceAccount, AccountManagerConstants.KEY_OC_BASE_URL);
            String authState = accountManager.getUserData(deviceAccount, AccountManagerConstants.KEY_AUTH_STATE);

            boolean isOpenId = authState != null && !authState.trim().isEmpty();
            if (isOpenId) {
                continue;
            }

            if (hostUrl == null || !AccountManagerHelper.INSTANCE.isMurenaWebHostUrl(hostUrl)) {
                continue;
            }

            // Check if the account email matches with account manager
            String emailId = accountManager.getUserData(deviceAccount,
                AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY);
+16 −9
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.fsck.k9.mail.AuthType
import com.fsck.k9.mail.ServerSettings
import com.fsck.k9.mailstore.LocalStoreProvider
import com.fsck.k9.mailstore.SpecialLocalFoldersCreator
import java.util.stream.Collectors
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

@@ -121,19 +122,23 @@ internal class EeloAccountCreator(context: Context) : KoinComponent {
            val accountManager = AccountManager.get(mContext)
            val accounts = preferences.getAccounts()
            deleteIncompleteAccounts(accounts, accountManager)
            // deleteIncompleteAccounts is asynchronous.
            // The second time we call preferences.getAccounts()
            // The accounts might not yet be removed
            val finalAccounts = accounts.stream()
                .filter(kAccount::isFinishedSetup)
                .collect(Collectors.toList())
            AccountManagerConstants.ACCOUNT_TYPES
                .forEach { accountType ->
                    loadAccounts(
                        accountType,
                        accounts,
                        finalAccounts,
                        accountManager,
                    )
                }
            // Return true if new accounts uuid were added
            return preferences.getAccounts()
                .any { it -> it.uuid !in accounts.map { it.uuid } }
            return true
        } catch (e: SecurityException) {
            Timber.d( "Failed to load accounts from accountManager because of security violation")
            Timber.d( "Failed to load accounts from accountManager because of security violation: $e")
        }
        return false
    }
@@ -146,6 +151,9 @@ internal class EeloAccountCreator(context: Context) : KoinComponent {
        val accountList = accountManager.getAccountsByType(accountType)
        for (account in accountList) {
            var emailId = accountManager.getUserData(account, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY)
            val authState = accountManager.getUserData(account, AccountManagerConstants.KEY_AUTH_STATE)
            val isOpenId = authState != null && authState.trim { it <= ' ' }.isNotEmpty()

            // Temp fix for yahoo login
            if (emailId == "null" || emailId.isNullOrEmpty()) {
                emailId = account.name
@@ -168,14 +176,13 @@ internal class EeloAccountCreator(context: Context) : KoinComponent {
                .filter { acc: kAccount -> emailId.equals(acc.email, ignoreCase = true) }
                .peek { acc: kAccount? ->
                    updateAccountNameIfMissing(emailId, acc!!)
                    if (!isOpenId) {
                        updatePasswordIfChanged(acc, password)
                    }
                }
                .findAny()

            if (!existenceAccount.isPresent) {
                val authState = accountManager.getUserData(account, AccountManagerConstants.KEY_AUTH_STATE)
                val isOpenId = authState != null && authState.trim { it <= ' ' }.isNotEmpty()

                if (isOpenId) {
                    createAccount(emailId, "", authState, accountType)
                } else if (!password.isNullOrEmpty()) {