InvalidToken: Rework MainActivity args
This commit is contained in:
parent
18649ebddb
commit
29087d4a87
@ -38,8 +38,8 @@ data class MatrixError(
|
|||||||
@Json(name = "admin_contact") val adminUri: String? = null,
|
@Json(name = "admin_contact") val adminUri: String? = null,
|
||||||
// For M_LIMIT_EXCEEDED
|
// For M_LIMIT_EXCEEDED
|
||||||
@Json(name = "retry_after_ms") val retryAfterMillis: Long? = null,
|
@Json(name = "retry_after_ms") val retryAfterMillis: Long? = null,
|
||||||
// For M_UNAUTHORIZED
|
// For M_UNKNOWN_TOKEN
|
||||||
@Json(name = "soft_logout") val isSoftLogout: Boolean? = null
|
@Json(name = "soft_logout") val isSoftLogout: Boolean = false
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -32,6 +32,7 @@ import retrofit2.Callback
|
|||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.net.HttpURLConnection
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.resumeWithException
|
import kotlin.coroutines.resumeWithException
|
||||||
|
|
||||||
@ -100,10 +101,11 @@ private fun toFailure(errorBody: ResponseBody?, httpCode: Int): Failure {
|
|||||||
if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) {
|
if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) {
|
||||||
// Also send this error to the bus, for a global management
|
// Also send this error to the bus, for a global management
|
||||||
EventBus.getDefault().post(GlobalError.ConsentNotGivenError(matrixError.consentUri))
|
EventBus.getDefault().post(GlobalError.ConsentNotGivenError(matrixError.consentUri))
|
||||||
} else if (matrixError.code == MatrixError.M_UNAUTHORIZED) {
|
} else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED /* 401 */
|
||||||
|
&& matrixError.code == MatrixError.M_UNKNOWN_TOKEN) {
|
||||||
// TODO Check that this is ok during the login flow
|
// TODO Check that this is ok during the login flow
|
||||||
// Also send this error to the bus, for a global management
|
// Also send this error to the bus, for a global management
|
||||||
EventBus.getDefault().post(GlobalError.InvalidToken(matrixError.isSoftLogout == true))
|
EventBus.getDefault().post(GlobalError.InvalidToken(matrixError.isSoftLogout))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Failure.ServerError(matrixError, httpCode)
|
return Failure.ServerError(matrixError, httpCode)
|
||||||
|
@ -73,10 +73,12 @@ internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI,
|
|||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
// Intercept 401
|
// Intercept 401
|
||||||
if (throwable is Failure.ServerError
|
// TODO Remove?
|
||||||
&& throwable.error.code == MatrixError.M_UNKNOWN_TOKEN) {
|
//if (throwable is Failure.ServerError
|
||||||
sessionParamsStore.delete(userId)
|
// && throwable.error.code == MatrixError.M_UNKNOWN_TOKEN
|
||||||
}
|
// && !throwable.error.isSoftLogout) {
|
||||||
|
// sessionParamsStore.delete(userId)
|
||||||
|
//}
|
||||||
throw throwable
|
throw throwable
|
||||||
}
|
}
|
||||||
syncResponseHandler.handleResponse(syncResponse, token)
|
syncResponseHandler.handleResponse(syncResponse, token)
|
||||||
|
@ -19,6 +19,7 @@ package im.vector.riotx.features
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Parcelable
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
@ -30,6 +31,7 @@ import im.vector.riotx.core.platform.VectorBaseActivity
|
|||||||
import im.vector.riotx.core.utils.deleteAllFiles
|
import im.vector.riotx.core.utils.deleteAllFiles
|
||||||
import im.vector.riotx.features.home.HomeActivity
|
import im.vector.riotx.features.home.HomeActivity
|
||||||
import im.vector.riotx.features.login.LoginActivity
|
import im.vector.riotx.features.login.LoginActivity
|
||||||
|
import kotlinx.android.parcel.Parcelize
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -37,23 +39,30 @@ import kotlinx.coroutines.withContext
|
|||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class MainActivityArgs(
|
||||||
|
val clearCache: Boolean = false,
|
||||||
|
val clearCredentials: Boolean = false,
|
||||||
|
val isUserLoggedOut: Boolean = false,
|
||||||
|
val isSoftLogout: Boolean = false
|
||||||
|
) : Parcelable
|
||||||
|
|
||||||
class MainActivity : VectorBaseActivity() {
|
class MainActivity : VectorBaseActivity() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val EXTRA_CLEAR_CACHE = "EXTRA_CLEAR_CACHE"
|
private const val EXTRA_ARGS = "EXTRA_ARGS"
|
||||||
private const val EXTRA_CLEAR_CREDENTIALS = "EXTRA_CLEAR_CREDENTIALS"
|
|
||||||
|
|
||||||
// Special action to clear cache and/or clear credentials
|
// Special action to clear cache and/or clear credentials
|
||||||
fun restartApp(activity: Activity, clearCache: Boolean = false, clearCredentials: Boolean = false) {
|
fun restartApp(activity: Activity, args: MainActivityArgs) {
|
||||||
val intent = Intent(activity, MainActivity::class.java)
|
val intent = Intent(activity, MainActivity::class.java)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||||
|
|
||||||
intent.putExtra(EXTRA_CLEAR_CACHE, clearCache)
|
intent.putExtra(EXTRA_ARGS, args)
|
||||||
intent.putExtra(EXTRA_CLEAR_CREDENTIALS, clearCredentials)
|
|
||||||
activity.startActivity(intent)
|
activity.startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var args: MainActivityArgs? = null
|
||||||
@Inject lateinit var sessionHolder: ActiveSessionHolder
|
@Inject lateinit var sessionHolder: ActiveSessionHolder
|
||||||
@Inject lateinit var errorFormatter: ErrorFormatter
|
@Inject lateinit var errorFormatter: ErrorFormatter
|
||||||
|
|
||||||
@ -63,8 +72,10 @@ class MainActivity : VectorBaseActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val clearCache = intent.getBooleanExtra(EXTRA_CLEAR_CACHE, false)
|
args = intent.getParcelableExtra(EXTRA_ARGS)
|
||||||
val clearCredentials = intent.getBooleanExtra(EXTRA_CLEAR_CREDENTIALS, false)
|
|
||||||
|
val clearCache = args?.clearCache ?: false
|
||||||
|
val clearCredentials = args?.clearCredentials ?: false
|
||||||
|
|
||||||
// Handle some wanted cleanup
|
// Handle some wanted cleanup
|
||||||
if (clearCache || clearCredentials) {
|
if (clearCache || clearCredentials) {
|
||||||
|
@ -43,6 +43,7 @@ import im.vector.riotx.core.preference.UserAvatarPreference
|
|||||||
import im.vector.riotx.core.preference.VectorPreference
|
import im.vector.riotx.core.preference.VectorPreference
|
||||||
import im.vector.riotx.core.utils.*
|
import im.vector.riotx.core.utils.*
|
||||||
import im.vector.riotx.features.MainActivity
|
import im.vector.riotx.features.MainActivity
|
||||||
|
import im.vector.riotx.features.MainActivityArgs
|
||||||
import im.vector.riotx.features.themes.ThemeUtils
|
import im.vector.riotx.features.themes.ThemeUtils
|
||||||
import im.vector.riotx.features.workers.signout.SignOutUiWorker
|
import im.vector.riotx.features.workers.signout.SignOutUiWorker
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -176,7 +177,12 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
|
|||||||
|
|
||||||
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||||
displayLoadingView()
|
displayLoadingView()
|
||||||
MainActivity.restartApp(activity!!, clearCache = true, clearCredentials = false)
|
MainActivity.restartApp(activity!!,
|
||||||
|
MainActivityArgs(
|
||||||
|
clearCache = true,
|
||||||
|
clearCredentials = false
|
||||||
|
)
|
||||||
|
)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import im.vector.riotx.R
|
|||||||
import im.vector.riotx.core.di.ActiveSessionHolder
|
import im.vector.riotx.core.di.ActiveSessionHolder
|
||||||
import im.vector.riotx.core.extensions.vectorComponent
|
import im.vector.riotx.core.extensions.vectorComponent
|
||||||
import im.vector.riotx.features.MainActivity
|
import im.vector.riotx.features.MainActivity
|
||||||
|
import im.vector.riotx.features.MainActivityArgs
|
||||||
import im.vector.riotx.features.notifications.NotificationDrawerManager
|
import im.vector.riotx.features.notifications.NotificationDrawerManager
|
||||||
|
|
||||||
class SignOutUiWorker(private val activity: FragmentActivity) {
|
class SignOutUiWorker(private val activity: FragmentActivity) {
|
||||||
@ -58,6 +59,11 @@ class SignOutUiWorker(private val activity: FragmentActivity) {
|
|||||||
notificationDrawerManager.clearAllEvents()
|
notificationDrawerManager.clearAllEvents()
|
||||||
notificationDrawerManager.persistInfo()
|
notificationDrawerManager.persistInfo()
|
||||||
|
|
||||||
MainActivity.restartApp(activity, clearCache = true, clearCredentials = true)
|
MainActivity.restartApp(activity,
|
||||||
|
MainActivityArgs(
|
||||||
|
clearCache = true,
|
||||||
|
clearCredentials = true
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user