mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 09:25:49 +03:00
Merge pull request #6029 from vector-im/feature/bma/sdk_sync_service
Feature/bma/sdk sync service
This commit is contained in:
commit
3b2f9d9404
55 changed files with 457 additions and 378 deletions
5
changelog.d/6029.sdk
Normal file
5
changelog.d/6029.sdk
Normal file
|
@ -0,0 +1,5 @@
|
|||
Some methods from `Session` have been moved to a new `SyncService`, that you can retrieve from a `Session`.
|
||||
- `SyncStatusService` method has been moved to the new `SyncService`
|
||||
- `InitSyncStep` have been moved and renamed to `InitialSyncStep`
|
||||
- `SyncStatusService.Status` has been renamed to `SyncRequestState`
|
||||
- The existing `SyncService` has been renamed to `SyncAndroidService` because of name clash with the new SDK Service
|
|
@ -88,7 +88,7 @@ class FlowSession(private val session: Session) {
|
|||
}
|
||||
|
||||
fun liveSyncState(): Flow<SyncState> {
|
||||
return session.getSyncStateLive().asFlow()
|
||||
return session.syncService().getSyncStateLive().asFlow()
|
||||
}
|
||||
|
||||
fun livePushers(): Flow<List<Pusher>> {
|
||||
|
|
|
@ -137,11 +137,11 @@ class CommonTestHelper private constructor(context: Context) {
|
|||
fun syncSession(session: Session, timeout: Long = TestConstants.timeOutMillis * 10) {
|
||||
val lock = CountDownLatch(1)
|
||||
coroutineScope.launch {
|
||||
session.startSync(true)
|
||||
val syncLiveData = session.getSyncStateLive()
|
||||
session.syncService().startSync(true)
|
||||
val syncLiveData = session.syncService().getSyncStateLive()
|
||||
val syncObserver = object : Observer<SyncState> {
|
||||
override fun onChanged(t: SyncState?) {
|
||||
if (session.hasAlreadySynced()) {
|
||||
if (session.syncService().hasAlreadySynced()) {
|
||||
lock.countDown()
|
||||
syncLiveData.removeObserver(this)
|
||||
}
|
||||
|
@ -160,10 +160,10 @@ class CommonTestHelper private constructor(context: Context) {
|
|||
fun clearCacheAndSync(session: Session, timeout: Long = TestConstants.timeOutMillis) {
|
||||
waitWithLatch(timeout) { latch ->
|
||||
session.clearCache()
|
||||
val syncLiveData = session.getSyncStateLive()
|
||||
val syncLiveData = session.syncService().getSyncStateLive()
|
||||
val syncObserver = object : Observer<SyncState> {
|
||||
override fun onChanged(t: SyncState?) {
|
||||
if (session.hasAlreadySynced()) {
|
||||
if (session.syncService().hasAlreadySynced()) {
|
||||
Timber.v("Clear cache and synced")
|
||||
syncLiveData.removeObserver(this)
|
||||
latch.countDown()
|
||||
|
@ -171,7 +171,7 @@ class CommonTestHelper private constructor(context: Context) {
|
|||
}
|
||||
}
|
||||
syncLiveData.observeForever(syncObserver)
|
||||
session.startSync(true)
|
||||
session.syncService().startSync(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -424,7 +424,7 @@ class KeyShareTests : InstrumentedTest {
|
|||
|
||||
// /!\ Stop initial alice session syncing so that it can't reply
|
||||
aliceSession.cryptoService().enableKeyGossiping(false)
|
||||
aliceSession.stopSync()
|
||||
aliceSession.syncService().stopSync()
|
||||
|
||||
// Let's now try to request
|
||||
aliceNewSession.cryptoService().reRequestRoomKeyForEvent(sentEvents.first().root)
|
||||
|
@ -447,7 +447,7 @@ class KeyShareTests : InstrumentedTest {
|
|||
|
||||
// let's wake up alice
|
||||
aliceSession.cryptoService().enableKeyGossiping(true)
|
||||
aliceSession.startSync(true)
|
||||
aliceSession.syncService().startSync(true)
|
||||
|
||||
// We should now get a reply from first session
|
||||
commonTestHelper.waitWithLatch { latch ->
|
||||
|
|
|
@ -83,7 +83,7 @@ class ThreadMessagingTest : InstrumentedTest {
|
|||
val timeline = aliceRoom.timelineService().createTimeline(null, TimelineSettings(30))
|
||||
timeline.start()
|
||||
|
||||
aliceSession.startSync(true)
|
||||
aliceSession.syncService().startSync(true)
|
||||
run {
|
||||
val lock = CountDownLatch(1)
|
||||
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
|
||||
|
@ -97,7 +97,7 @@ class ThreadMessagingTest : InstrumentedTest {
|
|||
timeline.addListener(eventsListener)
|
||||
commonTestHelper.await(lock, 600_000)
|
||||
}
|
||||
aliceSession.stopSync()
|
||||
aliceSession.syncService().stopSync()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -144,7 +144,7 @@ class ThreadMessagingTest : InstrumentedTest {
|
|||
val timeline = aliceRoom.timelineService().createTimeline(null, TimelineSettings(30))
|
||||
timeline.start()
|
||||
|
||||
aliceSession.startSync(true)
|
||||
aliceSession.syncService().startSync(true)
|
||||
run {
|
||||
val lock = CountDownLatch(1)
|
||||
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
|
||||
|
@ -156,9 +156,9 @@ class ThreadMessagingTest : InstrumentedTest {
|
|||
timeline.addListener(eventsListener)
|
||||
commonTestHelper.await(lock, 600_000)
|
||||
}
|
||||
aliceSession.stopSync()
|
||||
aliceSession.syncService().stopSync()
|
||||
|
||||
bobSession.startSync(true)
|
||||
bobSession.syncService().startSync(true)
|
||||
run {
|
||||
val lock = CountDownLatch(1)
|
||||
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
|
||||
|
@ -170,7 +170,7 @@ class ThreadMessagingTest : InstrumentedTest {
|
|||
timeline.addListener(eventsListener)
|
||||
commonTestHelper.await(lock, 600_000)
|
||||
}
|
||||
bobSession.stopSync()
|
||||
bobSession.syncService().stopSync()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -217,7 +217,7 @@ class ThreadMessagingTest : InstrumentedTest {
|
|||
val timeline = aliceRoom.timelineService().createTimeline(null, TimelineSettings(30))
|
||||
timeline.start()
|
||||
|
||||
aliceSession.startSync(true)
|
||||
aliceSession.syncService().startSync(true)
|
||||
run {
|
||||
val lock = CountDownLatch(1)
|
||||
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
|
||||
|
@ -233,7 +233,7 @@ class ThreadMessagingTest : InstrumentedTest {
|
|||
timeline.addListener(eventsListener)
|
||||
commonTestHelper.await(lock, 600_000)
|
||||
}
|
||||
aliceSession.stopSync()
|
||||
aliceSession.syncService().stopSync()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -314,7 +314,7 @@ class ThreadMessagingTest : InstrumentedTest {
|
|||
val timeline = aliceRoom.timelineService().createTimeline(null, TimelineSettings(30))
|
||||
timeline.start()
|
||||
|
||||
aliceSession.startSync(true)
|
||||
aliceSession.syncService().startSync(true)
|
||||
run {
|
||||
val lock = CountDownLatch(1)
|
||||
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
|
||||
|
@ -338,6 +338,6 @@ class ThreadMessagingTest : InstrumentedTest {
|
|||
timeline.addListener(eventsListener)
|
||||
commonTestHelper.await(lock, 600_000)
|
||||
}
|
||||
aliceSession.stopSync()
|
||||
aliceSession.syncService().stopSync()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ class PollAggregationTest : InstrumentedTest {
|
|||
// Bob creates a poll
|
||||
roomFromBobPOV.sendService().sendPoll(PollType.DISCLOSED, pollQuestion, pollOptions)
|
||||
|
||||
aliceSession.startSync(true)
|
||||
aliceSession.syncService().startSync(true)
|
||||
val aliceTimeline = roomFromAlicePOV.timelineService().createTimeline(null, TimelineSettings(30))
|
||||
aliceTimeline.start()
|
||||
|
||||
|
@ -133,7 +133,7 @@ class PollAggregationTest : InstrumentedTest {
|
|||
|
||||
aliceTimeline.removeAllListeners()
|
||||
|
||||
aliceSession.stopSync()
|
||||
aliceSession.syncService().stopSync()
|
||||
aliceTimeline.dispose()
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
|
|||
}
|
||||
|
||||
// Bob stop to sync
|
||||
bobSession.stopSync()
|
||||
bobSession.syncService().stopSync()
|
||||
|
||||
val firstMessage = "First messages from Alice"
|
||||
// Alice sends 30 messages
|
||||
|
@ -101,7 +101,7 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
|
|||
.eventId
|
||||
|
||||
// Bob start to sync
|
||||
bobSession.startSync(true)
|
||||
bobSession.syncService().startSync(true)
|
||||
|
||||
run {
|
||||
val lock = CountDownLatch(1)
|
||||
|
@ -125,7 +125,7 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
|
|||
}
|
||||
|
||||
// Bob stop to sync
|
||||
bobSession.stopSync()
|
||||
bobSession.syncService().stopSync()
|
||||
|
||||
val secondMessage = "Second messages from Alice"
|
||||
// Alice sends again 30 messages
|
||||
|
@ -136,7 +136,7 @@ class TimelinePreviousLastForwardTest : InstrumentedTest {
|
|||
)
|
||||
|
||||
// Bob start to sync
|
||||
bobSession.startSync(true)
|
||||
bobSession.syncService().startSync(true)
|
||||
|
||||
run {
|
||||
val lock = CountDownLatch(1)
|
||||
|
|
|
@ -71,7 +71,7 @@ class TimelineWithManyMembersTest : InstrumentedTest {
|
|||
val timelineForCurrentMember = roomForCurrentMember.timelineService().createTimeline(null, TimelineSettings(30))
|
||||
timelineForCurrentMember.start()
|
||||
|
||||
session.startSync(true)
|
||||
session.syncService().startSync(true)
|
||||
|
||||
run {
|
||||
val lock = CountDownLatch(1)
|
||||
|
@ -92,7 +92,7 @@ class TimelineWithManyMembersTest : InstrumentedTest {
|
|||
timelineForCurrentMember.addListener(eventsListener)
|
||||
commonTestHelper.await(lock, 600_000)
|
||||
}
|
||||
session.stopSync()
|
||||
session.syncService().stopSync()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
package org.matrix.android.sdk.api.session
|
||||
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.lifecycle.LiveData
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import okhttp3.OkHttpClient
|
||||
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
|
||||
import org.matrix.android.sdk.api.auth.data.SessionParams
|
||||
|
@ -37,7 +35,6 @@ import org.matrix.android.sdk.api.session.file.FileService
|
|||
import org.matrix.android.sdk.api.session.group.GroupService
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
||||
import org.matrix.android.sdk.api.session.identity.IdentityService
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
|
||||
import org.matrix.android.sdk.api.session.media.MediaService
|
||||
import org.matrix.android.sdk.api.session.openid.OpenIdService
|
||||
|
@ -55,8 +52,7 @@ import org.matrix.android.sdk.api.session.signout.SignOutService
|
|||
import org.matrix.android.sdk.api.session.space.SpaceService
|
||||
import org.matrix.android.sdk.api.session.statistics.StatisticsListener
|
||||
import org.matrix.android.sdk.api.session.sync.FilterService
|
||||
import org.matrix.android.sdk.api.session.sync.SyncState
|
||||
import org.matrix.android.sdk.api.session.sync.model.SyncResponse
|
||||
import org.matrix.android.sdk.api.session.sync.SyncService
|
||||
import org.matrix.android.sdk.api.session.terms.TermsService
|
||||
import org.matrix.android.sdk.api.session.thirdparty.ThirdPartyService
|
||||
import org.matrix.android.sdk.api.session.typing.TypingUsersTracker
|
||||
|
@ -98,59 +94,11 @@ interface Session {
|
|||
@MainThread
|
||||
fun open()
|
||||
|
||||
/**
|
||||
* Requires a one time background sync.
|
||||
*/
|
||||
fun requireBackgroundSync()
|
||||
|
||||
/**
|
||||
* Launches infinite self rescheduling background syncs via the WorkManager.
|
||||
*
|
||||
* While dozing, syncs will only occur during maintenance windows.
|
||||
* For reliability it's recommended to also start a long running foreground service
|
||||
* along with disabling battery optimizations.
|
||||
*/
|
||||
fun startAutomaticBackgroundSync(timeOutInSeconds: Long, repeatDelayInSeconds: Long)
|
||||
|
||||
fun stopAnyBackgroundSync()
|
||||
|
||||
/**
|
||||
* This method start the sync thread.
|
||||
*/
|
||||
fun startSync(fromForeground: Boolean)
|
||||
|
||||
/**
|
||||
* This method stop the sync thread.
|
||||
*/
|
||||
fun stopSync()
|
||||
|
||||
/**
|
||||
* Clear cache of the session.
|
||||
*/
|
||||
suspend fun clearCache()
|
||||
|
||||
/**
|
||||
* This method allows to listen the sync state.
|
||||
* @return a [LiveData] of [SyncState].
|
||||
*/
|
||||
fun getSyncStateLive(): LiveData<SyncState>
|
||||
|
||||
/**
|
||||
* This method returns the current sync state.
|
||||
* @return the current [SyncState].
|
||||
*/
|
||||
fun getSyncState(): SyncState
|
||||
|
||||
/**
|
||||
* This method returns a flow of SyncResponse. New value will be pushed through the sync thread.
|
||||
*/
|
||||
fun syncFlow(): SharedFlow<SyncResponse>
|
||||
|
||||
/**
|
||||
* This methods return true if an initial sync has been processed.
|
||||
*/
|
||||
fun hasAlreadySynced(): Boolean
|
||||
|
||||
/**
|
||||
* This method allow to close a session. It does stop some services.
|
||||
*/
|
||||
|
@ -247,9 +195,9 @@ interface Session {
|
|||
fun termsService(): TermsService
|
||||
|
||||
/**
|
||||
* Returns the SyncStatusService associated with the session.
|
||||
* Returns the SyncService associated with the session.
|
||||
*/
|
||||
fun syncStatusService(): SyncStatusService
|
||||
fun syncService(): SyncService
|
||||
|
||||
/**
|
||||
* Returns the SecureStorageService associated with the session.
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.matrix.android.sdk.api.session.initsync
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
|
||||
interface SyncStatusService {
|
||||
|
||||
fun getSyncStatusLive(): LiveData<Status>
|
||||
|
||||
sealed class Status {
|
||||
/**
|
||||
* For initial sync.
|
||||
*/
|
||||
abstract class InitialSyncStatus : Status()
|
||||
|
||||
object Idle : InitialSyncStatus()
|
||||
data class InitialSyncProgressing(
|
||||
val initSyncStep: InitSyncStep,
|
||||
val percentProgress: Int = 0
|
||||
) : InitialSyncStatus()
|
||||
|
||||
/**
|
||||
* For incremental sync.
|
||||
*/
|
||||
abstract class IncrementalSyncStatus : Status()
|
||||
|
||||
object IncrementalSyncIdle : IncrementalSyncStatus()
|
||||
data class IncrementalSyncParsing(
|
||||
val rooms: Int,
|
||||
val toDevice: Int
|
||||
) : IncrementalSyncStatus()
|
||||
|
||||
object IncrementalSyncError : IncrementalSyncStatus()
|
||||
object IncrementalSyncDone : IncrementalSyncStatus()
|
||||
}
|
||||
}
|
|
@ -14,9 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.api.session.initsync
|
||||
package org.matrix.android.sdk.api.session.sync
|
||||
|
||||
enum class InitSyncStep {
|
||||
enum class InitialSyncStep {
|
||||
ServerComputing,
|
||||
Downloading,
|
||||
ImportingAccount,
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.api.session.sync
|
||||
|
||||
sealed interface SyncRequestState {
|
||||
/**
|
||||
* For initial sync.
|
||||
*/
|
||||
interface InitialSyncRequestState : SyncRequestState
|
||||
|
||||
object Idle : InitialSyncRequestState
|
||||
data class InitialSyncProgressing(
|
||||
val initialSyncStep: InitialSyncStep,
|
||||
val percentProgress: Int = 0
|
||||
) : InitialSyncRequestState
|
||||
|
||||
/**
|
||||
* For incremental sync.
|
||||
*/
|
||||
interface IncrementalSyncRequestState : SyncRequestState
|
||||
|
||||
object IncrementalSyncIdle : IncrementalSyncRequestState
|
||||
data class IncrementalSyncParsing(
|
||||
val rooms: Int,
|
||||
val toDevice: Int
|
||||
) : IncrementalSyncRequestState
|
||||
|
||||
object IncrementalSyncError : IncrementalSyncRequestState
|
||||
object IncrementalSyncDone : IncrementalSyncRequestState
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.api.session.sync
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import org.matrix.android.sdk.api.session.sync.model.SyncResponse
|
||||
|
||||
interface SyncService {
|
||||
/**
|
||||
* This method start the sync thread.
|
||||
*/
|
||||
fun startSync(fromForeground: Boolean)
|
||||
|
||||
/**
|
||||
* This method stop the sync thread.
|
||||
*/
|
||||
fun stopSync()
|
||||
|
||||
/**
|
||||
* Requires a one time background sync.
|
||||
*/
|
||||
fun requireBackgroundSync()
|
||||
|
||||
/**
|
||||
* Launches infinite self rescheduling background syncs via the WorkManager.
|
||||
*
|
||||
* While dozing, syncs will only occur during maintenance windows.
|
||||
* For reliability it's recommended to also start a long running foreground service
|
||||
* along with disabling battery optimizations.
|
||||
*/
|
||||
fun startAutomaticBackgroundSync(timeOutInSeconds: Long, repeatDelayInSeconds: Long)
|
||||
|
||||
fun stopAnyBackgroundSync()
|
||||
|
||||
/**
|
||||
* This method returns the current sync state.
|
||||
* @return the current [SyncState].
|
||||
*/
|
||||
fun getSyncState(): SyncState
|
||||
|
||||
/**
|
||||
* This method allows to listen the sync state.
|
||||
* @return a [LiveData] of [SyncState].
|
||||
*/
|
||||
fun getSyncStateLive(): LiveData<SyncState>
|
||||
|
||||
/**
|
||||
* Get the [SyncRequestState] as a LiveData.
|
||||
*/
|
||||
fun getSyncRequestStateLive(): LiveData<SyncRequestState>
|
||||
|
||||
/**
|
||||
* This method returns a flow of SyncResponse. New value will be pushed through the sync thread.
|
||||
*/
|
||||
fun syncFlow(): SharedFlow<SyncResponse>
|
||||
|
||||
/**
|
||||
* This methods return true if an initial sync has been processed.
|
||||
*/
|
||||
fun hasAlreadySynced(): Boolean
|
||||
}
|
|
@ -46,7 +46,7 @@ import java.util.concurrent.atomic.AtomicBoolean
|
|||
* in order to be able to perform a sync even if the app is not running.
|
||||
* The <receiver> and <service> must be declared in the Manifest or the app using the SDK
|
||||
*/
|
||||
abstract class SyncService : Service() {
|
||||
abstract class SyncAndroidService : Service() {
|
||||
|
||||
private var sessionId: String? = null
|
||||
private var mIsSelfDestroyed: Boolean = false
|
||||
|
@ -158,9 +158,9 @@ abstract class SyncService : Service() {
|
|||
// never do that in foreground, let the syncThread work
|
||||
syncTask.execute(params)
|
||||
// Start sync if we were doing an initial sync and the syncThread is not launched yet
|
||||
if (isInitialSync && session.getSyncState() == SyncState.Idle) {
|
||||
if (isInitialSync && session.syncService().getSyncState() == SyncState.Idle) {
|
||||
val isForeground = !backgroundDetectionObserver.isInBackground
|
||||
session.startSync(isForeground)
|
||||
session.syncService().startSync(isForeground)
|
||||
}
|
||||
stopMe()
|
||||
} catch (throwable: Throwable) {
|
||||
|
@ -210,7 +210,7 @@ abstract class SyncService : Service() {
|
|||
session = sessionComponent.session()
|
||||
sessionId = safeSessionId
|
||||
syncTask = sessionComponent.syncTask()
|
||||
isInitialSync = !session.hasAlreadySynced()
|
||||
isInitialSync = !session.syncService().hasAlreadySynced()
|
||||
networkConnectivityChecker = sessionComponent.networkConnectivityChecker()
|
||||
taskExecutor = sessionComponent.taskExecutor()
|
||||
coroutineDispatchers = sessionComponent.coroutineDispatchers()
|
|
@ -55,7 +55,7 @@ internal class SessionManager @Inject constructor(
|
|||
|
||||
fun stopSession(sessionId: String) {
|
||||
val sessionComponent = sessionComponents[sessionId] ?: throw RuntimeException("You don't have a session for id $sessionId")
|
||||
sessionComponent.session().stopSync()
|
||||
sessionComponent.session().syncService().stopSync()
|
||||
}
|
||||
|
||||
fun getOrCreateSessionComponent(sessionParams: SessionParams): SessionComponent {
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.matrix.android.sdk.api.session.file.FileService
|
|||
import org.matrix.android.sdk.api.session.group.GroupService
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
||||
import org.matrix.android.sdk.api.session.identity.IdentityService
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
|
||||
import org.matrix.android.sdk.api.session.media.MediaService
|
||||
import org.matrix.android.sdk.api.session.openid.OpenIdService
|
||||
|
@ -61,6 +60,7 @@ import org.matrix.android.sdk.api.session.securestorage.SharedSecretStorageServi
|
|||
import org.matrix.android.sdk.api.session.signout.SignOutService
|
||||
import org.matrix.android.sdk.api.session.space.SpaceService
|
||||
import org.matrix.android.sdk.api.session.sync.FilterService
|
||||
import org.matrix.android.sdk.api.session.sync.SyncService
|
||||
import org.matrix.android.sdk.api.session.terms.TermsService
|
||||
import org.matrix.android.sdk.api.session.thirdparty.ThirdPartyService
|
||||
import org.matrix.android.sdk.api.session.typing.TypingUsersTracker
|
||||
|
@ -76,13 +76,8 @@ import org.matrix.android.sdk.internal.di.SessionId
|
|||
import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate
|
||||
import org.matrix.android.sdk.internal.di.WorkManagerProvider
|
||||
import org.matrix.android.sdk.internal.network.GlobalErrorHandler
|
||||
import org.matrix.android.sdk.internal.session.sync.SyncTokenStore
|
||||
import org.matrix.android.sdk.internal.session.sync.job.SyncThread
|
||||
import org.matrix.android.sdk.internal.session.sync.job.SyncWorker
|
||||
import org.matrix.android.sdk.internal.util.createUIHandler
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
|
||||
@SessionScope
|
||||
internal class DefaultSession @Inject constructor(
|
||||
|
@ -112,16 +107,14 @@ internal class DefaultSession @Inject constructor(
|
|||
private val permalinkService: Lazy<PermalinkService>,
|
||||
private val secureStorageService: Lazy<SecureStorageService>,
|
||||
private val profileService: Lazy<ProfileService>,
|
||||
private val syncService: Lazy<SyncService>,
|
||||
private val mediaService: Lazy<MediaService>,
|
||||
private val widgetService: Lazy<WidgetService>,
|
||||
private val syncThreadProvider: Provider<SyncThread>,
|
||||
private val contentUrlResolver: ContentUrlResolver,
|
||||
private val syncTokenStore: SyncTokenStore,
|
||||
private val sessionParamsStore: SessionParamsStore,
|
||||
private val contentUploadProgressTracker: ContentUploadStateTracker,
|
||||
private val typingUsersTracker: TypingUsersTracker,
|
||||
private val contentDownloadStateTracker: ContentDownloadStateTracker,
|
||||
private val syncStatusService: Lazy<SyncStatusService>,
|
||||
private val homeServerCapabilitiesService: Lazy<HomeServerCapabilitiesService>,
|
||||
private val accountDataService: Lazy<SessionAccountDataService>,
|
||||
private val sharedSecretStorageService: Lazy<SharedSecretStorageService>,
|
||||
|
@ -138,14 +131,11 @@ internal class DefaultSession @Inject constructor(
|
|||
private val toDeviceService: Lazy<ToDeviceService>,
|
||||
private val eventStreamService: Lazy<EventStreamService>,
|
||||
@UnauthenticatedWithCertificate
|
||||
private val unauthenticatedWithCertificateOkHttpClient: Lazy<OkHttpClient>
|
||||
private val unauthenticatedWithCertificateOkHttpClient: Lazy<OkHttpClient>,
|
||||
private val sessionState: SessionState,
|
||||
) : Session,
|
||||
GlobalErrorHandler.Listener {
|
||||
|
||||
private var isOpen = false
|
||||
|
||||
private var syncThread: SyncThread? = null
|
||||
|
||||
private val uiHandler = createUIHandler()
|
||||
|
||||
override val isOpenable: Boolean
|
||||
|
@ -153,8 +143,7 @@ internal class DefaultSession @Inject constructor(
|
|||
|
||||
@MainThread
|
||||
override fun open() {
|
||||
assert(!isOpen)
|
||||
isOpen = true
|
||||
sessionState.setIsOpen(true)
|
||||
globalErrorHandler.listener = this
|
||||
cryptoService.get().ensureDevice()
|
||||
uiHandler.post {
|
||||
|
@ -167,40 +156,9 @@ internal class DefaultSession @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun requireBackgroundSync() {
|
||||
SyncWorker.requireBackgroundSync(workManagerProvider, sessionId)
|
||||
}
|
||||
|
||||
override fun startAutomaticBackgroundSync(timeOutInSeconds: Long, repeatDelayInSeconds: Long) {
|
||||
SyncWorker.automaticallyBackgroundSync(workManagerProvider, sessionId, timeOutInSeconds, repeatDelayInSeconds)
|
||||
}
|
||||
|
||||
override fun stopAnyBackgroundSync() {
|
||||
SyncWorker.stopAnyBackgroundSync(workManagerProvider)
|
||||
}
|
||||
|
||||
override fun startSync(fromForeground: Boolean) {
|
||||
Timber.i("Starting sync thread")
|
||||
assert(isOpen)
|
||||
val localSyncThread = getSyncThread()
|
||||
localSyncThread.setInitialForeground(fromForeground)
|
||||
if (!localSyncThread.isAlive) {
|
||||
localSyncThread.start()
|
||||
} else {
|
||||
localSyncThread.restart()
|
||||
Timber.w("Attempt to start an already started thread")
|
||||
}
|
||||
}
|
||||
|
||||
override fun stopSync() {
|
||||
assert(isOpen)
|
||||
syncThread?.kill()
|
||||
syncThread = null
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
assert(isOpen)
|
||||
stopSync()
|
||||
assert(sessionState.isOpen)
|
||||
syncService.get().stopSync()
|
||||
// timelineEventDecryptor.destroy()
|
||||
uiHandler.post {
|
||||
lifecycleObservers.forEach { it.onSessionStopped(this) }
|
||||
|
@ -210,28 +168,12 @@ internal class DefaultSession @Inject constructor(
|
|||
}
|
||||
cryptoService.get().close()
|
||||
globalErrorHandler.listener = null
|
||||
isOpen = false
|
||||
}
|
||||
|
||||
override fun getSyncStateLive() = getSyncThread().liveState()
|
||||
|
||||
override fun syncFlow() = getSyncThread().syncFlow()
|
||||
|
||||
override fun getSyncState() = getSyncThread().currentState()
|
||||
|
||||
override fun hasAlreadySynced(): Boolean {
|
||||
return syncTokenStore.getLastToken() != null
|
||||
}
|
||||
|
||||
private fun getSyncThread(): SyncThread {
|
||||
return syncThread ?: syncThreadProvider.get().also {
|
||||
syncThread = it
|
||||
}
|
||||
sessionState.setIsOpen(false)
|
||||
}
|
||||
|
||||
override suspend fun clearCache() {
|
||||
stopSync()
|
||||
stopAnyBackgroundSync()
|
||||
syncService.get().stopSync()
|
||||
syncService.get().stopAnyBackgroundSync()
|
||||
uiHandler.post {
|
||||
lifecycleObservers.forEach {
|
||||
it.onClearCache(this)
|
||||
|
@ -271,7 +213,7 @@ internal class DefaultSession @Inject constructor(
|
|||
override fun pushersService(): PushersService = pushersService.get()
|
||||
override fun eventService(): EventService = eventService.get()
|
||||
override fun termsService(): TermsService = termsService.get()
|
||||
override fun syncStatusService(): SyncStatusService = syncStatusService.get()
|
||||
override fun syncService(): SyncService = syncService.get()
|
||||
override fun secureStorageService(): SecureStorageService = secureStorageService.get()
|
||||
override fun profileService(): ProfileService = profileService.get()
|
||||
override fun presenceService(): PresenceService = presenceService.get()
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.matrix.android.sdk.api.session.ToDeviceService
|
|||
import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
|
||||
import org.matrix.android.sdk.api.session.events.EventService
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.openid.OpenIdService
|
||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
||||
import org.matrix.android.sdk.api.session.securestorage.SecureStorageService
|
||||
|
@ -82,7 +81,6 @@ import org.matrix.android.sdk.internal.session.download.DownloadProgressIntercep
|
|||
import org.matrix.android.sdk.internal.session.events.DefaultEventService
|
||||
import org.matrix.android.sdk.internal.session.homeserver.DefaultHomeServerCapabilitiesService
|
||||
import org.matrix.android.sdk.internal.session.identity.DefaultIdentityService
|
||||
import org.matrix.android.sdk.internal.session.initsync.DefaultSyncStatusService
|
||||
import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManager
|
||||
import org.matrix.android.sdk.internal.session.openid.DefaultOpenIdService
|
||||
import org.matrix.android.sdk.internal.session.permalinks.DefaultPermalinkService
|
||||
|
@ -362,9 +360,6 @@ internal abstract class SessionModule {
|
|||
@IntoSet
|
||||
abstract fun bindEventSenderProcessorAsSessionLifecycleObserver(processor: EventSenderProcessorCoroutine): SessionLifecycleObserver
|
||||
|
||||
@Binds
|
||||
abstract fun bindSyncStatusService(service: DefaultSyncStatusService): SyncStatusService
|
||||
|
||||
@Binds
|
||||
abstract fun bindSecureStorageService(service: DefaultSecureStorageService): SecureStorageService
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
@SessionScope
|
||||
internal class SessionState @Inject constructor() {
|
||||
var isOpen = false
|
||||
private set
|
||||
|
||||
/**
|
||||
* Set the new state. Throw if already in the new state.
|
||||
*/
|
||||
fun setIsOpen(newState: Boolean) {
|
||||
assert(newState != isOpen)
|
||||
isOpen = newState
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.sync
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.api.session.sync.SyncService
|
||||
import org.matrix.android.sdk.internal.di.SessionId
|
||||
import org.matrix.android.sdk.internal.di.WorkManagerProvider
|
||||
import org.matrix.android.sdk.internal.session.SessionState
|
||||
import org.matrix.android.sdk.internal.session.sync.job.SyncThread
|
||||
import org.matrix.android.sdk.internal.session.sync.job.SyncWorker
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
|
||||
internal class DefaultSyncService @Inject constructor(
|
||||
@SessionId val sessionId: String,
|
||||
private val workManagerProvider: WorkManagerProvider,
|
||||
private val syncThreadProvider: Provider<SyncThread>,
|
||||
private val syncTokenStore: SyncTokenStore,
|
||||
private val syncRequestStateTracker: SyncRequestStateTracker,
|
||||
private val sessionState: SessionState,
|
||||
) : SyncService {
|
||||
private var syncThread: SyncThread? = null
|
||||
|
||||
override fun requireBackgroundSync() {
|
||||
SyncWorker.requireBackgroundSync(workManagerProvider, sessionId)
|
||||
}
|
||||
|
||||
override fun startAutomaticBackgroundSync(timeOutInSeconds: Long, repeatDelayInSeconds: Long) {
|
||||
SyncWorker.automaticallyBackgroundSync(workManagerProvider, sessionId, timeOutInSeconds, repeatDelayInSeconds)
|
||||
}
|
||||
|
||||
override fun stopAnyBackgroundSync() {
|
||||
SyncWorker.stopAnyBackgroundSync(workManagerProvider)
|
||||
}
|
||||
|
||||
override fun startSync(fromForeground: Boolean) {
|
||||
Timber.i("Starting sync thread")
|
||||
assert(sessionState.isOpen)
|
||||
val localSyncThread = getSyncThread()
|
||||
localSyncThread.setInitialForeground(fromForeground)
|
||||
if (!localSyncThread.isAlive) {
|
||||
localSyncThread.start()
|
||||
} else {
|
||||
localSyncThread.restart()
|
||||
Timber.w("Attempt to start an already started thread")
|
||||
}
|
||||
}
|
||||
|
||||
override fun stopSync() {
|
||||
assert(sessionState.isOpen)
|
||||
syncThread?.kill()
|
||||
syncThread = null
|
||||
}
|
||||
|
||||
override fun getSyncStateLive() = getSyncThread().liveState()
|
||||
|
||||
override fun syncFlow() = getSyncThread().syncFlow()
|
||||
|
||||
override fun getSyncState() = getSyncThread().currentState()
|
||||
|
||||
override fun getSyncRequestStateLive(): LiveData<SyncRequestState> {
|
||||
return syncRequestStateTracker.syncRequestState
|
||||
}
|
||||
|
||||
override fun hasAlreadySynced(): Boolean {
|
||||
return syncTokenStore.getLastToken() != null
|
||||
}
|
||||
|
||||
private fun getSyncThread(): SyncThread {
|
||||
return syncThread ?: syncThreadProvider.get().also {
|
||||
syncThread = it
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,18 +14,18 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.initsync
|
||||
package org.matrix.android.sdk.internal.session.sync
|
||||
|
||||
import org.matrix.android.sdk.api.session.initsync.InitSyncStep
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStep
|
||||
|
||||
internal inline fun <T> reportSubtask(
|
||||
reporter: ProgressReporter?,
|
||||
initSyncStep: InitSyncStep,
|
||||
initialSyncStep: InitialSyncStep,
|
||||
totalProgress: Int,
|
||||
parentWeight: Float,
|
||||
block: () -> T
|
||||
): T {
|
||||
reporter?.startTask(initSyncStep, totalProgress, parentWeight)
|
||||
reporter?.startTask(initialSyncStep, totalProgress, parentWeight)
|
||||
return block().also {
|
||||
reporter?.endTask()
|
||||
}
|
||||
|
@ -33,12 +33,12 @@ internal inline fun <T> reportSubtask(
|
|||
|
||||
internal inline fun <K, V, R> Map<out K, V>.mapWithProgress(
|
||||
reporter: ProgressReporter?,
|
||||
initSyncStep: InitSyncStep,
|
||||
initialSyncStep: InitialSyncStep,
|
||||
parentWeight: Float,
|
||||
transform: (Map.Entry<K, V>) -> R
|
||||
): List<R> {
|
||||
var current = 0F
|
||||
reporter?.startTask(initSyncStep, count() + 1, parentWeight)
|
||||
reporter?.startTask(initialSyncStep, count() + 1, parentWeight)
|
||||
return map {
|
||||
reporter?.reportProgress(current)
|
||||
current++
|
|
@ -14,13 +14,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.initsync
|
||||
package org.matrix.android.sdk.internal.session.sync
|
||||
|
||||
import org.matrix.android.sdk.api.session.initsync.InitSyncStep
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStep
|
||||
|
||||
internal interface ProgressReporter {
|
||||
fun startTask(
|
||||
initSyncStep: InitSyncStep,
|
||||
initialSyncStep: InitialSyncStep,
|
||||
totalProgress: Int,
|
||||
parentWeight: Float
|
||||
)
|
|
@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.session.sync
|
|||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import org.matrix.android.sdk.api.session.sync.SyncService
|
||||
import org.matrix.android.sdk.internal.session.SessionScope
|
||||
import retrofit2.Retrofit
|
||||
|
||||
|
@ -35,6 +36,9 @@ internal abstract class SyncModule {
|
|||
}
|
||||
}
|
||||
|
||||
@Binds
|
||||
abstract fun bindSyncService(service: DefaultSyncService): SyncService
|
||||
|
||||
@Binds
|
||||
abstract fun bindSyncTask(task: DefaultSyncTask): SyncTask
|
||||
|
||||
|
|
|
@ -13,42 +13,37 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.matrix.android.sdk.internal.session.initsync
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
package org.matrix.android.sdk.internal.session.sync
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import org.matrix.android.sdk.api.session.initsync.InitSyncStep
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStep
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.internal.session.SessionScope
|
||||
import javax.inject.Inject
|
||||
|
||||
@SessionScope
|
||||
internal class DefaultSyncStatusService @Inject constructor() :
|
||||
SyncStatusService,
|
||||
internal class SyncRequestStateTracker @Inject constructor() :
|
||||
ProgressReporter {
|
||||
|
||||
private val status = MutableLiveData<SyncStatusService.Status>()
|
||||
val syncRequestState = MutableLiveData<SyncRequestState>()
|
||||
|
||||
private var rootTask: TaskInfo? = null
|
||||
|
||||
override fun getSyncStatusLive(): LiveData<SyncStatusService.Status> {
|
||||
return status
|
||||
}
|
||||
|
||||
// Only to be used for incremental sync
|
||||
fun setStatus(newStatus: SyncStatusService.Status.IncrementalSyncStatus) {
|
||||
status.postValue(newStatus)
|
||||
fun setSyncRequestState(newSyncRequestState: SyncRequestState.IncrementalSyncRequestState) {
|
||||
syncRequestState.postValue(newSyncRequestState)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a rootTask.
|
||||
*/
|
||||
fun startRoot(
|
||||
initSyncStep: InitSyncStep,
|
||||
initialSyncStep: InitialSyncStep,
|
||||
totalProgress: Int
|
||||
) {
|
||||
endAll()
|
||||
rootTask = TaskInfo(initSyncStep, totalProgress, null, 1F)
|
||||
rootTask = TaskInfo(initialSyncStep, totalProgress, null, 1F)
|
||||
reportProgress(0F)
|
||||
}
|
||||
|
||||
|
@ -56,13 +51,13 @@ internal class DefaultSyncStatusService @Inject constructor() :
|
|||
* Add a child to the leaf.
|
||||
*/
|
||||
override fun startTask(
|
||||
initSyncStep: InitSyncStep,
|
||||
initialSyncStep: InitialSyncStep,
|
||||
totalProgress: Int,
|
||||
parentWeight: Float
|
||||
) {
|
||||
val currentLeaf = rootTask?.leaf() ?: return
|
||||
currentLeaf.child = TaskInfo(
|
||||
initSyncStep = initSyncStep,
|
||||
initialSyncStep = initialSyncStep,
|
||||
totalProgress = totalProgress,
|
||||
parent = currentLeaf,
|
||||
parentWeight = parentWeight
|
||||
|
@ -76,7 +71,7 @@ internal class DefaultSyncStatusService @Inject constructor() :
|
|||
// Update the progress of the leaf and all its parents
|
||||
leaf.setProgress(progress)
|
||||
// Then update the live data using leaf wording and root progress
|
||||
status.postValue(SyncStatusService.Status.InitialSyncProgressing(leaf.initSyncStep, root.currentProgress.toInt()))
|
||||
syncRequestState.postValue(SyncRequestState.InitialSyncProgressing(leaf.initialSyncStep, root.currentProgress.toInt()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,13 +86,13 @@ internal class DefaultSyncStatusService @Inject constructor() :
|
|||
// And close it
|
||||
endedTask.parent.child = null
|
||||
} else {
|
||||
status.postValue(SyncStatusService.Status.Idle)
|
||||
syncRequestState.postValue(SyncRequestState.Idle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun endAll() {
|
||||
rootTask = null
|
||||
status.postValue(SyncStatusService.Status.Idle)
|
||||
syncRequestState.postValue(SyncRequestState.Idle)
|
||||
}
|
||||
}
|
|
@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.sync
|
|||
|
||||
import androidx.work.ExistingPeriodicWorkPolicy
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import org.matrix.android.sdk.api.session.initsync.InitSyncStep
|
||||
import org.matrix.android.sdk.api.session.pushrules.PushRuleService
|
||||
import org.matrix.android.sdk.api.session.pushrules.RuleScope
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStep
|
||||
import org.matrix.android.sdk.api.session.sync.model.GroupsSyncResponse
|
||||
import org.matrix.android.sdk.api.session.sync.model.RoomsSyncResponse
|
||||
import org.matrix.android.sdk.api.session.sync.model.SyncResponse
|
||||
|
@ -32,8 +32,6 @@ import org.matrix.android.sdk.internal.di.WorkManagerProvider
|
|||
import org.matrix.android.sdk.internal.session.SessionListeners
|
||||
import org.matrix.android.sdk.internal.session.dispatchTo
|
||||
import org.matrix.android.sdk.internal.session.group.GetGroupDataWorker
|
||||
import org.matrix.android.sdk.internal.session.initsync.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.initsync.reportSubtask
|
||||
import org.matrix.android.sdk.internal.session.pushrules.ProcessEventForPushTask
|
||||
import org.matrix.android.sdk.internal.session.sync.handler.CryptoSyncHandler
|
||||
import org.matrix.android.sdk.internal.session.sync.handler.GroupSyncHandler
|
||||
|
@ -90,7 +88,7 @@ internal class SyncResponseHandler @Inject constructor(
|
|||
// to ensure to decrypt them properly
|
||||
measureTimeMillis {
|
||||
Timber.v("Handle toDevice")
|
||||
reportSubtask(reporter, InitSyncStep.ImportingAccountCrypto, 100, 0.1f) {
|
||||
reportSubtask(reporter, InitialSyncStep.ImportingAccountCrypto, 100, 0.1f) {
|
||||
if (syncResponse.toDevice != null) {
|
||||
cryptoSyncHandler.handleToDevice(syncResponse.toDevice, reporter)
|
||||
}
|
||||
|
@ -111,7 +109,7 @@ internal class SyncResponseHandler @Inject constructor(
|
|||
// IMPORTANT nothing should be suspend here as we are accessing the realm instance (thread local)
|
||||
measureTimeMillis {
|
||||
Timber.v("Handle rooms")
|
||||
reportSubtask(reporter, InitSyncStep.ImportingAccountRoom, 1, 0.7f) {
|
||||
reportSubtask(reporter, InitialSyncStep.ImportingAccountRoom, 1, 0.7f) {
|
||||
if (syncResponse.rooms != null) {
|
||||
roomSyncHandler.handle(realm, syncResponse.rooms, isInitialSync, aggregator, reporter)
|
||||
}
|
||||
|
@ -121,7 +119,7 @@ internal class SyncResponseHandler @Inject constructor(
|
|||
}
|
||||
|
||||
measureTimeMillis {
|
||||
reportSubtask(reporter, InitSyncStep.ImportingAccountGroups, 1, 0.1f) {
|
||||
reportSubtask(reporter, InitialSyncStep.ImportingAccountGroups, 1, 0.1f) {
|
||||
Timber.v("Handle groups")
|
||||
if (syncResponse.groups != null) {
|
||||
groupSyncHandler.handle(realm, syncResponse.groups, reporter)
|
||||
|
@ -132,7 +130,7 @@ internal class SyncResponseHandler @Inject constructor(
|
|||
}
|
||||
|
||||
measureTimeMillis {
|
||||
reportSubtask(reporter, InitSyncStep.ImportingAccountData, 1, 0.1f) {
|
||||
reportSubtask(reporter, InitialSyncStep.ImportingAccountData, 1, 0.1f) {
|
||||
Timber.v("Handle accountData")
|
||||
userAccountDataSyncHandler.handle(realm, syncResponse.accountData)
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ import okhttp3.ResponseBody
|
|||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.logger.LoggerTag
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.initsync.InitSyncStep
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.statistics.StatisticEvent
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStep
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStrategy
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.api.session.sync.initialSyncStrategy
|
||||
import org.matrix.android.sdk.api.session.sync.model.LazyRoomSyncEphemeral
|
||||
import org.matrix.android.sdk.api.session.sync.model.SyncResponse
|
||||
|
@ -38,8 +38,6 @@ import org.matrix.android.sdk.internal.session.SessionListeners
|
|||
import org.matrix.android.sdk.internal.session.dispatchTo
|
||||
import org.matrix.android.sdk.internal.session.filter.FilterRepository
|
||||
import org.matrix.android.sdk.internal.session.homeserver.GetHomeServerCapabilitiesTask
|
||||
import org.matrix.android.sdk.internal.session.initsync.DefaultSyncStatusService
|
||||
import org.matrix.android.sdk.internal.session.initsync.reportSubtask
|
||||
import org.matrix.android.sdk.internal.session.sync.parsing.InitialSyncResponseParser
|
||||
import org.matrix.android.sdk.internal.session.user.UserStore
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
|
@ -68,7 +66,7 @@ internal class DefaultSyncTask @Inject constructor(
|
|||
@UserId private val userId: String,
|
||||
private val filterRepository: FilterRepository,
|
||||
private val syncResponseHandler: SyncResponseHandler,
|
||||
private val defaultSyncStatusService: DefaultSyncStatusService,
|
||||
private val syncRequestStateTracker: SyncRequestStateTracker,
|
||||
private val syncTokenStore: SyncTokenStore,
|
||||
private val getHomeServerCapabilitiesTask: GetHomeServerCapabilitiesTask,
|
||||
private val userStore: UserStore,
|
||||
|
@ -115,7 +113,7 @@ internal class DefaultSyncTask @Inject constructor(
|
|||
displayName = user?.displayName,
|
||||
avatarUrl = user?.avatarUrl
|
||||
)
|
||||
defaultSyncStatusService.startRoot(InitSyncStep.ImportingAccount, 100)
|
||||
syncRequestStateTracker.startRoot(InitialSyncStep.ImportingAccount, 100)
|
||||
}
|
||||
// Maybe refresh the homeserver capabilities data we know
|
||||
getHomeServerCapabilitiesTask.execute(GetHomeServerCapabilitiesTask.Params(forceRefresh = false))
|
||||
|
@ -132,7 +130,7 @@ internal class DefaultSyncTask @Inject constructor(
|
|||
roomSyncEphemeralTemporaryStore.reset()
|
||||
workingDir.mkdirs()
|
||||
val file = downloadInitSyncResponse(requestParams, syncStatisticsData)
|
||||
syncResponseToReturn = reportSubtask(defaultSyncStatusService, InitSyncStep.ImportingAccount, 1, 0.7F) {
|
||||
syncResponseToReturn = reportSubtask(syncRequestStateTracker, InitialSyncStep.ImportingAccount, 1, 0.7F) {
|
||||
handleSyncFile(file, initSyncStrategy)
|
||||
}
|
||||
// Delete all files
|
||||
|
@ -150,15 +148,15 @@ internal class DefaultSyncTask @Inject constructor(
|
|||
syncStatisticsData.requestInitSyncTime = SystemClock.elapsedRealtime()
|
||||
syncStatisticsData.downloadInitSyncTime = syncStatisticsData.requestInitSyncTime
|
||||
logDuration("INIT_SYNC Database insertion", loggerTag, clock) {
|
||||
syncResponseHandler.handleResponse(syncResponse, token, defaultSyncStatusService)
|
||||
syncResponseHandler.handleResponse(syncResponse, token, syncRequestStateTracker)
|
||||
}
|
||||
syncResponseToReturn = syncResponse
|
||||
}
|
||||
}
|
||||
defaultSyncStatusService.endAll()
|
||||
syncRequestStateTracker.endAll()
|
||||
} else {
|
||||
Timber.tag(loggerTag.value).d("Start incremental sync request with since token $token")
|
||||
defaultSyncStatusService.setStatus(SyncStatusService.Status.IncrementalSyncIdle)
|
||||
syncRequestStateTracker.setSyncRequestState(SyncRequestState.IncrementalSyncIdle)
|
||||
val syncResponse = try {
|
||||
executeRequest(globalErrorReceiver) {
|
||||
syncAPI.sync(
|
||||
|
@ -168,7 +166,7 @@ internal class DefaultSyncTask @Inject constructor(
|
|||
}
|
||||
} catch (throwable: Throwable) {
|
||||
Timber.tag(loggerTag.value).e(throwable, "Incremental sync request error")
|
||||
defaultSyncStatusService.setStatus(SyncStatusService.Status.IncrementalSyncError)
|
||||
syncRequestStateTracker.setSyncRequestState(SyncRequestState.IncrementalSyncError)
|
||||
throw throwable
|
||||
}
|
||||
val nbRooms = syncResponse.rooms?.invite.orEmpty().size + syncResponse.rooms?.join.orEmpty().size + syncResponse.rooms?.leave.orEmpty().size
|
||||
|
@ -177,8 +175,8 @@ internal class DefaultSyncTask @Inject constructor(
|
|||
Timber.tag(loggerTag.value).d(
|
||||
"Incremental sync request parsing, $nbRooms room(s) $nbToDevice toDevice(s). Got nextBatch: $nextBatch"
|
||||
)
|
||||
defaultSyncStatusService.setStatus(
|
||||
SyncStatusService.Status.IncrementalSyncParsing(
|
||||
syncRequestStateTracker.setSyncRequestState(
|
||||
SyncRequestState.IncrementalSyncParsing(
|
||||
rooms = nbRooms,
|
||||
toDevice = nbToDevice
|
||||
)
|
||||
|
@ -186,7 +184,7 @@ internal class DefaultSyncTask @Inject constructor(
|
|||
syncResponseHandler.handleResponse(syncResponse, token, null)
|
||||
syncResponseToReturn = syncResponse
|
||||
Timber.tag(loggerTag.value).d("Incremental sync done")
|
||||
defaultSyncStatusService.setStatus(SyncStatusService.Status.IncrementalSyncDone)
|
||||
syncRequestStateTracker.setSyncRequestState(SyncRequestState.IncrementalSyncDone)
|
||||
}
|
||||
syncStatisticsData.treatmentSyncTime = SystemClock.elapsedRealtime()
|
||||
syncStatisticsData.nbOfRooms = syncResponseToReturn?.rooms?.join?.size ?: 0
|
||||
|
@ -201,20 +199,20 @@ internal class DefaultSyncTask @Inject constructor(
|
|||
val status = initialSyncStatusRepository.getStep()
|
||||
if (workingFile.exists() && status >= InitialSyncStatus.STEP_DOWNLOADED) {
|
||||
Timber.tag(loggerTag.value).d("INIT_SYNC file is already here")
|
||||
reportSubtask(defaultSyncStatusService, InitSyncStep.Downloading, 1, 0.3f) {
|
||||
reportSubtask(syncRequestStateTracker, InitialSyncStep.Downloading, 1, 0.3f) {
|
||||
// Empty task
|
||||
}
|
||||
} else {
|
||||
initialSyncStatusRepository.setStep(InitialSyncStatus.STEP_DOWNLOADING)
|
||||
val syncResponse = logDuration("INIT_SYNC Perform server request", loggerTag, clock) {
|
||||
reportSubtask(defaultSyncStatusService, InitSyncStep.ServerComputing, 1, 0.2f) {
|
||||
reportSubtask(syncRequestStateTracker, InitialSyncStep.ServerComputing, 1, 0.2f) {
|
||||
getSyncResponse(requestParams, MAX_NUMBER_OF_RETRY_AFTER_TIMEOUT)
|
||||
}
|
||||
}
|
||||
syncStatisticsData.requestInitSyncTime = SystemClock.elapsedRealtime()
|
||||
if (syncResponse.isSuccessful) {
|
||||
logDuration("INIT_SYNC Download and save to file", loggerTag, clock) {
|
||||
reportSubtask(defaultSyncStatusService, InitSyncStep.Downloading, 1, 0.1f) {
|
||||
reportSubtask(syncRequestStateTracker, InitialSyncStep.Downloading, 1, 0.1f) {
|
||||
syncResponse.body()?.byteStream()?.use { inputStream ->
|
||||
workingFile.outputStream().use { outputStream ->
|
||||
inputStream.copyTo(outputStream)
|
||||
|
@ -263,7 +261,7 @@ internal class DefaultSyncTask @Inject constructor(
|
|||
Timber.tag(loggerTag.value).d("INIT_SYNC $nbOfJoinedRooms rooms, $nbOfJoinedRoomsInFile ephemeral stored into files")
|
||||
|
||||
logDuration("INIT_SYNC Database insertion", loggerTag, clock) {
|
||||
syncResponseHandler.handleResponse(syncResponse, null, defaultSyncStatusService)
|
||||
syncResponseHandler.handleResponse(syncResponse, null, syncRequestStateTracker)
|
||||
}
|
||||
initialSyncStatusRepository.setStep(InitialSyncStatus.STEP_SUCCESS)
|
||||
syncResponse
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.initsync
|
||||
package org.matrix.android.sdk.internal.session.sync
|
||||
|
||||
import org.matrix.android.sdk.api.session.initsync.InitSyncStep
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStep
|
||||
import timber.log.Timber
|
||||
|
||||
internal class TaskInfo(
|
||||
val initSyncStep: InitSyncStep,
|
||||
val initialSyncStep: InitialSyncStep,
|
||||
val totalProgress: Int,
|
||||
val parent: TaskInfo?,
|
||||
val parentWeight: Float
|
|
@ -29,7 +29,7 @@ import org.matrix.android.sdk.api.session.sync.model.SyncResponse
|
|||
import org.matrix.android.sdk.api.session.sync.model.ToDeviceSyncResponse
|
||||
import org.matrix.android.sdk.internal.crypto.DefaultCryptoService
|
||||
import org.matrix.android.sdk.internal.crypto.verification.DefaultVerificationService
|
||||
import org.matrix.android.sdk.internal.session.initsync.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.sync.ProgressReporter
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
|
@ -17,16 +17,16 @@
|
|||
package org.matrix.android.sdk.internal.session.sync.handler
|
||||
|
||||
import io.realm.Realm
|
||||
import org.matrix.android.sdk.api.session.initsync.InitSyncStep
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStep
|
||||
import org.matrix.android.sdk.api.session.sync.model.GroupsSyncResponse
|
||||
import org.matrix.android.sdk.api.session.sync.model.InvitedGroupSync
|
||||
import org.matrix.android.sdk.internal.database.model.GroupEntity
|
||||
import org.matrix.android.sdk.internal.database.model.GroupSummaryEntity
|
||||
import org.matrix.android.sdk.internal.database.query.getOrCreate
|
||||
import org.matrix.android.sdk.internal.database.query.where
|
||||
import org.matrix.android.sdk.internal.session.initsync.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.initsync.mapWithProgress
|
||||
import org.matrix.android.sdk.internal.session.sync.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.sync.mapWithProgress
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class GroupSyncHandler @Inject constructor() {
|
||||
|
@ -52,17 +52,17 @@ internal class GroupSyncHandler @Inject constructor() {
|
|||
private fun handleGroupSync(realm: Realm, handlingStrategy: HandlingStrategy, reporter: ProgressReporter?) {
|
||||
val groups = when (handlingStrategy) {
|
||||
is HandlingStrategy.JOINED ->
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitSyncStep.ImportingAccountGroups, 0.6f) {
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitialSyncStep.ImportingAccountGroups, 0.6f) {
|
||||
handleJoinedGroup(realm, it.key)
|
||||
}
|
||||
|
||||
is HandlingStrategy.INVITED ->
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitSyncStep.ImportingAccountGroups, 0.3f) {
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitialSyncStep.ImportingAccountGroups, 0.3f) {
|
||||
handleInvitedGroup(realm, it.key)
|
||||
}
|
||||
|
||||
is HandlingStrategy.LEFT ->
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitSyncStep.ImportingAccountGroups, 0.1f) {
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitialSyncStep.ImportingAccountGroups, 0.1f) {
|
||||
handleLeftGroup(realm, it.key)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ import org.matrix.android.sdk.api.session.events.model.Event
|
|||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
||||
import org.matrix.android.sdk.api.session.initsync.InitSyncStep
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
||||
import org.matrix.android.sdk.api.session.room.send.SendState
|
||||
import org.matrix.android.sdk.api.session.room.threads.model.ThreadSummaryUpdateType
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStep
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStrategy
|
||||
import org.matrix.android.sdk.api.session.sync.initialSyncStrategy
|
||||
import org.matrix.android.sdk.api.session.sync.model.InvitedRoomSync
|
||||
|
@ -67,17 +67,17 @@ import org.matrix.android.sdk.internal.di.UserId
|
|||
import org.matrix.android.sdk.internal.extensions.clearWith
|
||||
import org.matrix.android.sdk.internal.session.StreamEventsManager
|
||||
import org.matrix.android.sdk.internal.session.events.getFixedRoomMemberContent
|
||||
import org.matrix.android.sdk.internal.session.initsync.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.initsync.mapWithProgress
|
||||
import org.matrix.android.sdk.internal.session.initsync.reportSubtask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.RoomChangeMembershipStateDataSource
|
||||
import org.matrix.android.sdk.internal.session.room.membership.RoomMemberEventHandler
|
||||
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryUpdater
|
||||
import org.matrix.android.sdk.internal.session.room.timeline.PaginationDirection
|
||||
import org.matrix.android.sdk.internal.session.room.timeline.TimelineInput
|
||||
import org.matrix.android.sdk.internal.session.room.typing.TypingEventContent
|
||||
import org.matrix.android.sdk.internal.session.sync.ProgressReporter
|
||||
import org.matrix.android.sdk.internal.session.sync.SyncResponsePostTreatmentAggregator
|
||||
import org.matrix.android.sdk.internal.session.sync.mapWithProgress
|
||||
import org.matrix.android.sdk.internal.session.sync.parsing.RoomSyncAccountDataHandler
|
||||
import org.matrix.android.sdk.internal.session.sync.reportSubtask
|
||||
import org.matrix.android.sdk.internal.util.computeBestChunkSize
|
||||
import org.matrix.android.sdk.internal.util.time.Clock
|
||||
import timber.log.Timber
|
||||
|
@ -146,18 +146,18 @@ internal class RoomSyncHandler @Inject constructor(
|
|||
// Rooms are already inserted, return an empty list
|
||||
emptyList()
|
||||
} else {
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitSyncStep.ImportingAccountJoinedRooms, 0.6f) {
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitialSyncStep.ImportingAccountJoinedRooms, 0.6f) {
|
||||
handleJoinedRoom(realm, it.key, it.value, insertType, syncLocalTimeStampMillis, aggregator)
|
||||
}
|
||||
}
|
||||
}
|
||||
is HandlingStrategy.INVITED ->
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitSyncStep.ImportingAccountInvitedRooms, 0.1f) {
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitialSyncStep.ImportingAccountInvitedRooms, 0.1f) {
|
||||
handleInvitedRoom(realm, it.key, it.value, insertType, syncLocalTimeStampMillis)
|
||||
}
|
||||
|
||||
is HandlingStrategy.LEFT -> {
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitSyncStep.ImportingAccountLeftRooms, 0.3f) {
|
||||
handlingStrategy.data.mapWithProgress(reporter, InitialSyncStep.ImportingAccountLeftRooms, 0.3f) {
|
||||
handleLeftRoom(realm, it.key, it.value, insertType, syncLocalTimeStampMillis)
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ internal class RoomSyncHandler @Inject constructor(
|
|||
)
|
||||
|
||||
if (bestChunkSize.shouldChunk()) {
|
||||
reportSubtask(reporter, InitSyncStep.ImportingAccountJoinedRooms, bestChunkSize.numberOfChunks, 0.6f) {
|
||||
reportSubtask(reporter, InitialSyncStep.ImportingAccountJoinedRooms, bestChunkSize.numberOfChunks, 0.6f) {
|
||||
Timber.d("INIT_SYNC ${handlingStrategy.data.keys.size} rooms to insert, split with $bestChunkSize")
|
||||
// I cannot find a better way to chunk a map, so chunk the keys and then create new maps
|
||||
handlingStrategy.data.keys
|
||||
|
@ -202,7 +202,7 @@ internal class RoomSyncHandler @Inject constructor(
|
|||
}
|
||||
} else {
|
||||
// No need to split
|
||||
val rooms = handlingStrategy.data.mapWithProgress(reporter, InitSyncStep.ImportingAccountJoinedRooms, 0.6f) {
|
||||
val rooms = handlingStrategy.data.mapWithProgress(reporter, InitialSyncStep.ImportingAccountJoinedRooms, 0.6f) {
|
||||
handleJoinedRoom(realm, it.key, it.value, EventInsertType.INITIAL_SYNC, syncLocalTimeStampMillis, aggregator)
|
||||
}
|
||||
realm.insertOrUpdate(rooms)
|
||||
|
|
|
@ -142,7 +142,7 @@ fun initialSyncIdlingResource(session: Session): IdlingResource {
|
|||
override fun getName() = "InitialSyncIdlingResource for ${session.myUserId}"
|
||||
|
||||
override fun isIdleNow(): Boolean {
|
||||
val isIdle = session.hasAlreadySynced()
|
||||
val isIdle = session.syncService().hasAlreadySynced()
|
||||
return isIdle
|
||||
}
|
||||
|
||||
|
@ -151,16 +151,16 @@ fun initialSyncIdlingResource(session: Session): IdlingResource {
|
|||
}
|
||||
|
||||
override fun onChanged(t: SyncState?) {
|
||||
val isIdle = session.hasAlreadySynced()
|
||||
val isIdle = session.syncService().hasAlreadySynced()
|
||||
if (isIdle) {
|
||||
callback?.onTransitionToIdle()
|
||||
session.getSyncStateLive().removeObserver(this)
|
||||
session.syncService().getSyncStateLive().removeObserver(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runOnUiThread {
|
||||
session.getSyncStateLive().observeForever(res)
|
||||
session.syncService().getSyncStateLive().observeForever(res)
|
||||
}
|
||||
|
||||
return res
|
||||
|
|
|
@ -116,14 +116,14 @@ abstract class VerificationTestBase {
|
|||
|
||||
GlobalScope.launch(Dispatchers.Main) { session.open() }
|
||||
|
||||
session.startSync(true)
|
||||
session.syncService().startSync(true)
|
||||
|
||||
val syncLiveData = runBlocking(Dispatchers.Main) {
|
||||
session.getSyncStateLive()
|
||||
session.syncService().getSyncStateLive()
|
||||
}
|
||||
val syncObserver = object : Observer<SyncState> {
|
||||
override fun onChanged(t: SyncState?) {
|
||||
if (session.hasAlreadySynced()) {
|
||||
if (session.syncService().hasAlreadySynced()) {
|
||||
lock.countDown()
|
||||
syncLiveData.removeObserver(this)
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ object BackgroundSyncStarter {
|
|||
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_BATTERY -> {
|
||||
// we rely on periodic worker
|
||||
Timber.i("## Sync: Work scheduled to periodically sync in ${vectorPreferences.backgroundSyncDelay()}s")
|
||||
activeSession.startAutomaticBackgroundSync(
|
||||
activeSession.syncService().startAutomaticBackgroundSync(
|
||||
vectorPreferences.backgroundSyncTimeOut().toLong(),
|
||||
vectorPreferences.backgroundSyncDelay().toLong()
|
||||
)
|
||||
|
|
|
@ -26,9 +26,9 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.core.content.getSystemService
|
||||
import im.vector.app.core.extensions.singletonEntryPoint
|
||||
import im.vector.app.core.platform.PendingIntentCompat
|
||||
import im.vector.app.core.services.VectorSyncService
|
||||
import im.vector.app.core.services.VectorSyncAndroidService
|
||||
import im.vector.app.core.time.Clock
|
||||
import org.matrix.android.sdk.api.session.sync.job.SyncService
|
||||
import org.matrix.android.sdk.api.session.sync.job.SyncAndroidService
|
||||
import timber.log.Timber
|
||||
|
||||
class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
||||
|
@ -43,8 +43,8 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
|||
val vectorPreferences = singletonEntryPoint.vectorPreferences()
|
||||
val clock = singletonEntryPoint.clock()
|
||||
|
||||
val sessionId = intent.getStringExtra(SyncService.EXTRA_SESSION_ID) ?: return
|
||||
VectorSyncService.newPeriodicIntent(
|
||||
val sessionId = intent.getStringExtra(SyncAndroidService.EXTRA_SESSION_ID) ?: return
|
||||
VectorSyncAndroidService.newPeriodicIntent(
|
||||
context = context,
|
||||
sessionId = sessionId,
|
||||
syncTimeoutSeconds = vectorPreferences.backgroundSyncTimeOut(),
|
||||
|
@ -69,8 +69,8 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
|||
// Reschedule
|
||||
Timber.v("## Sync: Scheduling alarm for background sync in $delayInSeconds seconds")
|
||||
val intent = Intent(context, AlarmSyncBroadcastReceiver::class.java).apply {
|
||||
putExtra(SyncService.EXTRA_SESSION_ID, sessionId)
|
||||
putExtra(SyncService.EXTRA_PERIODIC, true)
|
||||
putExtra(SyncAndroidService.EXTRA_SESSION_ID, sessionId)
|
||||
putExtra(SyncAndroidService.EXTRA_PERIODIC, true)
|
||||
}
|
||||
val pIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
|
@ -100,7 +100,7 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
|||
alarmMgr.cancel(pIntent)
|
||||
|
||||
// Stop current service to restart
|
||||
VectorSyncService.stopIntent(context).let {
|
||||
VectorSyncAndroidService.stopIntent(context).let {
|
||||
try {
|
||||
ContextCompat.startForegroundService(context, it)
|
||||
} catch (ex: Throwable) {
|
||||
|
|
|
@ -63,7 +63,7 @@ object FcmHelper {
|
|||
|
||||
fun onEnterForeground(context: Context, activeSessionHolder: ActiveSessionHolder) {
|
||||
// try to stop all regardless of background mode
|
||||
activeSessionHolder.getSafeActiveSession()?.stopAnyBackgroundSync()
|
||||
activeSessionHolder.getSafeActiveSession()?.syncService()?.stopAnyBackgroundSync()
|
||||
AlarmSyncBroadcastReceiver.cancelAlarm(context)
|
||||
}
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
|||
getEventFastLane(session, roomId, eventId)
|
||||
|
||||
Timber.tag(loggerTag.value).d("Requesting background sync")
|
||||
session.requireBackgroundSync()
|
||||
session.syncService().requireBackgroundSync()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -358,7 +358,7 @@
|
|||
|
||||
<!-- Add tools:ignore="Instantiatable" for the error reported only by Buildkite and for lintGplayRelease check :/ -->
|
||||
<service
|
||||
android:name=".core.services.VectorSyncService"
|
||||
android:name=".core.services.VectorSyncAndroidService"
|
||||
android:exported="false"
|
||||
tools:ignore="Instantiatable" />
|
||||
|
||||
|
|
|
@ -41,8 +41,8 @@ import org.matrix.android.sdk.api.session.Session
|
|||
import org.matrix.android.sdk.api.session.getRoom
|
||||
import org.matrix.android.sdk.api.session.getRoomSummary
|
||||
import org.matrix.android.sdk.api.session.group.model.GroupSummary
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -147,9 +147,9 @@ class AppStateHandler @Inject constructor(
|
|||
}
|
||||
|
||||
private fun observeSyncStatus(session: Session) {
|
||||
session.syncStatusService().getSyncStatusLive()
|
||||
session.syncService().getSyncRequestStateLive()
|
||||
.asFlow()
|
||||
.filterIsInstance<SyncStatusService.Status.IncrementalSyncDone>()
|
||||
.filterIsInstance<SyncRequestState.IncrementalSyncDone>()
|
||||
.map { session.spaceService().getRootSpaceSummaries().size }
|
||||
.distinctUntilChanged()
|
||||
.onEach { spacesNumber ->
|
||||
|
|
|
@ -36,7 +36,7 @@ import kotlinx.coroutines.launch
|
|||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
@ -260,11 +260,11 @@ class AutoRageShaker @Inject constructor(
|
|||
}
|
||||
this.currentActiveSessionId = sessionId
|
||||
|
||||
hasSynced = session.hasAlreadySynced()
|
||||
session.syncStatusService().getSyncStatusLive()
|
||||
hasSynced = session.syncService().hasAlreadySynced()
|
||||
session.syncService().getSyncRequestStateLive()
|
||||
.asFlow()
|
||||
.onEach {
|
||||
hasSynced = it !is SyncStatusService.Status.InitialSyncProgressing
|
||||
hasSynced = it !is SyncRequestState.InitialSyncProgressing
|
||||
}
|
||||
.launchIn(session.coroutineScope)
|
||||
activeSessionIds.add(sessionId)
|
||||
|
|
|
@ -176,7 +176,7 @@ class VectorApplication :
|
|||
Timber.i("App entered foreground")
|
||||
FcmHelper.onEnterForeground(appContext, activeSessionHolder)
|
||||
activeSessionHolder.getSafeActiveSession()?.also {
|
||||
it.stopAnyBackgroundSync()
|
||||
it.syncService().stopAnyBackgroundSync()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import android.content.Context
|
|||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import im.vector.app.core.services.VectorSyncService
|
||||
import im.vector.app.core.services.VectorSyncAndroidService
|
||||
import im.vector.app.features.session.VectorSessionStore
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupState
|
||||
|
@ -40,9 +40,9 @@ fun Session.configureAndStart(context: Context, startSyncing: Boolean = true) {
|
|||
|
||||
fun Session.startSyncing(context: Context) {
|
||||
val applicationContext = context.applicationContext
|
||||
if (!hasAlreadySynced()) {
|
||||
if (!syncService().hasAlreadySynced()) {
|
||||
// initial sync is done as a service so it can continue below app lifecycle
|
||||
VectorSyncService.newOneShotIntent(
|
||||
VectorSyncAndroidService.newOneShotIntent(
|
||||
context = applicationContext,
|
||||
sessionId = sessionId
|
||||
)
|
||||
|
@ -57,7 +57,7 @@ fun Session.startSyncing(context: Context) {
|
|||
} else {
|
||||
val isAtLeastStarted = ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)
|
||||
Timber.v("--> is at least started? $isAtLeastStarted")
|
||||
startSync(isAtLeastStarted)
|
||||
syncService().startSync(isAtLeastStarted)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,12 +38,12 @@ import im.vector.app.core.time.DefaultClock
|
|||
import im.vector.app.features.notifications.NotificationUtils
|
||||
import im.vector.app.features.settings.BackgroundSyncMode
|
||||
import org.matrix.android.sdk.api.Matrix
|
||||
import org.matrix.android.sdk.api.session.sync.job.SyncService
|
||||
import org.matrix.android.sdk.api.session.sync.job.SyncAndroidService
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class VectorSyncService : SyncService() {
|
||||
class VectorSyncAndroidService : SyncAndroidService() {
|
||||
|
||||
companion object {
|
||||
|
||||
|
@ -51,7 +51,7 @@ class VectorSyncService : SyncService() {
|
|||
context: Context,
|
||||
sessionId: String
|
||||
): Intent {
|
||||
return Intent(context, VectorSyncService::class.java).also {
|
||||
return Intent(context, VectorSyncAndroidService::class.java).also {
|
||||
it.putExtra(EXTRA_SESSION_ID, sessionId)
|
||||
it.putExtra(EXTRA_TIMEOUT_SECONDS, 0)
|
||||
it.putExtra(EXTRA_PERIODIC, false)
|
||||
|
@ -65,7 +65,7 @@ class VectorSyncService : SyncService() {
|
|||
syncDelaySeconds: Int,
|
||||
isNetworkBack: Boolean
|
||||
): Intent {
|
||||
return Intent(context, VectorSyncService::class.java).also {
|
||||
return Intent(context, VectorSyncAndroidService::class.java).also {
|
||||
it.putExtra(EXTRA_SESSION_ID, sessionId)
|
||||
it.putExtra(EXTRA_TIMEOUT_SECONDS, syncTimeoutSeconds)
|
||||
it.putExtra(EXTRA_PERIODIC, true)
|
||||
|
@ -75,7 +75,7 @@ class VectorSyncService : SyncService() {
|
|||
}
|
||||
|
||||
fun stopIntent(context: Context): Intent {
|
||||
return Intent(context, VectorSyncService::class.java).also {
|
||||
return Intent(context, VectorSyncAndroidService::class.java).also {
|
||||
it.action = ACTION_STOP
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ private fun Context.rescheduleSyncService(
|
|||
) {
|
||||
Timber.d("## Sync: rescheduleSyncService")
|
||||
val intent = if (isPeriodic) {
|
||||
VectorSyncService.newPeriodicIntent(
|
||||
VectorSyncAndroidService.newPeriodicIntent(
|
||||
context = this,
|
||||
sessionId = sessionId,
|
||||
syncTimeoutSeconds = syncTimeoutSeconds,
|
||||
|
@ -217,7 +217,7 @@ private fun Context.rescheduleSyncService(
|
|||
isNetworkBack = isNetworkBack
|
||||
)
|
||||
} else {
|
||||
VectorSyncService.newOneShotIntent(
|
||||
VectorSyncAndroidService.newOneShotIntent(
|
||||
context = this,
|
||||
sessionId = sessionId
|
||||
)
|
|
@ -37,7 +37,7 @@ import kotlinx.coroutines.launch
|
|||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.flow.flow
|
||||
import timber.log.Timber
|
||||
import java.util.UUID
|
||||
|
@ -66,11 +66,11 @@ class AnalyticsAccountDataViewModel @AssistedInject constructor(
|
|||
|
||||
private fun observeInitSync() {
|
||||
combine(
|
||||
session.syncStatusService().getSyncStatusLive().asFlow(),
|
||||
session.syncService().getSyncRequestStateLive().asFlow(),
|
||||
analytics.getUserConsent(),
|
||||
analytics.getAnalyticsId()
|
||||
) { status, userConsent, analyticsId ->
|
||||
if (status is SyncStatusService.Status.IncrementalSyncIdle &&
|
||||
if (status is SyncRequestState.IncrementalSyncIdle &&
|
||||
userConsent &&
|
||||
analyticsId.isEmpty() &&
|
||||
!checkDone) {
|
||||
|
|
|
@ -273,7 +273,7 @@ class WebRtcCallManager @Inject constructor(
|
|||
// did we start background sync? so we should stop it
|
||||
if (isInBackground) {
|
||||
if (FcmHelper.isPushSupported()) {
|
||||
currentSession?.stopAnyBackgroundSync()
|
||||
currentSession?.syncService()?.stopAnyBackgroundSync()
|
||||
} else {
|
||||
// for fdroid we should not stop, it should continue syncing
|
||||
// maybe we should restore default timeout/delay though?
|
||||
|
@ -380,7 +380,7 @@ class WebRtcCallManager @Inject constructor(
|
|||
if (isInBackground) {
|
||||
if (FcmHelper.isPushSupported()) {
|
||||
// only for push version as fdroid version is already doing it?
|
||||
currentSession?.startAutomaticBackgroundSync(30, 0)
|
||||
currentSession?.syncService()?.startAutomaticBackgroundSync(30, 0)
|
||||
} else {
|
||||
// Maybe increase sync freq? but how to set back to default values?
|
||||
}
|
||||
|
|
|
@ -81,9 +81,9 @@ import kotlinx.coroutines.flow.launchIn
|
|||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStrategy
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.api.session.sync.initialSyncStrategy
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
import timber.log.Timber
|
||||
|
@ -373,9 +373,9 @@ class HomeActivity :
|
|||
}
|
||||
|
||||
private fun renderState(state: HomeActivityViewState) {
|
||||
when (val status = state.syncStatusServiceStatus) {
|
||||
is SyncStatusService.Status.InitialSyncProgressing -> {
|
||||
val initSyncStepStr = initSyncStepFormatter.format(status.initSyncStep)
|
||||
when (val status = state.syncRequestState) {
|
||||
is SyncRequestState.InitialSyncProgressing -> {
|
||||
val initSyncStepStr = initSyncStepFormatter.format(status.initialSyncStep)
|
||||
Timber.v("$initSyncStepStr ${status.percentProgress}")
|
||||
views.waitingView.root.setOnClickListener {
|
||||
// block interactions
|
||||
|
@ -392,7 +392,7 @@ class HomeActivity :
|
|||
}
|
||||
views.waitingView.root.isVisible = true
|
||||
}
|
||||
else -> {
|
||||
else -> {
|
||||
// Idle or Incremental sync status
|
||||
views.waitingView.root.isVisible = false
|
||||
}
|
||||
|
|
|
@ -60,10 +60,10 @@ import org.matrix.android.sdk.api.session.crypto.crosssigning.CrossSigningServic
|
|||
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||
import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap
|
||||
import org.matrix.android.sdk.api.session.getUser
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.pushrules.RuleIds
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
|
||||
import org.matrix.android.sdk.api.util.awaitCallback
|
||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||
|
@ -218,25 +218,25 @@ class HomeActivityViewModel @AssistedInject constructor(
|
|||
private fun observeInitialSync() {
|
||||
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
||||
|
||||
session.syncStatusService().getSyncStatusLive()
|
||||
session.syncService().getSyncRequestStateLive()
|
||||
.asFlow()
|
||||
.onEach { status ->
|
||||
when (status) {
|
||||
is SyncStatusService.Status.Idle -> {
|
||||
is SyncRequestState.Idle -> {
|
||||
maybeVerifyOrBootstrapCrossSigning()
|
||||
}
|
||||
else -> Unit
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
setState {
|
||||
copy(
|
||||
syncStatusServiceStatus = status
|
||||
syncRequestState = status
|
||||
)
|
||||
}
|
||||
}
|
||||
.launchIn(viewModelScope)
|
||||
|
||||
if (session.hasAlreadySynced()) {
|
||||
if (session.syncService().hasAlreadySynced()) {
|
||||
maybeVerifyOrBootstrapCrossSigning()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ package im.vector.app.features.home
|
|||
|
||||
import com.airbnb.mvrx.MavericksState
|
||||
import im.vector.app.features.onboarding.AuthenticationDescription
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
|
||||
data class HomeActivityViewState(
|
||||
val syncStatusServiceStatus: SyncStatusService.Status = SyncStatusService.Status.Idle,
|
||||
val syncRequestState: SyncRequestState = SyncRequestState.Idle,
|
||||
val authenticationDescription: AuthenticationDescription? = null
|
||||
) : MavericksState
|
||||
|
|
|
@ -444,7 +444,7 @@ class HomeDetailFragment @Inject constructor(
|
|||
views.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_notification).render(it.notificationCountCatchup, it.notificationHighlightCatchup)
|
||||
views.syncStateView.render(
|
||||
it.syncState,
|
||||
it.incrementalSyncStatus,
|
||||
it.incrementalSyncRequestState,
|
||||
it.pushCounter,
|
||||
vectorPreferences.developerShowDebugInfo()
|
||||
)
|
||||
|
|
|
@ -50,10 +50,10 @@ import org.matrix.android.sdk.api.query.SpaceFilter
|
|||
import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.crypto.NewSessionListener
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.room.RoomSortOrder
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||
import org.matrix.android.sdk.flow.flow
|
||||
import timber.log.Timber
|
||||
|
@ -199,11 +199,11 @@ class HomeDetailViewModel @AssistedInject constructor(
|
|||
copy(syncState = syncState)
|
||||
}
|
||||
|
||||
session.syncStatusService().getSyncStatusLive()
|
||||
session.syncService().getSyncRequestStateLive()
|
||||
.asFlow()
|
||||
.filterIsInstance<SyncStatusService.Status.IncrementalSyncStatus>()
|
||||
.filterIsInstance<SyncRequestState.IncrementalSyncRequestState>()
|
||||
.setOnEach {
|
||||
copy(incrementalSyncStatus = it)
|
||||
copy(incrementalSyncRequestState = it)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ import com.airbnb.mvrx.MavericksState
|
|||
import com.airbnb.mvrx.Uninitialized
|
||||
import im.vector.app.R
|
||||
import im.vector.app.RoomGroupingMethod
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.api.session.sync.SyncState
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
|
||||
|
@ -40,7 +40,7 @@ data class HomeDetailViewState(
|
|||
val notificationHighlightRooms: Boolean = false,
|
||||
val hasUnreadMessages: Boolean = false,
|
||||
val syncState: SyncState = SyncState.Idle,
|
||||
val incrementalSyncStatus: SyncStatusService.Status.IncrementalSyncStatus = SyncStatusService.Status.IncrementalSyncIdle,
|
||||
val incrementalSyncRequestState: SyncRequestState.IncrementalSyncRequestState = SyncRequestState.IncrementalSyncIdle,
|
||||
val pushCounter: Int = 0,
|
||||
val pstnSupportFlag: Boolean = false,
|
||||
val forceDialPadTab: Boolean = false
|
||||
|
|
|
@ -18,25 +18,25 @@ package im.vector.app.features.home
|
|||
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import org.matrix.android.sdk.api.session.initsync.InitSyncStep
|
||||
import org.matrix.android.sdk.api.session.sync.InitialSyncStep
|
||||
import javax.inject.Inject
|
||||
|
||||
class InitSyncStepFormatter @Inject constructor(
|
||||
private val stringProvider: StringProvider
|
||||
) {
|
||||
fun format(initSyncStep: InitSyncStep): String {
|
||||
fun format(initialSyncStep: InitialSyncStep): String {
|
||||
return stringProvider.getString(
|
||||
when (initSyncStep) {
|
||||
InitSyncStep.ServerComputing -> R.string.initial_sync_start_server_computing
|
||||
InitSyncStep.Downloading -> R.string.initial_sync_start_downloading
|
||||
InitSyncStep.ImportingAccount -> R.string.initial_sync_start_importing_account
|
||||
InitSyncStep.ImportingAccountCrypto -> R.string.initial_sync_start_importing_account_crypto
|
||||
InitSyncStep.ImportingAccountRoom -> R.string.initial_sync_start_importing_account_rooms
|
||||
InitSyncStep.ImportingAccountGroups -> R.string.initial_sync_start_importing_account_groups
|
||||
InitSyncStep.ImportingAccountData -> R.string.initial_sync_start_importing_account_data
|
||||
InitSyncStep.ImportingAccountJoinedRooms -> R.string.initial_sync_start_importing_account_joined_rooms
|
||||
InitSyncStep.ImportingAccountInvitedRooms -> R.string.initial_sync_start_importing_account_invited_rooms
|
||||
InitSyncStep.ImportingAccountLeftRooms -> R.string.initial_sync_start_importing_account_left_rooms
|
||||
when (initialSyncStep) {
|
||||
InitialSyncStep.ServerComputing -> R.string.initial_sync_start_server_computing
|
||||
InitialSyncStep.Downloading -> R.string.initial_sync_start_downloading
|
||||
InitialSyncStep.ImportingAccount -> R.string.initial_sync_start_importing_account
|
||||
InitialSyncStep.ImportingAccountCrypto -> R.string.initial_sync_start_importing_account_crypto
|
||||
InitialSyncStep.ImportingAccountRoom -> R.string.initial_sync_start_importing_account_rooms
|
||||
InitialSyncStep.ImportingAccountGroups -> R.string.initial_sync_start_importing_account_groups
|
||||
InitialSyncStep.ImportingAccountData -> R.string.initial_sync_start_importing_account_data
|
||||
InitialSyncStep.ImportingAccountJoinedRooms -> R.string.initial_sync_start_importing_account_joined_rooms
|
||||
InitialSyncStep.ImportingAccountInvitedRooms -> R.string.initial_sync_start_importing_account_invited_rooms
|
||||
InitialSyncStep.ImportingAccountLeftRooms -> R.string.initial_sync_start_importing_account_left_rooms
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -22,11 +22,11 @@ import com.airbnb.mvrx.Uninitialized
|
|||
import im.vector.app.features.home.room.detail.arguments.TimelineArgs
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.sender.SenderInfo
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.api.session.sync.SyncState
|
||||
import org.matrix.android.sdk.api.session.threads.ThreadNotificationBadgeState
|
||||
import org.matrix.android.sdk.api.session.widgets.model.Widget
|
||||
|
@ -59,7 +59,7 @@ data class RoomDetailViewState(
|
|||
val tombstoneEvent: Event? = null,
|
||||
val joinUpgradedRoomAsync: Async<String> = Uninitialized,
|
||||
val syncState: SyncState = SyncState.Idle,
|
||||
val incrementalSyncStatus: SyncStatusService.Status.IncrementalSyncStatus = SyncStatusService.Status.IncrementalSyncIdle,
|
||||
val incrementalSyncRequestState: SyncRequestState.IncrementalSyncRequestState = SyncRequestState.IncrementalSyncIdle,
|
||||
val pushCounter: Int = 0,
|
||||
val highlightedEventId: String? = null,
|
||||
val unreadState: UnreadState = UnreadState.Unknown,
|
||||
|
|
|
@ -430,7 +430,7 @@ class TimelineFragment @Inject constructor(
|
|||
|
||||
timelineViewModel.onEach(
|
||||
RoomDetailViewState::syncState,
|
||||
RoomDetailViewState::incrementalSyncStatus,
|
||||
RoomDetailViewState::incrementalSyncRequestState,
|
||||
RoomDetailViewState::pushCounter
|
||||
) { syncState, incrementalSyncStatus, pushCounter ->
|
||||
views.syncStateView.render(
|
||||
|
|
|
@ -90,7 +90,6 @@ import org.matrix.android.sdk.api.session.events.model.toContent
|
|||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.file.FileService
|
||||
import org.matrix.android.sdk.api.session.getRoom
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.room.getStateEvent
|
||||
import org.matrix.android.sdk.api.session.room.getTimelineEvent
|
||||
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
|
||||
|
@ -105,6 +104,7 @@ import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
|
|||
import org.matrix.android.sdk.api.session.room.read.ReadService
|
||||
import org.matrix.android.sdk.api.session.room.timeline.Timeline
|
||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.api.session.threads.ThreadNotificationBadgeState
|
||||
import org.matrix.android.sdk.api.session.threads.ThreadNotificationState
|
||||
import org.matrix.android.sdk.api.session.widgets.model.WidgetType
|
||||
|
@ -1130,11 +1130,11 @@ class TimelineViewModel @AssistedInject constructor(
|
|||
copy(syncState = syncState)
|
||||
}
|
||||
|
||||
session.syncStatusService().getSyncStatusLive()
|
||||
session.syncService().getSyncRequestStateLive()
|
||||
.asFlow()
|
||||
.filterIsInstance<SyncStatusService.Status.IncrementalSyncStatus>()
|
||||
.filterIsInstance<SyncRequestState.IncrementalSyncRequestState>()
|
||||
.setOnEach {
|
||||
copy(incrementalSyncStatus = it)
|
||||
copy(incrementalSyncRequestState = it)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
|||
private fun onSessionRestored() {
|
||||
activeSessionHolder.setActiveSession(session)
|
||||
// Start the sync
|
||||
session.startSync(true)
|
||||
session.syncService().startSync(true)
|
||||
|
||||
// TODO Configure and start ? Check that the push still works...
|
||||
setState {
|
||||
|
|
|
@ -24,7 +24,7 @@ import androidx.core.view.isVisible
|
|||
import im.vector.app.R
|
||||
import im.vector.app.core.utils.isAirplaneModeOn
|
||||
import im.vector.app.databinding.ViewSyncStateBinding
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
import org.matrix.android.sdk.api.session.sync.SyncRequestState
|
||||
import org.matrix.android.sdk.api.session.sync.SyncState
|
||||
|
||||
class SyncStateView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
|
||||
|
@ -41,14 +41,14 @@ class SyncStateView @JvmOverloads constructor(context: Context, attrs: Attribute
|
|||
@SuppressLint("SetTextI18n")
|
||||
fun render(
|
||||
newState: SyncState,
|
||||
incrementalSyncStatus: SyncStatusService.Status.IncrementalSyncStatus,
|
||||
incrementalSyncRequestState: SyncRequestState.IncrementalSyncRequestState,
|
||||
pushCounter: Int,
|
||||
showDebugInfo: Boolean
|
||||
) {
|
||||
views.syncStateDebugInfo.isVisible = showDebugInfo
|
||||
if (showDebugInfo) {
|
||||
views.syncStateDebugInfoText.text =
|
||||
"Sync thread : ${newState.toHumanReadable()}\nSync request: ${incrementalSyncStatus.toHumanReadable()}"
|
||||
"Sync thread : ${newState.toHumanReadable()}\nSync request: ${incrementalSyncRequestState.toHumanReadable()}"
|
||||
views.syncStateDebugInfoPushCounter.text =
|
||||
"Push: $pushCounter"
|
||||
}
|
||||
|
@ -76,13 +76,13 @@ class SyncStateView @JvmOverloads constructor(context: Context, attrs: Attribute
|
|||
}
|
||||
}
|
||||
|
||||
private fun SyncStatusService.Status.IncrementalSyncStatus.toHumanReadable(): String {
|
||||
private fun SyncRequestState.IncrementalSyncRequestState.toHumanReadable(): String {
|
||||
return when (this) {
|
||||
SyncStatusService.Status.IncrementalSyncIdle -> "Idle"
|
||||
is SyncStatusService.Status.IncrementalSyncParsing -> "Parsing ${this.rooms} room(s) ${this.toDevice} toDevice(s)"
|
||||
SyncStatusService.Status.IncrementalSyncError -> "Error"
|
||||
SyncStatusService.Status.IncrementalSyncDone -> "Done"
|
||||
else -> "?"
|
||||
SyncRequestState.IncrementalSyncIdle -> "Idle"
|
||||
is SyncRequestState.IncrementalSyncParsing -> "Parsing ${this.rooms} room(s) ${this.toDevice} toDevice(s)"
|
||||
SyncRequestState.IncrementalSyncError -> "Error"
|
||||
SyncRequestState.IncrementalSyncDone -> "Done"
|
||||
else -> "?"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue