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

Let the SDK provide the "network is available information" #4215

Merged
merged 3 commits into from
Feb 3, 2025

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Jan 29, 2025

Content

We may have some trouble with the current network detection, since it rely on the ability to reach random server (not to name Google's one) and this can be broken when the application is run in air-gapped environment.

This PR move the network detection to the SDK providing the ability to perform sync request or not.

Need matrix-org/matrix-rust-sdk#4592, which is not merged yet.

Motivation and context

Improve network detection and bind it to the ability to communicate with the homeserver.

This will fix the "no network" banner which was displayed when the application was run in air-gapped mode.

Screenshots / GIFs

Tests

  • Open the app and see the room list
  • set airplane mode on
  • the no network banner is displayed
  • set airplane mode off
  • the no network banner go away and the app can be used normally

Tested devices

  • Physical
  • Emulator
  • OS version(s):

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

Comment on lines 51 to 55
SyncState.Idle,
SyncState.Running,
SyncState.Error,
SyncState.Terminated -> NetworkStatus.Online
SyncState.Offline -> NetworkStatus.Offline
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't only Running be Online?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since NetworkStatus.Offline will make the "no network" banner to be shown, I think it's better to be optimistic here.

@bmarty bmarty added the PR-Bugfix For bug fix label Jan 29, 2025
} else {
NetworkStatus.Offline
}
.stateIn(
Copy link
Member

Choose a reason for hiding this comment

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

I think when we discussed at the time, that the network monitor was still supposed to detect network changes, so we can re-trigger a sync as soon as possible (to avoid waiting for the auto retry timeout in those cases).

Also, I think we can remove the StateFlow from here and just expose an extension method on the SyncState like isConnected()

…atically when the network is back.

Also rely on the sync state to render the "Offline" banner.
@bmarty bmarty added the Z-NextRelease For issues and PRs which should be included in the NextRelease. label Feb 3, 2025
@bmarty bmarty force-pushed the feature/bma/airGappedSdk branch from 024a9e3 to f84aa03 Compare February 3, 2025 17:28
@bmarty bmarty marked this pull request as ready for review February 3, 2025 17:32
@bmarty bmarty requested a review from a team as a code owner February 3, 2025 17:32
@bmarty bmarty requested review from jmartinesp and removed request for a team February 3, 2025 17:32
@bmarty
Copy link
Member Author

bmarty commented Feb 3, 2025

@ganfra @jmartinesp I have reworked the PR, it's working fine on my side. Let me know what you think, then once merged we can do the release.

Copy link
Contributor

github-actions bot commented Feb 3, 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/vsTebh

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 86.36364% with 3 lines in your changes missing coverage. Please review.

Project coverage is 80.21%. Comparing base (f4afda1) to head (c8f4268).
Report is 18 commits behind head on develop.

Files with missing lines Patch % Lines
...ement/android/appnav/loggedin/LoggedInPresenter.kt 66.66% 0 Missing and 1 partial ⚠️
...t/android/libraries/matrix/api/sync/SyncService.kt 0.00% 0 Missing and 1 partial ⚠️
...id/libraries/matrix/impl/di/SessionMatrixModule.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4215      +/-   ##
===========================================
- Coverage    80.22%   80.21%   -0.01%     
===========================================
  Files         2042     2043       +1     
  Lines        54090    54095       +5     
  Branches      6570     6569       -1     
===========================================
  Hits         43393    43393              
- Misses        8424     8429       +5     
  Partials      2273     2273              

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

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.

One remark regarding SyncState/SyncService.

Also, I think we need to change the observeSyncStateAndNetworkStatus in LoggedInFlowNode : we don't want to listen to the sync state now, we can just listen to the network monitor state.
Note : it'll be changed anyway by Jorge PR

@@ -14,3 +14,11 @@ enum class SyncState {
Terminated,
Offline,
}

fun SyncState.isConnected() = when (this) {
Copy link
Member

Choose a reason for hiding this comment

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

I know the name was from me initially, but maybe we should instead call it isOffline?
fun SyncState.isOffline() = this is SyncState.Offline.

Or even an extension method on the SyncService
fun SyncService.isOffline(): StateFlow<Boolean> = syncState.mapState { it == SyncState.Offline }

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we do the opposite
fun SyncService.isOnline(): StateFlow<Boolean> = syncState.mapState { it != SyncState.Offline }
it will be simpler to use.

Copy link

sonarqubecloud bot commented Feb 3, 2025

@bmarty bmarty merged commit ccfccbb into develop Feb 3, 2025
28 checks passed
@bmarty bmarty deleted the feature/bma/airGappedSdk branch February 3, 2025 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Bugfix For bug fix Z-NextRelease For issues and PRs which should be included in the NextRelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants