Skip to content

Commit 087f5a2

Browse files
authored
Merge pull request #852 from vector-im/feature/bma/moreLogAndFixes
More log and various fixes
2 parents 21f9093 + d3a95af commit 087f5a2

File tree

11 files changed

+79
-36
lines changed

11 files changed

+79
-36
lines changed

app/src/main/kotlin/io/element/android/x/MainActivity.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class MainActivity : NodeComponentActivity() {
5252
Timber.tag(loggerTag.value).w("onCreate, with savedInstanceState: ${savedInstanceState != null}")
5353
installSplashScreen()
5454
super.onCreate(savedInstanceState)
55-
appBindings = bindings<AppBindings>()
56-
appBindings.matrixClientsHolder().restore(savedInstanceState)
55+
appBindings = bindings()
5756
WindowCompat.setDecorFitsSystemWindows(window, false)
5857
setContent {
5958
MainContent(appBindings)
@@ -125,9 +124,4 @@ class MainActivity : NodeComponentActivity() {
125124
super.onDestroy()
126125
Timber.tag(loggerTag.value).w("onDestroy")
127126
}
128-
129-
override fun onSaveInstanceState(outState: Bundle) {
130-
super.onSaveInstanceState(outState)
131-
bindings<AppBindings>().matrixClientsHolder().onSaveInstanceState(outState)
132-
}
133127
}

app/src/main/kotlin/io/element/android/x/di/AppBindings.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
package io.element.android.x.di
1818

1919
import com.squareup.anvil.annotations.ContributesTo
20-
import io.element.android.appnav.di.MatrixClientsHolder
2120
import io.element.android.libraries.designsystem.utils.SnackbarDispatcher
2221
import io.element.android.libraries.di.AppScope
2322

2423
@ContributesTo(AppScope::class)
2524
interface AppBindings {
26-
fun matrixClientsHolder(): MatrixClientsHolder
2725
fun mainDaggerComponentOwner(): MainDaggerComponentsOwner
2826
fun snackbarDispatcher(): SnackbarDispatcher
2927
}

appnav/src/main/kotlin/io/element/android/appnav/LoggedInFlowNode.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ class LoggedInFlowNode @AssistedInject constructor(
154154
syncService.stopSync()
155155
},
156156
onDestroy = {
157-
val imageLoaderFactory = bindings<MatrixUIBindings>().notLoggedInImageLoaderFactory()
158-
Coil.setImageLoader(imageLoaderFactory)
159157
plugins<LifecycleCallback>().forEach { it.onFlowReleased(id, inputs.matrixClient) }
160158
appNavigationStateService.onLeavingSpace(id)
161159
appNavigationStateService.onLeavingSession(id)

appnav/src/main/kotlin/io/element/android/appnav/NotLoggedInFlowNode.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package io.element.android.appnav
1919
import android.os.Parcelable
2020
import androidx.compose.runtime.Composable
2121
import androidx.compose.ui.Modifier
22+
import coil.Coil
2223
import com.bumble.appyx.core.composable.Children
2324
import com.bumble.appyx.core.lifecycle.subscribe
2425
import com.bumble.appyx.core.modality.BuildContext
@@ -34,15 +35,16 @@ import io.element.android.features.onboarding.api.OnBoardingEntryPoint
3435
import io.element.android.libraries.architecture.BackstackNode
3536
import io.element.android.libraries.architecture.animation.rememberDefaultTransitionHandler
3637
import io.element.android.libraries.di.AppScope
38+
import io.element.android.libraries.matrix.ui.media.NotLoggedInImageLoaderFactory
3739
import kotlinx.parcelize.Parcelize
38-
import timber.log.Timber
3940

4041
@ContributesNode(AppScope::class)
4142
class NotLoggedInFlowNode @AssistedInject constructor(
4243
@Assisted buildContext: BuildContext,
4344
@Assisted plugins: List<Plugin>,
4445
private val onBoardingEntryPoint: OnBoardingEntryPoint,
4546
private val loginEntryPoint: LoginEntryPoint,
47+
private val notLoggedInImageLoaderFactory: NotLoggedInImageLoaderFactory,
4648
) : BackstackNode<NotLoggedInFlowNode.NavTarget>(
4749
backstack = BackStack(
4850
initialElement = NavTarget.OnBoarding,
@@ -51,10 +53,12 @@ class NotLoggedInFlowNode @AssistedInject constructor(
5153
buildContext = buildContext,
5254
plugins = plugins,
5355
) {
54-
init {
56+
override fun onBuilt() {
57+
super.onBuilt()
5558
lifecycle.subscribe(
56-
onCreate = { Timber.v("OnCreate") },
57-
onDestroy = { Timber.v("OnDestroy") }
59+
onCreate = {
60+
Coil.setImageLoader(notLoggedInImageLoaderFactory)
61+
},
5862
)
5963
}
6064

appnav/src/main/kotlin/io/element/android/appnav/RootFlowNode.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.bumble.appyx.core.node.Node
3030
import com.bumble.appyx.core.node.node
3131
import com.bumble.appyx.core.plugin.Plugin
3232
import com.bumble.appyx.core.plugin.plugins
33+
import com.bumble.appyx.core.state.MutableSavedStateMap
3334
import com.bumble.appyx.navmodel.backstack.BackStack
3435
import com.bumble.appyx.navmodel.backstack.operation.pop
3536
import com.bumble.appyx.navmodel.backstack.operation.push
@@ -90,10 +91,16 @@ class RootFlowNode @AssistedInject constructor(
9091
) {
9192

9293
override fun onBuilt() {
94+
matrixClientsHolder.restore(buildContext.savedStateMap)
9395
super.onBuilt()
9496
observeLoggedInState()
9597
}
9698

99+
override fun onSaveInstanceState(state: MutableSavedStateMap) {
100+
super.onSaveInstanceState(state)
101+
matrixClientsHolder.save(state)
102+
}
103+
97104
private fun observeLoggedInState() {
98105
combine(
99106
cacheService.onClearedCacheEventFlow(),

appnav/src/main/kotlin/io/element/android/appnav/di/MatrixClientsHolder.kt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@
1616

1717
package io.element.android.appnav.di
1818

19-
import android.os.Bundle
20-
import io.element.android.libraries.di.AppScope
21-
import io.element.android.libraries.di.SingleIn
19+
import com.bumble.appyx.core.state.MutableSavedStateMap
20+
import com.bumble.appyx.core.state.SavedStateMap
2221
import io.element.android.libraries.matrix.api.MatrixClient
2322
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
2423
import io.element.android.libraries.matrix.api.core.SessionId
25-
import io.element.android.libraries.matrix.api.core.UserId
2624
import kotlinx.coroutines.runBlocking
2725
import timber.log.Timber
2826
import java.util.concurrent.ConcurrentHashMap
2927
import javax.inject.Inject
3028

3129
private const val SAVE_INSTANCE_KEY = "io.element.android.x.di.MatrixClientsHolder.SaveInstanceKey"
3230

33-
@SingleIn(AppScope::class)
3431
class MatrixClientsHolder @Inject constructor(private val authenticationService: MatrixAuthenticationService) {
3532

3633
private val sessionIdsToMatrixClient = ConcurrentHashMap<SessionId, MatrixClient>()
@@ -55,16 +52,20 @@ class MatrixClientsHolder @Inject constructor(private val authenticationService:
5552
return sessionIdsToMatrixClient[sessionId]
5653
}
5754

58-
@Suppress("DEPRECATION")
59-
fun restore(savedInstanceState: Bundle?) {
60-
if (savedInstanceState == null || sessionIdsToMatrixClient.isNotEmpty()) return
61-
val userIds = savedInstanceState.getSerializable(SAVE_INSTANCE_KEY) as? Array<UserId>
62-
if (userIds.isNullOrEmpty()) return
55+
@Suppress("UNCHECKED_CAST")
56+
fun restore(state: SavedStateMap?) {
57+
Timber.d("Restore state")
58+
if (state == null || sessionIdsToMatrixClient.isNotEmpty()) return Unit.also {
59+
Timber.w("Restore with non-empty map")
60+
}
61+
val sessionIds = state[SAVE_INSTANCE_KEY] as? Array<SessionId>
62+
Timber.d("Restore matrix session keys = ${sessionIds?.map { it.value }}")
63+
if (sessionIds.isNullOrEmpty()) return
6364
// Not ideal but should only happens in case of process recreation. This ensure we restore all the active sessions before restoring the node graphs.
6465
runBlocking {
65-
userIds.forEach { userId ->
66-
Timber.v("Restore matrix session: $userId")
67-
authenticationService.restoreSession(userId)
66+
sessionIds.forEach { sessionId ->
67+
Timber.d("Restore matrix session: $sessionId")
68+
authenticationService.restoreSession(sessionId)
6869
.onSuccess { matrixClient ->
6970
add(matrixClient)
7071
}
@@ -75,9 +76,9 @@ class MatrixClientsHolder @Inject constructor(private val authenticationService:
7576
}
7677
}
7778

78-
fun onSaveInstanceState(outState: Bundle) {
79+
fun save(state: MutableSavedStateMap) {
7980
val sessionKeys = sessionIdsToMatrixClient.keys.toTypedArray()
80-
Timber.v("Save matrix session keys = $sessionKeys")
81-
outState.putSerializable(SAVE_INSTANCE_KEY, sessionKeys)
81+
Timber.d("Save matrix session keys = ${sessionKeys.map { it.value }}")
82+
state[SAVE_INSTANCE_KEY] = sessionKeys
8283
}
8384
}

libraries/architecture/src/main/kotlin/io/element/android/libraries/architecture/BackstackNode.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package io.element.android.libraries.architecture
1919
import androidx.compose.runtime.Stable
2020
import com.bumble.appyx.core.children.ChildEntry
2121
import com.bumble.appyx.core.modality.BuildContext
22+
import com.bumble.appyx.core.node.Node
2223
import com.bumble.appyx.core.node.ParentNode
2324
import com.bumble.appyx.core.plugin.Plugin
2425
import com.bumble.appyx.navmodel.backstack.BackStack
@@ -39,4 +40,15 @@ abstract class BackstackNode<NavTarget : Any>(
3940
buildContext = buildContext,
4041
plugins = plugins,
4142
childKeepMode = childKeepMode,
42-
)
43+
) {
44+
override fun onBuilt() {
45+
super.onBuilt()
46+
lifecycle.logLifecycle(this::class.java.simpleName)
47+
whenChildAttached<Node> { _, child ->
48+
// BackstackNode will be logged by their parent.
49+
if (child !is BackstackNode<*>) {
50+
child.lifecycle.logLifecycle(child::class.java.simpleName)
51+
}
52+
}
53+
}
54+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2023 New Vector Ltd
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 io.element.android.libraries.architecture
18+
19+
import androidx.lifecycle.Lifecycle
20+
import com.bumble.appyx.core.lifecycle.subscribe
21+
import timber.log.Timber
22+
23+
fun Lifecycle.logLifecycle(name: String) {
24+
subscribe(
25+
onCreate = { Timber.tag("Lifecycle").d("onCreate $name") },
26+
onPause = { Timber.tag("Lifecycle").d("onPause $name") },
27+
onResume = { Timber.tag("Lifecycle").d("onResume $name") },
28+
onDestroy = { Timber.tag("Lifecycle").d("onDestroy $name") },
29+
)
30+
}

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/RoomSummaryDataSource.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ interface RoomSummaryDataSource {
3838

3939
suspend fun RoomSummaryDataSource.awaitAllRoomsAreLoaded(timeout: Duration = Duration.INFINITE) {
4040
try {
41+
Timber.d("awaitAllRoomsAreLoaded: wait")
4142
withTimeout(timeout) {
4243
allRoomsLoadingState().firstOrNull {
4344
it is RoomSummaryDataSource.LoadingState.Loaded
4445
}
4546
}
4647
} catch (timeoutException: TimeoutCancellationException) {
47-
Timber.v("AwaitAllRooms: no response after $timeout")
48+
Timber.d("awaitAllRoomsAreLoaded: no response after $timeout")
4849
}
4950
}

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RoomListExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fun RoomListService.roomOrNull(roomId: String): RoomListItem? {
6262
return try {
6363
room(roomId)
6464
} catch (exception: RoomListException) {
65-
Timber.e(exception, "Failed finding room with id=$roomId")
65+
Timber.d(exception, "Failed finding room with id=$roomId.")
6666
return null
6767
}
6868
}

0 commit comments

Comments
 (0)