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) {