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

Commit 136a96d6 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Revert "Revert "fix: fix NoSuchElementException""

This reverts commit 6f5e9a64.
parent 6f5e9a64
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -4,8 +4,12 @@ import android.accounts.AccountManager
import android.accounts.AccountManager.KEY_ACCOUNT_NAME
import android.accounts.AccountManager.KEY_ACCOUNT_TYPE
import android.accounts.AccountManager.KEY_BOOLEAN_RESULT
import android.accounts.AccountManager.KEY_INTENT
import android.accounts.AccountManagerFuture
import android.accounts.AuthenticatorException
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import at.bitfire.davdroid.log.Logger
@@ -40,7 +44,6 @@ class ReLoginWithOidcActivity : AppCompatActivity() {
        val activity = this

        eAccounts.firstOrNull() { it.name == accountName }?.run {
            Logger.log.info("Vincent: try to remove account: ${this.name} ") //todo remove this before merge
            accountManager.removeAccount(this, activity, callback, null)

        } ?: finish()
@@ -50,15 +53,13 @@ class ReLoginWithOidcActivity : AppCompatActivity() {
        val accountManager = AccountManager.get(this)
        val eAccountType = applicationContext.getString(R.string.eelo_account_type)

        Logger.log.info("Vincent: Will start add Account Session for: $eAccountType account type")

        try {

            accountManager.addAccount(eAccountType,
                null,
                null,
                null,
                this,
                null,
                { future -> startAddAccount(future) },
                null
            )
@@ -80,12 +81,18 @@ class ReLoginWithOidcActivity : AppCompatActivity() {
            return
        }

        val accountName = result.getString(KEY_ACCOUNT_NAME)
        val accountType = result.getString(KEY_ACCOUNT_TYPE, "unexepected account type")
        val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            result.getParcelable(KEY_INTENT, Intent::class.java)
        } else {
            result.getParcelable(KEY_INTENT)
        } ?: return

        if (accountName != null) {
            Logger.log.info("Vincent: ($accountType) account added: $accountName")
        try {
            startActivity(intent)
        } catch (exception: ActivityNotFoundException) {
            Logger.log.info("Vincent: can't start add account activity: ${exception.message}")
        }

        finish()
    }
}