mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-30 07:45:23 +01:00
Compare commits
No commits in common. "af503f465fe788c22902df7e9b7bcc0200576c49" and "0059d44571794e0504c931c34920c613b96cc2c3" have entirely different histories.
af503f465f
...
0059d44571
@ -50,7 +50,6 @@ live. Causes (`bypass` phone event, `data.cause`):
|
||||
| `notifications_off` | ring start and every launch (`Bypass.checkOnLaunch`) |
|
||||
| `fsi_revoked` | the same; uid app-op `USE_FULL_SCREEN_INTENT` denied |
|
||||
| `ring_killed` | every launch and boot: today's ring fired, was never dismissed, and is not sounding |
|
||||
| `uninstalled` | focus-owner, every pass, any day: `com.kuhy.wake_alarm_sync` not installed for user 0 (see below) |
|
||||
|
||||
`ring_killed` reads `watched_fired_date`, a stamp only builds with `Bypass`
|
||||
write, so a ring fired by an older build (11-22, paused, never dismissed) does
|
||||
@ -89,44 +88,6 @@ a minute is recorded once (both activities run the launch check).
|
||||
--published <file>` reads the phone's logs from a JSON list of
|
||||
`[device_id, alarm.json]` pairs instead of Firebase (`_published_file`).
|
||||
|
||||
## An uninstall that gets through (focus-owner, 2026-11-23)
|
||||
|
||||
WakeAlarm cannot be uninstalled: focus-owner holds `setUninstallBlocked`
|
||||
and `setUserControlDisabledPackages` on it every pass. The Pixel's
|
||||
`dumpsys device_policy` shows `packageUninstallBlocked` for it (2026-11-23).
|
||||
On the AVD, `adb uninstall`, `pm uninstall --user 0` and `-k --user 0` all
|
||||
fail with `DELETE_FAILED_INTERNAL_ERROR` ("Attempted to delete protected
|
||||
package"): the user-control pin refuses it before the uninstall block is
|
||||
asked. Deploys use `adb install -r`, which both allow.
|
||||
|
||||
If WakeAlarm is gone anyway, WakeAlarm cannot record a bypass, so
|
||||
focus-owner does (`phone-focus-mode` `focus-owner/.../UninstallLockdown.kt`,
|
||||
`UninstallEvents.kt`, `lib/sync/`):
|
||||
|
||||
- **Missing** means not found, or found with `FLAG_INSTALLED` clear. A
|
||||
hidden app is installed.
|
||||
- **Lockdown**, every day including free and sick days: the lockdown
|
||||
allowlist while the app is missing and through the day after it returns.
|
||||
Its own prefs, so wake_alarm's `LIFT_LOCKDOWN` does not clear it (a
|
||||
reinstalled WakeAlarm would send one at once). No day cap.
|
||||
- **Event**: `bypass` with `cause: uninstalled` and the phone-local `date`,
|
||||
under device `focus-owner`, record `alarm`, field `phone_events`. One at
|
||||
once when the app goes missing (it rings the PC only inside a tick
|
||||
window), then one per later day at the first pass at or after the alarm
|
||||
time focus-owner read from the sync (08:00 if none). The PC rings every
|
||||
morning until a full dismiss logs `dismissed`; on a free or sick day it
|
||||
stays silent while the phone stays locked.
|
||||
- **Queue**: the lockdown never waits on the push. An unsent event is
|
||||
retried every pass, a failure is logged once a day, nothing is dropped.
|
||||
- **Push-only**: focus-owner writes its own file and never merges a peer's
|
||||
log into it (a pulled list would replace its events, field by field).
|
||||
Its `phone_events` HLC is the newest event's own `at`, so a late retry
|
||||
never out-ranks a list the reinstalled phone published.
|
||||
- `newest_push` skips device `focus-owner`: its write is not the phone's.
|
||||
- Set up once per install: Google sign-in plus the passphrase (the cloud
|
||||
and lock icons in focus-owner's app bar). Each success pushes a harmless
|
||||
`install_check` field that no PC policy reads.
|
||||
|
||||
## Testing against a backend: the RTDB emulator
|
||||
|
||||
The AVD never signs in to prod. A probe build with
|
||||
|
||||
@ -21,13 +21,7 @@ import json
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from wake_alarm._constants import (
|
||||
FOCUS_OWNER_DEVICE_ID,
|
||||
MAX_HOUR,
|
||||
MAX_MINUTE,
|
||||
MIN_HOUR,
|
||||
MIN_MINUTE,
|
||||
)
|
||||
from wake_alarm._constants import MAX_HOUR, MAX_MINUTE, MIN_HOUR, MIN_MINUTE
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@ -194,10 +188,6 @@ def newest_alarm(
|
||||
"""
|
||||
ranked: list[tuple[str, str, tuple[int, int]]] = []
|
||||
for device_id, raw in published:
|
||||
# focus-owner publishes only its bypass events, never an alarm; parsing
|
||||
# it would log a WARNING on every live fetch.
|
||||
if device_id == FOCUS_OWNER_DEVICE_ID:
|
||||
continue
|
||||
parsed = parse_log(raw)
|
||||
if parsed is None:
|
||||
_logger.info("Ignoring unusable alarm published by %r", device_id)
|
||||
|
||||
@ -76,10 +76,6 @@ SYNC_LEGACY_PREFIX: str = "wake-alarm-sync/devices"
|
||||
# lists. Copied over from the plaintext prefix like everything else.
|
||||
SYNC_ALARM_PATH: str = f"{SYNC_DEVICES_PREFIX}/phone/alarm.json"
|
||||
|
||||
# focus-owner's own device directory. It publishes ``bypass`` with cause
|
||||
# ``uninstalled`` when WakeAlarm is gone, so it is never the phone's push.
|
||||
FOCUS_OWNER_DEVICE_ID: str = "focus-owner"
|
||||
|
||||
# The file each device publishes its alarm as, inside its own directory.
|
||||
SYNC_ALARM_FILENAME: str = "alarm.json"
|
||||
|
||||
|
||||
@ -25,7 +25,6 @@ from wake_alarm._constants import (
|
||||
ESCAPE_HATCH_LAST_DAY,
|
||||
ESCAPE_REASON_MIN_CHARS,
|
||||
ESCAPES_FIELD,
|
||||
FOCUS_OWNER_DEVICE_ID,
|
||||
PHONE_EVENTS_FIELD,
|
||||
RING_STARTED_FIELD,
|
||||
STICK_STATE_FIELD,
|
||||
@ -205,13 +204,10 @@ def newest_push(logs: list[tuple[str, dict[str, Any]]]) -> float | None:
|
||||
|
||||
Every phone write stamps the field it changed, so the largest instant is
|
||||
when the phone last uploaded anything. A stamp that cannot be dated is
|
||||
skipped: None means "cannot tell", never "old". focus-owner's writes are
|
||||
not the phone's: it publishes exactly when WakeAlarm is uninstalled.
|
||||
skipped: None means "cannot tell", never "old".
|
||||
"""
|
||||
stamps: list[float] = []
|
||||
for device_id, log in logs:
|
||||
if device_id == FOCUS_OWNER_DEVICE_ID:
|
||||
continue
|
||||
for _, log in logs:
|
||||
record = log.get("alarm")
|
||||
fields = record.get("fields") if isinstance(record, dict) else None
|
||||
for name in fields if isinstance(fields, dict) else ():
|
||||
|
||||
@ -215,19 +215,3 @@ class TestHlcInstant:
|
||||
def test_an_unparsable_prefix_is_undated(self) -> None:
|
||||
"""Garbage before the Z must not raise out of a per-minute tick."""
|
||||
assert hlc_instant("not-a-timestampZ-0000-device") is None
|
||||
|
||||
|
||||
def test_newest_alarm_skips_focus_owner_without_a_warning(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""focus-owner's log never carries an alarm; reading it is not a fault."""
|
||||
hlc = "2026-11-23T06:00:00.000Z-0000-p"
|
||||
phone = json.dumps(
|
||||
{"alarm": {"fields": {"alarm_hour": [7, hlc], "alarm_minute": [30, hlc]}}}
|
||||
)
|
||||
owner = json.dumps({"alarm": {"fields": {"phone_events": [[], hlc]}}})
|
||||
with caplog.at_level("INFO"):
|
||||
result = newest_alarm([("focus-owner", owner), ("p", phone)])
|
||||
assert result is not None
|
||||
assert result[:2] == (7, 30)
|
||||
assert not [r for r in caplog.records if r.levelname == "WARNING"]
|
||||
|
||||
@ -102,11 +102,3 @@ def test_last_push_is_the_newest_dated_hlc_of_any_field_on_any_device() -> None:
|
||||
def test_last_push_is_none_without_a_dated_stamp() -> None:
|
||||
assert enforcement_view([("a", _log(alarm_hour=(7, "h")))]).last_push is None
|
||||
assert enforcement_view([]).last_push is None
|
||||
|
||||
|
||||
def test_last_push_ignores_focus_owner_writes() -> None:
|
||||
"""focus-owner publishes ``bypass:uninstalled``; that is not a phone push."""
|
||||
phone = _log(alarm_hour=(7, "2026-11-20T06:00:00.000Z-0000-p"))
|
||||
owner = _log(phone_events=([], "2026-11-23T09:00:00.000Z-0000-f"))
|
||||
view = enforcement_view([("p", phone), ("focus-owner", owner)])
|
||||
assert view.last_push == datetime(2026, 11, 20, 6, 0, tzinfo=UTC).timestamp()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user