๐Ÿ—๏ธ 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

DomainWhat It Does
ADB LifecycleStarts ADB server, connects device, sets up reverse port forwarding
Server InfrastructureRuns four TCP/WebSocket servers that Android components connect to
JAR DeploymentLocates, pushes, and launches the Logic Engine on the device
APK ManagementDetects, installs, and starts the companion APK service
RenderingEmbeds scrcpy windows as native Win32 child windows inside Flutter
UIBoot screen, home screen, app drawer, taskbar, reconnection overlay
ReconnectionMonitors connection state; auto-heals without user restart
Device SelectionAuto-detects ADB devices; shows picker dialog when needed

Communication (Inbound โ€” from Android)

ServerProtocolFromPurpose
JAR ServerRaw TCP + JSONLogic Engine (JAR)Commands, status, handshake (jar.hello)
APK ServerWebSocket + JSONFeature Hub (APK)Telemetry, notifications, handshake (apk.hello)
Media Data ServerWebSocketFeature HubMedia session metadata + artwork
Notification ServerWebSocketFeature HubNotification stream

Communication (Outbound โ€” to Android)

ChannelProtocolPurpose
ADB CommandsProcess executionDevice setup, APK install, service start
ADB Pipe (JAR launch)adb shell app_processBoot the Logic Engine process
ADB Reverseadb reverse tcp:PORTBridges Android โ†’ Windows TCP ports
scrcpy channelIPCVideo 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

FeatureHow
Volume ControlDirect AudioManager stream access at shell level
App LaunchActivityManager.startActivity() with flags for foreground
App KillActivityManager.forceStopPackage()
Screen Wake/SleepPowerManager + WakeManager invocation
Display InteractionDirect 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

FeatureAPI Used
Notification StreamingNotificationListenerService
Media SessionMediaSessionManager โ€” title, artist, artwork, state
Battery TelemetryBatteryManager broadcast receiver
Device StatesWi-Fi, Bluetooth, Mobile Data, Airplane, Mute, Rotation, Location, Torch
Permission StatusRuntime permission check + severity reporting
Volume CommandsAudioManager 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 ยป