Power, Charging & Brownout Guard
Smartphones running 24/7 as headless Linux servers have unique power behavior: an active OLED panel wastes ~1 W, holding a Li-ion battery at 100% causes cell swelling over months, and plugging a heavy camera/TPU workload into a weak 5 V / 500 mA USB-SDP port silently drains the battery until voltage collapse.
headless-phone ships dedicated, cleanly configurable services to handle all of these out of the box.
Brownout Protection Guard (brownout-guard)
Section titled “Brownout Protection Guard (brownout-guard)”Available in rootfs images built after v0.2.0, brownout-guard.service (/usr/local/sbin/brownout-guard) monitors battery SOC, battery voltage sag, signed/unsigned discharge current, and weak-charger conditions (USB-SDP, <= 500 mA input current limit, pd_partner=no) directly from sysfs.
Why It Exists & How Triggers Work
Section titled “Why It Exists & How Triggers Work”When running sustained workloads (such as Frigate camera capture + Exynos MFC encoding + Tensor Edge TPU) on a 5 V / 500 mA USB-SDP host port — or unplugged on battery — Pixel fuel gauges (max1720x / google_battery) report active net discharge (status=Not charging or Discharging with negative current_now). Without intervention, sustained drain eventually triggers voltage sag, I2C errors, and latched accelerator failures (for example on Mali-G78 OpenCL).
Two independent shedding triggers protect the device regardless of whether a weak USB charger is attached:
- Sustained low SOC: Active battery discharge (
>= DISCHARGE_CURRENT_UA) with capacity<= SHED_SOC(default15%) sustained forSUSTAINED_SECONDS(default60 s). - Sustained critical voltage sag: Battery voltage
<= CRITICAL_VOLTAGE_MV(default3450 mV) sustained forVOLTAGE_SUSTAINED_SECONDS(default15 s), even if SOC reads higher.
(Weak-charger detection independently logs rate-limited journal warnings and surfaces reasons in --status whenever active drain occurs while usb_online is true with SDP, <= 500 mA ICL, or pd_partner=no.)
When either shedding trigger fires, the guard stops configured active systemd units (default: frigate-camera.service), records shed state with flock-serialized persistence in /run/headless-phone/brownout-guard-state.json, keeps enforcement active through recovery hysteresis (>= RECOVER_SOC and >= RECOVER_VOLTAGE_MV while charging/stable for RECOVER_SECONDS), and resumes shed units automatically (or manually via --resume).
Day-to-Day Commands
Section titled “Day-to-Day Commands”# Inspect live power telemetry, weak-charger detection, shed state, and effective configbrownout-guard --status
# Machine-readable JSON reportbrownout-guard --status --json
# Manually resume shed units and clear shed statesudo brownout-guard --resume
# Evaluate one cycle without mutating services or statebrownout-guard --once --dry-runDisabling or Re-Enabling Cleanly
Section titled “Disabling or Re-Enabling Cleanly”The guard is a standalone systemd service — toggle it anytime without affecting any other subsystem:
# Disable completelysudo systemctl disable --now brownout-guard.service
# Re-enable anytimesudo systemctl enable --now brownout-guard.serviceCustomizing /etc/headless-phone/brownout-guard.conf
Section titled “Customizing /etc/headless-phone/brownout-guard.conf”Create or edit /etc/headless-phone/brownout-guard.conf using simple KEY=VALUE lines (parsed strictly in Python without shell evaluation; never overwritten by os-upgrade).
Precedence (highest wins): CLI flags > environment variables > /etc/headless-phone/brownout-guard.conf > built-in defaults.
# Shed active units on sustained drain <= 15% SOC or voltage sag <= 3450 mVSHED_SOC=15RECOVER_SOC=25CRITICAL_VOLTAGE_MV=3450RECOVER_VOLTAGE_MV=3650
# Hysteresis timers (seconds)SUSTAINED_SECONDS=60VOLTAGE_SUSTAINED_SECONDS=15RECOVER_SECONDS=30POLL_INTERVAL_SECONDS=15
# Space- or comma-separated systemd unit names to shed when activeSHED_UNITS=frigate-camera.service,my-heavy-worker.service
# Behavior toggles (0 or 1)RESUME_ON_RECOVER=1WARN_WEAK_CHARGER=1
# Net discharge current threshold (uA) treated as active battery drainDISCHARGE_CURRENT_UA=50000Full Configuration Reference
Section titled “Full Configuration Reference”| Key | CLI Override | Default | Valid Range / Notes |
|---|---|---|---|
SHED_SOC |
--shed-soc |
15 |
5..95 (%). Sustained low-SOC drain threshold before shedding. |
RECOVER_SOC |
--recover-soc |
25 |
> SHED_SOC..100 (%). SOC required before auto-recovery begins. |
CRITICAL_VOLTAGE_MV |
--critical-voltage-mv |
3450 |
3000..4200 (mV). Fast voltage-sag shed trigger. |
RECOVER_VOLTAGE_MV |
--recover-voltage-mv |
3650 |
> CRITICAL_VOLTAGE_MV (mV). Voltage required before auto-recovery. |
SUSTAINED_SECONDS |
--sustained-seconds |
60 |
Seconds low SOC must persist before shedding. |
VOLTAGE_SUSTAINED_SECONDS |
--voltage-sustained-seconds |
15 |
Seconds critical voltage sag must persist before shedding. |
RECOVER_SECONDS |
--recover-seconds |
30 |
Sustained healthy-power duration before resuming shed units. |
POLL_INTERVAL_SECONDS |
--poll-interval-seconds |
15 |
Daemon poll interval in seconds. |
SHED_UNITS |
--shed-units |
frigate-camera.service |
Space/comma-separated allowlisted unit names (.service, .timer, .socket, .target, .mount, etc.). Disabled or masked units are skipped on resume. |
RESUME_ON_RECOVER |
--resume-on-recover |
1 |
1 auto-resumes previously active shed units on recovery; 0 leaves them stopped until manual --resume. |
WARN_WEAK_CHARGER |
--warn-weak-charger |
1 |
1 logs a rate-limited journal warning (~every 15 min) when draining on a weak charger. |
DISCHARGE_CURRENT_UA |
--discharge-current-ua |
50000 |
Net discharge current threshold (50 mA) used to confirm active battery drain. |
Additional CLI options: --config <PATH>, --sysfs-root <PATH> (or HEADLESS_SYSFS_ROOT), --state-file <PATH>, --once, --dry-run, --status, --json, --resume.
Exit codes: 0 on clean daemon exit, --status, --once, or successful --resume; 1 if manual --resume fails to restart a unit; 2 on invalid configuration (ConfigError).
Battery Charge Capping (charge-limit.service)
Section titled “Battery Charge Capping (charge-limit.service)”For safe 24/7 plugged-in operation without battery swelling, charge-limit.service runs /usr/local/sbin/charge-limit on boot and configures hardware battery thresholds to 55% start / 70% stop by default.
Customizing Thresholds
Section titled “Customizing Thresholds”Create /etc/headless-phone/charge-limit.conf (protected from OTA overwrites; also configurable in the WebUSB Installer):
CHARGE_START=60CHARGE_STOP=80Both values must be integers satisfying 20 <= CHARGE_START < CHARGE_STOP <= 100. Apply immediately without rebooting:
sudo systemctl restart charge-limit.serviceHow it works under the hood:
- Polls sysfs up to
HEADLESS_CHARGE_LIMIT_RETRIESseconds (default15) to handle boot-timeENODATAfrom fuel gauge drivers. - Probes interfaces in priority order: (a) Pixel
google,charger/battery(charge_start_level+charge_stop_level), (b) standard Linuxcharge_control_start_threshold+charge_control_end_threshold, (c) standard Linux end-onlycharge_control_end_threshold. - Writes
stopbeforestartwhen raising thresholds (avoiding kernelstart >= cur_stoprejection) and performs read-back verification.
16-Rail ODPM Power Telemetry (power-metrics)
Section titled “16-Rail ODPM Power Telemetry (power-metrics)”Google Tensor SoCs expose 16 hardware power-rail energy accumulators (s2mpg10-odpm and s2mpg11-odpm) through Linux IIO (/sys/bus/iio/devices/iio:device*). /usr/local/sbin/power-metrics samples two snapshots over --interval seconds (default 1.0) to compute exact milliwatt draw per rail alongside Linux battery telemetry.
# Live human-readable power breakdown across all 16 ODPM rails + batterysudo power-metrics
# Longer averaging window (5 seconds)sudo power-metrics --interval 5
# Emit Prometheus textfile metrics to stdoutsudo power-metrics --prometheus
# Atomically write a Prometheus node_exporter textfile collector filesudo power-metrics --prom-file /var/lib/node_exporter/textfile_collector/headless_power.promExported Prometheus Metrics
Section titled “Exported Prometheus Metrics”| Metric | Type | Labels / Meaning |
|---|---|---|
headless_phone_rail_energy_microjoules |
counter |
{chip, rail, subsystem} — cumulative rail energy in µJ |
headless_phone_rail_power_milliwatts |
gauge |
{chip, rail, subsystem} — average draw in mW over --interval |
headless_phone_battery_capacity_percent |
gauge |
Battery state of charge (%) |
headless_phone_battery_voltage_volts |
gauge |
Battery voltage (V) |
headless_phone_battery_power_milliwatts |
gauge |
Battery power (mW, negative = discharging) |
headless_phone_battery_temperature_celsius |
gauge |
Battery pack temperature (°C) |
OLED Display Shutoff (display-off)
Section titled “OLED Display Shutoff (display-off)”The Pixel bootloader leaves continuous-splash enabled on the OLED panel (~0.8–1.1 W draw and burn-in risk on intact screens). Udev rule /etc/udev/rules.d/90-headless-display-off.rules automatically invokes display-off@card0.service whenever a DRM display card appears.
/usr/local/sbin/display-off uses pure-Python Linux DRM KMS ioctls (no libdrm, no Wayland/X11) to take DRM master ownership with a temporary black dumb buffer, disable every connected CRTC, and drop idle power from ~1.34 W down to 0.22 W (VSYS_PWR_DISPLAY = 0.00 mW).
# Run manually across all /dev/dri/card* nodes or a specific cardsudo display-offsudo display-off --card /dev/dri/card0(Note: systemd-backlight@.service is masked in the rootfs so systemd never restores stale backlight brightness.)
USB-C Dual-Role Switching (usb-role)
Section titled “USB-C Dual-Role Switching (usb-role)”Pixels feature a dual-role USB-C port (Host/DFP for Ethernet adapters, USB 3.0 hubs, and PD docks; Device/UFP for a PC recovery serial console). Udev rule /etc/udev/rules.d/90-headless-usb-role.rules triggers usb-role.service on typec and udc events with StartLimitIntervalSec=0 so rapid PD dock negotiation bursts never trip systemd rate limits.
- In
host(orunknown) role: Unbinds/sys/kernel/config/usb_gadget/headless/UDCsoxhci-exynosand USB-C Ethernet adapters/docks cleanly own the bus. - In
devicerole: Mountsconfigfs, configures the CDC ACM serial gadget (0525:a4a7,acm.usb0— chosen to bind Windows inboxusbser.syscleanly without colliding with Google ADB18d1:4ee7), applies GS101 DWC3 enumeration knobs (usb_data_enabled=1,force_speed=high-speed,update_sdp_enum_timeout=0x1), and triggersserial-getty@ttyGS0.service.
# Force a specific USB role manually (defaults to auto-detecting /sys/class/typec/port*/data_role)sudo /usr/local/sbin/usb-role hostsudo /usr/local/sbin/usb-role deviceQi Wireless Charging & Reverse Battery Share
Section titled “Qi Wireless Charging & Reverse Battery Share”Pixel 6 Pro’s Renesas P9412 Qi wireless coil (p9221 at 8-003c) supports both wireless charging telemetry (RX) and Reverse Wireless Power Share (Battery Share / RTX) via wireless-power:
# Inspect Qi RX voltage/current/alignment/negotiated power & RTX state (unprivileged)wireless-power statuswireless-power --json status
# Enable Reverse Battery Share TX (refuses if battery SOC < --min-soc, default 20%)sudo wireless-power rtx on --min-soc 30
# Turn off Reverse Battery Share TXsudo wireless-power rtx offTop-level flag: --json (must precede subcommand). rtx {on,off,status} also supports --min-soc <0..100> (default 20) and --force (override SOC guard).