Loading app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +18 −26 Original line number Diff line number Diff line Loading @@ -7,24 +7,20 @@ package at.bitfire.davdroid import android.accounts.AccountManager import android.accounts.AccountManager.KEY_ACCOUNT_NAME 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 import com.owncloud.android.lib.common.operations.OperationCancelledException import java.io.IOException class ReLoginWithOidcActivity : AppCompatActivity() { override fun onStart() { super.onStart() val accountName = intent?.extras?.getString(KEY_ACCOUNT_NAME, null) ?: return val accountName = intent?.extras?.getString(KEY_ACCOUNT_NAME, null) ?: run { finish() return } logoutAccount(accountName) } Loading Loading @@ -56,39 +52,35 @@ class ReLoginWithOidcActivity : AppCompatActivity() { private fun loginAccount(accountType: String) { val accountManager = AccountManager.get(this) Logger.log.info("Vincent: Will start add Account Session") try { accountManager.addAccount( accountType, null, null, null, null, //todo: choose between this & null this, { future -> startAddAccountActivity(future) }, null ) } catch (exception: AuthenticatorException) { Logger.log.info("Vincent: AuthenticatorException: can't add account: ${exception.message}") } catch (exception: IOException) { Logger.log.info("Vincent: IOException: can't add account: ${exception.message}") } catch (exception: OperationCancelledException) { Logger.log.info("Vincent: OperationCancelledException: can't add account: ${exception.message}") } catch (exception: Exception) { Logger.log.warning("${exception.javaClass}: can't add account: ${exception.message}") } } private fun startAddAccountActivity(future: AliasFuture) { val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { future.result.getParcelable(KEY_INTENT, Intent::class.java) } else { future.result.getParcelable(KEY_INTENT) } ?: return val result = future.result?: run { Logger.log.warning("Can't add new account: future.result is null") finish() return } try { startActivity(intent) } catch (exception: ActivityNotFoundException) { Logger.log.info("Vincent: StartAddAccount: exception: ${exception.message}") val accountName = result.getString(KEY_ACCOUNT_NAME) val accountType = result.getString(AccountManager.KEY_ACCOUNT_TYPE, "invalidAccountType") if (accountName != null) { Logger.log.info("($accountType) account added: $accountName") } finish() } } Loading app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +0 −2 Original line number Diff line number Diff line Loading @@ -34,14 +34,12 @@ class BootCompletedReceiver: BroadcastReceiver() { Logger.log.info("Device has been rebooted; checking sync intervals etc.") val eAccountType = context.getString(R.string.eelo_account_type) val accountManager = AccountManager.get(context) // sync intervals are checked in App.onCreate() AccountUtils.getMainAccounts(context) .forEach { if (eAccountType == it.type && !isLoggedWithOpenId(it, accountManager)) { Logger.log.info("Vincent: eAccountFound. Will notify") notifySwitchToOpenId(it, context) } else { val accountSettings = AccountSettings(context, it) Loading Loading
app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +18 −26 Original line number Diff line number Diff line Loading @@ -7,24 +7,20 @@ package at.bitfire.davdroid import android.accounts.AccountManager import android.accounts.AccountManager.KEY_ACCOUNT_NAME 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 import com.owncloud.android.lib.common.operations.OperationCancelledException import java.io.IOException class ReLoginWithOidcActivity : AppCompatActivity() { override fun onStart() { super.onStart() val accountName = intent?.extras?.getString(KEY_ACCOUNT_NAME, null) ?: return val accountName = intent?.extras?.getString(KEY_ACCOUNT_NAME, null) ?: run { finish() return } logoutAccount(accountName) } Loading Loading @@ -56,39 +52,35 @@ class ReLoginWithOidcActivity : AppCompatActivity() { private fun loginAccount(accountType: String) { val accountManager = AccountManager.get(this) Logger.log.info("Vincent: Will start add Account Session") try { accountManager.addAccount( accountType, null, null, null, null, //todo: choose between this & null this, { future -> startAddAccountActivity(future) }, null ) } catch (exception: AuthenticatorException) { Logger.log.info("Vincent: AuthenticatorException: can't add account: ${exception.message}") } catch (exception: IOException) { Logger.log.info("Vincent: IOException: can't add account: ${exception.message}") } catch (exception: OperationCancelledException) { Logger.log.info("Vincent: OperationCancelledException: can't add account: ${exception.message}") } catch (exception: Exception) { Logger.log.warning("${exception.javaClass}: can't add account: ${exception.message}") } } private fun startAddAccountActivity(future: AliasFuture) { val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { future.result.getParcelable(KEY_INTENT, Intent::class.java) } else { future.result.getParcelable(KEY_INTENT) } ?: return val result = future.result?: run { Logger.log.warning("Can't add new account: future.result is null") finish() return } try { startActivity(intent) } catch (exception: ActivityNotFoundException) { Logger.log.info("Vincent: StartAddAccount: exception: ${exception.message}") val accountName = result.getString(KEY_ACCOUNT_NAME) val accountType = result.getString(AccountManager.KEY_ACCOUNT_TYPE, "invalidAccountType") if (accountName != null) { Logger.log.info("($accountType) account added: $accountName") } finish() } } Loading
app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +0 −2 Original line number Diff line number Diff line Loading @@ -34,14 +34,12 @@ class BootCompletedReceiver: BroadcastReceiver() { Logger.log.info("Device has been rebooted; checking sync intervals etc.") val eAccountType = context.getString(R.string.eelo_account_type) val accountManager = AccountManager.get(context) // sync intervals are checked in App.onCreate() AccountUtils.getMainAccounts(context) .forEach { if (eAccountType == it.type && !isLoggedWithOpenId(it, accountManager)) { Logger.log.info("Vincent: eAccountFound. Will notify") notifySwitchToOpenId(it, context) } else { val accountSettings = AccountSettings(context, it) Loading