Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / clock / AGENTS.md

AGENTS.md8.4 KiBRenderedCodeRaw
1# AGENTS.md — clock/ (':clock')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `clock/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install clock (dev by default)._
6- Gradle: :clock / dir: clock/
7- Package roots present: ui, data, domain, platform, intents, service, widget, sync
8- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt
9- Deps: :library:widgets, :library:room, :library:wearlink, :library:log, Wear Compose (material + foundation)
10- Metadata: metadata_data/clock.md (present)
11- Rust: no / screenshotTest: yes
12
13## Overview
14**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.
15**Key features:**
16- Alarms with full-screen lockscreen surface + sound service; timer + stopwatch controllable from notifications
17- World-clock city picker; analog Glance widget (`AnalogClockGlanceWidget` + `AnalogClockWidgetProvider` receiver)
18- Assistant `intents/` (`SetAlarm` / `SetTimer`) wired to the same schedulers as the UI
19**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 `*ActionReceiver`s.
20**Entry points + reading order:** `Route` (alarm/timer/stopwatch/world-clock tabs) → `MainActivity.kt` → `Navigation.kt` → `ui/ClockTabs.kt` → `platform/ClockViewModel.kt` → `platform/AlarmScheduler.kt`.
21
22## One APK, two form factors (phone + watch)
23This module is the single Clock APK for phones and watches: same
24`applicationId = "com.vayunmathur.clock"` and signing on both, as the
25WearLink handshake requires. The manifest deliberately declares no
26`android.hardware.type.watch` feature (required=true would block
27phones; required=false is disallowed for this feature), plus
28touchscreen not-required and
29`com.google.android.wearable.standalone=false`; distribution is
30sideload/F-Droid, not Play's watch channel, so the APK installs on
31phones and watches alike. `platform/FormFactor.kt`
32reads `PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the
33sole launcher entry) forwards watches to `ui/WearMainActivity` before
34any phone state loads; phones get the tab UI. Boot restore is split the
35same way — `platform/BootReceiver` (phone) and
36`platform/WearBootReceiver` (watch) each gate on `FormFactor`.
37
38## Wear sync (Watch conduit client)
39**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.
40- Snapshot + watch-state sync: conduit data items (`/clock/snapshot` phone -> watch, `/clock/watch-state` watch -> phone)
41- Sync request: conduit message (`/clock/request-sync`), watch -> phone only
42- **Transport: Watch conduit client** — phone side `sync/WearClockSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `clock`); 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 reports `NotInstalled`/`Unavailable` and the sync stays idle; snapshots republish on conduit `Connected` and on alarm/world-clock changes.
43
44## Watch experience (in this module)
45- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over home / world clocks (synced, display-only) / alarms (synced; armed on the watch by `platform/WatchAlarmScheduler`, with armed proof in `domain/WearAlarmState.kt`) / timers + stopwatch (watch-native: `platform/WatchTimerScheduler`, `domain/WatchTimerState.kt`).
46- Watch state persists in `data/WearClockStore` (`wear-clock.json`); `ui/WearRingActivity` + `platform/WatchRingNotifier` are the ringing surface.
47- Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:clock:metadata` into `metadata_data/photos/clock/wear/`; phone shots use the `phone` bucket.
48**Gotchas:**
49- Alarm scheduling must work before first unlock — test the boot path, not just in-app
50- Notification action receivers and the sound service are the timer/stopwatch control plane; UI pages are views onto the same state
51- The filename is `TimerReciever.kt`, spelled as-is — do NOT rename (receivers are manifest-registered)
52
53## Key files
54### Root — entry + navigation
55- com/vayunmathur/clock/MainActivity.kt
56- com/vayunmathur/clock/Navigation.kt
57- com/vayunmathur/clock/Route.kt
58### data/ — Room store
59- com/vayunmathur/clock/data/ClockDatabase.kt
60- com/vayunmathur/clock/data/ClockRepository.kt
61### platform/ — ViewModel, schedulers, receivers
62- com/vayunmathur/clock/platform/ClockViewModel.kt
63- com/vayunmathur/clock/platform/ClockUiContract.kt
64- com/vayunmathur/clock/platform/AlarmScheduler.kt
65- com/vayunmathur/clock/platform/AlarmReceiver.kt
66- com/vayunmathur/clock/platform/AlarmActivity.kt
67- com/vayunmathur/clock/platform/BootReceiver.kt — re-arm alarms on boot (gated to phones)
68- com/vayunmathur/clock/platform/NotificationUtils.kt
69- com/vayunmathur/clock/platform/StopwatchActionReceiver.kt
70- com/vayunmathur/clock/platform/StopwatchNotificationHelper.kt
71- com/vayunmathur/clock/platform/TimerActionReceiver.kt
72- com/vayunmathur/clock/platform/TimerReciever.kt — spelled as-is, do not rename
73- com/vayunmathur/clock/platform/WorldClockCities.kt
74### service/ — alarm sound
75- com/vayunmathur/clock/service/AlarmSoundService.kt
76### ui/ + ui/components/ + ui/dialogs/ — tab pages and controls
77- com/vayunmathur/clock/ui/ClockTabs.kt
78- com/vayunmathur/clock/ui/ClockPage.kt
79- com/vayunmathur/clock/ui/ClockScreen.kt
80- com/vayunmathur/clock/ui/AlarmPage.kt
81- com/vayunmathur/clock/ui/AlarmScreen.kt
82- com/vayunmathur/clock/ui/AlarmSettingsPage.kt
83- com/vayunmathur/clock/ui/TimerPage.kt
84- com/vayunmathur/clock/ui/TimerScreen.kt
85- com/vayunmathur/clock/ui/StopwatchPage.kt
86- com/vayunmathur/clock/ui/StopwatchScreen.kt
87- com/vayunmathur/clock/ui/InitialPermissionsScreen.kt
88- com/vayunmathur/clock/ui/components/AlarmCard.kt
89- com/vayunmathur/clock/ui/components/AlarmOptionControls.kt
90- com/vayunmathur/clock/ui/components/AlarmRingingScreen.kt
91- com/vayunmathur/clock/ui/components/KeypadButton.kt
92- com/vayunmathur/clock/ui/components/KeypadRow.kt
93- com/vayunmathur/clock/ui/components/LapRow.kt
94- com/vayunmathur/clock/ui/components/TimerCard.kt
95- com/vayunmathur/clock/ui/components/TimerKeypadContent.kt
96- com/vayunmathur/clock/ui/components/TimerNotification.kt
97- com/vayunmathur/clock/ui/components/TimeUnitDisplay.kt
98- com/vayunmathur/clock/ui/dialogs/NewAlarmDialog.kt
99- com/vayunmathur/clock/ui/dialogs/NewTimerDialog.kt
100- com/vayunmathur/clock/ui/dialogs/SelectTimeZonesDialog.kt
101### sync/ — wear companion sync
102- com/vayunmathur/clock/sync/WearClockSync.kt — phone conduit client node; snapshot publish, watch-state receive, request-sync handling
103- com/vayunmathur/clock/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive + watch arming reconcile, watch-state publish
104### Watch experience (ui/ + platform/ + data/ + domain/)
105- com/vayunmathur/clock/ui/WearMainActivity.kt — watch entry (WearShellActivity)
106- com/vayunmathur/clock/ui/WearRoute.kt, WearHomeScreen.kt, WearWorldClockScreen.kt, WearAlarmsScreen.kt, WearAlarmDetailScreen.kt, WearTimersScreen.kt, WearStopwatchScreen.kt, WearRingActivity.kt
107- com/vayunmathur/clock/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)
108- com/vayunmathur/clock/platform/WearBootReceiver.kt — watch boot/timezone restore (gated to watches)
109- com/vayunmathur/clock/platform/WatchAlarmScheduler.kt, WatchAlarmReceiver.kt, WatchTimerScheduler.kt, WatchTimerReceiver.kt, WatchRingNotifier.kt
110- com/vayunmathur/clock/data/WearClockStore.kt
111- com/vayunmathur/clock/domain/WearAlarmState.kt, WatchTimerState.kt
112### intents/ + widget/ — assistant hooks and widgets
113- com/vayunmathur/clock/intents/SetAlarmIntent.kt
114- com/vayunmathur/clock/intents/SetTimerIntent.kt
115- com/vayunmathur/clock/widget/AnalogClockGlanceWidget.kt
116- com/vayunmathur/clock/widget/AnalogClockWidgetProvider.kt
117
118## Verify (this module only)
119```
120./gradlew :clock:compileDevKotlin
121./gradlew :clock:lint
122./gradlew :clock:checkMetadata
123```