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: crash about persistent websocket being started from background [WPB-6551] #2748

Merged

Conversation

AndroidBob
Copy link
Collaborator

@AndroidBob AndroidBob commented Feb 28, 2024

BugWPB-6551 [Android] Crash caused by Foreground services not allowed

Cherry pick from the original PR:


⚠️ Conflicts during cherry-pick:
kalium


PR Submission Checklist for internal contributors

  • The PR Title

    • conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    • contains a reference JIRA issue number like
    • answers the question: If merged, this PR will: ... ³
  • The PR Description

    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

What's new in this PR?

Issues

Sometimes for results in .

Causes (Optional)

This exception means that was executed when it's not allowed to, there are multiple restrictions on when foreground service can be started - more here: https://developer.android.com/develop/background-work/services/foreground-services#background-start-restriction-exemptions
For us, we are allowed to start foreground service from Activity when the app is in the foreground and when the device is booted or app is updated (probably within 20 seconds) and we use for that. The problem is probably that we in a coroutine, so it's just left hanging and receiving new values even in the background.

Solutions

When is called, get the list of persistent websocket statuses only once to make sure that we open the service within the permitted time frame. This persistent websocket flag can be changed only in settings by the user when the app is in the foreground so no need to observe for changes in this receiver - if changed then the service will be started from .
The logic of deciding whether the service should be started or not is extracted to dedicated use case and tested.

Testing

Test Coverage (Optional)

  • I have added automated test to this contribution

How to Test

There's no specific reproduction path, from the logs it looks like it could happen when the app was updated in the background and the sync was started so that the user's values in database are updated and emits new list.


PR Post Submission Checklist for internal contributors (Optional)

  • Wire's Github Workflow has automatically linked the PR to a JIRA issue

PR Post Merge Checklist for internal contributors

  • If any soft of configuration variable was introduced by this PR, it has been added to the relevant documents and the CI jobs have been updated.

References
  1. https://sparkbox.com/foundry/semantic_commit_messages
  2. https://github.com/wireapp/.github#usage
  3. E.g. .

@AndroidBob AndroidBob added the cherry-pick PR is cherry-picking changes from another banch label Feb 28, 2024
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 16 lines in your changes are missing coverage. Please review.

Project coverage is 43.24%. Comparing base (21505f4) to head (55b386c).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2748      +/-   ##
===========================================
+ Coverage    43.13%   43.24%   +0.10%     
===========================================
  Files          408      409       +1     
  Lines        13554    13571      +17     
  Branches      2392     2396       +4     
===========================================
+ Hits          5847     5869      +22     
+ Misses        7021     7015       -6     
- Partials       686      687       +1     
Files Coverage Δ
...re/ShouldStartPersistentWebSocketServiceUseCase.kt 100.00% <100.00%> (ø)
.../com/wire/android/ui/debug/StartServiceReceiver.kt 13.04% <5.88%> (+3.51%) ⬆️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21505f4...55b386c. Read the comment docs.

@saleniuk saleniuk requested review from a team, typfel, yamilmedina, alexandreferris, Garzas and ohassine and removed request for a team February 28, 2024 15:45
Copy link
Contributor

Test Results

827 tests  +6   827 ✅ +6   14m 35s ⏱️ + 1m 28s
115 suites +1     0 💤 ±0 
115 files   +1     0 ❌ ±0 

Results for commit 55b386c. ± Comparison against base commit 21505f4.

Copy link
Contributor

APKs built during tests are available here. Scroll down to Artifacts!

@AndroidBob
Copy link
Collaborator Author

Build 3369 succeeded.

The build produced the following APK's:

@alexandreferris alexandreferris added this pull request to the merge queue Feb 28, 2024
Merged via the queue into develop with commit a07eca9 Feb 28, 2024
14 checks passed
@alexandreferris alexandreferris deleted the fix/start-persistent-socket-service-crash-cherry-pick branch February 28, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick PR is cherry-picking changes from another banch size/S
Projects
None yet
3 participants