The Unescapable Digital Detox Solution
FocusLock is a high-security productivity application engineered to enforce genuine digital disconnects. Unlike standard blocking apps that are easily bypassed via task managers or system gestures, FocusLock leverages low-level Android APIs and a specialized hybrid architecture to ensure total compliance during detox sessions.
| Setup Checklist | Detox Timer | Penalty Modes | Lock Screen |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
| Ensures Permissions | Set your goal | Choose your trap | No Escape |
FocusLock is not just a Flutter UI; it is a native Android enforcer wrapped in a modern Dart shell. We utilize high-performance MethodChannels to bridge the Flutter framework directly with Android's WindowManager, AudioManager, and DevicePolicyManager.
We implemented a defense-in-depth strategy to prevent bypass attempts:
- System Alert Window Overlay: A
TYPE_APPLICATION_OVERLAYview is injected directly into the Window Manager stack, detectingonPauselifecycles (e.g., floating windows or split-screen attempts) and instantly occluding the screen. - Touch Event Interception: A custom Accessibility Service (
FocusLockAccessibilityService) runs at the system level to intercept and consume specificKeyEventsignals. - Gesture Exclusion Rects: We programmatically set
systemGestureExclusionRectsto nullify Android 10+ edge-swipe "Back" gestures.
To prevent users from silencing alarms during a session:
- Audio Focus Seizure: The app programmatically forces the
STREAM_MUSICchannel to logical maximum on session start. - Input Consumption: The Accessibility Service actively listens for
KEYCODE_VOLUME_DOWNandKEYCODE_VOLUME_MUTE. These events are "eaten" (consumed) before they reach the OS, rendering the physical volume buttons inert.
FocusLock requests Device Admin privileges to invoke startLockTask(), putting the device into a pinned state that disables the Status Bar, Notification Shade, and Home Button.
- Frontend: Flutter (Dart 3.x) - Null Safety, Material 3 Design
- Backend Enforcer: Kotlin - Android Native Development Kit
- State Management:
ListenableBuilder/ChangeNotifierservice pattern. - Sensors:
sensors_plusfor Accelerometer-based "Gravity Trap".
Due to the aggressive nature of the locking mechanism, FocusLock requires sensitive permissions. A built-in Setup Checklist Dialogue ensures these are granted before use:
- Display Over Other Apps (
SYSTEM_ALERT_WINDOW): To block floating windows. - Device Admin (
BIND_DEVICE_ADMIN): To enable Screen Pinning. - Accessibility Service (
BIND_ACCESSIBILITY_SERVICE): To block Recents/Home gestures and Volume buttons.
FocusLock is designed for Android.
# Clone the repository
git clone https://github.com/Priyanshu-x/focuslock.git
# Install Dependencies
flutter pub get
# Run on Device (Release Mode recommended for full performance)
flutter run --releaseThis application demonstrates advanced usage of Android System APIs and should be used responsibly.




