fix: guard against ActivityNotFoundException when requesting all-files access#458
Closed
MiMoHo wants to merge 1 commit into
Closed
fix: guard against ActivityNotFoundException when requesting all-files access#458MiMoHo wants to merge 1 commit into
MiMoHo wants to merge 1 commit into
Conversation
handleStoragePermission() falls back to ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION when the app-specific all-files-access screen is unavailable, but that fallback startActivityForResult was not guarded. On devices whose Settings lacks both all-files-access screens (e.g. Android TV) the fallback also throws ActivityNotFoundException, which was uncaught and crashed the app. Wrap the fallback intent launch in its own try/catch and finish() gracefully on failure, mirroring the existing SecurityException branch. Closes FossifyOrg#295
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.
Type of change(s)
What changed and why
On Android 11+ (R+),
SimpleActivity.handleStoragePermission()first launchesSettings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSIONinside atry. If that screen is unavailable it catchesActivityNotFoundExceptionand falls back to the genericSettings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION. That fallbackstartActivityForResultcall was itself unguarded, so on devices whose Settings lacks both all-files-access screens (e.g. Android TV) the fallback also throwsActivityNotFoundException, which propagated uncaught and crashed the app.This matches the issue's logcat exactly: two
ActivityTaskManagerSTART lines (MANAGE_APP_ALL_FILES_ACCESS_PERMISSIONthenMANAGE_ALL_FILES_ACCESS_PERMISSION) followed byFATAL EXCEPTIONNo Activity found to handle Intent { act=android.settings.MANAGE_ALL_FILES_ACCESS_PERMISSION }originating fromhandleStoragePermission$lambda$0.The fix wraps the fallback intent launch in its own
try/catch; on failure it callsfinish()gracefully, mirroring the existingSecurityExceptionbranch directly below. No new imports are required. CHANGELOG updated under the Unreleased### Fixedsection.Tests performed
detekt,lint, unit tests and the build all pass locally (CI-equivalent).startActivityForResult(ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)is now wrapped intry/catch, falling back tofinish()if no matching Settings activity exists (the reportedActivityNotFoundException). This is a defensive guard that can only prevent the crash.Closes the following issue(s)
Checklist
CHANGELOG.md(if applicable).Coded with Opus 4.8 ultracode.