mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-26 09:37:14 +01:00
Resend the lockdown on an already-penalised day
The workday lockdown signal was fire-once: a day already penalised returned ALREADY_PENALISED and sent nothing, so a signal focus-owner missed (not running, not yet Device Owner) never landed (live check C6, 2026-11-22). StickCheck.run now re-sends the stored locked_through when it is today or later, without touching the streak or the date; lockdown_sent carries resend=true. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
83e1e158fd
commit
8253836612
@ -62,6 +62,10 @@ a minute is recorded once (both activities run the launch check).
|
|||||||
does afterwards: a lockdown through the next day, stacking. The streak
|
does afterwards: a lockdown through the next day, stacking. The streak
|
||||||
links penalty days, stick days (Tue–Thu) plus bypass days; free and sick
|
links penalty days, stick days (Tue–Thu) plus bypass days; free and sick
|
||||||
days are skipped. A plain late dismiss on Fri–Mon still changes nothing.
|
days are skipped. A plain late dismiss on Fri–Mon still changes nothing.
|
||||||
|
A later check or bypass on the day already penalised sends the stored
|
||||||
|
lockdown (`locked_through`, if today or later) again, same date and
|
||||||
|
streak, so a signal focus-owner missed (not running, not yet Device
|
||||||
|
Owner) still lands.
|
||||||
- **The phone rings again** (`Bypass.ringAgain`). During a session it is a
|
- **The phone rings again** (`Bypass.ringAgain`). During a session it is a
|
||||||
re-ring: only the full dismiss sequence silences it and `re_rings` goes up
|
re-ring: only the full dismiss sequence silences it and `re_rings` goes up
|
||||||
by one when it does (`SessionHandoff.afterDismiss`).
|
by one when it does (`SessionHandoff.afterDismiss`).
|
||||||
|
|||||||
@ -157,7 +157,8 @@ Phone (`phone_events.kind`): `alarm_fired` (data: `reason` =
|
|||||||
`exact`|`boot`|`watchdog`, `date` judged, `verdict`, incl. `free_day`|`sick_day`), `bypass` (data: `cause`, `date`, `session`; `DOCS-bypass.md`),
|
`exact`|`boot`|`watchdog`, `date` judged, `verdict`, incl. `free_day`|`sick_day`), `bypass` (data: `cause`, `date`, `session`; `DOCS-bypass.md`),
|
||||||
`bypass_ignored`, `notifications` (data: `enabled`, `trigger` =
|
`bypass_ignored`, `notifications` (data: `enabled`, `trigger` =
|
||||||
`evening`|`app_block`|`channel_block`; `DOCS-bypass.md`), `unsuspended`, `lockdown_sent` (data:
|
`evening`|`app_block`|`channel_block`; `DOCS-bypass.md`), `unsuspended`, `lockdown_sent` (data:
|
||||||
`until`, `streak`), `lift_sent`, `escape_used`, `boot`.
|
`until`, `streak`, `resend`: true when a day already penalised sent its
|
||||||
|
stored lockdown again), `lift_sent`, `escape_used`, `boot`.
|
||||||
|
|
||||||
`ring_started` is published twice over: a headless Dart engine started by
|
`ring_started` is published twice over: a headless Dart engine started by
|
||||||
`AlarmReceiver` at the fire (so a full-screen intent downgraded to a heads-up
|
`AlarmReceiver` at the fire (so a full-screen intent downgraded to a heads-up
|
||||||
|
|||||||
@ -67,6 +67,8 @@ data class StickRun(
|
|||||||
val state: StickState,
|
val state: StickState,
|
||||||
val checkedThrough: LocalDate,
|
val checkedThrough: LocalDate,
|
||||||
val signalUntil: LocalDate?,
|
val signalUntil: LocalDate?,
|
||||||
|
/** [signalUntil] repeats a lockdown already bought, not a new miss's. */
|
||||||
|
val resend: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,6 +95,9 @@ object StickCheck {
|
|||||||
/**
|
/**
|
||||||
* Judges every unchecked day, oldest first, then today.
|
* Judges every unchecked day, oldest first, then today.
|
||||||
*
|
*
|
||||||
|
* A day found [StickVerdict.ALREADY_PENALISED] re-sends the stored
|
||||||
|
* lockdown when it still runs through today ([StickRun.resend]).
|
||||||
|
*
|
||||||
* Past days run from the day after [StickInputs.checkedThrough], at most
|
* Past days run from the day after [StickInputs.checkedThrough], at most
|
||||||
* [BACKLOG_DAYS] back -- in order, so the streak builds exactly as if
|
* [BACKLOG_DAYS] back -- in order, so the streak builds exactly as if
|
||||||
* each day had been checked on time. A first run (no checkedThrough)
|
* each day had been checked on time. A first run (no checkedThrough)
|
||||||
@ -104,6 +109,7 @@ object StickCheck {
|
|||||||
val verdicts = mutableListOf<DayVerdict>()
|
val verdicts = mutableListOf<DayVerdict>()
|
||||||
var state = inputs.state
|
var state = inputs.state
|
||||||
var signal: LocalDate? = null
|
var signal: LocalDate? = null
|
||||||
|
var resend = false
|
||||||
val checked = inputs.checkedThrough
|
val checked = inputs.checkedThrough
|
||||||
var day = if (checked == null) {
|
var day = if (checked == null) {
|
||||||
today
|
today
|
||||||
@ -117,12 +123,22 @@ object StickCheck {
|
|||||||
verdicts += DayVerdict(day, verdict)
|
verdicts += DayVerdict(day, verdict)
|
||||||
if (verdict == StickVerdict.MISS) {
|
if (verdict == StickVerdict.MISS) {
|
||||||
signal = next.lockedThrough?.takeIf { !it.isBefore(today) }
|
signal = next.lockedThrough?.takeIf { !it.isBefore(today) }
|
||||||
|
resend = false
|
||||||
|
} else if (verdict == StickVerdict.ALREADY_PENALISED) {
|
||||||
|
// The one signal may never have landed (focus-owner not
|
||||||
|
// running or not yet Device Owner, C6 2026-11-22), so a day
|
||||||
|
// already penalised sends the stored lockdown again. Same
|
||||||
|
// date, same streak: focus-owner applies it idempotently.
|
||||||
|
state.lockedThrough?.takeIf { !it.isBefore(today) }?.let {
|
||||||
|
signal = it
|
||||||
|
resend = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
state = next
|
state = next
|
||||||
day = day.plusDays(1)
|
day = day.plusDays(1)
|
||||||
}
|
}
|
||||||
val settled = if (verdicts.last().verdict.final) today else today.minusDays(1)
|
val settled = if (verdicts.last().verdict.final) today else today.minusDays(1)
|
||||||
return StickRun(verdicts, state, maxOf(settled, checked ?: settled), signal)
|
return StickRun(verdicts, state, maxOf(settled, checked ?: settled), signal, resend)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** One day's verdict and the state after it; [now] is when it is judged. */
|
/** One day's verdict and the state after it; [now] is when it is judged. */
|
||||||
|
|||||||
@ -15,8 +15,8 @@ import java.time.LocalDateTime
|
|||||||
* alarm") and `watchdog` (the daily net). Every run also catches up on the
|
* alarm") and `watchdog` (the daily net). Every run also catches up on the
|
||||||
* unchecked days before today ([StickCheck.run]), so a phone off for days
|
* unchecked days before today ([StickCheck.run]), so a phone off for days
|
||||||
* is judged day by day when it comes back. Running twice is harmless --
|
* is judged day by day when it comes back. Running twice is harmless --
|
||||||
* [StickVerdict.ALREADY_PENALISED] makes a second miss on one day a no-op,
|
* [StickVerdict.ALREADY_PENALISED] makes a second miss on one day a no-op
|
||||||
* which matters because Android replays BOOT_COMPLETED to a force-stopped
|
* for the streak (it only re-sends the same lockdown), which matters because Android replays BOOT_COMPLETED to a force-stopped
|
||||||
* app on its next launch.
|
* app on its next launch.
|
||||||
*/
|
*/
|
||||||
object StickRunner {
|
object StickRunner {
|
||||||
@ -50,13 +50,18 @@ object StickRunner {
|
|||||||
if (run.state != before) StickStore.save(context, run.state)
|
if (run.state != before) StickStore.save(context, run.state)
|
||||||
StickStore.setCheckedThrough(context, run.checkedThrough)
|
StickStore.setCheckedThrough(context, run.checkedThrough)
|
||||||
// A missed day whose lockdown already ended (caught up days later)
|
// A missed day whose lockdown already ended (caught up days later)
|
||||||
// still counts toward the streak, but nothing is sent for it.
|
// still counts toward the streak, but nothing is sent for it. A day
|
||||||
|
// already penalised sends its lockdown again ([StickRun.resend]).
|
||||||
run.signalUntil?.let { until ->
|
run.signalUntil?.let { until ->
|
||||||
WorkdayStick.sendLockdown(context, until)
|
WorkdayStick.sendLockdown(context, until)
|
||||||
EventLog.append(
|
EventLog.append(
|
||||||
context,
|
context,
|
||||||
"lockdown_sent",
|
"lockdown_sent",
|
||||||
mapOf("until" to until.toString(), "streak" to run.state.streak),
|
mapOf(
|
||||||
|
"until" to until.toString(),
|
||||||
|
"streak" to run.state.streak,
|
||||||
|
"resend" to run.resend,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return run.verdicts.last().verdict
|
return run.verdicts.last().verdict
|
||||||
|
|||||||
@ -89,16 +89,6 @@ class StickCheckBypassTest {
|
|||||||
assertEquals(StickState(), sick.state)
|
assertEquals(StickState(), sick.state)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun aSecondBypassTheSameDayIsAlreadyPenalised() {
|
|
||||||
val afterSunday = StickState(streak = 1, lockedThrough = mon, lastMiss = sun)
|
|
||||||
val run = StickCheck.run(
|
|
||||||
inputs(sun.atTime(8, 0), bypass = setOf(sun), state = afterSunday, checkedThrough = sun),
|
|
||||||
)
|
|
||||||
assertEquals(StickVerdict.ALREADY_PENALISED, run.verdicts.single().verdict)
|
|
||||||
assertNull(run.signalUntil)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun aBypassCountsOnlyOnARingingDayWithARingOrSessionLive() {
|
fun aBypassCountsOnlyOnARingingDayWithARingOrSessionLive() {
|
||||||
assertTrue(BypassRules.counts(ringingDay = true, ringLive = true, sessionLive = false))
|
assertTrue(BypassRules.counts(ringingDay = true, ringLive = true, sessionLive = false))
|
||||||
|
|||||||
@ -0,0 +1,87 @@
|
|||||||
|
package com.kuhy.wake_alarm_sync
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.LocalTime
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A day already penalised re-sends the lockdown it bought (2026-11-22, C6):
|
||||||
|
* the one signal went out while focus-owner was neither Device Owner nor
|
||||||
|
* running, and every later bypass that day got `already_penalised` and sent
|
||||||
|
* nothing, so the lockdown never landed.
|
||||||
|
*/
|
||||||
|
class StickResendTest {
|
||||||
|
// 2026-11-22 is a Sunday, 24 a Tuesday.
|
||||||
|
private val sun = LocalDate.of(2026, 11, 22)
|
||||||
|
private val mon = sun.plusDays(1)
|
||||||
|
private val tue = sun.plusDays(2)
|
||||||
|
|
||||||
|
private fun inputs(
|
||||||
|
now: LocalDateTime,
|
||||||
|
state: StickState,
|
||||||
|
escaped: Set<LocalDate> = emptySet(),
|
||||||
|
) = StickInputs(
|
||||||
|
now = now,
|
||||||
|
alarm = LocalTime.of(7, 30),
|
||||||
|
dismissedOn = { false },
|
||||||
|
escapedOn = { it in escaped },
|
||||||
|
isFree = { false },
|
||||||
|
isSick = { false },
|
||||||
|
state = state,
|
||||||
|
checkedThrough = now.toLocalDate(),
|
||||||
|
bypassOn = { it == sun },
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun aSecondBypassTheSameDayResendsTheSameLockdown() {
|
||||||
|
val afterSunday = StickState(streak = 1, lockedThrough = mon, lastMiss = sun)
|
||||||
|
val run = StickCheck.run(inputs(sun.atTime(8, 0), afterSunday))
|
||||||
|
assertEquals(StickVerdict.ALREADY_PENALISED, run.verdicts.single().verdict)
|
||||||
|
assertEquals(mon, run.signalUntil)
|
||||||
|
assertTrue(run.resend)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun aResendNeverExtendsTheStreakOrTheDate() {
|
||||||
|
val stacked = StickState(streak = 3, lockedThrough = sun.plusDays(3), lastMiss = sun)
|
||||||
|
val run = StickCheck.run(inputs(sun.atTime(9, 0), stacked))
|
||||||
|
assertEquals(stacked, run.state)
|
||||||
|
assertEquals(sun.plusDays(3), run.signalUntil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun aLockdownThatAlreadyEndedIsNotResent() {
|
||||||
|
val ended = StickState(streak = 1, lockedThrough = sun.minusDays(1), lastMiss = sun)
|
||||||
|
val run = StickCheck.run(inputs(sun.atTime(8, 0), ended))
|
||||||
|
assertEquals(StickVerdict.ALREADY_PENALISED, run.verdicts.single().verdict)
|
||||||
|
assertNull(run.signalUntil)
|
||||||
|
assertFalse(run.resend)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun noStoredDateMeansNothingToResend() {
|
||||||
|
val undated = StickState(streak = 1, lockedThrough = null, lastMiss = sun)
|
||||||
|
assertNull(StickCheck.run(inputs(sun.atTime(8, 0), undated)).signalUntil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun anEscapedDayIsNotResent() {
|
||||||
|
val afterSunday = StickState(streak = 1, lockedThrough = mon, lastMiss = sun)
|
||||||
|
val run = StickCheck.run(inputs(sun.atTime(8, 0), afterSunday, escaped = setOf(sun)))
|
||||||
|
assertEquals(StickVerdict.ESCAPED, run.verdicts.single().verdict)
|
||||||
|
assertNull(run.signalUntil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun aFreshMissIsSentButNotMarkedAResend() {
|
||||||
|
val run = StickCheck.run(inputs(tue.atTime(9, 0), StickState()))
|
||||||
|
assertEquals(StickVerdict.MISS, run.verdicts.single().verdict)
|
||||||
|
assertEquals(tue.plusDays(1), run.signalUntil)
|
||||||
|
assertFalse(run.resend)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user