fix(calendar): don't register calendar observer before permission granted #19
Reference in New Issue
Block a user
Delete Branch "fix/calendar-observer-permission-crash"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes the startup crash where the app died instantly on launch whenever calendar access wasn't granted (fresh install / revoked permission).
The repo registers a calendar ContentObserver eagerly in its init block, and an activity-scoped SettingsViewModel (drives the theme) injects it — so the @Singleton is built at launch, above RootScreen's permission gate. Newer Android throws SecurityException when registering an observer on a provider you lack permission for, so the app crashed before the permission screen could appear.
Fix: guard registration behind a calendar-permission check and re-attach the observer lazily on the first calendars()/instances() read (runs once the gate opens). Observer collections are now synchronized.
Verified on-device (debug): permission-denied launch shows the permission screen; granting it proceeds to the calendar with live updates. Unit tests pass.
Cuts release v2.7.1 (CHANGELOG + version bump included).