Skip to main content

Android Smart Glasses (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)

  1. BLE Reception: BluetoothManager receives data
  2. Parse & Route: AsgClientService processes JSON
  3. Execute Command: Appropriate manager handles action
  4. Send Response: Status sent back via BLE

Outgoing Messages (Glasses → Phone)

  1. Event Occurs: Button press, status change, etc.
  2. Format Message: Create JSON message
  3. Send via BLE: BluetoothManager transmits
  4. 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

  1. Service Start
    • Initialize managers
    • Setup BLE advertising/connection
    • Start monitoring hardware
  2. Runtime Operation
    • Process incoming messages
    • Handle hardware events
    • Manage network state
    • Upload queued media
  3. 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