dilink-auto-android

Phone Client App (app-client)

Overview

The phone client manages VD server deployment, car auto-update, and 3-connection relay. The phone app:

  1. Listens for TCP connections from the car on port 9637 (control, NIO ServerSocketChannel)
  2. Responds to the handshake with device info, vdServerJarPath, and reads targetFps
  3. Compares appVersionName from handshake (with versionCode fallback) — sends UPDATING_CAR and auto-updates car app via dadb if version mismatch
  4. Accepts video (9638) and input (9639) connections from the car after handshake
  5. Deploys vd-server.jar to /sdcard/DiLinkAuto/ and starts VD server (with FPS arg)
  6. Accepts reverse connection from VD server on localhost:19637 (NIO ServerSocketChannel)
  7. Relays H.264 video from VD server to car via the video connection
  8. Relays touch events from car (input connection) to VD server, dispatched on Dispatchers.IO

No screen capture. No MediaProjection. All video comes from the VD server process.

Components

ClientApp

Application class. Creates notification channels (dilinkauto_service, dilinkauto_update), initializes UpdateManager and ShizukuManager on create.

UpdateManager

Self-update mechanism that checks GitHub Releases for new versions.

MainActivity

Entry point with two screens:

ConnectionService

Foreground service that manages the phone-car connection lifecycle with 3 dedicated connections. Auto-starts when the phone app is opened (e.g., via car USB ADB).

VirtualDisplayClient

Accepts reverse connection from the VD server process on localhost:19637. Takes two Connection params: videoConnection and controlConnection.

AdbBridge

Fallback shell command helper. Provides execShell() and execFast() using Runtime.exec() for VD server operations and display power management when direct API reflection fails.

VirtualDisplayManager

Manages app launching on the physical display when VD is not in use. Bridges to InputInjectionService for gesture-based input injection.

VideoEncoder

MediaProjection + MediaCodec H.264 encoder using AUTO_MIRROR virtual display. Alternative encoding path (not used in the primary streaming pipeline which flows through VD server).

FileLog

File-based logger that bypasses Android logcat filtering (HyperOS filters Log.i/d for non-system apps).

Multi-Touch Relay

Touch events arrive from the car via the input connection as CMD_INPUT_TOUCH (0x32) with raw MotionEvent data. The handleInputFrame is dispatched on Dispatchers.IO (not Main) to allow localhost socket writes. The phone streams DOWN/MOVE/UP events with pointerId directly to the VD server, which handles full MotionEvent construction with all active pointers.

Permissions Required

Permission Purpose
MANAGE_EXTERNAL_STORAGE All Files Access for sdcard deployment of VD JAR
Accessibility Service Touch injection on virtual display via dispatchGesture (no event monitoring)
Notification Access Forward notifications to car (with progress)
Shizuku API Elevated shell access for ADB-free VD server deployment and silent self-update
QUERY_ALL_PACKAGES App launcher grid
REQUEST_INSTALL_PACKAGES Car app auto-update via dadb

Dependencies