Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
bd8cd09
feat(logout): handle logout and session expiration
mchenani Jul 7, 2022
9fa3202
feat(logout): handle logout and session expiration
mchenani Jul 7, 2022
8dc81a3
refactor authSession subclasses and fix some issues
mchenani Jul 7, 2022
1d0d65d
refactor authSession subclasses and fix some issues
mchenani Jul 7, 2022
f5f41ce
handled different auth session states
mchenani Jul 7, 2022
bd153b0
Merge branch 'develop' of https://github.com/wireapp/wire-android-rel…
mchenani Jul 11, 2022
b5e2ed2
add logout reason
mchenani Jul 12, 2022
2431035
Merge branch 'develop' of https://github.com/wireapp/wire-android-rel…
mchenani Jul 17, 2022
7bdea20
handle all states and refactor authsession
mchenani Jul 18, 2022
ab64105
refactor ui message in login screen
mchenani Jul 18, 2022
08f72f0
Merge branch 'develop' of https://github.com/wireapp/wire-android-rel…
mchenani Jul 19, 2022
cc4277a
Merge branch 'develop' of https://github.com/wireapp/wire-android-rel…
mchenani Jul 26, 2022
2508baa
Merge branch 'develop' of https://github.com/wireapp/wire-android-rel…
mchenani Jul 27, 2022
cd2676f
ci: add kalium ref validation workflow
tmspzz Jul 29, 2022
7a59139
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
d6b6952
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
2487d39
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
adc9e36
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
c6e6c96
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
ae0d406
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
fa0e168
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
2891b1a
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
b5656f5
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
a1fd764
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
6b7c626
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
3c7441d
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
1bf7446
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
ceb01f7
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
8c0a70f
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
5e1f286
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
fe9073d
apply invalid session to ar
mchenani Jul 29, 2022
a7c8ba1
refactor LoginError
mchenani Jul 29, 2022
49b4b8f
Merge branch 'develop' of https://github.com/wireapp/wire-android-rel…
mchenani Jul 29, 2022
71f6bf9
fix styles
mchenani Jul 29, 2022
714257d
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
73c78a0
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
d33338d
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
0a79f91
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
f2bf813
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
14c4c29
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
86f4783
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
a404b5a
ci: improve kalium ref validation workflow
tmspzz Jul 29, 2022
a9683a4
update kalium ref
mchenani Jul 29, 2022
ff8222b
Merge branch 'develop' into feat/AR-1656_handle_session_expiration
mchenani Jul 29, 2022
3112171
Merge branch 'develop' of https://github.com/wireapp/wire-android-rel…
mchenani Aug 1, 2022
6dd21e1
fix tests
mchenani Aug 1, 2022
ebaf8af
update kalium ref
mchenani Aug 1, 2022
47be419
fix showing error conditions
mchenani Aug 1, 2022
00fc823
update kalium ref
mchenani Aug 1, 2022
4cd3be1
Merge branch 'develop' of https://github.com/wireapp/wire-android-rel…
mchenani Aug 1, 2022
dd96aab
separate sso and email loading variables
mchenani Aug 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import javax.inject.Singleton

