๐๏ธ Architecture
March 29, 2026 ยท View on GitHub
โ Back to README
Deep-dive into how Android DEX distributes responsibilities across its three-layer system. This document covers the design rationale, communication channels, and data flow between each layer.
Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ WINDOWS SIDE โ
โ Flutter UI ยท ADB Lifecycle ยท Server Infrastructure ยท Scrcpy โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโ
โ TCP Socket โ WebSocket
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โก Logic Engine โ โ ๐ฑ Feature Hub (APK) โ
โ Java JAR โ โ Kotlin Service โ
โ ADB Shell Context โ โ Android System Context โ
โโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Both Android-side components connect back to the Windows side โ the Windows app runs the servers; Android clients connect to them.
Layer 1 โ Windows Side
Role: Orchestrator, UI host, server infrastructure, and rendering engine.
Responsibilities
| Domain | What It Does |
|---|---|
| ADB Lifecycle | Starts ADB server, connects device, sets up reverse port forwarding |
| Server Infrastructure | Runs four TCP/WebSocket servers that Android components connect to |
| JAR Deployment | Locates, pushes, and launches the Logic Engine on the device |
| APK Management | Detects, installs, and starts the companion APK service |
| Rendering | Embeds scrcpy windows as native Win32 child windows inside Flutter |
| UI | Boot screen, home screen, app drawer, taskbar, reconnection overlay |
| Reconnection | Monitors connection state; auto-heals without user restart |
| Device Selection | Auto-detects ADB devices; shows picker dialog when needed |
Communication (Inbound โ from Android)
| Server | Protocol | From | Purpose |
|---|---|---|---|
| JAR Server | Raw TCP + JSON | Logic Engine (JAR) | Commands, status, handshake (jar.hello) |
| APK Server | WebSocket + JSON | Feature Hub (APK) | Telemetry, notifications, handshake (apk.hello) |
| Media Data Server | WebSocket | Feature Hub | Media session metadata + artwork |
| Notification Server | WebSocket | Feature Hub | Notification stream |
Communication (Outbound โ to Android)
| Channel | Protocol | Purpose |
|---|---|---|
| ADB Commands | Process execution | Device setup, APK install, service start |
| ADB Pipe (JAR launch) | adb shell app_process | Boot the Logic Engine process |
| ADB Reverse | adb reverse tcp:PORT | Bridges Android โ Windows TCP ports |
| scrcpy channel | IPC | Video stream, input injection |
Layer 2 โ Logic Engine (Java JAR)
Role: Shell-level command executor running with elevated ADB daemon privileges.
Why a JAR?
The Android APK layer cannot access certain low-level system APIs due to Android's permission model. The JAR, launched via adb shell app_process, executes at the ADB shell user level โ the same level that allows setenforce, input keyevent, volume manipulation via AudioService, and control over the ActivityManager without launcher process restrictions.
Responsibilities
| Feature | How |
|---|---|
| Volume Control | Direct AudioManager stream access at shell level |
| App Launch | ActivityManager.startActivity() with flags for foreground |
| App Kill | ActivityManager.forceStopPackage() |
| Screen Wake/Sleep | PowerManager + WakeManager invocation |
| Display Interaction | Direct display state manipulation |
Lifecycle
Windows Side locates androiddex.jar locally
โ
โผ
adb push โ uploads to /data/local/tmp/ on device
โ
โผ
adb shell app_process โ JAR entry point executes
โ
โผ
JAR opens TCP connection back to Windows Server
โ
โผ
JAR sends: {"type":"jar.hello"} โ handshake confirmed
โ
โผ
Windows marks JarManager.jarReady = complete โ
JAR progress bar reaches 1.00
Layer 3 โ Feature Hub (Kotlin APK)
Role: Permission-holding daemon for all telemetry and high-level Android APIs.
Why a separate APK?
Unlike the JAR, the APK runs in the Android application context, giving it access to listener APIs that require app registration: NotificationListenerService, MediaSessionManager, Bluetooth callbacks, and BIND_ACCESSIBILITY_SERVICE. These cannot be accessed from a bare shell process.
Responsibilities
| Feature | API Used |
|---|---|
| Notification Streaming | NotificationListenerService |
| Media Session | MediaSessionManager โ title, artist, artwork, state |
| Battery Telemetry | BatteryManager broadcast receiver |
| Device States | Wi-Fi, Bluetooth, Mobile Data, Airplane, Mute, Rotation, Location, Torch |
| Permission Status | Runtime permission check + severity reporting |
| Volume Commands | AudioManager from app context |
Lifecycle
Windows Side checks if APK is installed (pm list packages)
โ
โโ Not installed โ adb install โ installs APK
โ
โผ
adb shell am start โ launches ServerStartService intent
โ
โผ
APK opens WebSocket connection back to Windows APK Server
โ
โผ
APK sends: {"type":"apk.hello"} โ handshake confirmed
โ
โผ
Windows marks ApkServer.apkReady = complete โ
APP progress bar reaches 1.00
System fully synchronized โ Desktop UI unlocked
Data Flow Diagram
Android Device Windows PC
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
JAR (TCP Client) โโโโโโโโโโโโโโโโโโโโโโโบ JAR Server (TCP Listener)
โ
โผ
AndroidCore State Store
โ
APK (WebSocket Client) โโโโโโโโโโโโโโโโโบ APK Server (WS Listener) โ
โ โผ
Media Events โโโโโโโโโโโโโโโโโโโโโโโโโโโบ Media Server Flutter UI
โ (reads state,
Notification Events โโโโโโโโโโโโโโโโโโโโบ Notify Server responds to
โ ValueNotifiers)
scrcpy stream โโโโโโโโโโโ Win32 โ Flutter embedded window (H.264)
โ Back to README ยท Boot Flow ยป ยท Modules ยป