-
-
Notifications
You must be signed in to change notification settings - Fork 461
feat(android-distribution): Run checkForUpdate on background thread (EME-413) #4811
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3bcbaea
feat(android-distribution): Run checkForUpdate on background thread (…
runningcode f0ba78d
refactor(android-distribution): Use Future instead of callback for as…
runningcode d3b97eb
refactor(sentry): Use custom CompletedFuture for API 21+ compatibilit…
runningcode 4b7d514
refactor(android-distribution): Import Future type for cleaner code (…
runningcode 64832c8
fix(samples): Update MainActivity to use Future-based checkForUpdate …
runningcode 9c228e4
refactor(samples): Add Future import and async library comment (EME-413)
runningcode 8f3b337
style(samples): Reflow comment for proper line length (EME-413)
runningcode 9b430e8
release: 8.24.0-alpha.2
getsentry-bot a6edae3
Merge branch 'main' into no/eme-413-async-update-check
runningcode f571681
Merge branch 'main' into no/eme-413-async-update-check
runningcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Changelog | ||
|
|
||
| ## Unreleased | ||
| ## 8.24.0-alpha.2 | ||
|
|
||
| ### Features | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sentry-android-distribution/api/sentry-android-distribution.api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Unnecessary Thread Creation in Update Check
The
checkForUpdatesample unnecessarily creates a newThreadto block on theFutureresult. This goes against the goal of using a shared thread pool and avoiding unbounded thread creation, ascheckForUpdatealready runs on a background thread. It leads to inefficient resource use.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no, we can’t call future.get() on the main thread since it will be blocking so we spawn a thread to wait for the result. Does that seem right?
I feel like this sample is overly complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Java async quagmire always makes me so sad.
This is much better now it's only in the sample but still ideally we would not encourage users to create a thread for each call.
I think most users will already have some kind of background worker setup which they could use convert the
Futureinto something usable (kotlinx-coroutines-guava,androidx.concurrent, their own worker pool, etc). Assuming we don't already have such a library in the sample I would suggest something like:e.g. Something that continually reposts the task to a handler with an increasing backoff until the future is resolvable and once it's resolvable calls the callback.
Alternatively we can do what we have now (or even just make a blocking call / do
.get()on the UI thread) - and leave a big comment about the user needs to convert this to be async with their favorite library.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to pull any dependencies we need for the sample btw
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romtsn I think adding dependencies is the way to go. This module is java only but I don’t think any Android developers are java only so I think we should add some kotlin and coroutines here.
But that would be a much bigger change since this entire file would have to be switched to kotlin in order to use coroutines.
@chromy I appreciate the sample code you wrote but I don’t think it would help anyone to have that since it will not be relevant to all users who have their own async libs so it will just cause extra confusion. I will just add a comment as you suggest to use your own asynchronous code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make it easier we could have a separate screen which polls for updates (or maybe even a foreground service?) which could be in kotlin from the get go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think polling is needed here in this sample nor for customer’s apps. I think there are two main use cases: 1. check for update on startup 2. check for update with a custom check for update button.