Skip to content
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

Merged
merged 15 commits into from
Feb 6, 2025
Merged

Create SyncOrchestrator #4176

merged 15 commits into from
Feb 6, 2025

Conversation

jmartinesp
Copy link
Member

@jmartinesp jmartinesp commented Jan 20, 2025

Content

Centralise the start/stop sync logic in a single component of the app:

  • Create 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).
  • Add the extra cases (app in call, syncing an event) to AppForegroundStateService.
  • Remove the start/stop sync logic from several parts of the code, replace them with toggling the inputs for the 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

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

Copy link
Contributor

github-actions bot commented Jan 20, 2025

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/e8LUsC

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 76.63551% with 25 lines in your changes missing coverage. Please review.

Project coverage is 80.24%. Comparing base (6362e01) to head (b3bba14).
Report is 18 commits behind head on develop.

Files with missing lines Patch % Lines
...oid/libraries/matrix/impl/timeline/RustTimeline.kt 0.00% 6 Missing ⚠️
...pnavstate/impl/DefaultAppForegroundStateService.kt 0.00% 6 Missing ⚠️
...tures/networkmonitor/impl/DefaultNetworkMonitor.kt 0.00% 4 Missing ⚠️
...n/io/element/android/appnav/di/SyncOrchestrator.kt 94.59% 1 Missing and 1 partial ⚠️
...ent/android/appnav/root/RootNavStateFlowFactory.kt 0.00% 2 Missing ⚠️
...io/element/android/appnav/di/MatrixSessionCache.kt 95.83% 0 Missing and 1 partial ⚠️
...atures/lockscreen/impl/DefaultLockScreenService.kt 0.00% 1 Missing ⚠️
...d/libraries/designsystem/utils/ForceOrientation.kt 0.00% 1 Missing ⚠️
.../android/libraries/matrix/impl/RustMatrixClient.kt 0.00% 1 Missing ⚠️
...pnavstate/impl/DefaultAppNavigationStateService.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4176      +/-   ##
===========================================
+ Coverage    80.22%   80.24%   +0.02%     
===========================================
  Files         2043     2044       +1     
  Lines        54113    54156      +43     
  Branches      6570     6573       +3     
===========================================
+ Hits         43411    43460      +49     
+ Misses        8429     8421       -8     
- Partials      2273     2275       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jmartinesp jmartinesp added the PR-Feature For a new feature label Jan 22, 2025
@jmartinesp jmartinesp force-pushed the refactor/sync-observer branch from 396fe48 to 801dd62 Compare January 22, 2025 11:12
@jmartinesp jmartinesp marked this pull request as ready for review January 22, 2025 11:19
@jmartinesp jmartinesp requested a review from a team as a code owner January 22, 2025 11:19
@jmartinesp jmartinesp requested review from ganfra and removed request for a team January 22, 2025 11:19
@jmartinesp jmartinesp changed the title Create SyncObserver Create SyncOrchestrator Jan 22, 2025
@jmartinesp jmartinesp requested a review from bmarty January 22, 2025 15:29
Copy link
Member

@bmarty bmarty left a 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.

Copy link
Member

@ganfra ganfra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some remarks

@jmartinesp
Copy link
Member Author

@ganfra all the points should have been fixed in the latest commit.

Copy link
Member

@ganfra ganfra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

…ugh the whole app.

The decision is based on several inputs: sync state, network available, app in foreground, app in call, app needing to sync an event for a notification.
…fail instead

This prevents an issue when using the offline mode of the SDK, which made the wrong UI states to be shown when the `SyncState` is `Idle` (that is, after the service being manually stopped).
…they're not easily mistaken with internet connectivity instead
@jmartinesp jmartinesp force-pushed the refactor/sync-observer branch from 3033b67 to 64abdf6 Compare February 5, 2025 10:30
@jmartinesp jmartinesp requested a review from ganfra February 5, 2025 10:32
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new bunch of comments, I have not run the code yet

initialSyncMutex.lock()

combine(
// small debounce to avoid spamming startSync when the state is changing quickly in case of error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the debounced can be moved after the combine block (before .distinctUntilChanged())?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes issues in the tests, since it's preventing some intermediate states from being generated. I'd rather keep it were it is, if possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try with this patch?

moveDebounce.patch

@jmartinesp jmartinesp requested a review from bmarty February 5, 2025 13:11
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more remarks

@jmartinesp jmartinesp requested a review from bmarty February 5, 2025 16:47
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I'll do more tests tomorrow. There are still some remarks that are not yet handled (some of them are old), maybe you missed them, this is just a kind reminder.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update.
I think the tests could be simplified a bit, now that we do not start an initial sync.
Then I believe that the PR can be merged to be in the latest nightly.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have found something, please wait before merging, I will comment

Copy link

sonarqubecloud bot commented Feb 6, 2025

@jmartinesp jmartinesp merged commit 3c87fb0 into develop Feb 6, 2025
27 of 28 checks passed
@jmartinesp jmartinesp deleted the refactor/sync-observer branch February 6, 2025 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Feature For a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants