← back

CONTROL

2024

CTO & Android Engineer

A high-restriction Android application that enforces sleep schedules by making doom-scrolling genuinely uncomfortable. Unlike standard app blockers that can be dismissed in a tap, CONTROL draws an un-bypassable system-level overlay with a 60-second breathing timer — backed by a watchdog stack that survives Android's aggressive background process killing.

KEY METRIC

Sub-100ms app detection latency with near-zero CPU usage at idle

Stack

KotlinJetpack ComposeAccessibilityServiceWorkManagerSupabaseStripeRoomForeground Services

Overview

CONTROL operates on a "contract" system — users commit to a sleep schedule, and the app enforces it. The detection engine uses an AccessibilityService listening to TYPE_WINDOW_STATE_CHANGED events rather than polling, achieving instant detection with near-zero CPU cost.

When a monitored app (TikTok, Instagram, YouTube) is opened during restricted hours, a TYPE_APPLICATION_OVERLAY window is drawn at the system level. It captures all KEYCODE_BACK hardware events, applies FLAG_SHOW_WHEN_LOCKED, and runs a 60-second countdown the user cannot dismiss. After 60 seconds the user consciously chooses to Honor (the blocked app is killed) or Bypass (it launches, and the bypass is logged).

Architecture

Monitored App(TikTok etc.)AccessibilityServiceDetection EngineOverlaySessionManagerPauseOverlayServiceWatchdog(WorkManager)Room DBAudit LogSupabaseCloud Sync

System architecture overview

Technical Challenges

Android OS Battery Aggression

Android 12+ aggressively kills background processes. Built a 3-tier defense: FOREGROUND_SERVICE_SPECIAL_USE permission, a PowerManager.PARTIAL_WAKE_LOCK, and a 15-minute WorkManager heartbeat that silently restarts killed services.

Closing Every Bypass Loophole

Users could circumvent a standard overlay via the Back button, Home button, or by locking the screen. Escalated to TYPE_APPLICATION_OVERLAY, consumed all KEYCODE_BACK events at the window level, applied FLAG_KEEP_SCREEN_ON and FLAG_SHOW_WHEN_LOCKED — closing all hardware bypass paths.

Infinite Overlay Loop Prevention

Returning from a bypassed app re-triggered the AccessibilityService, trapping users in endless 60-second loops. Engineered a 3-phase state machine (OverlaySessionManager) that drops new triggers while a countdown is active, whitelists bypassed apps, and auto-flushes the whitelist on home screen navigation.

View on GitHub ↗Live Demo ↗