-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create SyncOrchestrator
#4176
base: develop
Are you sure you want to change the base?
Create SyncOrchestrator
#4176
Conversation
📱 Scan the QR code below to install the build (arm64 only) for this PR. |
...sh/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/SyncOnNotifiableEvent.kt
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4176 +/- ##
===========================================
- Coverage 83.31% 83.31% -0.01%
===========================================
Files 1881 1883 +2
Lines 49101 49157 +56
Branches 5769 5781 +12
===========================================
+ Hits 40910 40953 +43
- Misses 6116 6122 +6
- Partials 2075 2082 +7 ☔ View full report in Codecov by Sentry. |
…in `SyncOnNotifiableEvent`
396fe48
to
801dd62
Compare
appnav/src/main/kotlin/io/element/android/appnav/SyncObserver.kt
Outdated
Show resolved
Hide resolved
@@ -147,6 +138,9 @@ class LoggedInFlowNode @AssistedInject constructor( | |||
|
|||
override fun onBuilt() { | |||
super.onBuilt() | |||
|
|||
syncOrchestrator.start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code will not be run if the app is killed and a Push is received. In this case the sync will not start?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right, and I completely overlooked this... This complicates things, as we would have to use SyncOrchestrator
in the AppScope
and that means holding as many as MatrixClient
s there are in MatrixClientsHolder
, maybe following a similar approach 🫤 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Please see my comments.
} | ||
} | ||
// Make sure we mark the call as ended in the app state | ||
if (appForegroundStateService.isInCall.value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I do not think it is useful to read the value before changing it, or do I miss something here?
@@ -199,7 +199,7 @@ class LoginFlowNode @AssistedInject constructor( | |||
|
|||
@Composable | |||
override fun View(modifier: Modifier) { | |||
activity = LocalContext.current as? Activity | |||
activity = LocalActivity.current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe stick to the same line of code than for other classes:
val activity = requireNotNull(LocalActivity.current)
…rator` given an existing `MatrixClient`.
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some remarks
/** | ||
* Observes the app state and network state to start/stop the sync service. | ||
*/ | ||
interface SyncOrchestrator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this class belongs the the matrix api, it's more an app thing to me
/** | ||
* Provides a [SyncOrchestrator] for a given [SessionId]. | ||
*/ | ||
fun interface SyncOrchestratorProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same ^
@@ -29,13 +30,14 @@ private const val SAVE_INSTANCE_KEY = "io.element.android.x.di.MatrixClientsHold | |||
@ContributesBinding(AppScope::class) | |||
class MatrixClientsHolder @Inject constructor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should rename this class so it's a bit clearer it's not just about MatrixClients
?
Also we might want to create a class instead of using Pair?
I don't think we need the DefaultSyncOrchestratorProvider
, we should let MatrixClientsHolder
(with a new name :P) implements the SyncOrchestratorProvider
Content
Centralise the start/stop sync logic in a single component of the app:
SyncOrchestrator
, which will act as the single point where sync start/stop can happen, based on several inputs (sync state, network available, app in foreground, app in call, app needing to sync an event for a notification).AppForegroundStateService
.SyncOrchestrator
.Motivation and context
Having too many points where the sync could be started and stopped could cause issues where the sync was unexpectedly stopped when it should instead be running or a deadlock may happen for several start/stop calls.
It should help with #4150
Tests
Just play with the sync state with network online/offline and app foreground state, receiving notifications, joining calls, etc.
Tested devices
Checklist