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

SecureBackup: update matrix sdk module. #1653

Merged
merged 1 commit into from
Oct 27, 2023
Merged

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Oct 26, 2023

SDK part of #1648.

@bmarty bmarty requested a review from a team as a code owner October 26, 2023 16:03
@bmarty bmarty requested review from julioromano and removed request for a team October 26, 2023 16:03
@@ -58,7 +58,7 @@ class DefaultLogoutPreferencePresenter @Inject constructor(private val matrixCli

private fun CoroutineScope.logout(logoutAction: MutableState<Async<String?>>) = launch {
suspend {
matrixClient.logout()
matrixClient.logout(false /* TODO */)
Copy link
Member Author

Choose a reason for hiding this comment

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

Will be updated in a later PR.

@sonarcloud
Copy link

sonarcloud bot commented Oct 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@github-actions
Copy link
Contributor

📱 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/5yVhUN

@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Attention: 33 lines in your changes are missing coverage. Please review.

Comparison is base (00d24ce) 63.06% compared to head (3a15b92) 63.04%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1653      +/-   ##
===========================================
- Coverage    63.06%   63.04%   -0.03%     
===========================================
  Files         1215     1219       +4     
  Lines        31345    31392      +47     
  Branches      6447     6450       +3     
===========================================
+ Hits         19768    19790      +22     
- Misses        8604     8629      +25     
  Partials      2973     2973              
Files Coverage Δ
...tures/lockscreen/impl/unlock/PinUnlockPresenter.kt 78.00% <100.00%> (ø)
...es/logout/impl/DefaultLogoutPreferencePresenter.kt 80.00% <100.00%> (ø)
...ement/android/libraries/matrix/api/MatrixClient.kt 100.00% <ø> (ø)
...d/libraries/matrix/api/encryption/RecoveryState.kt 100.00% <100.00%> (ø)
.../element/android/libraries/matrix/test/TestData.kt 100.00% <ø> (ø)
.../android/libraries/matrix/test/FakeMatrixClient.kt 86.20% <80.00%> (-0.70%) ⬇️
...es/matrix/api/encryption/EnableRecoveryProgress.kt 20.00% <20.00%> (ø)
...braries/matrix/api/encryption/BackupUploadState.kt 11.11% <11.11%> (ø)
...es/matrix/test/encryption/FakeEncryptionService.kt 23.07% <23.07%> (ø)

... and 1 file with indirect coverage changes

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

Copy link
Contributor

@julioromano julioromano left a comment

Choose a reason for hiding this comment

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

LGTM, just nits.

import kotlinx.coroutines.flow.StateFlow

interface EncryptionService {
val backupStateStateFlow: StateFlow<BackupState>
Copy link
Contributor

Choose a reason for hiding this comment

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

Just style:
StateState :/
unless we have a very strict naming scheme we want to stick to I'd suggest we could drop the StateFlow suffix and just use Flow even though it doesn't match the actual type name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree it's not ideal... I will change it in a coming PR.

val backupUploadStateStateFlow: StateFlow<BackupUploadState>
val enableRecoveryProgressStateFlow: StateFlow<EnableRecoveryProgress>

suspend fun enableBackups(): Result<Unit>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way to disable them (I mean... there's a enableBackups API but not a diableBackups one... is it possible to disable the backup?)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, there is one, but the name from the SDK is disableRecovery, do not ask me why. I will document the API later.
We have to decide if we stick to the SDK name or if we change it to make is clearer.


suspend fun enableBackups(): Result<Unit>

suspend fun isLastDevice(): Result<Boolean>
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing context: last what? Maybe add docstring
I mean.. last device that logged in? Last device created? Last device used?

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 is the last Session, so last device that logged in. Will document the API.

}
)
// enableRecovery returns the encryption key, but we read it from the state flow
.let { }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why .let{} when Unit was enough ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unit is working, but quality check does not like it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why doesn't it? It's the most correct thing to do in this case kotlin-wise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I agree. Detekt is reporting this:

~/workspaces/element-x-android/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/encryption/RustEncryptionService.kt:84:13: A single Unit expression is unnecessary and can safely be removed. [OptionalUnit]

There are several similar reports in the detekt project https://github.com/detekt/detekt, but all the issues seems to be close.

In the mean time, using .let { } is the solution, and it's already used in the codebase.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like a detekt bug


override suspend fun enableBackups(): Result<Unit> = withContext(dispatchers.io) {
runCatching {
service.enableBackups()
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question, why none of these ffi methods are suspend? Didn't we just get rid of all *blocking versions of many APIs?

@bmarty bmarty merged commit aaaad23 into develop Oct 27, 2023
18 of 20 checks passed
@bmarty bmarty deleted the feature/bma/secureBackupSdk branch October 27, 2023 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants