Android Architecture (MVP)
Components
MainActivity: minimal UX (Connect, Disconnect, Import Bundle, state/log display).ShadowNetVpnService: AndroidVpnServiceowner of TUN lifecycle.AgentService: foreground background runtime supervisor.SingBoxController: writes/uses config path, starts/stops/restarts sing-box.Bridge: Kotlin -> Go bridge entry points.StateRepository: persisted connection state for UI and restart resilience.Logs: bounded local-only in-memory log stream.
Control Flow
- UI requests connect.
- VPN permission is requested/granted.
ShadowNetVpnServiceestablishes TUN.AgentServicestarts Go loop viaBridge.StartAgent(config).- Go loop selects profile and renders config file.
SingBoxControllerstarts sing-box process with rendered config.AgentServicemonitors status and restarts sing-box with bounded retries.
Go Bridge Contract
Exported in pkg/mobilebridge:
StartAgent(config string)StopAgent()ImportBundle(path string) errorGetStatus() string
The status payload is JSON and consumed by StateRepository.
Safety Design
- Fail-safe fallback on bridge/orchestrator/sing-box failures.
- No remote telemetry.
- Local encrypted state via existing profile/template stores.
- Optional Pi orchestration remains non-blocking.