-
-
Notifications
You must be signed in to change notification settings - Fork 459
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
Open
runningcode
wants to merge
9
commits into
main
Choose a base branch
from
no/eme-413-async-update-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8ba2f76
feat(android-distribution): Run checkForUpdate on background thread (…
runningcode 23a841c
refactor(android-distribution): Use Future instead of callback for as…
runningcode d60461b
refactor(sentry): Use custom CompletedFuture for API 21+ compatibilit…
runningcode 939947e
refactor(android-distribution): Import Future type for cleaner code (…
runningcode af0fa28
fix(samples): Update MainActivity to use Future-based checkForUpdate …
runningcode 367bb10
refactor(samples): Add Future import and async library comment (EME-413)
runningcode 9aaadc6
style(samples): Reflow comment for proper line length (EME-413)
runningcode becae51
release: 8.24.0-alpha.2
getsentry-bot 7997cac
Merge branch 'release/8.24.0-alpha.2' into no/eme-413-async-update-check
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
checkForUpdate
sample unnecessarily creates a newThread
to block on theFuture
result. This goes against the goal of using a shared thread pool and avoiding unbounded thread creation, ascheckForUpdate
already 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
Future
into 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