Skip to content

omamobile-settings: a Battery page with a charge limit (80-100 %) for husky - #860

Merged
derekross merged 5 commits into
derekross:mainfrom
Somnius:settings-charge-limit-1116
Nov 18, 2026
Merged

derekross merged 5 commits into
derekross:mainfrom
Somnius:settings-charge-limit-1116

Conversation

@Somnius

@Somnius Somnius commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

This adds a Battery page to omamobile-settings with a charge limit: 80, 85, 90, 95 or 100 %. It writes charge_control_end_threshold on the max77759-charger.

It depends on the charger PRs, starting with derekross/linux-omarchy-mobile#266. Without them there is no max77759-charger power supply on husky (omamobile-device-husky still blacklists max77759_charger), so the page just says the charge limit is not available.

How it works: the page calls backends/charge.sh like the Display page does. Setting a value runs systemctl start --no-ask-password omamobile-charge-limit@N.service. A polkit rule lets the active local user start only those five instances, same pattern as the gnss and earpiece rules. The unit runs a small root helper that sets the start threshold to 0, then the end threshold, and only after that saves the value to /etc/omamobile/charge-limit (same file tegu uses). Anything other than 80/85/90/95/100 is refused.

At boot a udev rule on the charger pulls in omamobile-charge-limit-apply.service, which applies the saved value. It only does that on husky (google,zuma-husky in the device tree), so other max77759 phones are left alone. The second commit drops the ACTION=="add" filter from that rule, because with it the apply unit never started at boot on my phone.

I put the udev rule and units in the settings package since the helper lives there. If the hook fits better in omamobile-device-husky like tegu's, I can move it.

What I tested: test/all passes on my desktop (charge backend and helper tests against a scratch root, core tests, lifetime, single-instance), and --check is clean. On my Pixel 8 Pro with the charger PRs installed: I tapped 90 % and it applied, the limit came back at boot after the udev fix, and it held at 90 % overnight (Nov 16 to 17). I haven't tried it on any other phone.

Version is 0.1.3 for now, it will need renumbering against #629 and #630.

@Somnius

Somnius commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Here's the page on my Pixel 8 Pro, and the overnight run with the limit at 90 %: it charged from 83 % to 90 % by about 00:10, then held at 89-90 % with the battery current near zero until morning.

The page builds on omamobile-settings that @marselnenaj started in #526. It's a great app to have on the phone, so I'd rather add pages to it than keep separate scripts.

Battery page

overnight at the 90 % limit

@derekross

Copy link
Copy Markdown
Owner

Thank you, Lef. This is carefully built: the fixed argument list, the polkit rule limited to five instance names with the helper checking the value again, the charger written before the file is saved, the boot path that does nothing without a saved value, and tests for each refusal. I ran the helper in a scratch root and read it against derekross/linux-omarchy-mobile#266. On today's published kernel it is inert on every phone, as you say. The overnight chart at 90 % is nice to see.

Four things before it can merge. The first two are about the other phones, because Settings is installed everywhere:

  1. Only the boot path is husky-only. charge.sh get says "available" wherever max77759-charger has charge_control_end_threshold, and charge-limit N with an argument never checks the phone. In Boot splash for the 8 Pro: an Omarchy-style animated trace (two previews, can I send a PR?) #266 the two threshold properties are in the charger's property list for every board, so once that kernel is published the page is live on the Pixel 7 Pro and the other MAX77759 phones: a tap writes the limit there, and the boot unit then skips those phones, so the limit is gone after a reboot with nothing said. In a scratch root with a google,gs201-cheetah device tree, charge-limit 80 writes 80 and saves the file; with no argument it touches nothing. I'd like this to be husky's by declaration: the device package ships a small file that says "this phone has a charge limit on this power supply", the backend and both paths of the helper require it, and the udev rule and the apply unit move into omamobile-device-husky, as you offered and as the 9a's package does. Then nothing changes for the 7 Pro whatever kernel it runs, and another phone can opt in after its own run.

  2. The Battery row on phones without a limit. Every phone gets the row at its next update, and on all of them today (your 8 Pro on the published kernel too) the page's whole content is "Charge limit is not available on this phone." Please either hide the row when the backend reports no limit, or give the page something true everywhere (level and charging state) with the limit below it where it exists. On the 9a the sentence is also wrong: that phone has a limit through /etc/omamobile/charge-limit.

  3. Order. The page can do something only after Boot splash for the 8 Pro: an Omarchy-style animated trace (two previews, can I send a PR?) #266 is merged and in a published kernel and after device-husky stops blacklisting max77759_charger, which is the charging work on Pixel 8 Pro (husky): charging stops at 92 %, the cause and a plan for review #761. I'm happy to take the userspace side first once 1 and 2 are in, since it is then inert everywhere else by construction; I just don't want the row on every phone before that.

  4. The phone run. Please add the kernel release (uname -r) of the test kernel, the package versions, a tools/phone-smoke report from that boot, and systemctl status of omamobile-charge-limit@90.service and of omamobile-charge-limit-apply.service after the reboot.

