testsAndMisc/phone_focus_mode/README.md

132 lines
3.7 KiB
Markdown
Raw Normal View History

## Phone focus mode
2026-02-22 16:57:36 +01:00
Rooted-Android hardening + recovery workflow for daily backup/monitoring and
post-format recovery.
2026-02-22 16:57:36 +01:00
The visible entrypoint is:
2026-02-22 16:57:36 +01:00
```bash
./scripts/run_all/run_phone.sh
```
2026-02-22 16:57:36 +01: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
## Quick usage
2026-02-22 16:57:36 +01:00
### Normal day
2026-02-22 16:57:36 +01:00
```bash
./scripts/run_all/run_phone.sh
2026-02-22 16:57:36 +01:00
```
This runs `auto` mode:
2026-02-22 16:57:36 +01: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
`auto` never restores APK/media and never re-deploys.
2026-02-22 16:57:36 +01:00
### After a factory reset
2026-02-22 16:57:36 +01:00
```bash
./scripts/run_all/run_phone.sh fresh-phone
2026-02-22 16:57:36 +01:00
```
This mode:
2026-02-22 16:57:36 +01: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
### If something looks wrong
2026-02-22 16:57:36 +01:00
```bash
./scripts/run_all/run_phone.sh doctor
2026-02-22 16:57:36 +01:00
```
This mode:
2026-02-22 16:57:36 +01: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
### Other modes
2026-02-22 16:57:36 +01: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
```
## Device targeting
Both the wrapper and `deploy.sh` support explicit device selection:
```bash
ADB_SERIAL=<device-serial> ./scripts/run_all/run_phone.sh auto
ADB_SERIAL=<device-serial> bash phone_focus_mode/deploy.sh --status
```
`deploy.sh` still supports the existing phone-IP flow:
```bash
bash phone_focus_mode/deploy.sh 192.168.1.42 --status
```
## Requirements
- 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
## Setup essentials
2026-02-22 16:57:36 +01: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
```bash
bash phone_focus_mode/deploy.sh <phone_ip>
```
2026-02-22 16:57:36 +01:00
## Systemd automation (PC user service)
2026-02-22 16:57:36 +01:00
Install timer-based periodic runs:
2026-02-22 16:57:36 +01:00
```bash
bash phone_focus_mode/systemd/install_pc_phone_automation.sh
```
2026-02-22 16:57:36 +01:00
This installs user units under `~/.config/systemd/user/`:
2026-02-22 16:57:36 +01:00
- `phone-auto-sync.service`
- `phone-auto-sync.timer` (every 30 minutes, persistent)
2026-02-22 16:57:36 +01:00
## Relevant files
2026-02-22 16:57:36 +01: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
## Notes
2026-02-22 16:57:36 +01: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`.