{ "intent": "Make focus mode's policy and blocklist reusable on an unrooted phone, and ship a device-owner app whose removal path is proven before any restriction exists. Also fix a live bug that left YouTube's CDN blocked during workouts on the rooted phone.", "scope": [ "python_pkg/focus_policy/ - new: typed policy model, config.sh loader, hosts->domain blocklist, JSON export", "focus_owner/ - new: com.kuhy.focus_owner Flutter+Kotlin app, INERT (no restrictions applied, not provisioned)", "phone_focus_mode/strip_workout_hosts.py - fix exact-match domain filter", "linux_configuration/tests/test_strip_workout_hosts.py - regression tests for the above", "Non-goal: no Device Owner provisioning, no factory reset, no enforcement of any kind", "Non-goal: shell-side hosts/iptables enforcement is unchanged" ], "changes": [ "focus_policy parses phone_focus_mode/config.sh rather than duplicating its lists, so the shell config stays the single source of truth. HOME_LAT/LON load from the gitignored config_secrets.sh; the shipped REDACTED_* placeholder is rejected loudly instead of defaulting to (0,0), which would silently relocate 'home' to the Atlantic and disable the location gate.", "blocklist.py converts the hosts file to domains. It honours commented-out entries as deliberate unblocks (generate_hosts_file.sh comments rather than deletes, so a naive parser re-blocks facebook/linkedin/4chan), skips loopback and IPv6 housekeeping lines, and rejects ~1060 upstream annotation tokens such as '#[adware.zeno]' and '\"spam' that would otherwise render as address=/\"spam/ and make dnsmasq refuse to start.", "strip_workout_hosts.py now matches domain suffixes instead of exact set membership. YouTube streams from dynamic r*---sn-*.googlevideo.com hosts, which never equalled the allowlisted 'googlevideo.com', so the workout unblock was only partially effective on the live rooted phone.", "focus_owner ships DevicePolicyBridge.releaseDeviceOwner() (clearDeviceOwnerApp) implemented and tested BEFORE any restriction. dpm remove-active-admin does not work on a device owner, so an app that locks down before proving it can let go leaves a soft-brick recoverable only via fastboot on a locked bootloader." ], "verification": [ { "command": "pre-commit run --files python_pkg/focus_policy/*.py python_pkg/focus_policy/tests/*.py", "result": "pass", "evidence": "All hooks pass including ruff, ruff format, mypy (strict), pylint, bandit, no-noqa. Zero lint suppressions: the three initially-added ones (S104, two type: ignore) were removed by fixing the underlying code, not by suppressing." }, { "command": "coverage run --branch --source=python_pkg/focus_policy -m pytest python_pkg/focus_policy/tests/ && coverage report", "result": "pass", "evidence": "109 passed. 219 statements, 56 branches, 0 missed = 100% branch coverage across all 5 modules." }, { "command": "dnsmasq --test --conf-file=", "result": "pass", "evidence": "'dnsmasq: syntax check OK.' over all 185681 domains generated from the real 194463-line hosts file. An earlier run FAILED with 'missing \" at line 1' until invalid-domain rejection was added - this check is what caught it." }, { "command": "pytest linux_configuration/tests/test_strip_workout_hosts.py", "result": "pass", "evidence": "8 passed (5 pre-existing + 3 new). Non-vacuity confirmed: the 3 new tests were run against the ORIGINAL code in a throwaway git worktree and 2 of 3 FAILED there, so they genuinely pin the fix." }, { "command": "cd focus_owner && flutter analyze && flutter test", "result": "pass", "evidence": "'No issues found!' and '+10: All tests passed!' covering status parsing, the release path, null-reply handling, and the confirm-before-release dialog." }, { "command": "flutter build apk --debug && adb -s 23181JEGR08034 install -r && am start", "result": "pass", "evidence": "Built, installed, and launched on the Pixel 6a. Screenshot shows live platform-channel data ('Android SDK 36' read from the device), 'Device owner: no', 'Restrictions: none (inert build)'. Post-run dumpsys confirms Device Owner Type: -1, user restrictions 'none', mAppsSuspended=false - the phone is unchanged." } ], "risks": [ "focus_owner declares a DeviceAdminReceiver. Declaring it is inert - it applies nothing until someone runs dpm set-device-owner, which cannot succeed while the device has accounts. Still, the component now exists and should not be provisioned until the release path is exercised on a real device.", "The suffix matching in strip_workout_hosts.py releases a broader set than before (17 lines stripped vs 14). That is the intended fix, but it means any future entry in WORKOUT_UNBLOCK_DOMAINS now releases its entire subtree - a short domain there would release a lot.", "focus_policy duplicates the Haversine and curfew semantics of focus_daemon.sh in Python. The two must stay in agreement; the loader reads the same config.sh, but the geometry is a reimplementation, not a shared one.", "Measured this session and NOT yet reflected in any enforcement code: both pm suspend and pm disable-user are cleared by a reboot on Android 16. setApplicationHidden is assumed to persist but is UNTESTED." ], "rollback": [ "git revert the commit. focus_policy and focus_owner are new directories with no other module importing them, so removing them affects nothing else.", "The only change to live behaviour is strip_workout_hosts.py, used by deploy.sh when generating the workout hosts variant on the PC. Reverting restores exact-match filtering (i.e. restores the bug).", "After rollback validate: pytest linux_configuration/tests/test_strip_workout_hosts.py still passes, and phone_focus_mode/deploy.sh still produces a workout variant." ] }