-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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: ignore shared deck download and dialog dismissal at inappropriate lifecycle states #17483
fix: ignore shared deck download and dialog dismissal at inappropriate lifecycle states #17483
Conversation
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.
Fine for both changes.
To be honest, with the current code around shared decks, I'm surprised with the small amounts of related bug reports that we get.
After looking at it, I'm not sure why any of the code exists. I don't know how we're doing anything better than just letting the WebView download the thing and then having the user open it ? It's a lot of code and custom UI and stuff for what exactly? If it's the user experience of starting the import immediately when download is complete, couldn't it just do that instead - like a completion listener vs the full custom UI Anyway, with this it won't crash |
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.
@mikehardy You added Brayan as a reviewer, so I'm holding off on the merge button
FragmentManager.POP_BACK_STACK_INCLUSIVE | ||
) | ||
// trying to pop fragment manager back state crashes if state already saved | ||
if (!supportFragmentManager.isStateSaved) { |
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.
Normally, the callers shouldn't be trying to manually dismiss a dialog when an activity is being destroyed.
Given our need to fix an issue and the current disorder in AnkiActivity, this is reasonable. But, the whole area needs some work in the future.
Purpose / Description
Fix a crash where the shared deck download state is such that the WebView is attempting to instantiate our shared fragment download listener, but activity/fragment lifecycle state is already saved during teardown process
Fixes
ACRA crash https://ankidroid.org/acra/app/1/bug/260938/report/667f6607-e575-4499-8860-2bb61b5db51b
Second commit also fixes a bunch of other crashes where dialog dismissal is attempted but state is already saved
Approach
Read up on lifecycle stuff for Fragments, think about how to most-correctly just cut out of the download if for some reason state is saved but the download listener is still called
Couldn't directly reproduce the issue but my reasoning is that we should ignore a download completely if the activity is already in teardown?
Also saw a bunch of others were dialog dismissal was attempted but the exceptions in the crashes were clearly indicating it just wasn't possible, and just cut that attempted dismissal out if state wouldn't permit it
How Has This Been Tested?
Verified shared deck downloads still work with this change in place, so no regression
I tried to alter emulator network settings to open up possibility of triggering the race condition that caused this while simulating a slower / crappier network but couldn't trigger it
Learning (optional, can help others)
Race conditions are fierce
Checklist
Please, go through these checks before submitting the PR.