1
0
mirror of https://github.com/etesync/android synced 2025-01-10 15:51:08 +00:00

Account: logout and clear cache on account removal.

This commit is contained in:
Tom Hacohen 2020-08-26 10:22:04 +03:00
parent 85fd9fdd7c
commit efdce8c557

View File

@ -29,6 +29,7 @@ import androidx.core.content.ContextCompat
import at.bitfire.ical4android.TaskProvider.Companion.OPENTASK_PROVIDERS import at.bitfire.ical4android.TaskProvider.Companion.OPENTASK_PROVIDERS
import at.bitfire.vcard4android.ContactsStorageException import at.bitfire.vcard4android.ContactsStorageException
import com.etebase.client.CollectionManager import com.etebase.client.CollectionManager
import com.etebase.client.exceptions.EtebaseException
import com.etesync.syncadapter.* import com.etesync.syncadapter.*
import com.etesync.journalmanager.Crypto import com.etesync.journalmanager.Crypto
import com.etesync.journalmanager.Exceptions import com.etesync.journalmanager.Exceptions
@ -509,17 +510,32 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
private fun deleteAccount() { private fun deleteAccount() {
val accountManager = AccountManager.get(this) val accountManager = AccountManager.get(this)
val settings = AccountSettings(this@AccountActivity, account) val settings = AccountSettings(this@AccountActivity, account)
val authToken = settings.authToken
val principal = settings.uri?.toHttpUrlOrNull()
doAsync { doAsync {
try { if (settings.isLegacy) {
val httpClient = HttpClient.Builder(this@AccountActivity, null, authToken).build().okHttpClient val authToken = settings.authToken
val journalAuthenticator = JournalAuthenticator(httpClient, principal!!) val principal = settings.uri?.toHttpUrlOrNull()
journalAuthenticator.invalidateAuthToken(authToken)
} catch (e: Exceptions.HttpException) { try {
// Ignore failures for now val httpClient = HttpClient.Builder(this@AccountActivity, null, authToken).build().okHttpClient
Logger.log.warning(e.toString()) val journalAuthenticator = JournalAuthenticator(httpClient, principal!!)
journalAuthenticator.invalidateAuthToken(authToken)
} catch (e: Exceptions.HttpException) {
// Ignore failures for now
Logger.log.warning(e.toString())
}
} else {
val etebaseLocalCache = EtebaseLocalCache.getInstance(this@AccountActivity, account.name)
etebaseLocalCache.clearUserCache()
try {
val httpClient = HttpClient.Builder(this@AccountActivity).build()
val etebase = EtebaseLocalCache.getEtebase(this@AccountActivity, httpClient.okHttpClient, settings)
etebase.logout()
} catch(e: EtebaseException) {
// Ignore failures for now
Logger.log.warning(e.toString())
}
} }
} }