The Nudges module is a core behavioral intervention component of the application. It provides users with real-time awareness of their app usage by “nudging” them at specific intervals (e.g., every 20 minutes) or when specific problematic patterns (Insights) are detected.To the user, this manifests as a non-intrusive floating chip or a notification showing the time spent in the current app, accompanied by a motivational follow-up.
When the user opens the Nudges screen, the NudgesViewModel uses a combine operator. It merges the list of installed apps from AppMetadataRepository with the current day’s nudge settings from NudgesRepository. This ensures that if an app is uninstalled or a setting is changed elsewhere, the UI updates reactively.
The NudgeMonitor is the most critical part of the system. It operates outside the UI lifecycle:
App Change: When onForegroundAppChanged is called, it cancels any pending nudges.
Eligibility Check: It verifies if the app is a system app, a launcher, or the “Scrollless” app itself (which are excluded).
Threshold Calculation: It fetches the baselineUsageMs (total time spent in the app today) and calculates the nextThreshold (e.g., if usage is 17m and interval is 10m, the next nudge is at 20m).
Scheduling: It uses a with a delay to wait until the threshold is reached.
When a threshold is hit, the system attempts to show a Floating Chip via NudgeOverlayManager. If overlay permissions are missing, it falls back to a Low-Priority Notification via NudgesNotifier.