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

Fix various crashes #3533

Merged
merged 12 commits into from
Sep 25, 2024
Merged

Fix various crashes #3533

merged 12 commits into from
Sep 25, 2024

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Sep 24, 2024

Content

Fix various crashes reported by Sentry.
Also cleanup the code at a few location.

To be reviewed commit per commit.

Motivation and context

More stable application.

Screenshots / GIFs

Tests

Not always easy to repro the crashes.
For the PDF crash, changing the extension of a Gif file (for instance), then send it to a room and try to open it made the application crash. It's no fixed and display an inlined error.

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

  • Changes have been tested on an Android device or Android emulator with API 23
  • 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
  • Pull request includes a sign off
  • You've made a self review of your PR

@bmarty bmarty requested a review from a team as a code owner September 24, 2024 15:30
@bmarty bmarty requested review from jmartinesp and removed request for a team September 24, 2024 15:30
@bmarty bmarty added Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. PR-Bugfix For bug fix labels Sep 24, 2024
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Sep 24, 2024
Copy link
Contributor

github-actions bot commented Sep 24, 2024

📱 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/VhvJpv

Copy link
Member

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

Thanks, I have a couple of suggestions.

try {
managedLauncher.launch(defaultRequest)
} catch (activityNotFoundException: ActivityNotFoundException) {
Timber.w(activityNotFoundException, "No activity found")
Copy link
Member

Choose a reason for hiding this comment

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

Should we use toast int these 2 cases too besides just logging the issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue happen when the device has no Camera application, so I would not bother too much.

Comment on lines 39 to 42
PdfRenderer(parcelFileDescriptor)
}.fold(
onSuccess = { pdfRenderer ->
this@PdfRendererManager.pdfRenderer = pdfRenderer
Copy link
Member

Choose a reason for hiding this comment

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

Maybe directly do:

runCatching {
    pdfRenderer = PdfRenderer(parcelFileDescriptor)
}

So we get rid of the ugly this@pdfRendererManager.pdfRenderer = ... line.

Copy link
Member Author

Choose a reason for hiding this comment

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

ugly yes, but I need the runCatching to return the value.

Maybe using a also block like

runCatching {
    PdfRenderer(parcelFileDescriptor).also {
        pdfRenderer = it
    }
}.fold(
    onSuccess = { pdfRenderer ->
        // Preload just 3 pages so we can render faster
        val firstPages = pdfRenderer.loadPages(from = 0, to = 3)
        mutablePdfPages.value = AsyncData.Success(firstPages.toImmutableList())
        val nextPages = pdfRenderer.loadPages(from = 3, to = pdfRenderer.pageCount)
        mutablePdfPages.value = AsyncData.Success((firstPages + nextPages).toImmutableList())
    },
    onFailure = {
        mutablePdfPages.value = AsyncData.Failure(it)
    }
)

is less ugly?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have found another solution 55704f0

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 the change is ok and maybe I'm overlooking something but with the change I proposed wouldn't the pdfRenderer property only be assigned if the initiailzation using the parcelFileDescriptor works too?

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, but with the change you proposed, the result of the assignation is Unit, so I can't get the PdfRenderer instance in the onSuccess parameter block.

Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 33.96226% with 35 lines in your changes missing coverage. Please review.

Project coverage is 82.63%. Comparing base (41126c7) to head (53fc2f3).
Report is 17 commits behind head on develop.

Files with missing lines Patch % Lines
...es/mediaviewer/api/local/pdf/PdfRendererManager.kt 0.00% 13 Missing ⚠️
...d/libraries/mediaviewer/api/local/pdf/PdfViewer.kt 65.38% 7 Missing and 2 partials ⚠️
...droid/libraries/androidutils/system/SystemUtils.kt 0.00% 6 Missing ⚠️
...droid/libraries/mediapickers/api/PickerLauncher.kt 0.00% 4 Missing ⚠️
...droid/features/call/impl/ui/ElementCallActivity.kt 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3533      +/-   ##
===========================================
- Coverage    82.68%   82.63%   -0.06%     
===========================================
  Files         1732     1732              
  Lines        40904    40940      +36     
  Branches      4973     4980       +7     
===========================================
+ Hits         33823    33829       +6     
- Misses        5316     5343      +27     
- Partials      1765     1768       +3     

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

@@ -105,8 +105,12 @@ class RustMatrixRoom(

override val roomInfoFlow: Flow<MatrixRoomInfo> = mxCallbackFlow {
launch {
Copy link
Member

Choose a reason for hiding this comment

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

Remove launch here too?

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, will try. I did not want to change the logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

.getOrNull()
?.let(matrixRoomInfoMapper::map)
?.let { initial ->
channel.trySend(initial)
Copy link
Member

Choose a reason for hiding this comment

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

use channel.send instead of trySend?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not want to change the existing code here. Maybe in another PR?

Copy link

sonarcloud bot commented Sep 24, 2024

@bmarty bmarty added the Run-Maestro Starts a Maestro Cloud session to run integration tests label Sep 25, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label Sep 25, 2024
@bmarty bmarty merged commit 7f9e176 into develop Sep 25, 2024
28 of 30 checks passed
@bmarty bmarty deleted the feature/bma/fixCrashes branch September 25, 2024 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Bugfix For bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants