-
-
Notifications
You must be signed in to change notification settings - Fork 152
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: Fetch synchronously in the background if no foreground service is allowed #3501
base: main
Are you sure you want to change the base?
Conversation
// we need to handle the message within 20s, and the time window may be even shorter than 20s, | ||
// so, use 10s to be safe. | ||
fetchingSynchronously = true; | ||
if (ApplicationContext.dcAccounts.backgroundFetch(10)) { |
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.
Could also make it 15 instead of 10 seconds if we want to.
// The background fetch was successful, but we need to wait until all events were processed. | ||
// After all events were processed, we will get DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE, | ||
// and stop() will be called. | ||
while (fetchingSynchronously) { | ||
try { | ||
// The `wait()` needs to be enclosed in a while loop because there may be | ||
// "spurious wake-ups", i.e. `wait()` may return even though `notifyAll()` wasn't called. | ||
STOP_NOTIFIER.wait(); | ||
} catch (InterruptedException ex) { } | ||
} |
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.
In order to simplify the logic here, we could also simply call Thread.sleep(1000) and assume that the UI will be done with showing a notification within 1s.
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 the logic is too complicated, and it is well documented, better than some fixed sleeping that might be too much in some cases and too little in another
To test the changes in this pull request, install this apk: |
Fix #3500.