-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Scoped Storage: Handle storage being revoked #13396
Scoped Storage: Handle storage being revoked #13396
Conversation
Message to maintainers, this PR contains strings changes.
Read more about updating strings on the wiki, |
0fe921e
to
edcb2ef
Compare
edcb2ef
to
86ffb13
Compare
86ffb13
to
774746f
Compare
774746f
to
ab9474f
Compare
ab9474f
to
271ee7a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
271ee7a
to
4eadafe
Compare
@@ -452,7 +452,9 @@ open class AnkiActivity : AppCompatActivity, SimpleMessageDialogListener, Collec | |||
* @param newFragment the DialogFragment you want to show | |||
*/ | |||
open fun showDialogFragment(newFragment: DialogFragment) { | |||
showDialogFragment(this, newFragment) | |||
runOnUiThread { |
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.
Can you explain the rationale behind this change?
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.
If this is not called on the UI thread we get the exception:
Exception: java.lang.IllegalStateException: Must be called from main thread of fragment host
I don't recall the situation which caused this. I strongly suspect it's the line(s):
deckPicker.launchCatchingTask {
CollectionHelper.ankiDroidDirectoryOverride = newAnkiDroidDirectory
CollectionManager.withCol {
deckPicker.showImportDialog(
ImportOptions(
importTextFile = false,
importColpkg = true,
importApkg = false
)
)
}
}
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.
IMHO, you might want to revisit that code instead. withCol is intended to operate on the collection and optionally return a value - doing UI work inside it is generally a code smell. In this case it doesn't even appear to be using the provided collection scope, so as far as I can see, if this code has any effect, it would just be to serialize concurrent access if it's not already serialized. If the importing dialog needs to access the collection, it should be calling withCol itself, or the collection object should be passed in to it (but the former is probably a better option in most cases, since that minimizes the time the collection is held locked from other UI).
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.
@david-allison not sure what you want to do with this one - this does indeed seem like a valid suggestion (move where the withCol happens / remove UI thread thing here) but it seems like it will be halt merge here. If we merge as is we are open to ANRs / UI non-responsiveness which is certainly a performance concern / could be considered a correctness concern.
I'm leaning towards merging this PR with this as a known defect peeled into a different issue. What do you think?
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.
Concrete suggestion that would work for me then, and stop a back-and-forth: if you agree a new issue works, create the issue, link here, and then I think this is merge-able.
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.
Okay - having napped on this (insert old man joke here...) I'm going to peel it to an issue and go with this.
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.
#13499 is the peel out issue - I napped on this and I want to keep it moving on the main track, smaller issues should not derail progress
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.
Unless I'm getting this wrong, this is trivial to solve, because if the withCol
collection isn't used, it can be simply removed.
deckPicker.launchCatchingTask {
CollectionHelper.ankiDroidDirectoryOverride = newAnkiDroidDirectory
deckPicker.showImportDialog(
ImportOptions(
importTextFile = false,
importColpkg = true,
importApkg = false
)
)
}
And being on the "likely to bug, but trivial to fix" side of things" makes it better to fix on this PR.
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.
P.s.: perhaps the launchCatchingTask can be dropped as well
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.
Sorry @BrayanDSO - I hit the merge button before I saw this 🙈
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DatabaseErrorDialog.kt
Outdated
Show resolved
Hide resolved
4eadafe
to
d76f47a
Compare
d76f47a
to
679a826
Compare
@ShridharGoel - David responded I think to your comments and re-pushed but with one trivial refactor element missing. I just fixed that and rebased upstream/main back into the PR then pushed that. I think it is ready for review again 🤞 . Thank you! |
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.
Overall, LGTM. Soft approval because I haven't tested it yet
If a user uninstalls AnkiDroid, `preserveLegacyStorage` no longer works This means they have a deckPath of `/storage/emulated/0/AnkiDroid` which can no longer be accessed. Their data exists, but cannot be accessed unless: * They restore from AnkiWeb * They have a colpkg * They manually copy the folder over * They install a non-Google-Play copy Options: * Restore from AnkiWeb * Restore folder access (https://github.com/ankidroid/Anki-Android/wiki/Full-Storage-Access) * Restore backup (Hidden - Not Implemented) * Get Help (Link to: Google Group) * Delete collection and create a new one Issue 5304
`getCollectionPath` should be used when the collection is closed
Exception: java.lang.IllegalStateException: Must be called from main thread of fragment host
If a user has uninstalled the app, one of the options should be to restore from a .colpkg Use `ankiDroidDirectoryOverride` as code uses the location in CollectionHelper rather than `col.path`. Defining a temporary collection in `CollectionManager` was deemed to be too challenging Tested with 'Don't keep activities' and failures in the import copy Issue 5304
679a826
to
737f1b0
Compare
Pull Request template
Purpose / Description
If a user uninstalls and selects 'keep data', the user retains access to their preferences, so we retain
deckPath
and can use it to determine if their collection is no longer accessibleIf a user uninstalls AnkiDroid,
preserveLegacyExternalStorage
no longer works.This means they have a deckPath of
/storage/emulated/0/AnkiDroid
which can no longer be accessed.Their data exists, but cannot be accessed unless:
Provide a dialog with options:
(https://github.com/ankidroid/Anki-Android/wiki/Full-Storage-Access)
Fixes
Related: #5304
Approach
How Has This Been Tested?
API 31 emulator, manually with the provided shell script
Checklist