feat: no longer implicitly set collection path when DB is used - #21343
Conversation
cbe4d38 to
f86073c
Compare
Yes, please do this. |
f86073c to
33b2d1a
Compare
CollectionManager to :anki-commonBreaking change, this was previously done on first collection access. Now this is set in AnkiDroidApp, and reading throws StorageNotConfiguredException beforehand. This contains a workaround for the OS-level bug: `SystemStorageException` if the exception is caught, it is explicitly rethrown. This is preparation for a full 'storage decision' screen during onboarding * Part of 19552 * Part of 13574 * Part of 20737 Assisted-by: Claude Fable 5
The decision now mirrors whether `getCurrentAnkiDroidDirectory` is usable or throws. The path is set during startup (`ensureCollectionPathSet`), so `Undecided` is only observable if startup storage initialization failed. This is now classified as an `InitializationError` and displayed in the app startup flow (with a TODO for 19552 to improve this). * Part of 19552 * Part of 13574 Assisted-by: Claude Fable 5
33b2d1a to
9ac0a08
Compare
BrayanDSO
left a comment
There was a problem hiding this comment.
I like the path that is being taken. It makes easier to reason with the initialization logic
| CollectionHelper.storageDecisionTestOverride | ||
| ?: AnkiDroidApp.sharedPrefsOrNull()?.let { CollectionHelper.storageDecision(it) } | ||
| // test-only: in-memory test collections have no preferences and read no path | ||
| ?: if (isRunningAsUnitTest) { | ||
| StorageDecision.Decided | ||
| } else { | ||
| // the app instance is unset: treat this as a bug. | ||
| throw IllegalStateException("Collection accessed before AnkiDroidApp was initialized") | ||
| } |
There was a problem hiding this comment.
nit: maybe this logic should be under CollectionHelper. Maybe not. Sometimes the distinction between CollectionHelper and CollectionManager isn't clear.
ericli3690
left a comment
There was a problem hiding this comment.
Looks fantastic!! Merge at will
| * @param preferences the preferences the collection path will be read from: pass the same | ||
| * (profile) context's preferences as the [getCurrentAnkiDroidDirectory] call being gated | ||
| * | ||
| * TODO: What if a user revokes full storage? |
There was a problem hiding this comment.
To confirm, this TODO will not be a problem once the dedicated setup flow is created and rolled out, right? Should it be added to the issue this PR is linked to?
| * Ensures [CollectionHelper.PREF_COLLECTION_PATH] is set, choosing and persisting | ||
| * [getDefaultAnkiDroidDirectory] if it is unset. | ||
| * | ||
| * This decides the storage location on the user's behalf: until a storage setup flow exists |
There was a problem hiding this comment.
nit:
| * This decides the storage location on the user's behalf: until a storage setup flow exists | |
| * This is a *temporary* function that decides the storage location on the user's behalf, and will be in place until a storage setup flow exists |
As I understand it this function is a stopgap until a full storage setup flow exists. I worked with the external permissions stuff a bit a while ago but have now forgotten how it worked; it took me a while to remember / realize that this collection-path-setting method is temporary, perhaps flag that stopgap nature more explicitly in the docstring. Feel free to ignore, might just be me haha
Note
Assisted-by: Claude Fable 5
Purpose / Description
getCurrentAnkiDroidDirectoryvia moving storage initialization intostartup/SetupStorage.ktFixes
full(F-Droid/GitHub) releases users to grant theAll files accesspermission #13574Approach
storageDecision()based on whether the collection path is setstorageDecisionisn't setAnkiDroidAppgetCurrentAnkiDroidDirectoryno longer sets the collection path; throwingStorageNotConfiguredExceptionensureOpenInneralso throwsI maintained
SystemStorageExceptionfor the OS-level errors ifcontext.getExternalFilesDirreturns nullHow Has This Been Tested?
Unit tested
Checklist