* FocusModeApiImpl.kt implements the Pigeon-generated FocusModeHostApi interface.
* enableDndMode() sets INTERRUPTION_FILTER_PRIORITY with a policy allowing alarms and calls from starred contacts.
* disableDndMode() restores INTERRUPTION_FILTER_ALL.
* hasDndPermission() checks isNotificationPolicyAccessGranted.
* requestDndPermission() opens ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS.
* A separate FocusOverlayService.kt manages the SYSTEM_ALERT_WINDOW overlay shown when a blocked app is detected during a focus session.
* The overlay is a minimal UI showing a motivational message and a "Return to Habit" button, styled with Material You colors read from system resources.
* The overlay uses WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY.
* A focus foreground service keeps the app process alive during the session and provides a persistent notification with the remaining time.
* The foreground notification updates every minute with the elapsed time.
* All native methods include try-catch blocks to prevent crashes from propagating to Flutter.
gherkin
Given the Kotlin FocusModeApiImpl is registered
When Flutter invokes enableDndMode with valid permission
Then the device enters Do Not Disturb priority mode and only alarms and starred contact calls ring through
Given DND mode has been enabled by the focus session
When Flutter invokes disableDndMode at session end
Then the device returns to normal notification mode with all notifications delivered
Given the user opens a blocked app during a focus session
When the overlay service detects the blocked app in the foreground
Then a system overlay appears on top of the blocked app with a motivational message
Given the overlay is displayed and the user taps "Return to Habit"
When the tap is processed
Then the overlay is dismissed and Habit is brought to the foreground
Given the focus foreground service is running
When 5 minutes of a 25-minute session have elapsed
Then the persistent notification displays "Focus Mode: 20 minutes remaining"
Given the focus session ends
When the foreground service and overlay service are stopped
Then both services terminate cleanly, persistent notifications are removed, and DND mode is restored to the previous state
Details and Assumptions
Acceptance Criteria