Skip to content

Commit 942bc13

Browse files
Merge pull request #5721 from vector-im/feature/aris/fix_account_deactivation_issue
Fix Account deactivation issues
2 parents f5973fa + 780f1ff commit 942bc13

File tree

10 files changed

+97
-28
lines changed

10 files changed

+97
-28
lines changed

changelog.d/5721.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improving deactivation experience along with a crash fix
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2022 The Matrix.org Foundation C.I.C.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.matrix.android.sdk.api.session.uia
18+
19+
enum class UiaResult {
20+
SUCCESS,
21+
FAILURE,
22+
CANCELLED
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2022 The Matrix.org Foundation C.I.C.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.matrix.android.sdk.api.session.uia.exceptions
18+
19+
class UiaCancelledException(message: String? = null) : Exception(message)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/UIAExt.kt

+14-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import org.matrix.android.sdk.api.auth.UIABaseAuth
2020
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
2121
import org.matrix.android.sdk.api.failure.Failure
2222
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
23+
import org.matrix.android.sdk.api.session.uia.UiaResult
24+
import org.matrix.android.sdk.api.session.uia.exceptions.UiaCancelledException
2325
import timber.log.Timber
2426
import kotlin.coroutines.suspendCoroutine
2527

@@ -30,14 +32,15 @@ import kotlin.coroutines.suspendCoroutine
3032
* @param interceptor see doc in [UserInteractiveAuthInterceptor]
3133
* @param retryBlock called at the end of the process, in this block generally retry executing the task, with
3234
* provided authUpdate
33-
* @return true if UIA is handled without error
35+
* @return UiaResult if UIA handled, failed or cancelled
36+
*
3437
*/
3538
internal suspend fun handleUIA(failure: Throwable,
3639
interceptor: UserInteractiveAuthInterceptor,
37-
retryBlock: suspend (UIABaseAuth) -> Unit): Boolean {
40+
retryBlock: suspend (UIABaseAuth) -> Unit): UiaResult {
3841
Timber.d("## UIA: check error ${failure.message}")
3942
val flowResponse = failure.toRegistrationFlowResponse()
40-
?: return false.also {
43+
?: return UiaResult.FAILURE.also {
4144
Timber.d("## UIA: not a UIA error")
4245
}
4346

@@ -50,14 +53,19 @@ internal suspend fun handleUIA(failure: Throwable,
5053
interceptor.performStage(flowResponse, (failure as? Failure.ServerError)?.error?.code, continuation)
5154
}
5255
} catch (failure2: Throwable) {
53-
Timber.w(failure2, "## UIA: failed to participate")
54-
return false
56+
return if (failure2 is UiaCancelledException) {
57+
Timber.w(failure2, "## UIA: cancelled")
58+
UiaResult.CANCELLED
59+
} else {
60+
Timber.w(failure2, "## UIA: failed to participate")
61+
UiaResult.FAILURE
62+
}
5563
}
5664

5765
Timber.d("## UIA: updated auth")
5866
return try {
5967
retryBlock(authUpdate)
60-
true
68+
UiaResult.SUCCESS
6169
} catch (failure3: Throwable) {
6270
handleUIA(failure3, interceptor, retryBlock)
6371
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.crypto.tasks
1818

1919
import org.matrix.android.sdk.api.auth.UIABaseAuth
2020
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
21+
import org.matrix.android.sdk.api.session.uia.UiaResult
2122
import org.matrix.android.sdk.internal.auth.registration.handleUIA
2223
import org.matrix.android.sdk.internal.crypto.api.CryptoApi
2324
import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams
@@ -47,13 +48,13 @@ internal class DefaultDeleteDeviceTask @Inject constructor(
4748
}
4849
} catch (throwable: Throwable) {
4950
if (params.userInteractiveAuthInterceptor == null ||
50-
!handleUIA(
51+
handleUIA(
5152
failure = throwable,
5253
interceptor = params.userInteractiveAuthInterceptor,
5354
retryBlock = { authUpdate ->
5455
execute(params.copy(userAuthParam = authUpdate))
5556
}
56-
)
57+
) != UiaResult.SUCCESS
5758
) {
5859
Timber.d("## UIA: propagate failure")
5960
throw throwable

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/InitializeCrossSigningTask.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import dagger.Lazy
2020
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
2121
import org.matrix.android.sdk.api.session.crypto.crosssigning.CryptoCrossSigningKey
2222
import org.matrix.android.sdk.api.session.crypto.crosssigning.KeyUsage
23+
import org.matrix.android.sdk.api.session.uia.UiaResult
2324
import org.matrix.android.sdk.api.util.toBase64NoPadding
2425
import org.matrix.android.sdk.internal.auth.registration.handleUIA
2526
import org.matrix.android.sdk.internal.crypto.MXOlmDevice
@@ -126,13 +127,13 @@ internal class DefaultInitializeCrossSigningTask @Inject constructor(
126127
uploadSigningKeysTask.execute(uploadSigningKeysParams)
127128
} catch (failure: Throwable) {
128129
if (params.interactiveAuthInterceptor == null ||
129-
!handleUIA(
130+
handleUIA(
130131
failure = failure,
131132
interceptor = params.interactiveAuthInterceptor,
132133
retryBlock = { authUpdate ->
133134
uploadSigningKeysTask.execute(uploadSigningKeysParams.copy(userAuthParam = authUpdate))
134135
}
135-
)
136+
) != UiaResult.SUCCESS
136137
) {
137138
Timber.d("## UIA: propagate failure")
138139
throw failure

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt

+20-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package org.matrix.android.sdk.internal.session.account
1818

1919
import org.matrix.android.sdk.api.auth.UIABaseAuth
2020
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
21+
import org.matrix.android.sdk.api.session.uia.UiaResult
22+
import org.matrix.android.sdk.api.session.uia.exceptions.UiaCancelledException
2123
import org.matrix.android.sdk.internal.auth.registration.handleUIA
2224
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
2325
import org.matrix.android.sdk.internal.network.executeRequest
@@ -51,18 +53,24 @@ internal class DefaultDeactivateAccountTask @Inject constructor(
5153
}
5254
true
5355
} catch (throwable: Throwable) {
54-
if (!handleUIA(
55-
failure = throwable,
56-
interceptor = params.userInteractiveAuthInterceptor,
57-
retryBlock = { authUpdate ->
58-
execute(params.copy(userAuthParam = authUpdate))
59-
}
60-
)
61-
) {
62-
Timber.d("## UIA: propagate failure")
63-
throw throwable
64-
} else {
65-
false
56+
when (handleUIA(
57+
failure = throwable,
58+
interceptor = params.userInteractiveAuthInterceptor,
59+
retryBlock = { authUpdate ->
60+
execute(params.copy(userAuthParam = authUpdate))
61+
}
62+
)) {
63+
UiaResult.SUCCESS -> {
64+
false
65+
}
66+
UiaResult.FAILURE -> {
67+
Timber.d("## UIA: propagate failure")
68+
throw throwable
69+
}
70+
UiaResult.CANCELLED -> {
71+
Timber.d("## UIA: cancelled")
72+
throw UiaCancelledException()
73+
}
6674
}
6775
}
6876

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
2222
import org.matrix.android.sdk.api.failure.Failure
2323
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
2424
import org.matrix.android.sdk.api.session.identity.ThreePid
25+
import org.matrix.android.sdk.api.session.uia.UiaResult
2526
import org.matrix.android.sdk.internal.auth.registration.handleUIA
2627
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity
2728
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields
@@ -72,13 +73,13 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
7273
true
7374
} catch (throwable: Throwable) {
7475
if (params.userInteractiveAuthInterceptor == null ||
75-
!handleUIA(
76+
handleUIA(
7677
failure = throwable,
7778
interceptor = params.userInteractiveAuthInterceptor,
7879
retryBlock = { authUpdate ->
7980
execute(params.copy(userAuthParam = authUpdate))
8081
}
81-
)
82+
) != UiaResult.SUCCESS
8283
) {
8384
Timber.d("## UIA: propagate failure")
8485
throw throwable.toRegistrationFlowResponse()

vector/src/main/java/im/vector/app/features/settings/account/deactivation/DeactivateAccountFragment.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import im.vector.app.features.analytics.plan.MobileScreen
3434
import im.vector.app.features.auth.ReAuthActivity
3535
import im.vector.app.features.settings.VectorSettingsActivity
3636
import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
37+
import org.matrix.android.sdk.api.session.uia.exceptions.UiaCancelledException
3738
import javax.inject.Inject
3839

3940
class DeactivateAccountFragment @Inject constructor() : VectorBaseFragment<FragmentDeactivateAccountBinding>() {
@@ -114,7 +115,9 @@ class DeactivateAccountFragment @Inject constructor() : VectorBaseFragment<Fragm
114115
is DeactivateAccountViewEvents.OtherFailure -> {
115116
settingsActivity?.ignoreInvalidTokenError = false
116117
dismissLoadingDialog()
117-
displayErrorDialog(it.throwable)
118+
if (it.throwable !is UiaCancelledException) {
119+
displayErrorDialog(it.throwable)
120+
}
118121
}
119122
DeactivateAccountViewEvents.Done -> {
120123
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCredentials = true, isAccountDeactivated = true))
@@ -123,7 +126,8 @@ class DeactivateAccountFragment @Inject constructor() : VectorBaseFragment<Fragm
123126
ReAuthActivity.newIntent(requireContext(),
124127
it.registrationFlowResponse,
125128
it.lastErrorCode,
126-
getString(R.string.deactivate_account_title)).let { intent ->
129+
getString(R.string.deactivate_account_title)
130+
).let { intent ->
127131
reAuthActivityResultLauncher.launch(intent)
128132
}
129133
}

vector/src/main/java/im/vector/app/features/settings/account/deactivation/DeactivateAccountViewModel.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
3232
import org.matrix.android.sdk.api.failure.isInvalidUIAAuth
3333
import org.matrix.android.sdk.api.session.Session
3434
import org.matrix.android.sdk.api.session.uia.DefaultBaseAuth
35+
import org.matrix.android.sdk.api.session.uia.exceptions.UiaCancelledException
3536
import org.matrix.android.sdk.api.util.fromBase64
3637
import timber.log.Timber
3738
import kotlin.coroutines.Continuation
@@ -59,13 +60,15 @@ class DeactivateAccountViewModel @AssistedInject constructor(@Assisted private v
5960
is DeactivateAccountAction.DeactivateAccount -> handleDeactivateAccount(action)
6061
DeactivateAccountAction.SsoAuthDone -> {
6162
Timber.d("## UIA - FallBack success")
63+
_viewEvents.post(DeactivateAccountViewEvents.Loading())
6264
if (pendingAuth != null) {
6365
uiaContinuation?.resume(pendingAuth!!)
6466
} else {
6567
uiaContinuation?.resumeWithException(IllegalArgumentException())
6668
}
6769
}
6870
is DeactivateAccountAction.PasswordAuthDone -> {
71+
_viewEvents.post(DeactivateAccountViewEvents.Loading())
6972
val decryptedPass = session.secureStorageService()
7073
.loadSecureSecret<String>(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS)
7174
uiaContinuation?.resume(
@@ -78,7 +81,7 @@ class DeactivateAccountViewModel @AssistedInject constructor(@Assisted private v
7881
}
7982
DeactivateAccountAction.ReAuthCancelled -> {
8083
Timber.d("## UIA - Reauth cancelled")
81-
uiaContinuation?.resumeWithException(Exception())
84+
uiaContinuation?.resumeWithException(UiaCancelledException())
8285
uiaContinuation = null
8386
pendingAuth = null
8487
}
@@ -101,7 +104,7 @@ class DeactivateAccountViewModel @AssistedInject constructor(@Assisted private v
101104
}
102105
)
103106
DeactivateAccountViewEvents.Done
104-
} catch (failure: Exception) {
107+
} catch (failure: Throwable) {
105108
if (failure.isInvalidUIAAuth()) {
106109
DeactivateAccountViewEvents.InvalidAuth
107110
} else {

0 commit comments

Comments
 (0)