Refresh the charge icon immediately on charger plug/unplug
This commit is contained in:
1 parent
6a6222c198
commit
eaf08abcd4
9 files changed
+159
-6
No files matched your search
@@ -176,6 +176,7 @@ chmod 0644 "$TARGET_ROOTFS/etc/chrony/chrony.conf" 2>/dev/null || true
|
||||
chmod 0755 "$TARGET_ROOTFS/usr/bin/bananarchy-idle-blank.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-idle-lock.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-screen-wake.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-battery-charge-event.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-time-sync.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-sync-net-time.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-network-event.sh" \
|
||||
|
||||
@@ -1180,6 +1180,31 @@ if command -v g++ >/dev/null 2>&1 && \
|
||||
fail "host Bluetooth scan parser test failed"
|
||||
fi
|
||||
|
||||
echo "[check] Charger plug/unplug charge icon..."
|
||||
BATTERY_RULES="$BASE_DIR/overlay/rootfs/etc/udev/rules.d/85-bananarchy-battery.rules"
|
||||
CHARGE_EVENT="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-battery-charge-event.sh"
|
||||
if [ ! -x "$CHARGE_EVENT" ] || ! sh -n "$CHARGE_EVENT" 2>/dev/null; then
|
||||
fail "bananarchy-battery-charge-event.sh is missing or has bad syntax"
|
||||
fi
|
||||
if ! grep -q 'bananarchy-battery-charge-event.sh' "$BATTERY_RULES" || \
|
||||
! grep -q 'KERNEL=="pm8916-lbc-chgr"' "$BATTERY_RULES" || \
|
||||
! grep -q 'POWER_SUPPLY_ONLINE' "$BATTERY_RULES"; then
|
||||
fail "battery udev rules no longer force a charge icon refresh on VBUS events"
|
||||
fi
|
||||
if ! grep -q '"$HOOK" force' "$CHARGE_EVENT" || \
|
||||
! grep -q 'flock -n 9' "$CHARGE_EVENT"; then
|
||||
fail "charger event helper no longer forces and coalesces icon refreshes"
|
||||
fi
|
||||
if ! grep -q 'bananarchy-battery-charge-event.sh' \
|
||||
"$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then
|
||||
fail "apply-bananarchy-overlay.sh no longer installs the charger event helper"
|
||||
fi
|
||||
if [ -x "$BASE_DIR/scripts/test-battery-charge-event.py" ] && \
|
||||
command -v python3 >/dev/null 2>&1 && \
|
||||
! "$BASE_DIR/scripts/test-battery-charge-event.py" >/dev/null 2>&1; then
|
||||
fail "host charger plug/unplug event test failed"
|
||||
fi
|
||||
|
||||
if [ "$FAILURES" -ne 0 ]; then
|
||||
echo "[check] $FAILURES check(s) failed."
|
||||
exit 1
|
||||
|
||||
Executable
+80
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Host integration test for the charger plug/unplug status bar refresh."""
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
BASE = pathlib.Path(__file__).resolve().parent.parent
|
||||
HELPER = BASE / "overlay/rootfs/usr/bin/bananarchy-battery-charge-event.sh"
|
||||
RULES = BASE / "overlay/rootfs/etc/udev/rules.d/85-bananarchy-battery.rules"
|
||||
HOOK = BASE / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_battery.sh"
|
||||
|
||||
HOOK_STUB = '''#!/bin/sh
|
||||
printf '%s\\n' "$*" >> "$FAKE_ROOT/hook.log"
|
||||
exit 0
|
||||
'''
|
||||
|
||||
|
||||
def main():
|
||||
for path in (HELPER, RULES, HOOK):
|
||||
if not path.is_file():
|
||||
sys.stderr.write("FAIL: missing %s\n" % path)
|
||||
return 1
|
||||
if subprocess.run(["sh", "-n", str(HELPER)]).returncode or \
|
||||
subprocess.run(["sh", "-n", str(HOOK)]).returncode:
|
||||
sys.stderr.write("FAIL: shell syntax\n")
|
||||
return 1
|
||||
rules = RULES.read_text(encoding="utf-8")
|
||||
if "bananarchy-battery-charge-event.sh" not in rules or \
|
||||
'KERNEL=="pm8916-lbc-chgr"' not in rules or \
|
||||
"ENV{POWER_SUPPLY_ONLINE}" not in rules:
|
||||
sys.stderr.write("FAIL: charger uevent rules are not wired\n")
|
||||
return 1
|
||||
hook = HOOK.read_text(encoding="utf-8")
|
||||
if '"force"' not in hook or 'FORCE_UPDATE=1' not in hook or \
|
||||
'rm -f "$ICON_FILE"' not in hook:
|
||||
sys.stderr.write("FAIL: battery hook cannot force an icon republish\n")
|
||||
return 1
|
||||
print("[ok] udev rules and forced battery hook")
|
||||
with tempfile.TemporaryDirectory(prefix="bananarchy-battery-") as tmp:
|
||||
root = pathlib.Path(tmp)
|
||||
stub = root / "hook.sh"
|
||||
stub.write_text(HOOK_STUB, encoding="utf-8")
|
||||
stub.chmod(0o755)
|
||||
log = root / "hook.log"
|
||||
env = dict(os.environ)
|
||||
env.update({
|
||||
"FAKE_ROOT": str(root),
|
||||
"BANANARCHY_BATTERY_HOOK": str(stub),
|
||||
"BANANARCHY_BATTERY_LOCK": str(root / "charge.lock"),
|
||||
"BANANARCHY_BATTERY_RECHECK_DELAY": "0",
|
||||
"DISPLAY": ":0",
|
||||
"XDG_RUNTIME_DIR": str(root / "runtime"),
|
||||
"HOME": str(root / "home"),
|
||||
})
|
||||
res = subprocess.run(["sh", str(HELPER)], env=env,
|
||||
capture_output=True, text=True)
|
||||
if res.returncode:
|
||||
sys.stderr.write("FAIL: helper exited %d: %s\n" % (res.returncode, res.stderr))
|
||||
return 1
|
||||
deadline = time.time() + 3
|
||||
calls = []
|
||||
while time.time() < deadline:
|
||||
calls = log.read_text().splitlines() if log.exists() else []
|
||||
if len(calls) >= 2:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
if calls != ["force", "force"]:
|
||||
sys.stderr.write("FAIL: expected an immediate and one delayed forced "
|
||||
"refresh, got %r\n" % calls)
|
||||
return 1
|
||||
print("[ok] immediate + delayed forced charge icon refresh")
|
||||
print("battery charger event: all checks passed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user