2026-05-01 19:07:27 +02:00
|
|
|
## Phone focus mode
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
Rooted-Android hardening + recovery workflow for daily backup/monitoring and
|
|
|
|
|
post-format recovery.
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
The visible entrypoint is:
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
```bash
|
|
|
|
|
./scripts/run_all/run_phone.sh
|
|
|
|
|
```
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
That wrapper forwards to `phone_focus_mode/run_phone.sh`, which orchestrates
|
|
|
|
|
backup, monitoring, drift repair, and full recovery.
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
## Quick usage
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
### Normal day
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
```bash
|
|
|
|
|
./scripts/run_all/run_phone.sh
|
2026-02-22 16:57:36 +01:00
|
|
|
```
|
|
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
This runs `auto` mode:
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
- verifies and selects one device (USB or paired wireless ADB)
|
|
|
|
|
- checks format indicators first
|
|
|
|
|
- if phone appears wiped: prints warning + suggests `fresh-phone`, then exits
|
|
|
|
|
- otherwise collects monitoring snapshot, runs incremental backup, applies only
|
|
|
|
|
low-risk minor repairs, prints summary
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
`auto` never restores APK/media and never re-deploys.
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
### After a factory reset
|
2026-02-22 16:57:36 +01:00
|
|
|
|
|
|
|
|
```bash
|
2026-05-01 19:07:27 +02:00
|
|
|
./scripts/run_all/run_phone.sh fresh-phone
|
2026-02-22 16:57:36 +01:00
|
|
|
```
|
|
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
This mode:
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
- verifies prerequisites (ADB auth, root, Magisk runtime)
|
|
|
|
|
- takes pre-change snapshot
|
|
|
|
|
- restores security stack by delegating to `deploy.sh`
|
|
|
|
|
- restores safe APK/media backup items
|
|
|
|
|
- takes post-restore snapshot and prints required manual follow-up steps
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
### If something looks wrong
|
2026-02-22 16:57:36 +01:00
|
|
|
|
|
|
|
|
```bash
|
2026-05-01 19:07:27 +02:00
|
|
|
./scripts/run_all/run_phone.sh doctor
|
2026-02-22 16:57:36 +01:00
|
|
|
```
|
|
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
This mode:
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
- runs monitoring checks
|
|
|
|
|
- repairs common drift (daemon restarts, hosts file re-push)
|
|
|
|
|
- re-runs deployment only when boot persistence is missing
|
|
|
|
|
- avoids broad data restore actions
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
### Other modes
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
```bash
|
|
|
|
|
./scripts/run_all/run_phone.sh backup
|
|
|
|
|
./scripts/run_all/run_phone.sh monitor
|
|
|
|
|
./scripts/run_all/run_phone.sh --help
|
2026-02-22 16:57:36 +01:00
|
|
|
```
|
|
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
## Device targeting
|
phone_focus_mode: add persistent home-mode status notification
- New companion Android app (com.kuhy.focusstatus) under
phone_focus_mode/focus_status_app/ with a pure-Java, Gradle-less
command-line build pipeline (build.sh). Shows an ongoing
notification titled 'Focus: HOME / AWAY / DAEMON DOWN' with
distance, GPS, disabled-app count, last check, daemon checkmarks,
and a 'Re-check now' action button.
- focus_daemon.sh: write_status_snapshot() + sleep_with_recheck()
for JSON status + early-wake on trigger file. init() chmods
STATE_DIR 777 so the app can drop the trigger file.
- config.sh: new STATUS_FILE / RECHECK_TRIGGER; WHITELIST expanded
with com.kuhy.focusstatus and 11 more user-requested apps
(podcini X, mpv, bible/openbible, pkp/portalpasazera, orange,
runnerup, splitbills/splitwise, xiaomi smarthome).
- focus_ctl.sh: new 'recheck' + 'notif-status' subcommands.
- deploy.sh: new step [7/7] builds APK, installs, grants
POST_NOTIFICATIONS, pre-approves Magisk SU policy, launches
foreground service.
- .gitignore: exclude focus_status_app/build symlink + debug.keystore.
End-to-end verified on device: notification live with real values;
Re-check button triggers a daemon location check within ~1s.
2026-04-20 15:33:32 +02:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
Both the wrapper and `deploy.sh` support explicit device selection:
|
phone_focus_mode: add persistent home-mode status notification
- New companion Android app (com.kuhy.focusstatus) under
phone_focus_mode/focus_status_app/ with a pure-Java, Gradle-less
command-line build pipeline (build.sh). Shows an ongoing
notification titled 'Focus: HOME / AWAY / DAEMON DOWN' with
distance, GPS, disabled-app count, last check, daemon checkmarks,
and a 'Re-check now' action button.
- focus_daemon.sh: write_status_snapshot() + sleep_with_recheck()
for JSON status + early-wake on trigger file. init() chmods
STATE_DIR 777 so the app can drop the trigger file.
- config.sh: new STATUS_FILE / RECHECK_TRIGGER; WHITELIST expanded
with com.kuhy.focusstatus and 11 more user-requested apps
(podcini X, mpv, bible/openbible, pkp/portalpasazera, orange,
runnerup, splitbills/splitwise, xiaomi smarthome).
- focus_ctl.sh: new 'recheck' + 'notif-status' subcommands.
- deploy.sh: new step [7/7] builds APK, installs, grants
POST_NOTIFICATIONS, pre-approves Magisk SU policy, launches
foreground service.
- .gitignore: exclude focus_status_app/build symlink + debug.keystore.
End-to-end verified on device: notification live with real values;
Re-check button triggers a daemon location check within ~1s.
2026-04-20 15:33:32 +02:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
```bash
|
|
|
|
|
ADB_SERIAL=<device-serial> ./scripts/run_all/run_phone.sh auto
|
|
|
|
|
ADB_SERIAL=<device-serial> bash phone_focus_mode/deploy.sh --status
|
|
|
|
|
```
|
phone_focus_mode: add persistent home-mode status notification
- New companion Android app (com.kuhy.focusstatus) under
phone_focus_mode/focus_status_app/ with a pure-Java, Gradle-less
command-line build pipeline (build.sh). Shows an ongoing
notification titled 'Focus: HOME / AWAY / DAEMON DOWN' with
distance, GPS, disabled-app count, last check, daemon checkmarks,
and a 'Re-check now' action button.
- focus_daemon.sh: write_status_snapshot() + sleep_with_recheck()
for JSON status + early-wake on trigger file. init() chmods
STATE_DIR 777 so the app can drop the trigger file.
- config.sh: new STATUS_FILE / RECHECK_TRIGGER; WHITELIST expanded
with com.kuhy.focusstatus and 11 more user-requested apps
(podcini X, mpv, bible/openbible, pkp/portalpasazera, orange,
runnerup, splitbills/splitwise, xiaomi smarthome).
- focus_ctl.sh: new 'recheck' + 'notif-status' subcommands.
- deploy.sh: new step [7/7] builds APK, installs, grants
POST_NOTIFICATIONS, pre-approves Magisk SU policy, launches
foreground service.
- .gitignore: exclude focus_status_app/build symlink + debug.keystore.
End-to-end verified on device: notification live with real values;
Re-check button triggers a daemon location check within ~1s.
2026-04-20 15:33:32 +02:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
`deploy.sh` still supports the existing phone-IP flow:
|
phone_focus_mode: add persistent home-mode status notification
- New companion Android app (com.kuhy.focusstatus) under
phone_focus_mode/focus_status_app/ with a pure-Java, Gradle-less
command-line build pipeline (build.sh). Shows an ongoing
notification titled 'Focus: HOME / AWAY / DAEMON DOWN' with
distance, GPS, disabled-app count, last check, daemon checkmarks,
and a 'Re-check now' action button.
- focus_daemon.sh: write_status_snapshot() + sleep_with_recheck()
for JSON status + early-wake on trigger file. init() chmods
STATE_DIR 777 so the app can drop the trigger file.
- config.sh: new STATUS_FILE / RECHECK_TRIGGER; WHITELIST expanded
with com.kuhy.focusstatus and 11 more user-requested apps
(podcini X, mpv, bible/openbible, pkp/portalpasazera, orange,
runnerup, splitbills/splitwise, xiaomi smarthome).
- focus_ctl.sh: new 'recheck' + 'notif-status' subcommands.
- deploy.sh: new step [7/7] builds APK, installs, grants
POST_NOTIFICATIONS, pre-approves Magisk SU policy, launches
foreground service.
- .gitignore: exclude focus_status_app/build symlink + debug.keystore.
End-to-end verified on device: notification live with real values;
Re-check button triggers a daemon location check within ~1s.
2026-04-20 15:33:32 +02:00
|
|
|
|
|
|
|
|
```bash
|
2026-05-01 19:07:27 +02:00
|
|
|
bash phone_focus_mode/deploy.sh 192.168.1.42 --status
|
phone_focus_mode: add persistent home-mode status notification
- New companion Android app (com.kuhy.focusstatus) under
phone_focus_mode/focus_status_app/ with a pure-Java, Gradle-less
command-line build pipeline (build.sh). Shows an ongoing
notification titled 'Focus: HOME / AWAY / DAEMON DOWN' with
distance, GPS, disabled-app count, last check, daemon checkmarks,
and a 'Re-check now' action button.
- focus_daemon.sh: write_status_snapshot() + sleep_with_recheck()
for JSON status + early-wake on trigger file. init() chmods
STATE_DIR 777 so the app can drop the trigger file.
- config.sh: new STATUS_FILE / RECHECK_TRIGGER; WHITELIST expanded
with com.kuhy.focusstatus and 11 more user-requested apps
(podcini X, mpv, bible/openbible, pkp/portalpasazera, orange,
runnerup, splitbills/splitwise, xiaomi smarthome).
- focus_ctl.sh: new 'recheck' + 'notif-status' subcommands.
- deploy.sh: new step [7/7] builds APK, installs, grants
POST_NOTIFICATIONS, pre-approves Magisk SU policy, launches
foreground service.
- .gitignore: exclude focus_status_app/build symlink + debug.keystore.
End-to-end verified on device: notification live with real values;
Re-check button triggers a daemon location check within ~1s.
2026-04-20 15:33:32 +02:00
|
|
|
```
|
|
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
## Requirements
|
phone_focus_mode: add persistent home-mode status notification
- New companion Android app (com.kuhy.focusstatus) under
phone_focus_mode/focus_status_app/ with a pure-Java, Gradle-less
command-line build pipeline (build.sh). Shows an ongoing
notification titled 'Focus: HOME / AWAY / DAEMON DOWN' with
distance, GPS, disabled-app count, last check, daemon checkmarks,
and a 'Re-check now' action button.
- focus_daemon.sh: write_status_snapshot() + sleep_with_recheck()
for JSON status + early-wake on trigger file. init() chmods
STATE_DIR 777 so the app can drop the trigger file.
- config.sh: new STATUS_FILE / RECHECK_TRIGGER; WHITELIST expanded
with com.kuhy.focusstatus and 11 more user-requested apps
(podcini X, mpv, bible/openbible, pkp/portalpasazera, orange,
runnerup, splitbills/splitwise, xiaomi smarthome).
- focus_ctl.sh: new 'recheck' + 'notif-status' subcommands.
- deploy.sh: new step [7/7] builds APK, installs, grants
POST_NOTIFICATIONS, pre-approves Magisk SU policy, launches
foreground service.
- .gitignore: exclude focus_status_app/build symlink + debug.keystore.
End-to-end verified on device: notification live with real values;
Re-check button triggers a daemon location check within ~1s.
2026-04-20 15:33:32 +02:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
- rooted phone with Magisk installed
|
|
|
|
|
- USB debugging enabled and authorized (or paired wireless ADB)
|
|
|
|
|
- `adb` available on PC (`sudo pacman -S android-tools` on Arch Linux)
|
|
|
|
|
- location services enabled on phone
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
## Setup essentials
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
1. Set home coordinates in `phone_focus_mode/config_secrets.sh`.
|
|
|
|
|
2. Optionally tune whitelist and behavior in `phone_focus_mode/config.sh`.
|
|
|
|
|
3. Perform initial deploy:
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
```bash
|
|
|
|
|
bash phone_focus_mode/deploy.sh <phone_ip>
|
|
|
|
|
```
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
## Systemd automation (PC user service)
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
Install timer-based periodic runs:
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
```bash
|
|
|
|
|
bash phone_focus_mode/systemd/install_pc_phone_automation.sh
|
|
|
|
|
```
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
This installs user units under `~/.config/systemd/user/`:
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
- `phone-auto-sync.service`
|
|
|
|
|
- `phone-auto-sync.timer` (every 30 minutes, persistent)
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
## Relevant files
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
| File | Purpose |
|
|
|
|
|
| ------------------------------------- | ------------------------------------------ |
|
|
|
|
|
| `scripts/run_all/run_phone.sh` | Thin, visible wrapper for daily use |
|
|
|
|
|
| `phone_focus_mode/run_phone.sh` | Main orchestration logic |
|
|
|
|
|
| `phone_focus_mode/lib/adb_common.sh` | ADB selection, locking, identity helpers |
|
|
|
|
|
| `phone_focus_mode/lib/backup.sh` | Incremental backup logic |
|
|
|
|
|
| `phone_focus_mode/lib/monitor.sh` | Security/health checks and reports |
|
|
|
|
|
| `phone_focus_mode/lib/restore.sh` | Safe restore helpers used by `fresh-phone` |
|
|
|
|
|
| `phone_focus_mode/deploy.sh` | Security-stack deployment primitive |
|
|
|
|
|
| `phone_focus_mode/backup_manifest.sh` | Declarative backup/restore scope |
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
## Notes
|
2026-02-22 16:57:36 +01:00
|
|
|
|
2026-05-01 19:07:27 +02:00
|
|
|
- Backup scope and restore policies live in `phone_focus_mode/backup_manifest.sh`.
|
|
|
|
|
- Sensitive coordinates should stay in `config_secrets.sh` and out of version
|
|
|
|
|
control.
|
|
|
|
|
- On-device direct control remains available via `focus_ctl.sh`.
|