Repository navigation
Agents
The implementation guide for anyone, agent or person, working in this repository.
OpenWatch is the devices half of OpenVitals: the Wear OS watch app (:wear), the
phone-to-watch link (:wearlink), and a phone app (:app) that pairs Garmin and Wear OS
watches, a Xiaomi S400 scale and devices of the Bluetooth standard health profiles (a heart
rate strap), writes what they record to Health Connect, and manages them. OpenVitals is the dashboard. The two share no code at run time; this repository's
device code was copied from OpenVitals 2.16.0 and adapted at a few seams
(docs/engineering/architecture.md lists them).
Health Connect's data origin is the writing app's package, so a record OpenVitals wrote cannot be edited here, nor the reverse. Both apps may be installed side by side.
-
app/src/main/kotlin/tech/mmarca/openwatch/— the shell: the application, the activities, the navigation, the Hilt root (docs/engineering/architecture.md, Phone modules).-
features/home/HomeRoute.kt— Home's route, which fills Home's slots with each family's section; every screen is a module underfeature/(below). -
data/repository— what joins a device family's own contract to:core:data: the Garmin and scale tables over their DAOs, the Garmin and Wear OS preferences overOpenWatchPreferences. -
di/— the Hilt modules.DevicesModulebinds what every family shares and the rules across families (the classifiers' order); each family binds itself in its own module. The device layer itself is the modules underdevices/(below); the app holds none of it.
-
-
feature/healthconnect(:feature:healthconnect) — the Health Connect setup screen and the health data list, which the app's rationale activity shows. A screen module: it names no device family and not the app; what only the app has (its activities) comes in as a callback. -
feature/connectedapps(:feature:connectedapps) — the apps that use OpenWatch over OpenLink: allow, block, the switches per capability, forget. It depends on:link-host. -
feature/settings(:feature:settings) — Settings and the body profile, with its exchange with OpenVitals over OpenLink (:link-host). The version name comes in through Hilt (@AppVersionName). -
feature/home(:feature:home) — Home's frame: a slot for each family's section, which the app'sfeatures/home/HomeRoutefills, Health Connect's and Settings' rows, and the empty side of the list-detail layout. -
feature/device(:feature:device) — the screens every device family shares, which name none: the device route and the device screen with the generic panel, Home's watch list with the add-a-watch flow and its "Other devices" section with the app's own add flow, a sync's summary, the phone's notifications on the watch (the apps that send, which every watch's panel opens), and the contributions a family's screens plug in through (features/device/DeviceContributions.kt). Its test fixture isrouteHandle(), a route's SavedStateHandle for a ViewModel test. -
feature/watches-wearos(:feature:watches-wearos) — the Wear OS watch's screens: its panel in the device screen and its pairing in the add-a-watch flow, bound under the family's name (WearOsFeatureModule). It depends on:devices:wearosand:feature:device. -
feature/scales-xiaomi(:feature:scales-xiaomi) — the S400 scale's screens: Home's scale section with its add flow, and the scale's own destination, bound under the family's name (XiaomiScaleFeatureModule). It depends on:devices:xiaomiand:feature:device. -
feature/watches-garmin(:feature:watches-garmin) — the Garmin watches' screens: their panel in the device screen and their pairing in the add-a-watch flow, bound under the family's name (GarminFeatureModule), and the screens the panel opens (the data, the alarms, the settings tree, the point), whose routes it declares; the notifications' apps are:feature:device's. It depends on:devices:garminand:feature:device. -
core/model(:core:model) andcore/fit(:core:fit) — pure Kotlin on the JDK, with the app's package names:domain/model,domain/preferencesandcore/geoin the first, the FIT codeccore/fitin the second. The unit-system provider that reads the platform's locale data is the app's (core/presentation/LocaleUnitSystemProvider).:core:modelalso holds the plain values the device protocols read from the platform sources (WeatherSnapshot,NotificationMsg),runSuspendCatching, the injectedDispatcherProviderand the@ApplicationScopequalifier. Its test fixture isMainDispatcherRule, which every screen's state holder tests run under. -
core/devices-api(:core:devices-api) — the device contracts indevices/core, pure Kotlin:DeviceFamilyandDeviceFamilies,DeviceFeature, live readings, the classifiers,BleUuids,WatchPairingPort,CompanionPresenceObserver, the sync port and its outcome and failure types, the auto-sync interval,SyncWakeLock, the record id salt, and the registry as a device sees it (data/repository/contract/DeviceRegistry, whichBleDeviceRepositoryimplements). Its test fixtures are the shared fakes (FakeDeviceSyncPort,FakeWatchPairing,FakeDeviceFamily,FakeDeviceRegistry). -
devices/core(:devices:core) — the platform half every device family shares, an Android library indevices/core's packages: the radio lease,DeviceLog, the GATT link (GattLink: the dial and its redial, the MTU, discovery, notifications, writes) and the BLE scanner (BleScanner), companion pairing and its service (OpenWatchCompanionDeviceService, in the module's manifest), and the sync controller, its schedule, worker, budget and wake lock; and the phone's sources a watch relays, each in its own package: the notification listener, its filter and the wrist actions every family carries out on the phone (devices/notifications, withWatchNotificationPrefsStore), the media sessions (devices/media), the weather broadcasts (devices/weather) and the CoMaps guidance feed (comaps); the BLE discovery scan the add-a-device flows share (sensors/ble); the FIT activity file import (activityimport) and the app's foreground gate (core/performance/AppForegroundGate). Its test fixtures areFakeSharedPreferences,testSeal()andactivityimport/FitTestFiles, which the device modules' tests and the app's share. -
devices/garmin(:devices:garmin) — the Garmin watches' platform half, a device module: the GATT client overGattLink, the radio, notification and settings links, the relays, the stores, the file import into Health Connect, the onboarding, the family, the find-phone notification's strings and receiver, andGarminModule, which binds its family, sync port, radio, notification bridge and stores. Its tables' contracts (GarminWellnessRepository,GarminSleepMinuteRepository) and its one preference (GarminActivityPreferences) are its own; the app implements them. -
devices/wearos(:devices:wearos) — the phone side of the watch app, a device module: the RFCOMM link and its session cache, the series sync and its Health Connect mapping, the relay of the phone's notifications to the watches switched on for them and the phone's own RFCOMM listener for the wrist's actions on them, the onboarding, the family, the link states' strings, andWearOsModule, which binds its family, sync port, node port, notification sink and startup actors. The preferences it reads are its own contract (WearOsSyncPreferences);OpenWatchPreferencesimplements it. -
devices/xiaomi(:devices:xiaomi) — the S400 scale's platform half, a device module: the scan, the receiver and the listening service (in its manifest), the listener and its worker, the store, the pipeline to Room and Health Connect, the strings its notification shows, andXiaomiScaleModule, which binds its family, ports and store. The weigh-in table's contract (ScaleWeighInRepository) is its own; the app implements it over:core:data's DAO. -
core/data(:core:data) — what the phone keeps: the Room database (data/local, its schemas incore/data/schemas), the registry (BleDeviceRepository), the per-device state,OpenWatchPreferencesand the body profile. It depends on no device family. Its test fixtures are the registry and the body profile in memory (FakeDeviceDao,testDeviceRepository(),FakeBodyProfilePreferences). -
core/ui(:core:ui) — what every screen shares: the theme and the shared components (ui/theme,ui/components), the formatters andScreenError(core/presentation) and the OS permission checks (core/permissions). It knows no device family. -
core/health(:core:health) — Health Connect as the app reaches it, inhealthconnect/:HealthConnectGateway, the one class that touches the client,ActivityRecordWriter, the activity write path copied from OpenVitals, the sync gate, the intents andHealthDataCatalog; and indata/repositorythe record sinkImportedRecordRepositoryandActivityWriteRepository. It implements:core:health-api. -
core/health-api(:core:health-api) — how the devices talk to Health Connect, as contracts: the record sinkHealthRecordStoreand its write helpers (ImportedRecordWrites), the strict readsHealthConnectReads, the paused-sync exception and the rate-limit check. An Android library, since the records are Health Connect's types. Its test fixture isFakeHealthRecordStore. The gateway andImportedRecordRepositoryimplement it in:core:health. -
devices/garmin/protocol(:devices:garmin:protocol) — the Garmin protocol, pure Kotlin withexplicitApi()and the app's package names: bytes, COBS, GFDI, protobuf, the multi-link transport, the session, file sync, the uploads and the FIT wellness decoder. Its test fixtures hold the FIT test bytes the app's import tests use. -
devices/xiaomi/protocol(:devices:xiaomi:protocol) — the S400 scale's codec, the same way: MiBeacon v5 framing, AES-CCM under the bind key, the weigh-in object, the scan filters. -
devices/ble-standard(:devices:ble-standard, packagedevices/blestandard) — the devices of the Bluetooth standard health profiles as one family,BLE_STANDARD: a heart rate strap, a blood pressure monitor, a weight scale and a glucose meter. Its pairing for the app's add flow, its link overGattLink, its live stream and the Health Connect mapping of what it pushes through theMeasurementSink;BleStandardModulebinds it. Its bytes are:devices:ble-standard:protocol, pure Kotlin: the measurement characteristics as the specifications lay them out, and the payloads it keeps a measurement in. -
link-host(:link-host, packagelink) — the OpenLink host: the exportedOpenWatchLinkService(in its manifest), the capabilities, the first-party list and the streaming notification. The app'sdi/LinkModulebuilds the trust store and the binder. -
health-calculations/— a git submodule and composite build, likeopenlink/: the health calculations OpenWatch and OpenVitals share (the Wear OS night and resting heart rate, body composition, workout and walking energy, the watch's HRV and respiratory rate from the raw PPG, the floors credit) and the models they read, as plain Kotlin undertech.mmarca.healthcalculations.:core:model(and through it:app),:wearlink(itsWorkoutMetrics, the workout figures both apps show),:wearand:wear:recording-coredepend on it; its ownAGENTS.mdholds its rules. -
wear/— the watch app, no DI.wear/recording-core/— its pure core (:wear:recording-core): what the recorders decide and compute, with the watch app's packages, pure JVM.wearlink/— the protocol and a workout's figures (WorkoutMetrics, over health-calculations), pure JVM.-
wear/.../wear/sources— what a recorder reads a measurement from, as contracts (HeartRateSource,HrvWindowSource,SpotSource), whoever serves it. -
wear/.../wear/vendor/<name>— what only one watch vendor has:vendor/samsung(the Samsung Health Platform's client, Samsung's raw PPG sensor),vendor/google(the Pixel Watch's skin temperature sensor). Each hands back contracts ofsources.
-
-
build-logic/— the convention plugins (SDK levels, signing, build types, lint, locking) the modules apply by id; an included build.
Do not break these without an explicit decision.
-
No
INTERNETpermission. The manifest removesINTERNET,ACCESS_NETWORK_STATEandACCESS_WIFI_STATE. Never add a dependency that needs a socket. -
The watch app is offline too. Its manifest removes the same three network permissions.
It reads the raw Android sensors; Health Services and the Samsung Health Sensor SDK are not
dependencies, and the SDK's
.aarnever enters the repository or a build. The one Samsung source is the clean-room Binder client inwear/.../vendor/samsung/, opt-in and offered only on a watch that has the Samsung Health Platform. Why, and what a Samsung source would have to respect:docs/engineering/samsung-health-and-privacy.md. -
One foreground service, and only for the scale. The 45-second
ScaleListeningServiceis the one service the app starts without a tap. A watch sync runs with no foreground service; its process-priority story is the companion association. -
One BLE radio, leased per address. Everything that opens a BLE link takes a lease from
devices/core/RadioLease.kt(:devices:core) under one of its owner tags:SYNC,FIND,SETTINGS,NOTIFICATIONS,PROBE,LIVE. A scan opens no link and takes no lease. A new GATT device opens its link throughGattLink, never its ownconnectGatt. -
One companion device service.
OpenWatchCompanionDeviceServiceis the primary one; it fans out to everyCompanionPresenceObserverbound@IntoSet, byDevicesModuleor a family's own Hilt module. -
Health Connect is reached through
HealthConnectGatewayonly. A device takes the contracts of:core:health-api, never the gateway: it reads throughHealthConnectReadsand every device write goes through the record sink,ImportedRecordRepository.insertImportedRecords, with a deterministicclientRecordId, so a re-sync upserts; the gateway's reads throw on failure, they never return an empty answer that would pass for "no data". There is no rate-limit backoff: the devices issue a handful of reads per sync. Add one only once a refusal is seen. -
Another app reaches OpenWatch through OpenLink only.
link/OpenWatchLinkServiceis the one exported entry for apps; every call is gated byOpenLinkHostCore's trust store, answered from memory on the binder thread, and never carries a Health Connect record, a notification or the scale's key. The library is theopenlink/submodule; its spec isopenlink/docs/spec.md. -
A missing permission is
ScreenError.PermissionDenied. UseisPermissionFailure()/toScreenError(); never pattern-match exception messages. -
Nothing waits on the main thread. No
runBlockinginsrc/main(NoRunBlockingRatchetTest); Health Connect and Room calls aresuspendondispatchers.io; a receiver never holds a broadcast for a Health Connect read. -
Text that leaves the app is structure, not data. A log line logs a count or passes the
throwable, never a value (
LogMessageInterpolationRatchetTestholds the count). -
Every locale ships complete for the copied strings. A key that comes from OpenVitals is
re-extracted with
scripts/extract-strings.py; a key OpenWatch adds lives invalues/until it is translated.python3 scripts/verify-translations.pychecks the files. -
Room is at version 2. The database is
:core:data's, its exported schemas incore/data/schemas. A change means aMIGRATION_2_3indata/local/OpenWatchMigrations, a bump and its case inOpenWatchDatabaseMigrationTest, neverfallbackToDestructiveMigration. The three device tables are named as OpenVitals' are, and also key their rows by the device's id salt. -
A device family is a module that binds itself (decision 4, 2026-11). A family in a Gradle
module of its own,
:devices:<vendor>, declares its own Hilt module, which binds its family into theDeviceFamilymap (@StringKeywith its persisted name), its ports, stores and startup actors. Only:app, those modules and the screen modules (:feature:*) declare Hilt modules (not:devices:core, a contract or a protocol module, a:core:*module, the link host, nor the app'sdevices/packages), and a device module depends on no other family, on no screen module and not on the app. A screen module depends on no device family but the one its name ends with (:feature:<screens>-<family>, a family's own screens).DevicesLayeringTestholds it. -
The ratchets hold.
DevicesLayeringTest(who declares Hilt modules, see above),CompanionPairingWiringTest(an Activity callsattachToActivity),GarminSessionConfinementTest,FileSizeRatchetTest(800 lines, with a ceiling list),FunctionLengthRatchetTest(the count over 150 lines only falls),NoRunBlockingRatchetTest,SuspendRunCatchingRatchetTest,GattConnectionRatchetTest,PackageDirectionTest(which package may import which),LogCallersRatchetTest(which files may write to the log) andHealthPermissionsTest. The file-size, function-length,runBlockingand log ratchets cover the watch app and:wear:recording-coretoo,WearPackageDirectionTestholds the watch app's package direction andWearVendorNamesRatchetTestwhere it may name a watch vendor. When one fails, fix the code, not the test. -
A watch vendor is a package, and a sensor's quirk is a fact. What only one Wear OS vendor
has (a private service, a vendor sensor type, a vendor settings key, a vendor permission) is
reached from
wear/.../vendor/<name>and handed back as a contract ofwear/.../sources; no recorder, screen or pure-core class names a vendor, beyond the stored and sent names that are never renamed (MeasurementSource, the link's tokens). How a standard sensor behaves on one watch (no buffer, no waking variant) is decided from the sensor's own facts, never fromBuild.MANUFACTURERor a model name. One APK serves every watch. Each vendor, what is reached of it and under which grant:docs/engineering/watch-vendors.md. -
A health permission is in the catalog, or it is not declared.
healthconnect/HealthDataCataloglists every health permission of both manifests by the device its data comes from; the app shows that list, andHealthPermissionsTestholds the manifests and the records the integrations build to it. A new type means its catalog row, its line inPRIVACY.mdanddocs/app/permissions.md, and Play's health declaration, before it ships.
- Protocol changes for the Wear OS link go in
:wearlink, never into a copy. - A new device integration is a module
:devices:<vendor>(its pure protocol in:devices:<vendor>:protocol): it implements thedevices/coreports, opens a BLE link only throughGattLinkunder a radio lease, keeps its protocol code transport-free, binds itself in its own Hilt module, and is oneimplementationline in the app's build file. A family whose devices need no flow of their own declares aDevicePairingand gets the app's add flow, Home's "Other devices" list and the generic device panel; one that pushes its data hands each measurement to theMeasurementSink, which keeps it before Health Connect has it. A family with screens of its own brings them beside its other screens and binds them, under its persisted name, into the generic screens' contributions (features/device/DeviceContributions.kt: its own destination, its panel in the device screen, its pairing in the add-a-watch flow); the generic screens never name a family, and the device module holds no screen. - A health calculation goes into health-calculations, not into
:core:model,:wearor a feature: one copy, so both apps give the same number. Moving the submodule changes OpenVitals' numbers too, so it moves in both apps together. - Keep the copied code close to OpenVitals where it can be: a fix that applies to both repositories is easier to carry across when the files still read the same.
- Prefer one ViewModel per screen; ViewModels own loading state and call repositories.
./gradlew verifyCi (phone app and its modules) and ./gradlew verifyWearCi (watch app), or
scripts/ci-android-gradle.sh <task> on a machine without the SDK pieces set up. The
instrumented tests run on emulators on every push to main (.github/workflows/android-test.yml);
a test that needs real hardware carries @RequiresDevice. See
docs/engineering/development.md.
One release ships both form factors: the version lives in gradle.properties
(openwatch.versionCode, openwatch.versionName), the watch adds 2000000000 to the code,
and .github/workflows/release.yml signs both with one key and uploads the phone bundle to
the Play beta/production tracks and the watch bundle to wear:beta/wear:production.
scripts/release.sh X.Y.Z cuts a release; the procedure is .claude/skills/release/SKILL.md.
Generated from AGENTS.md. Edit it there; changes made here are overwritten.
This wiki mirrors the Markdown in Hale-MTU/OpenWatch on every push to main.
Features
How-to
App
Engineering
- Architecture
- Development
- OpenLink: security fixes, and workouts the watch records itself (proposal)
- Samsung services on the watch: sources, privacy, and the SDK
- Sleep minute features (SM line, version 3)
- Watch vendors
Proposals
Releases
Research
- Research spike: raw PPG and HRV on the watch without the Samsung Health SDK
- Research: which Galaxy Watch7 sensors an app can read without the Samsung SDK
Project