fix: guard takePersistableUriPermission against SecurityException when storing alarm sound#360
Closed
MiMoHo wants to merge 1 commit into
Closed
fix: guard takePersistableUriPermission against SecurityException when storing alarm sound#360MiMoHo wants to merge 1 commit into
MiMoHo wants to merge 1 commit into
Conversation
Picking a custom alarm/timer sound via a file manager that answers ACTION_OPEN_DOCUMENT with a plain content:// uri (only a one-time read grant, no persistable grant) made storeNewYourAlarmSound() crash: contentResolver.takePersistableUriPermission() threw an uncaught SecurityException that propagated up through the host app's onActivityResult. The selected sound is already saved to baseConfig.yourAlarmSounds before this call, so wrapping only the takePersistableUriPermission() call in a try/catch keeps the sound selected and playable for the current session while preventing the crash. Benefits every app that uses SelectAlarmSoundDialog (Clock, Calendar). Fixes FossifyOrg/Clock#267
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
Context.storeNewYourAlarmSound()callscontentResolver.takePersistableUriPermission(uri, ...)on the URI returned by the file picker. Some file managers (including cases reported against Fossify Clock) return acontent://URI without a persistable permission grant, sotakePersistableUriPermissionthrowsSecurityExceptionand the app crashes when the user picks a custom alarm/timer sound.Fix: wrap the call in a
try/catch (_: SecurityException). The sound URI is still stored; only the (best-effort) persistable-permission grab is guarded. The catch is scoped narrowly toSecurityException, so it can only prevent the documented crash, never mask unrelated failures. The unused-exception formcatch (_: …)follows the existing commons convention.Tests performed
./gradlew :commons:detekt :commons:lintRelease :commons:assembleReleaseall pass locally. This is a defensive guard around a call that currently throws in the reported scenario; by construction it cannot change behavior except to avoid the crash.Related issue(s)
Checklist
Coded with Opus 4.8 ultracode.