From ebcd8d2f074a92b725b55bc043e3e9d3c0c3375a Mon Sep 17 00:00:00 2001 From: Amanpal Singh <87360222+aman-alfresco@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:24:33 +0530 Subject: [PATCH] ADST-528 (#353) * fixed cache clear login crash --- .gitignore | 2 ++ .../com/alfresco/content/account/Account.kt | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ee7f3004..f79e099d 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,5 @@ app/google-services_2.json /build-other.gradle /gradle/libs.versions-other.toml /alfresco-auth/ +/build-app.gradle +/gradle/libs.versions-app.toml diff --git a/account/src/main/kotlin/com/alfresco/content/account/Account.kt b/account/src/main/kotlin/com/alfresco/content/account/Account.kt index d6d3eb54..2daaeaaa 100644 --- a/account/src/main/kotlin/com/alfresco/content/account/Account.kt +++ b/account/src/main/kotlin/com/alfresco/content/account/Account.kt @@ -54,12 +54,25 @@ data class Account( b.putString(myFilesKey, myFiles) b.putString(hostNameKey, hostName) b.putString(clientIdKey, clientId) - val acc = AndroidAccount(id, context.getString(R.string.android_auth_account_type)) + + val accountType = context.getString(R.string.android_auth_account_type) + + val acc = AndroidAccount(id, accountType) // Save credentials securely using the SecureSharedPreferencesManager sharedSecure.saveCredentials(email, authState, displayName, hostName, clientId) - AccountManager.get(context).addAccountExplicitly(acc, KEY_PASSWORD, b) + val accountManager = AccountManager.get(context) + val accounts = accountManager.getAccountsByType(accountType) + + val removeOtherAccounts = accounts.filter { it.name != id } + + if (removeOtherAccounts.isNotEmpty()) { + removeOtherAccounts.forEach { account -> + accountManager.removeAccountExplicitly(account) + } + } + accountManager.addAccountExplicitly(acc, KEY_PASSWORD, b) } fun update(context: Context, id: String, authState: String) {