How android/connectivity-samples works
Project type and purpose
• UwbRanging is an Android sample app demonstrating Ultra-Wideband (UWB) ranging.
• It comprises two Gradle modules:
• app – the Android application, UI, ViewModels, settings.
• uwbranging – a Kotlin library providing UWB session management via Google’s Nearby Connections.
File structure
• Top-level modules:
• uwbranging/… – core library with connectors (NearbyConnections, OOB), UwbConnectionManager, session scope, proto definitions, tests.
• app/… – Android app with HelloUwbApplication, AppContainer (dependency-injection), SettingsStore (Proto DataStore), UwbRangingControlSource, UI code under ui/, individual screens & ViewModels.
• Notice MVVM pattern in app and a repository-style control-source interface.
• Proto files: appsettings.proto (app settings) and uwbinfo.proto (UWB session info).
Main components
A. Android App (module: app)
• UI Layer
– HelloUwbApp.kt (Compose host)
– Screen composables under ui/home, ui/control, ui/send, ui/settings, ui/ranging.
• ViewModel Layer
– HomeViewModel, ControlViewModel, SendViewModel, SettingsViewModel, RangingViewModel.
• AppContainer (dependency injection)
– Provides instances of SettingsStore, UwbRangingControlSource, UwbRangingControlSourceImpl.
• Data Layer
– SettingsStore (Proto DataStore) → persists user settings.
– UwbRangingControlSource interface → abstract control API.
– UwbRangingControlSourceImpl → delegates to UwbConnectionManager in uwbranging module.
B. UWB Library (module: uwbranging)
• UwbConnectionManager (session orchestration)
• UwbEndpoint, EndpointEvents, UwbSessionScope (lifecycle)
• Impl sub-package:
– NearbyConnections & connectors (NearbyConnector, NearbyControllerConnector, NearbyControleeConnector, OobConnector).
– UwbConnectionManagerImpl, UwbOobEvent, UwbSessionScopeImpl
• Proto definitions (uwbinfo.proto) describing messages sent over Nearby Connections.
C. External Dependencies
• Google Nearby Connections API
• Android UWB hardware & platform APIs
• Proto DataStore (Jetpack DataStore)
• Jetpack Compose UI toolkit
Relationships and data flow
• UI → ViewModel: user events, callbacks (Compose calls).
• ViewModel → AppContainer: obtains control-source & settings store.
• ViewModel → SettingsStore: read/write settings.
• ViewModel → UwbRangingControlSource API: start/stop ranging, send data.
• UwbRangingControlSourceImpl → UwbConnectionManager (library): orchestrates NearbyConnections sessions.
• UwbConnectionManager → connectors → Google Nearby Connections → UWB radio transport.
• NearbyConnections → data arrives → UwbConnectionManager → callbacks → UI layer via Flow/LiveData.
Architectural patterns and principles
• MVVM – clear separation of UI (Compose) and business logic (ViewModels).
• Dependency injection via AppContainer.
• Repository/Control-Source pattern – exposes a simple interface to the UI.
• Modularization – decoupling app-specific UI from core UWB library.
• Proto DataStore – type-safe settings persistence.
Putting it all together
• Settings flow: SettingsStore ↔ Proto DataStore.
• Message formats (appsettings.proto, uwbinfo.proto).