Merge pull request #7605 from vector-im/fix/mna/anr-on-session-start

ANR on session start when sending client info is enabled
This commit is contained in:
Maxime NATUREL 2022-11-18 09:38:39 +01:00 committed by GitHub
commit cf5b96f9cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 6 deletions

1
changelog.d/7604.bugfix Normal file
View file

@ -0,0 +1 @@
ANR on session start when sending client info is enabled

View file

@ -111,9 +111,7 @@ class ActiveSessionHolder @Inject constructor(
}
?: sessionInitializer.tryInitialize(readCurrentSession = { activeSessionReference.get() }) { session ->
setActiveSession(session)
runBlocking {
configureAndStartSessionUseCase.execute(session, startSyncing = startSync)
}
configureAndStartSessionUseCase.execute(session, startSyncing = startSync)
}
}

View file

@ -22,7 +22,9 @@ import im.vector.app.core.extensions.startSyncing
import im.vector.app.core.notification.EnableNotificationsSettingUpdater
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.session.coroutineScope
import im.vector.app.features.settings.VectorPreferences
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.sync.FilterService
import timber.log.Timber
@ -36,7 +38,7 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
private val enableNotificationsSettingUpdater: EnableNotificationsSettingUpdater,
) {
suspend fun execute(session: Session, startSyncing: Boolean = true) {
fun execute(session: Session, startSyncing: Boolean = true) {
Timber.i("Configure and start session for ${session.myUserId}. startSyncing: $startSyncing")
session.open()
session.filterService().setFilter(FilterService.FilterPreset.ElementFilter)
@ -45,8 +47,10 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
}
session.pushersService().refreshPushers()
webRtcCallManager.checkForProtocolsSupportIfNeeded()
if (vectorPreferences.isClientInfoRecordingEnabled()) {
updateMatrixClientInfoUseCase.execute(session)
session.coroutineScope.launch {
if (vectorPreferences.isClientInfoRecordingEnabled()) {
updateMatrixClientInfoUseCase.execute(session)
}
}
enableNotificationsSettingUpdater.onSessionsStarted(session)
}

View file

@ -18,6 +18,7 @@ package im.vector.app.core.session
import im.vector.app.core.extensions.startSyncing
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
import im.vector.app.features.session.coroutineScope
import im.vector.app.test.fakes.FakeContext
import im.vector.app.test.fakes.FakeEnableNotificationsSettingUpdater
import im.vector.app.test.fakes.FakeSession
@ -32,6 +33,7 @@ import io.mockk.mockkStatic
import io.mockk.runs
import io.mockk.unmockkAll
import io.mockk.verify
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
@ -57,6 +59,7 @@ class ConfigureAndStartSessionUseCaseTest {
@Before
fun setup() {
mockkStatic("im.vector.app.core.extensions.SessionKt")
mockkStatic("im.vector.app.features.session.SessionCoroutineScopesKt")
}
@After
@ -68,6 +71,7 @@ class ConfigureAndStartSessionUseCaseTest {
fun `given start sync needed and client info recording enabled when execute then it should be configured properly`() = runTest {
// Given
val fakeSession = givenASession()
every { fakeSession.coroutineScope } returns this
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
@ -75,6 +79,7 @@ class ConfigureAndStartSessionUseCaseTest {
// When
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true)
advanceUntilIdle()
// Then
verify { fakeSession.startSyncing(fakeContext.instance) }
@ -88,6 +93,7 @@ class ConfigureAndStartSessionUseCaseTest {
fun `given start sync needed and client info recording disabled when execute then it should be configured properly`() = runTest {
// Given
val fakeSession = givenASession()
every { fakeSession.coroutineScope } returns this
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = false)
@ -95,6 +101,7 @@ class ConfigureAndStartSessionUseCaseTest {
// When
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true)
advanceUntilIdle()
// Then
verify { fakeSession.startSyncing(fakeContext.instance) }
@ -108,6 +115,7 @@ class ConfigureAndStartSessionUseCaseTest {
fun `given a session and no start sync needed when execute then it should be configured properly`() = runTest {
// Given
val fakeSession = givenASession()
every { fakeSession.coroutineScope } returns this
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
@ -115,6 +123,7 @@ class ConfigureAndStartSessionUseCaseTest {
// When
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = false)
advanceUntilIdle()
// Then
verify(inverse = true) { fakeSession.startSyncing(fakeContext.instance) }