@Singleton
class AuthServerConfigProvider @Inject constructor() {
//todo check with soft logout
private val _authServer: MutableStateFlow<ServerConfig.Links> = MutableStateFlow(ServerConfig.DEFAULT)
val authServer: StateFlow<ServerConfig.Links> = _authServer

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class SessionModule {
fun provideCurrentSession(@KaliumCoreLogic coreLogic: CoreLogic): UserId {
return runBlocking {
return@runBlocking when (val result = coreLogic.getGlobalScope().session.currentSession.invoke()) {
is CurrentSessionResult.Success -> result.authSession.tokens.userId
is CurrentSessionResult.Success -> result.authSession.session.userId
else -> {
throw IllegalStateException("no current session was found")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.wire.android.di

import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.feature.session.GetSessionsUseCase
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject

class UserSessionsUseCaseProvider @AssistedInject constructor(
@KaliumCoreLogic private val coreLogic: CoreLogic,
) {
val sessionsUseCase: GetSessionsUseCase
get() = coreLogic.getGlobalScope().getSessions

@AssistedFactory
interface Factory {
fun create(): UserSessionsUseCaseProvider
}
}
51 changes: 31 additions & 20 deletions app/src/main/kotlin/com/wire/android/navigation/NavigationItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ enum class NavigationItem(

Login(
primaryRoute = LOGIN,
canonicalRoute = "$LOGIN?$EXTRA_USER_ID={$EXTRA_USER_ID}",
content = { contentParams ->
val ssoLoginResult = contentParams.arguments.filterIsInstance<DeepLinkResult.SSOLogin>().firstOrNull()
LoginScreen(ssoLoginResult)
},
animationConfig = NavigationAnimationConfig.CustomAnimation(smoothSlideInFromRight(), smoothSlideOutFromLeft())
),
) {
override fun getRouteWithArgs(arguments: List<Any>): String {
val userId: QualifiedID? = arguments.filterIsInstance<QualifiedID>().firstOrNull()
return if (userId == null) primaryRoute else "$primaryRoute?$EXTRA_USER_ID=$userId"
}
},

CreateTeam(
primaryRoute = CREATE_TEAM,
Expand Down Expand Up @@ -172,11 +178,13 @@ enum class NavigationItem(
OtherUserProfile(
primaryRoute = OTHER_USER_PROFILE,
canonicalRoute = "$OTHER_USER_PROFILE?$EXTRA_USER_ID={$EXTRA_USER_ID}&$EXTRA_CONVERSATION_ID={$EXTRA_CONVERSATION_ID}",
deepLinks = listOf(navDeepLink {
uriPattern = "${DeepLinkProcessor.DEEP_LINK_SCHEME}://" +
"${DeepLinkProcessor.OTHER_USER_PROFILE_DEEPLINK_HOST}/" +
"{$EXTRA_USER_ID}"
}),
deepLinks = listOf(
navDeepLink {
uriPattern = "${DeepLinkProcessor.DEEP_LINK_SCHEME}://" +
"${DeepLinkProcessor.OTHER_USER_PROFILE_DEEPLINK_HOST}/" +
"{$EXTRA_USER_ID}"
}
),
content = { OtherUserProfileScreen() },
animationConfig = NavigationAnimationConfig.NoAnimation
) {
Expand All @@ -196,11 +204,13 @@ enum class NavigationItem(
Conversation(
primaryRoute = CONVERSATION,
canonicalRoute = "$CONVERSATION?$EXTRA_CONVERSATION_ID={$EXTRA_CONVERSATION_ID}",
deepLinks = listOf(navDeepLink {
uriPattern = "${DeepLinkProcessor.DEEP_LINK_SCHEME}://" +
"${DeepLinkProcessor.CONVERSATION_DEEPLINK_HOST}/" +
"{$EXTRA_CONVERSATION_ID}"
}),
deepLinks = listOf(
navDeepLink {
uriPattern = "${DeepLinkProcessor.DEEP_LINK_SCHEME}://" +
"${DeepLinkProcessor.CONVERSATION_DEEPLINK_HOST}/" +
"{$EXTRA_CONVERSATION_ID}"
}
),
content = { ConversationScreen(hiltSavedStateViewModel(it.navBackStackEntry)) },
) {
override fun getRouteWithArgs(arguments: List<Any>): String {
Expand All @@ -224,7 +234,6 @@ enum class NavigationItem(
content = {
val viewModel = hiltViewModel<AddMembersToConversationViewModel>()


SearchPeopleRouter(
searchPeopleViewModel = viewModel,
searchBarTitle = stringResource(id = R.string.label_add_participants),
Expand Down Expand Up @@ -271,11 +280,13 @@ enum class NavigationItem(
IncomingCall(
primaryRoute = INCOMING_CALL,
canonicalRoute = "$INCOMING_CALL?$EXTRA_CONVERSATION_ID={$EXTRA_CONVERSATION_ID}",
deepLinks = listOf(navDeepLink {
uriPattern = "${DeepLinkProcessor.DEEP_LINK_SCHEME}://" +
"${DeepLinkProcessor.INCOMING_CALL_DEEPLINK_HOST}/" +
"{$EXTRA_CONVERSATION_ID}"
}),
deepLinks = listOf(
navDeepLink {
uriPattern = "${DeepLinkProcessor.DEEP_LINK_SCHEME}://" +
"${DeepLinkProcessor.INCOMING_CALL_DEEPLINK_HOST}/" +
"{$EXTRA_CONVERSATION_ID}"
}
),
content = { IncomingCallScreen() },
screenMode = ScreenMode.WAKE_UP,
animationConfig = NavigationAnimationConfig.DelegatedAnimation
Expand Down Expand Up @@ -379,7 +390,7 @@ data class ContentParams(
)

enum class ScreenMode {
KEEP_ON, // keep screen on while that NavigationItem is visible (i.e CallScreen)
WAKE_UP, // wake up the device on navigating to that NavigationItem (i.e IncomingCall)
NONE // do not wake up and allow device to sleep
KEEP_ON, // keep screen on while that NavigationItem is visible (i.e CallScreen)
WAKE_UP, // wake up the device on navigating to that NavigationItem (i.e IncomingCall)
NONE // do not wake up and allow device to sleep
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class WireNotificationManager @Inject constructor(
when (it) {
is GetAllSessionsResult.Success -> {
for (sessions in it.sessions) {
if (sessions.tokens.userId.value == userId)
return@let sessions.tokens.userId
if (sessions.session.userId.value == userId)
return@let sessions.session.userId
}
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CallNotificationDismissReceiver : BroadcastReceiver() {
} else {
val currentSession = coreLogic.globalScope { session.currentSession() }
if (currentSession is CurrentSessionResult.Success) {
coreLogic.getSessionScope(currentSession.authSession.tokens.userId)
coreLogic.getSessionScope(currentSession.authSession.session.userId)
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ConnectionRequestNotificationDismissReceiver : BroadcastReceiver() {
} else {
val currentSession = coreLogic.globalScope { session.currentSession() }
if (currentSession is CurrentSessionResult.Success) {
coreLogic.getSessionScope(currentSession.authSession.tokens.userId)
coreLogic.getSessionScope(currentSession.authSession.session.userId)
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MessageNotificationDismissReceiver : BroadcastReceiver() {
} else {
val currentSession = coreLogic.globalScope { session.currentSession() }
if (currentSession is CurrentSessionResult.Success) {
coreLogic.getSessionScope(currentSession.authSession.tokens.userId)
coreLogic.getSessionScope(currentSession.authSession.session.userId)
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.Context
import android.content.Intent
import com.wire.android.appLogger
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.notification.MessageNotificationManager
import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.id.QualifiedID
Expand Down Expand Up @@ -39,7 +38,7 @@ class SummaryNotificationDismissReceiver : BroadcastReceiver() {
} else {
val currentSession = coreLogic.globalScope { session.currentSession() }
if (currentSession is CurrentSessionResult.Success) {
coreLogic.getSessionScope(currentSession.authSession.tokens.userId)
coreLogic.getSessionScope(currentSession.authSession.session.userId)
} else {
null
}
Expand Down
36 changes: 32 additions & 4 deletions app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.kalium.logic.configuration.server.ServerConfig
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.auth.AuthSession
import com.wire.kalium.logic.feature.server.GetServerConfigResult
import com.wire.kalium.logic.feature.server.GetServerConfigUseCase
import com.wire.kalium.logic.feature.session.CurrentSessionFlowUseCase
Expand All @@ -37,20 +39,27 @@ import javax.inject.Inject
@HiltViewModel
class WireActivityViewModel @Inject constructor(
dispatchers: DispatcherProvider,
currentSessionFlow: CurrentSessionFlowUseCase,
val currentSessionFlow: CurrentSessionFlowUseCase,
private val getServerConfigUseCase: GetServerConfigUseCase,
private val deepLinkProcessor: DeepLinkProcessor,
private val notificationManager: WireNotificationManager,
private val navigationManager: NavigationManager,
private val authServerConfigProvider: AuthServerConfigProvider
private val authServerConfigProvider: AuthServerConfigProvider,
) : ViewModel() {

private val navigationArguments = mutableMapOf<String, Any>(SERVER_CONFIG_ARG to ServerConfig.DEFAULT)

private val observeUserId = currentSessionFlow()
.map { result ->
if (result is CurrentSessionResult.Success) result.authSession.tokens.userId
else null
if (result is CurrentSessionResult.Success) {
if (result.authSession.session is AuthSession.Session.Invalid) {
navigateToLogin(result.authSession.session.userId)
null
} else
result.authSession.session.userId
} else {
null
}
}
.distinctUntilChanged()
.flowOn(dispatchers.io())
Expand All @@ -62,6 +71,15 @@ class WireActivityViewModel @Inject constructor(
}
}

private suspend fun navigateToLogin(userId: UserId) {
navigationManager.navigate(
NavigationCommand(
NavigationItem.Login.getRouteWithArgs(listOf(userId)),
BackStackMode.CLEAR_WHOLE
)
)
}

fun navigationArguments() = navigationArguments.values.toList()

fun startNavigationRoute(): String =
Expand All @@ -82,8 +100,10 @@ class WireActivityViewModel @Inject constructor(
authServerConfigProvider.updateAuthServer(serverLinks)
navigationArguments.put(SERVER_CONFIG_ARG, serverLinks)
}

is DeepLinkResult.SSOLogin ->
navigationArguments.put(SSO_DEEPLINK_ARG, result)

is DeepLinkResult.IncomingCall -> {
if (isLaunchedFromHistory(intent)) {
//We don't need to handle deepLink, if activity was launched from history.
Expand All @@ -94,20 +114,23 @@ class WireActivityViewModel @Inject constructor(
navigationArguments.put(INCOMING_CALL_CONVERSATION_ID_ARG, result.conversationsId)
}
}

is DeepLinkResult.OpenConversation -> {
if (isLaunchedFromHistory(intent)) {
appLogger.i("OpenConversation deepLink launched from the history")
} else {
navigationArguments.put(OPEN_CONVERSATION_ID_ARG, result.conversationsId)
}
}

is DeepLinkResult.OpenOtherUserProfile -> {
if (isLaunchedFromHistory(intent)) {
appLogger.i("OpenOtherUserProfile deepLink launched from the history")
} else {
navigationArguments.put(OPEN_OTHER_USER_PROFILE_ARG, result.userId)
}
}

DeepLinkResult.Unknown -> {
appLogger.e("unknown deeplink result $result")
}
Expand Down Expand Up @@ -139,14 +162,17 @@ class WireActivityViewModel @Inject constructor(
openIncomingCall(navigationArguments[INCOMING_CALL_CONVERSATION_ID_ARG] as ConversationId)
false
}

shouldGoToConversation() -> {
openConversation(navigationArguments[OPEN_CONVERSATION_ID_ARG] as ConversationId)
false
}

shouldGoToOtherProfile() -> {
openOtherUserProfile(navigationArguments[OPEN_OTHER_USER_PROFILE_ARG] as QualifiedID)
false
}

intent == null -> false
else -> true
}
Expand Down Expand Up @@ -181,10 +207,12 @@ class WireActivityViewModel @Inject constructor(
appLogger.e("something went wrong during handling the scustom server deep link: ${result.genericFailure}")
null
}

GetServerConfigResult.Failure.TooNewVersion -> {
appLogger.e("server version is too new")
null
}

GetServerConfigResult.Failure.UnknownServerVersion -> {
appLogger.e("unknown server version")
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ sealed class LoginError {
}

sealed class DialogError : LoginError() {
data class GenericError(val coreFailure: CoreFailure) : LoginError.DialogError()
data class GenericError(val coreFailure: CoreFailure) : DialogError()
object InvalidCredentialsError : DialogError()
object InvalidSSOCookie : DialogError()
object InvalidCodeError : DialogError()
object UserAlreadyExists : DialogError()
object PasswordNeededToRegisterClient : DialogError()
sealed class InvalidSession : DialogError() {
object RemovedClient : InvalidSession()
object DeletedAccount : InvalidSession()
object SessionExpired : InvalidSession()

}

data class SSOResultError constructor(val result: SSOFailureCodes) :
LoginError.DialogError()
DialogError()
}

object TooManyDevicesError : LoginError()

}
Loading