Skip to content

fix: guard takePersistableUriPermission against SecurityException when storing alarm sound#360

Closed
MiMoHo wants to merge 1 commit into
FossifyOrg:mainfrom
MiMoHo:fix/issue-267
Closed

fix: guard takePersistableUriPermission against SecurityException when storing alarm sound#360
MiMoHo wants to merge 1 commit into
FossifyOrg:mainfrom
MiMoHo:fix/issue-267

Conversation

@MiMoHo

@MiMoHo MiMoHo commented Jul 3, 2026

Copy link
Copy Markdown

Type of change(s)

  • Bug fix

What changed and why

Context.storeNewYourAlarmSound() calls contentResolver.takePersistableUriPermission(uri, ...) on the URI returned by the file picker. Some file managers (including cases reported against Fossify Clock) return a content:// URI without a persistable permission grant, so takePersistableUriPermission throws SecurityException and 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 to SecurityException, so it can only prevent the documented crash, never mask unrelated failures. The unused-exception form catch (_: …) follows the existing commons convention.

Tests performed

./gradlew :commons:detekt :commons:lintRelease :commons:assembleRelease all 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

  • I read the contribution guidelines.
  • I manually verified the affected logic.
  • I have self-reviewed my pull request.
  • I understand every change in this pull request.

Coded with Opus 4.8 ultracode.

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
@MiMoHo MiMoHo requested a review from naveensingh as a code owner July 3, 2026 19:49
@MiMoHo MiMoHo closed this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App crashes when selecting file with fossify file manager

1 participant