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

Modern-Apps.git / clock / AGENTS.md

AGENTS.md9.9 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- **Push triggers:** the publish also runs on the phone Watch app's scheduled sync-trigger intent (`sync/ConduitSyncTriggerReceiver`, exported only under the `CONDUIT` signature permission, invoking `WearClockSync.syncNow()` — no UI, no prompt). Data arriving while the receiving process is dead lands in the conduit host's persistent store and replays on registration.
44- **Open on phone:** the watch request (`/<appId>/open-on-phone` conduit message; camera: `OPEN_ON_PHONE` op) is handled live by the sync message listener when this app is registered, and otherwise the phone conduit host broadcasts `OpenOnPhoneContract.ACTION` (package-addressed, `CONDUIT` signature permission) to `sync/OpenOnPhoneReceiver`, which launches the main activity as a new task — no phone process needs to be running first.
45
46## Watch experience (in this module)
47- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute`: the root `Home` is a swipe pager (`ui/WearPagerScreen` + `ui/WearClockPage`: home time face, world clocks, alarms, timers, stopwatch) and `AlarmDetail` pushes over it on the shell back stack. World clocks are synced/display-only; alarms are synced and armed on the watch by `platform/WatchAlarmScheduler` (armed proof in `domain/WearAlarmState.kt`); timers + stopwatch are watch-native (`platform/WatchTimerScheduler`, `domain/WatchTimerState.kt`). The pager uses the Material 1 wear generation the repo ships (foundation `HorizontalPager` + Material `Scaffold` TimeText/page-indicator, `TransformingLazyColumn` per page); see `ui/WearPagerScreen.kt` for the Material 3 hierarchy mapping.
48- Watch state persists in `data/WearClockStore` (`wear-clock.json`); `ui/WearRingActivity` + `platform/WatchRingNotifier` are the ringing surface.
49- 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.
50**Gotchas:**
51- Alarm scheduling must work before first unlock — test the boot path, not just in-app
52- Notification action receivers and the sound service are the timer/stopwatch control plane; UI pages are views onto the same state
53- The filename is `TimerReciever.kt`, spelled as-is — do NOT rename (receivers are manifest-registered)
54
55## Key files
56### Root — entry + navigation
57- com/vayunmathur/clock/MainActivity.kt
58- com/vayunmathur/clock/Navigation.kt
59- com/vayunmathur/clock/Route.kt
60### data/ — Room store
61- com/vayunmathur/clock/data/ClockDatabase.kt
62- com/vayunmathur/clock/data/ClockRepository.kt
63### platform/ — ViewModel, schedulers, receivers
64- com/vayunmathur/clock/platform/ClockViewModel.kt
65- com/vayunmathur/clock/platform/ClockUiContract.kt
66- com/vayunmathur/clock/platform/AlarmScheduler.kt
67- com/vayunmathur/clock/platform/AlarmReceiver.kt
68- com/vayunmathur/clock/platform/AlarmActivity.kt
69- com/vayunmathur/clock/platform/BootReceiver.kt — re-arm alarms on boot (gated to phones)
70- com/vayunmathur/clock/platform/NotificationUtils.kt
71- com/vayunmathur/clock/platform/StopwatchActionReceiver.kt
72- com/vayunmathur/clock/platform/StopwatchNotificationHelper.kt
73- com/vayunmathur/clock/platform/TimerActionReceiver.kt
74- com/vayunmathur/clock/platform/TimerReciever.kt — spelled as-is, do not rename
75- com/vayunmathur/clock/platform/WorldClockCities.kt
76### service/ — alarm sound
77- com/vayunmathur/clock/service/AlarmSoundService.kt
78### ui/ + ui/components/ + ui/dialogs/ — tab pages and controls
79- com/vayunmathur/clock/ui/ClockTabs.kt
80- com/vayunmathur/clock/ui/ClockPage.kt
81- com/vayunmathur/clock/ui/ClockScreen.kt
82- com/vayunmathur/clock/ui/AlarmPage.kt
83- com/vayunmathur/clock/ui/AlarmScreen.kt
84- com/vayunmathur/clock/ui/AlarmSettingsPage.kt
85- com/vayunmathur/clock/ui/TimerPage.kt
86- com/vayunmathur/clock/ui/TimerScreen.kt
87- com/vayunmathur/clock/ui/StopwatchPage.kt
88- com/vayunmathur/clock/ui/StopwatchScreen.kt
89- com/vayunmathur/clock/ui/InitialPermissionsScreen.kt
90- com/vayunmathur/clock/ui/components/AlarmCard.kt
91- com/vayunmathur/clock/ui/components/AlarmOptionControls.kt
92- com/vayunmathur/clock/ui/components/AlarmRingingScreen.kt
93- com/vayunmathur/clock/ui/components/KeypadButton.kt
94- com/vayunmathur/clock/ui/components/KeypadRow.kt
95- com/vayunmathur/clock/ui/components/LapRow.kt
96- com/vayunmathur/clock/ui/components/TimerCard.kt
97- com/vayunmathur/clock/ui/components/TimerKeypadContent.kt
98- com/vayunmathur/clock/ui/components/TimerNotification.kt
99- com/vayunmathur/clock/ui/components/TimeUnitDisplay.kt
100- com/vayunmathur/clock/ui/dialogs/NewAlarmDialog.kt
101- com/vayunmathur/clock/ui/dialogs/NewTimerDialog.kt
102- com/vayunmathur/clock/ui/dialogs/SelectTimeZonesDialog.kt
103### sync/ — wear companion sync
104- com/vayunmathur/clock/sync/WearClockSync.kt — phone conduit client node; snapshot publish, watch-state receive, request-sync handling
105- com/vayunmathur/clock/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive + watch arming reconcile, watch-state publish
106### Watch experience (ui/ + platform/ + data/ + domain/)
107- com/vayunmathur/clock/ui/WearMainActivity.kt — watch entry (WearShellActivity)
108- com/vayunmathur/clock/ui/WearRoute.kt, WearClockPage.kt, WearPagerScreen.kt, WearHomeScreen.kt, WearWorldClockScreen.kt, WearAlarmsScreen.kt, WearAlarmDetailScreen.kt, WearTimersScreen.kt, WearStopwatchScreen.kt, WearRingActivity.kt
109- com/vayunmathur/clock/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)
110- com/vayunmathur/clock/platform/WearBootReceiver.kt — watch boot/timezone restore (gated to watches)
111- com/vayunmathur/clock/platform/WatchAlarmScheduler.kt, WatchAlarmReceiver.kt, WatchTimerScheduler.kt, WatchTimerReceiver.kt, WatchRingNotifier.kt
112- com/vayunmathur/clock/data/WearClockStore.kt
113- com/vayunmathur/clock/domain/WearAlarmState.kt, WatchTimerState.kt
114### intents/ + widget/ — assistant hooks and widgets
115- com/vayunmathur/clock/intents/SetAlarmIntent.kt
116- com/vayunmathur/clock/intents/SetTimerIntent.kt
117- com/vayunmathur/clock/widget/AnalogClockGlanceWidget.kt
118- com/vayunmathur/clock/widget/AnalogClockWidgetProvider.kt
119
120## Verify (this module only)
121```
122./gradlew :clock:compileDevKotlin
123./gradlew :clock:lint
124./gradlew :clock:checkMetadata
125```
126- Wear Tile: `service/ClockTileService` (a `MaTileService` in `:library:weartiles`) renders the next enabled alarm (or the time with `No alarms`) from `WearClockStore`; the store requests a tile update on every new snapshot, plus 15-minute freshness. Tap opens `WearMainActivity`.