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

Commit aa4d27e0 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

fix: try something else

parent 1b2627ec
Loading
Loading
Loading
Loading
Loading
+2 −22
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@ import at.bitfire.davdroid.log.Logger

class ReLoginWithOidcActivity : AppCompatActivity() {

    private var needLogout = true

    override fun onStart() {
        super.onStart()

@@ -26,12 +24,8 @@ class ReLoginWithOidcActivity : AppCompatActivity() {
            finish()
            return
        }

        Logger.log.info("Vincent: onStart() call and gonna logout account")
        if (needLogout) {
            logoutAccount(accountName)
    }
    }

    private fun logoutAccount(accountName: String)
    {
@@ -43,7 +37,6 @@ class ReLoginWithOidcActivity : AppCompatActivity() {
            val success = future.result.getBoolean(KEY_BOOLEAN_RESULT)

            if (success) {
                needLogout = false
                loginAccount(eAccountType)
            } else {
                Logger.log.info("failed to remove account: $accountName ")
@@ -62,12 +55,6 @@ class ReLoginWithOidcActivity : AppCompatActivity() {
    private fun loginAccount(accountType: String) {
        val accountManager = AccountManager.get(this)

        val callback: (AliasFuture) -> Unit = { future ->
            val intent = getIntentFromFuture(future)
            intent?.let(::startActivity)
            finish()
        }

        try {
            accountManager.addAccount(
                accountType,
@@ -75,20 +62,13 @@ class ReLoginWithOidcActivity : AppCompatActivity() {
                null,
                null,
                null,
                { future -> callback(future)},
                null,
                null
            )
        } catch (exception: Exception) {
            Logger.log.warning("${exception.javaClass}: can't add account: ${exception.message}")
        }
    }

    private fun getIntentFromFuture(future: AliasFuture): Intent? {
        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            future.result?.getParcelable(KEY_INTENT, Intent::class.java)
        } else {
            future.result?.getParcelable(KEY_INTENT)
        }
        finish()
    }
}