Smaller:

@Somnius
Somnius force-pushed the settings-charge-limit-1116 branch from cf35ec9 to 72aa306 Compare November 18, 2026 08:50
@Somnius

Somnius commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@derekross thanks. Reworked in 72aa306, rebased on main:

  1. It's husky's by declaration now. omamobile-device-husky ships /usr/share/omamobile/charge-limit.conf with one line, supply=max77759-charger. charge.sh get/set and both paths of the helper need it (the name is checked, so nothing like ../ gets through): without it get says not available, charge-limit N refuses with exit 1 and saves nothing, and the no-argument path exits 0 and touches nothing. The old device-tree check is gone. The udev rule and omamobile-charge-limit-apply.service moved into the husky package, and the apply unit has ConditionFileIsExecutable= on the helper, so husky without Settings just skips it. The @N unit and the polkit rule stay in Settings. There's a test for your case, a charger with the threshold but no declaration: nothing is written.
  2. The Battery row is hidden unless the backend says the limit is available, also in search. The page's own sentence is now "Settings cannot set a charge limit on this phone.", which is also true on the 9a (its limit lives in /etc/omamobile/charge-limit and Settings leaves it alone; the README says so).
  3. The small ones: the tr | grep -qx is gone with the device-tree check, the udev comment reads in order with your reason for dropping ACTION, and the test message is fixed.

Husky is 0.1.16 here because #836 takes 0.1.15; I know you set the numbers at merge.

Not done yet: the phone run you asked for in 4 (uname -r, versions, tools/phone-smoke, and the two systemctl status after a reboot). It needs #266 in my kernel and the charger driver loaded, so I'll post it with the #266 re-runs. Until #266 is in a published kernel this stays inert everywhere, husky included.

@derekross

Copy link
Copy Markdown
Owner

Thank you, Lef. Both of the larger points are done the way I hoped, and I checked them by running the helper rather than reading it: in a scratch root shaped like a Pixel 7 Pro on a kernel with linux-omarchy-mobile#266 (a max77759-charger with both threshold files and no declaration), charge-limit 80 says "this phone declares no charge limit", exits 1, leaves the threshold alone and saves nothing, and the boot path exits 0 without touching anything. The row hidden by "requires": "charge", in the list and in search, is a nice general mechanism; the haptics page can use it too.

CI is red on this head, and it isn't yours: the one failure is flash: the saved brightness goes back only after the panel is off in omamobile-shell's key test, a race in our own test that #889 fixes. The Settings and device-husky suites both passed in that run.

One thing I'd like changed before I merge:

  • The new Qt tests read whatever backend is installed on the machine running them. batteryPageLoadsAndShowsTheBackendAnswer runs the real charge get through the runner's fixed directory and then expects "not available". On your 8 Pro with this package installed and the charger live, the installed backend says "available", so the test fails and the package can no longer be built on the phone it is for (tools/phone-install-package runs the tests). The start-up probe in Backend has the same reach in every test that builds a Backend and then waits on the event loop. Please give both a backend directory the tests can set and point them at a stub, once answering available and once not. omamobile-settings: lock screen timeout, and lock after 30 minutes while a keyboard is connected #866 already adds ActionRunner::setBackendDir(); the probe needs the same.

Smaller, as you like:

  • The helper's check of the supply name isn't really tested: an empty name and ../max77759-charger both end at a path that doesn't exist, so the test passes with the check removed. supply=../power_supply/max77759-charger would test the check itself.
  • A README line that the row appears only if the charger was there when Settings started.

On order, I'm changing what I said last time. #866 now waits for #879 and for phone runs, and this one is inert on every phone until the charger work lands, so I'll take this one first as omamobile-settings 0.1.3 and #866 can be rebased onto it as 0.1.4 (the conflicts are all "keep both"; the one to watch is depends, where #866's test wants coreutils before systemd). For husky, 0.1.16 is right if #836 goes in first; I'll set the numbers when I merge.

The phone run from my last comment still stands, and I understand it needs #266 in your kernel: uname -r, the package versions, a tools/phone-smoke report, systemctl status of omamobile-charge-limit@90.service and of omamobile-charge-limit-apply.service after a reboot, and one sleep with the cable in while the limit is holding. Post it with the #266 re-runs; it doesn't hold this PR.

…77759-charger

The page runs backends/charge.sh like the Display page does. Setting a value
runs systemctl start --no-ask-password omamobile-charge-limit@N.service (a
polkit rule allows those five instances for the active local user), which runs
libexec/charge-limit as root: start threshold 0 (resume 5 below), then the end
threshold, and only then /etc/omamobile/charge-limit is saved. No writable end
threshold or a failed write: exit 1, nothing saved.

At boot a udev rule on the charger's add pulls in
omamobile-charge-limit-apply.service, which applies the saved value on husky
only (device tree google,zuma-husky). Units have StartLimitIntervalSec=0.

