testsAndMisc/phone_focus_mode/docs/youtube-block-unrooted.md
Krzysztof kuhy Rudnicki 10fff1d1a8 Block YouTube on the unrooted Pixel, and trust more than one phone
`pm uninstall --user 0` unregisters a package for one user while leaving
the APK on the system image. It needs no root and no factory reset, and
unlike `pm suspend` and `pm disable-user` -- both measured to be cleared
by a reboot on this device -- it survives one. Applied to the YouTube
app, YouTube Music, and Chrome; `--restore` puts any of them back with no
download.

focus_owner could not have done this: its sweep filters to third-party
packages, and YouTube ships at /product/app/YouTube with FLAG_SYSTEM, so
the Device Owner path would skip it even after the wipe.

Verified on 23181JEGR08034 across two reboots: all three read
installed=false, and in Firefox m.youtube.com, www.youtube.com, a /watch
URL and a youtu.be short link all fail to connect while example.com
loads. The web half of that is RethinkDNS domain rules, which live on the
device and are not in this commit; docs/youtube-block-unrooted.md records
how to rebuild them, and what this does NOT resist -- the VPN is a few
taps from off, which only Device Owner can prevent.

The trusted-device record becomes one file per device, so managing a
second phone no longer evicts the first. Unenrolled devices still abort,
and a changed model or build fingerprint aborts rather than falling
through to the next record.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JxNrcMDcizNB3XrrYpZF23
2026-08-10 19:16:01 +02:00

83 lines
3.4 KiB
Markdown

# Blocking YouTube on an unrooted Pixel 6a
Applied and verified 2026-08-09 on `23181JEGR08034` (Android 16, SDK 36).
No root, no Device Owner, no factory reset.
## What actually works: `pm uninstall --user 0`
Unregisters a package for one user while leaving the APK on the read-only
system image.
| Mechanism | Survives reboot? |
| --- | --- |
| `pm suspend` | No — measured |
| `pm disable-user` | No — measured |
| `dpm setApplicationHidden` | Yes — but needs Device Owner, i.e. a wipe |
| **`pm uninstall --user 0`** | **Yes — measured, twice** |
Reversible with `pm install-existing --user 0 <pkg>`: no download, no data
loss, because the APK never left the device.
## Why focus_owner cannot do this job
`EnforcementRunner.installedThirdPartyPackages()` filters to packages without
`FLAG_SYSTEM`. YouTube ships at `/product/app/YouTube` **with** `FLAG_SYSTEM`,
so the Device Owner sweep would skip it — even after the factory reset. The
apps most worth blocking are preinstalled, which is exactly the set that sweep
excludes. Worth fixing there separately; it does not block anything today.
## Current state
Removed for user 0, all reboot-verified:
- `com.google.android.youtube`
- `com.google.android.apps.youtube.music`
- `com.android.chrome`
Driven by `phone_focus_mode/distraction_purge.sh` (`--list`, `--status`,
`--restore`). It re-checks each package with `dumpsys` after acting rather
than trusting the `pm` exit code, and exits non-zero if anything is still
installed — so a Play Store reinstall surfaces as a failure instead of a
silent no-op.
## What is NOT blocked
**Firefox (`org.mozilla.fenix`) is still installed and still reaches
youtube.com.** It is the only remaining browser after Chrome's removal.
Unlike the three packages above, Firefox is user-installed
(`/data/app/...`, no `FLAG_SYSTEM`), so `pm uninstall --user 0` would
**permanently delete it and its data** — no `install-existing` recovery, a
full reinstall from the Play Store. That asymmetry is why it was left alone
rather than swept up with the rest. Decide deliberately.
`com.google.android.webview` was checked and left in place: it is the system
WebView provider, so removing it would break in-app browsers everywhere.
Chrome and WebView are separate packages on this device, which is why
removing Chrome is safe.
## The web path, and why DNS is parked
Removing the app kills the recommendation feed, notifications and the
account-linked session — most of the pull. It does not stop typing
`youtube.com` into a browser.
Previously rejected approaches, from `focus_owner/docs/`:
- **Home-hosted DoT resolver.** Android's Private DNS fails *closed*, so PC
off = phone has no internet at all. Rejected: the phone must work with the
PC off.
- **Hosted DNS (NextDNS, AdGuard, ControlD).** No provider ingests the 185k
domain blocklist; free tiers fail *open* past ~300k queries/month.
The remaining candidate is a **local-VPN content blocker** — an on-device
`VpnService` that filters without any network dependency, so it works with the
PC off and does not fail closed on network loss. Not yet scoped; the VPN slot
was going to be checked when the device disconnected. Note Android allows only
one active VPN at a time, so this would conflict with any real VPN.
## Redoing this after a factory reset
The purge is per-user state and does not survive a wipe. Re-run
`./distraction_purge.sh` after re-enrolling the device.