AGENTS.md — clock/ (':clock')
Scoped supplement. Global rules in root AGENTS.md apply. Stay inside clock/ + allowed shared modules. Do not root-scan.
Install: ./install clock (dev by default).
- Gradle: :clock / dir: clock/
- Package roots present: ui, data, domain, platform, intents, service, widget, sync
- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt
- Deps: :library:widgets, :library:room, :library:wearlink, :library:log, Wear Compose (material + foundation)
- Metadata: metadata_data/clock.md (present)
- Rust: no / screenshotTest: yes
Overview
Purpose: Offline clock — alarms (exact, survive reboot pre-unlock), timer, stopwatch, world clock, analog widget; answers system alarm/timer intents so assistants can set them. Key features:
- Alarms with full-screen lockscreen surface + sound service; timer + stopwatch controllable from notifications
- World-clock city picker; analog Glance widget (
AnalogClockGlanceWidget+AnalogClockWidgetProviderreceiver) - Assistant
intents/(SetAlarm/SetTimer) wired to the same schedulers as the UI
Architecture / data-flow: ui/ tab pages → platform/ClockViewModel (+ ClockUiContract) → data/ClockRepository over Room; scheduling via platform/AlarmScheduler → AlarmReceiver → AlarmActivity + service/AlarmSoundService, re-armed by BootReceiver. Timer/stopwatch actions arrive from notifications via *ActionReceivers. Entry points + reading order: Route (alarm/timer/stopwatch/world-clock tabs) → MainActivity.kt → Navigation.kt → ui/ClockTabs.kt → platform/ClockViewModel.kt → platform/AlarmScheduler.kt.
One APK, two form factors (phone + watch)
This module is the single Clock APK for phones and watches: same applicationId = "com.vayunmathur.clock" and signing on both, as the WearLink handshake requires. The manifest deliberately declares no android.hardware.type.watch feature (required=true would block phones; required=false is disallowed for this feature), plus touchscreen not-required and com.google.android.wearable.standalone=false; distribution is sideload/F-Droid, not Play's watch channel, so the APK installs on phones and watches alike. platform/FormFactor.kt reads PackageManager.FEATURE_WATCH at runtime: MainActivity (the sole launcher entry) forwards watches to ui/WearMainActivity before any phone state loads; phones get the tab UI. Boot restore is split the same way — platform/BootReceiver (phone) and platform/WearBootReceiver (watch) each gate on FormFactor.
Wear sync (Watch conduit client)
Protocol: shared wire types live in :library:wearlink at com.vayunmathur.library.wearlink.clock.WearClockProtocol; the golden-JSON tests in this module pin the shared code's wire format.
- Snapshot + watch-state sync: conduit data items (
/clock/snapshotphone -> watch,/clock/watch-statewatch -> phone) - Sync request: conduit message (
/clock/request-sync), watch -> phone only - Transport: Watch conduit client — phone side
sync/WearClockSync.ktand watch sidesync/WearLinkBridge.ktboth useWearLinkClientNode(Messenger to the Watch app'swatch_conduitservice, appIdclock); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reportsNotInstalled/Unavailableand the sync stays idle; snapshots republish on conduitConnectedand on alarm/world-clock changes.
Watch experience (in this module)
ui/WearMainActivity(aWearShellActivity) routesui/WearRouteover home / world clocks (synced, display-only) / alarms (synced; armed on the watch byplatform/WatchAlarmScheduler, with armed proof indomain/WearAlarmState.kt) / timers + stopwatch (watch-native:platform/WatchTimerScheduler,domain/WatchTimerState.kt).- Watch state persists in
data/WearClockStore(wear-clock.json);ui/WearRingActivity+platform/WatchRingNotifierare the ringing surface. - Watch listing screenshots are the
group = "wear"previews insrc/screenshotTest/.../ui/WearMetadataPreviews.kt, collected by:clock:metadataintometadata_data/photos/clock/wear/; phone shots use thephonebucket.
Gotchas:
- Alarm scheduling must work before first unlock — test the boot path, not just in-app
- Notification action receivers and the sound service are the timer/stopwatch control plane; UI pages are views onto the same state
- The filename is
TimerReciever.kt, spelled as-is — do NOT rename (receivers are manifest-registered)
Key files
Root — entry + navigation
- com/vayunmathur/clock/MainActivity.kt
- com/vayunmathur/clock/Navigation.kt
- com/vayunmathur/clock/Route.kt
data/ — Room store
- com/vayunmathur/clock/data/ClockDatabase.kt
- com/vayunmathur/clock/data/ClockRepository.kt
platform/ — ViewModel, schedulers, receivers
- com/vayunmathur/clock/platform/ClockViewModel.kt
- com/vayunmathur/clock/platform/ClockUiContract.kt
- com/vayunmathur/clock/platform/AlarmScheduler.kt
- com/vayunmathur/clock/platform/AlarmReceiver.kt
- com/vayunmathur/clock/platform/AlarmActivity.kt
- com/vayunmathur/clock/platform/BootReceiver.kt — re-arm alarms on boot (gated to phones)
- com/vayunmathur/clock/platform/NotificationUtils.kt
- com/vayunmathur/clock/platform/StopwatchActionReceiver.kt
- com/vayunmathur/clock/platform/StopwatchNotificationHelper.kt
- com/vayunmathur/clock/platform/TimerActionReceiver.kt
- com/vayunmathur/clock/platform/TimerReciever.kt — spelled as-is, do not rename
- com/vayunmathur/clock/platform/WorldClockCities.kt
service/ — alarm sound
- com/vayunmathur/clock/service/AlarmSoundService.kt
ui/ + ui/components/ + ui/dialogs/ — tab pages and controls
- com/vayunmathur/clock/ui/ClockTabs.kt
- com/vayunmathur/clock/ui/ClockPage.kt
- com/vayunmathur/clock/ui/ClockScreen.kt
- com/vayunmathur/clock/ui/AlarmPage.kt
- com/vayunmathur/clock/ui/AlarmScreen.kt
- com/vayunmathur/clock/ui/AlarmSettingsPage.kt
- com/vayunmathur/clock/ui/TimerPage.kt
- com/vayunmathur/clock/ui/TimerScreen.kt
- com/vayunmathur/clock/ui/StopwatchPage.kt
- com/vayunmathur/clock/ui/StopwatchScreen.kt
- com/vayunmathur/clock/ui/InitialPermissionsScreen.kt
- com/vayunmathur/clock/ui/components/AlarmCard.kt
- com/vayunmathur/clock/ui/components/AlarmOptionControls.kt
- com/vayunmathur/clock/ui/components/AlarmRingingScreen.kt
- com/vayunmathur/clock/ui/components/KeypadButton.kt
- com/vayunmathur/clock/ui/components/KeypadRow.kt
- com/vayunmathur/clock/ui/components/LapRow.kt
- com/vayunmathur/clock/ui/components/TimerCard.kt
- com/vayunmathur/clock/ui/components/TimerKeypadContent.kt
- com/vayunmathur/clock/ui/components/TimerNotification.kt
- com/vayunmathur/clock/ui/components/TimeUnitDisplay.kt
- com/vayunmathur/clock/ui/dialogs/NewAlarmDialog.kt
- com/vayunmathur/clock/ui/dialogs/NewTimerDialog.kt
- com/vayunmathur/clock/ui/dialogs/SelectTimeZonesDialog.kt
sync/ — wear companion sync
- com/vayunmathur/clock/sync/WearClockSync.kt — phone conduit client node; snapshot publish, watch-state receive, request-sync handling
- com/vayunmathur/clock/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive + watch arming reconcile, watch-state publish
Watch experience (ui/ + platform/ + data/ + domain/)
- com/vayunmathur/clock/ui/WearMainActivity.kt — watch entry (WearShellActivity)
- com/vayunmathur/clock/ui/WearRoute.kt, WearHomeScreen.kt, WearWorldClockScreen.kt, WearAlarmsScreen.kt, WearAlarmDetailScreen.kt, WearTimersScreen.kt, WearStopwatchScreen.kt, WearRingActivity.kt
- com/vayunmathur/clock/platform/FormFactor.kt — watch detection (
FEATURE_WATCH) - com/vayunmathur/clock/platform/WearBootReceiver.kt — watch boot/timezone restore (gated to watches)
- com/vayunmathur/clock/platform/WatchAlarmScheduler.kt, WatchAlarmReceiver.kt, WatchTimerScheduler.kt, WatchTimerReceiver.kt, WatchRingNotifier.kt
- com/vayunmathur/clock/data/WearClockStore.kt
- com/vayunmathur/clock/domain/WearAlarmState.kt, WatchTimerState.kt
intents/ + widget/ — assistant hooks and widgets
- com/vayunmathur/clock/intents/SetAlarmIntent.kt
- com/vayunmathur/clock/intents/SetTimerIntent.kt
- com/vayunmathur/clock/widget/AnalogClockGlanceWidget.kt
- com/vayunmathur/clock/widget/AnalogClockWidgetProvider.kt
Verify (this module only)
./gradlew :clock:compileDevKotlin
./gradlew :clock:lint
./gradlew :clock:checkMetadata