Note: the page is inert on husky today. omamobile-device-husky blacklists
max77759_charger, so there is no max77759-charger power supply and the page
says the limit is not available until that blacklist is lifted.

Version 0.1.3 (to be renumbered at merge; derekross#629 and derekross#630 hold 0.1.3/0.1.4).
Tests: test/charge-backend.sh against a scratch root (backend, helper, a
stand-in systemctl, polkit/unit/udev contents, staged paths and modes), core
tests open BatteryPage and check the runner's charge entry.
…CTION filter

With ACTION=="add" the apply unit never started at boot on a Pixel 8
Pro; with the filter gone it starts and sets the saved limit. Checked
across a reboot on the phone.
…where the device package declares it

Settings' charge backend and both paths of the root helper now need
/usr/share/omamobile/charge-limit.conf (supply=NAME), which only
omamobile-device-husky ships. The udev rule and the apply unit move to
device-husky. The Battery row is hidden unless charge.sh get says a limit
is available. The device-tree check (and its tr | grep -qx pipe) is gone,
the udev comment is put back in order and the test message fixed.
ActionRunner and Backend's start-up probe take a backend directory
(setBackendDir, as in derekross#866); the probe now starts from the event loop so
the setter applies. The Qt tests point both at stub charge.sh scripts and
check the available and not-available answers. The helper test adds
supply=../power_supply/max77759-charger, which only the name check
refuses. README: the Battery row needs the charger present at start.
… backends too

The separately built session test entrypoint sets both backend dirs from
OMAMOBILE_SETTINGS_TEST_BACKENDS (a path that doesn't exist by default), so
test/single-instance.py no longer runs the installed charge.sh. The runner
test checks the stub's own answer, not only that the error isn't a refusal.
@Somnius
Somnius force-pushed the settings-charge-limit-1116 branch from 72aa306 to 7c586ae Compare November 18, 2026 16:41
@Somnius

Somnius commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@derekross done in c20a80d and 7c586ae:

  • ActionRunner::setBackendDir() with the same name and shape as omamobile-settings: lock screen timeout, and lock after 30 minutes while a keyboard is connected #866's, and the same setter on Backend for the start-up probe. The probe now starts one event-loop turn after the constructor, so a setter called right after construction comes in time. The tests point every Backend and ActionRunner at stub dirs, one answering {"available":true,"limit":90} and one {"available":false}. The Battery page test and a new probe test run once with each.
  • The separately built session test app (test/single-instance.py) was still running the installed charge.sh once through its probe. It now takes both dirs from OMAMOBILE_SETTINGS_TEST_BACKENDS, a path that doesn't exist by default. The runner test also checks the stub's own answer now, not only that the error isn't a refusal.
  • The supply-name check has its own test: supply=../power_supply/max77759-charger is refused on the set path and the boot path. With the check taken out the test fails ("accepted: 95").
  • README: the row only appears if the charger was there when Settings started.

Rebased on main. test/all and tools/pr-check pass here. When this and #866 meet, the conflicts are the comment and tool lists, the core tests side by side, PKGBUILD, README and install, all keep-both. setBackendDir itself is the same on both sides. The phone run waits for #266 as you said.

@derekross derekross left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Lef. That is everything I asked for, and I checked it rather than read it: with the name check taken out of the helper, test/charge-backend.sh now fails on supply=../power_supply/max77759-charger ("accepted: 95"), where last round it stayed green; the Qt tests point every Backend and ActionRunner at stubs and run the page once with a limit and once without; and the test-only backend directory exists only in the separately built session test app, not in the shipped binary. CI is green on this head.

I'm merging this as omamobile-settings 0.1.3 and omamobile-device-husky 0.1.16. I'll write the squash message by hand, since the first commit still describes the device-tree check.

Two things follow from it:

  • #866 now conflicts with main in seven files. They are all "keep both": depends is the union with coreutils before systemd (your test checks that), the runner's list becomes display, charge, lock, and setBackendDir is the same on both sides. It becomes 0.1.4.
  • The phone run stays as agreed, with the #266 re-runs: uname -r, the package versions, a tools/phone-smoke report, systemctl status of omamobile-charge-limit@90.service and of omamobile-charge-limit-apply.service after a reboot, and one sleep with the cable in while the limit is holding. Until then nothing on any phone can reach the page.

@derekross
derekross merged commit 8a44adc into derekross:main Nov 18, 2026
2 checks passed
Somnius added a commit to Somnius/omarchy-mobile that referenced this pull request Nov 18, 2026
… keyboard

The Display page gets 30 s, 1, 2, 3, 5 min and Never, plus an on/off for
staying unlocked while a keyboard is connected. The text says that lock and
screen off are the same timer and that Never also keeps the phone awake.
0.1.3 clashes with open derekross#629, derekross#630 and derekross#860; renumber at merge.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants