fp6-img/aports/device/fp6-charging-mode/charging-mode-generator
Jorijn van der Graaf eb13c18ea8 aports: add fp6-charging-mode (offline charging, charger-boot detection)
Charger-insertion boots (androidboot.mode=charger, ABL-appended) divert to
a minimal charging.target instead of the full UI, ending the dead-battery
bootloop: ADSP charging/USB-PD runs, splash+panel killed ~6-10s in via an
initramfs hook, modem+cdsp stopped, radios/sensors suppressed, CPU capped.
Power key reboots to a normal boot, volume-up shows battery status,
volume-down enables USB ssh, unplug powers off. Measured >= breakeven on a
100mA-classified SDP port, strongly net-positive on real chargers.

Suspend duty-cycling (~13mA floor) exists behind an off-by-default flag:
resume from deep suspend intermittently kills the UFS link (hibern8 exit
failed ret=5) - do not enable until that kernel bug is fixed.

Byte-identical to the deployment verified on the dev phone 2026-08-24
(journal/power: r5 armed tests, crash autopsies, measurements).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-24 04:03:06 +02:00

41 lines
1.9 KiB
Shell
Executable file

#!/bin/sh
# systemd system generator: divert a charger-triggered boot to charging.target.
#
# The FP6 ABL appends "androidboot.mode=charger" to the kernel cmdline when
# the PMIC PON reason is a charger insertion (confirmed on-device 2026-08-24,
# journal/power). On such boots we swap the default target for the minimal
# charging.target instead of booting to the full UI.
#
# This must NEVER break a normal boot: every failure path falls through to
# exit 0 and the stock default.target.
#
# Escape hatch: /etc/charging-mode/disable — while it exists this generator
# is inert (deploy.sh creates it; arming = removing it).
#
# The CHARGING_MODE_* env overrides exist only for side-effect-free dry-runs
# on a live system; systemd invokes generators with a clean environment.
[ -e "${CHARGING_MODE_DISABLE_FILE:-/etc/charging-mode/disable}" ] && exit 0
grep -Eq '(^| )androidboot\.mode=charger( |$)' /proc/cmdline || exit 0
# $2 = early generator dir (highest priority in the unit search path that a
# generator can write to — beats /etc/systemd/system). Old single-arg
# invocation falls back to $1.
EARLY_DIR="${2:-$1}"
[ -n "$EARLY_DIR" ] && [ -d "$EARLY_DIR" ] || exit 0
ln -sf /etc/systemd/system/charging.target "$EARLY_DIR/default.target" || exit 0
# Marker for the ConditionPathExists=!/run/charging-mode drop-ins that keep
# radios/sensors (bluetooth, iio-sensor-proxy, hkdm) out of charging mode.
# Only created after the default.target diversion succeeded, so the
# suppressions can never leak into a normal boot.
: > "${CHARGING_MODE_MARKER:-/run/charging-mode}" 2>/dev/null
# Power key exits charging mode via reboot: a warm reboot PONs as HARD_RESET,
# so ABL does not re-append mode=charger and the next boot is a normal boot.
LOGIND_DIR="${CHARGING_MODE_LOGIND_DIR:-/run/systemd/logind.conf.d}"
mkdir -p "$LOGIND_DIR" 2>/dev/null && printf '[Login]\nHandlePowerKey=reboot\nHandlePowerKeyLongPress=reboot\n' > "$LOGIND_DIR/10-charging-mode.conf"
exit 0