diff --git a/phone_app/android/app/src/main/kotlin/com/kuhy/wake_alarm_sync/AlarmChannel.kt b/phone_app/android/app/src/main/kotlin/com/kuhy/wake_alarm_sync/AlarmChannel.kt index fef8be7..6e98e0e 100644 --- a/phone_app/android/app/src/main/kotlin/com/kuhy/wake_alarm_sync/AlarmChannel.kt +++ b/phone_app/android/app/src/main/kotlin/com/kuhy/wake_alarm_sync/AlarmChannel.kt @@ -146,6 +146,7 @@ object AlarmChannel { // dismiss sequence in front the moment it is looked at. "isRinging" -> result.success(AlarmService.running) "takeBypassReRing" -> result.success(BypassReRing.take(context)) + "peekBypassReRing" -> result.success(BypassReRing.peek(context)) "beginStepCount" -> { StepCounter.markRingStart(context) result.success(null) diff --git a/phone_app/android/app/src/main/kotlin/com/kuhy/wake_alarm_sync/BypassReRing.kt b/phone_app/android/app/src/main/kotlin/com/kuhy/wake_alarm_sync/BypassReRing.kt index 42f9f4f..5796f96 100644 --- a/phone_app/android/app/src/main/kotlin/com/kuhy/wake_alarm_sync/BypassReRing.kt +++ b/phone_app/android/app/src/main/kotlin/com/kuhy/wake_alarm_sync/BypassReRing.kt @@ -19,6 +19,11 @@ object BypassReRing { prefs(context).edit().putString(KEY, BypassRules.encodeStamp(cause, date)).commit() } + /** The stamped cause, left in place: every screen ticking on this ring sees it. */ + fun peek(context: Context): String? = + BypassRules.takeStamp(prefs(context).getString(KEY, null), LocalDate.now().toString()) + + /** The stamped cause, cleared: called once, when the re-ring is recorded. */ fun take(context: Context): String? { val stored = prefs(context).getString(KEY, null) ?: return null prefs(context).edit().remove(KEY).commit() diff --git a/phone_app/lib/services/alarm_scheduler.dart b/phone_app/lib/services/alarm_scheduler.dart index 6f9c438..e3cf045 100644 --- a/phone_app/lib/services/alarm_scheduler.dart +++ b/phone_app/lib/services/alarm_scheduler.dart @@ -212,6 +212,11 @@ class AlarmScheduler { Future takeBypassReRing() => _channel.invokeMethod('takeBypassReRing'); + /// [takeBypassReRing] without clearing it, for the session screen's tick: + /// two screens can tick on one ring, and only the dismiss records it. + Future peekBypassReRing() => + _channel.invokeMethod('peekBypassReRing'); + /// Raw presence observations: `ssid`, `bssid`, `lat`, `lon`, `accuracy`, /// `distanceMeters`, `reason`. /// diff --git a/phone_app/lib/services/session_notice.dart b/phone_app/lib/services/session_notice.dart index 366c805..4651be9 100644 --- a/phone_app/lib/services/session_notice.dart +++ b/phone_app/lib/services/session_notice.dart @@ -39,7 +39,7 @@ Future pointNativeAtLeg( Future nativeRingReason( AlarmScheduler scheduler, MorningSession session, -) async => session.reRingReasonFor(await scheduler.takeBypassReRing()); +) async => session.reRingReasonFor(await scheduler.peekBypassReRing()); /// The notification's one line: glyph + position count, with a running-clock /// marker when the re-ring was spent. diff --git a/phone_app/test/session_screen_bypass_test.dart b/phone_app/test/session_screen_bypass_test.dart index f0c1f29..d8bc170 100644 --- a/phone_app/test/session_screen_bypass_test.dart +++ b/phone_app/test/session_screen_bypass_test.dart @@ -28,7 +28,7 @@ void main() { calls.add(call.method); if (call.method == 'hasNfc') return true; if (call.method == 'isRinging') return true; - if (call.method == 'takeBypassReRing') return bypassCause; + if (call.method == 'peekBypassReRing') return bypassCause; return null; }, ); @@ -58,7 +58,10 @@ void main() { ) async { bypassCause = 'suspended'; expect(await ringReasonAfterOneTick(tester), 'bypass:suspended'); - expect(calls, contains('takeBypassReRing')); + // Only the dismiss takes the stamp: two screens can tick on one ring + // (emulator 2026-11-23), and the second must not see it gone. + expect(calls, contains('peekBypassReRing')); + expect(calls, isNot(contains('takeBypassReRing'))); }); testWidgets('a ring nothing stamped is the deadline', (tester) async {