Summary
The application relies on a robust background processing system to maintain accurate usage data, enforce limits, and manage notifications without draining the user’s battery. It uses WorkManager for deferrable tasks (like data summarization and cleanup) and BroadcastReceivers to react immediately to system changes (like app installations or device reboots).Overview Diagram
Workers
The app uses WorkManager to handle tasks that must run reliably, even if the app is closed.AppMetadataSyncWorker
What it does: Updates the local database with details about installed applications, such as their names and icons, whenever an app is installed, updated, or removed.| Property | Value |
|---|---|
| Type | OneTime |
| Interval | On Demand (Event-based) |
| Constraints | None |
Trigger
The
AppInstallReceiver detects a package change (install/uninstall) and schedules this worker.Process
The worker reads the package name and action type (Install vs. Uninstall) from the input data.
AppInstallReceiver
DailyProcessingWorker
What it does: Performs end-of-day calculations to summarize usage, compute whether limits were succeeded or failed, and generate “Coach” suggestions for limit adjustments.| Property | Value |
|---|---|
| Type | Periodic |
| Interval | Daily |
| Constraints | None explicit in snippet |
Triggered by: Periodic WorkManager schedule.
UsageStatsWorker
What it does: Fetches raw system usage events (Android UsageStats) and syncs them into the app’s local database for processing.| Property | Value |
|---|---|
| Type | Periodic |
| Interval | Regular intervals (implied) |
| Constraints | None explicit in snippet |
Triggered by: Periodic WorkManager schedule.
CategorySyncWorker
What it does: Fetches and updates app categories (e.g., “Social”, “Productivity”) for installed applications.| Property | Value |
|---|---|
| Type | OneTime (Targeted) or Periodic (Full) |
| Interval | On Demand or Regular |
| Constraints | Network (Implied for fetching categories) |
Triggered by: App installation (targeted) or periodic maintenance.
NotificationBatchWorker
What it does: Delivers a “Post Box” summary notification containing all the notifications that were withheld during a focus session or batch period.| Property | Value |
|---|---|
| Type | OneTime (Scheduled recursively) |
| Interval | User-defined specific times |
| Constraints | None |
Triggered by:
NotificationBatchScheduler (initially via Boot or Settings change).
NotificationRetentionWorker
What it does: Maintains database hygiene by deleting notification logs that are older than the user’s retention setting (default 60 days).| Property | Value |
|---|---|
| Type | Periodic |
| Interval | Daily (Every 24 hours) |
| Constraints | None |
Triggered by: Periodic WorkManager schedule (starts 6 hours after schedule).
Foreground Services
Services that run with a visible notification to ensure the system does not kill them.AppTrackerService
What it does: Monitors the currently active application in real-time to detect when a user opens a restricted app or unlocks the phone.| Property | Value |
|---|---|
| Notification | Required for Foreground Service |
| Starts when | Device Boot or App Launch |
| Stops when | App is force stopped |
Receivers
BroadcastReceivers allow the app to wake up and react to system-wide events.| Receiver | Listens For | What It Does |
|---|---|---|
| BootReceiver | BOOT_COMPLETED | 1. Starts AppTrackerService to resume monitoring.2. Schedules LimitEnforcementWorker for immediate checks.3. Reschedules the NotificationBatchScheduler. |
| AppInstallReceiver | PACKAGE_ADDEDPACKAGE_REMOVEDPACKAGE_REPLACED | 1. Updates the repository immediately for UI responsiveness. 2. Schedules AppMetadataSyncWorker to fetch icons/labels.3. Removes limits if an app is uninstalled. |
Scheduling Flow
This diagram illustrates how theNotificationBatchWorker reschedules itself to create a recurring schedule based on dynamic user settings.