fix: show permission screen for missing storage access#21280
Draft
onurds wants to merge 1 commit into
Draft
Conversation
|
First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose / Description
Shortcuts and share intents can currently fail when AnkiDroid is missing the required collection storage permission. Instead of guiding the user through the existing permission screen, some flows show a toast or can crash when startup continues without permission.
This can happen after the permission is manually revoked, Android removes it after long inactivity, or the app is opened through a shortcut or share target before permission is granted again.
I saw that there is broader planned work in #21204 to improve collection creation and startup permission handling. That work should give this area a cleaner long term shape, but it is larger architecture work. This PR is a smaller fix that can stay in place until that refactor lands.
Fixes
Approach
Replaced the toast only missing permission handling with the existing
PermissionsActivityflow.For activities that require collection access during startup, missing permission now opens the permission screen and postpones the original target intent through
DeckPickeruntil startup completes.The previous activity is finished immediately, which avoids partially initialized screens such as Card Browser continuing lifecycle work without the expected startup state.
Intent handlers now use the same folder permission check as startup and route missing permission cases through
PermissionsActivity.For external share intents with stale
content://grants,DeckPickernow catchesSecurityExceptionwhen attempting to resume the deferred intent.This prevents the app from crashing.
In that rare case the user may land on the home screen after granting permission and can retry the share action.
How Has This Been Tested?
CardBrowserTest.startupFromCardBrowserActionItemShouldOpenPermissionsActivityIfNoPermissions,IntentHandlerPermissionTest,IntentHandlerTest.:AnkiDroid:ktlintMainSourceSetCheck,:AnkiDroid:ktlintTestSourceSetCheck.git diff --check.Screenshots
N/A. This uses the existing permission screen.
Checklist