Repository navigation
fix: catch SecurityException when persisting gallery URI permission - #21
Open
ankit-edii wants to merge 1 commit into
Open
ankit-edii wants to merge 1 commit into
ankit-edii wants to merge 1 commit into
Conversation
makeUriPermissionPersistable called takePersistableUriPermission on Android 11+ with no error handling. Some pickers (GMS-backported photo picker, OEM galleries on Android 11/12) return URIs without a persistable grant, so the call threw SecurityException inside the activity-result callback and crashed the app. Catch the exception and log a warning. The temporary read grant is still there, so the media is processed as it already is on Android 10 and below, where this method does nothing. Fixes ionic-team/capacitor-camera#58 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Description
On Android 11 and up,
IONCAMROpenPhotoPickerActivity.makeUriPermissionPersistablecallsContentResolver.takePersistableUriPermissionwith no error handling. If the picker returns a URI that has no persistable grant, the call throwsSecurityExceptioninside the activity-result callback, and the whole app crashes.This PR wraps the call in
try/catch (SecurityException)and logs a warning. The picker's temporary read grant is still there, so the media is processed the same way it already is on Android 10 and below, where this method does nothing.Context
Fixes ionic-team/capacitor-camera#58
We see this crash in production in a Capacitor app on
@capacitor/camera8.2.1 (ioncamera-android1.0.2) when users callchooseFromGallery. Affected devices run Android 11–12 (SDK 30–32), mostly low-RAM Redmi and realme phones. On these devicesPickVisualMediafalls back to a picker (the GMS-backported photo picker or an OEM gallery) that returns URIs such ascontent://media/external/file/40736, which have no persistable grant. The top frames match the stack trace in the issue:Type of changes
Tests
./gradlew testReleaseUnitTest: 60 tests, 0 failures.io.ionic.libs:ioncamera-android:1.0.2from Maven Central usingjavap -p -c. 76 of the 77 classes are identical.IONCAMROpenPhotoPickerActivitydiffers only by the new try/catch aroundtakePersistableUriPermission, plus constant-pool renumbering. The manifest and resources are unchanged.I left the version bump for your release process.
Checklist
🤖 Generated with Claude Code