ASG Client Architecture
Overview
The ASG Client is an Android application that runs on smart glasses, acting as the bridge between hardware capabilities and the MentraOS ecosystem.System Architecture
Core Components
AsgClientService
The main Android service that coordinates all functionality:Manager Pattern
The client uses interface-based managers for device abstraction:Factory Pattern
Managers are created via factories based on device type:Message Flow
Incoming Messages (Phone → Glasses)
- BLE Reception: BluetoothManager receives data
- Parse & Route: AsgClientService processes JSON
- Execute Command: Appropriate manager handles action
- Send Response: Status sent back via BLE
Outgoing Messages (Glasses → Phone)
- Event Occurs: Button press, status change, etc.
- Format Message: Create JSON message
- Send via BLE: BluetoothManager transmits
- Phone Relay: Mobile app forwards to cloud
Command Processing
MCU Commands
Commands from the microcontroller (hardware events):Cloud Commands
Commands from MentraOS Cloud (via phone):Service Lifecycle
-
Service Start
- Initialize managers
- Setup BLE advertising/connection
- Start monitoring hardware
-
Runtime Operation
- Process incoming messages
- Handle hardware events
- Manage network state
- Upload queued media
-
Service Stop
- Clean up resources
- Stop active streams
- Save state for restart
Threading Model
- Main Thread: UI operations, service lifecycle
- BLE Thread: Bluetooth communication
- Network Thread: WiFi operations, uploads
- Camera Thread: Media capture operations
State Management
The service maintains state for:- Connection status (BLE, WiFi)
- Active operations (streaming, recording)
- Hardware state (battery, temperature)
- Configuration (button modes, settings)
Error Handling
- Graceful Degradation: Fallback behaviors for failures
- Retry Logic: Automatic retry for network operations
- State Recovery: Restore after service restart
- User Feedback: Status messages via BLE