No battery level in status bar on Nexus 5

On my Nexus 5 I don't see the battery level in the status bar. The reason is that the script sxmo-utils/scripts/core/sxmo_statusbar.sh assumes to find the battery level in /sys/class/power_supply/*-battery/capacity. But on my Nexus 5, the path is /sys/class/power_supply/battery/capacity.

This simple patch could fix the status on the Nexus 5 while (probably) keep it working on other devices:

diff --git a/scripts/core/sxmo_statusbar.sh b/scripts/core/sxmo_statusbar.sh
index ae62a9d..76eef93 100755
--- a/scripts/core/sxmo_statusbar.sh
+++ b/scripts/core/sxmo_statusbar.sh
@@ -54,9 +54,9 @@ update() {

        # Battery pct
-       PCT="$(cat /sys/class/power_supply/*-battery/capacity)"
+       PCT="$(cat /sys/class/power_supply/*battery/capacity)"
-               cat /sys/class/power_supply/*-battery/status |
+               cat /sys/class/power_supply/*battery/status |
                cut -c1
        if [ "$BATSTATUS" = "C" ]; then

Could this cause problems on other devices? Like matching more than one folder when *battery is used as glob pattern!?

Assigned to
1 year, 5 months ago
1 year, 1 month ago
bug ready

~anjan 1 year, 5 months ago

Hi ~maxgyver83,

I would prefer if we made the battery cat issue by using the device profiles from this patch: https://lists.sr.ht/~mil/sxmo-devel/patches/22251 rather than file globbing.

Do you have this file on the nexus 5? /sys/firmware/devicetree/base/compatible. That is required for the device profiles to work.

~anjan 1 year, 5 months ago

~craftyguy says that what is in that patch "could be expanded, e.g. some function to try base/compatible from the DT, then maybe look elsewhere for other clues about the device type, for selecting the right profile"

Might be worthwhile exploring in case nexus 5 doesnt have that file.

~maxgyver83 1 year, 5 months ago

Sounds good! /sys/firmware/devicetree/base/compatible exists on my Nexus 5 and it contains: lge,hammerheadqcom,msm8974.

~craftyguy 1 year, 5 months ago

Great, so you can add a new script in the sxmo-utils repo under scripts/deviceprofile/hammerheadqcom.sh, that can set something like BATTERY_DEVICE=/sys/class/power_supply/foo/status (use real path, obviously :P). Then in sxmo_statusbar.sh use that value if that var is set, else default to the glob (to preserve existing behavior).

Though at some point it might make more sense to do away with default values for these things and just have a profile for every device, including the Pinephone? (a bigger question to the sxmo maintainers/folks)

~anjan closed duplicate ticket #253 1 year, 4 months ago

~anjan 1 year, 4 months ago

We added support for custom battery locations in deviceprofiles with this patch: https://lists.sr.ht/~mil/sxmo-devel/patches/22787

Feel free to add the nexus and other devices.


~sorsha 1 year, 3 months ago


This bug still persists on my PinePhone.

PCT="$(cat "$BATTERY_DEVICE"/capacity)"
cat: '/sys/class/power_supply/*-battery/capacity': No such file or directory

This works for me:

BATTERY_DEVICE="$(eval echo /sys/class/power_supply/*-battery)"


~proycon 1 year, 3 months ago

I can reproduce the problem on my pinephone as well, I think something went wrong when we accepted that patch, will fix...

~proycon 1 year, 3 months ago

Actually, I see ~stacyharper already fixed this in commit 200ecfa1a72ca87913e27b22f90cb40c7280d715 (in the latest git master tree)

~stacyharper 1 year, 3 months ago

Yes sorry for not pointed this earlier !

~noneofyourbusiness 1 year, 3 months ago

you could also have replaced PCT="$(cat "$BATTERY_DEVICE"/capacity)" with PCT="$(eval cat "$BATTERY_DEVICE"/capacity)"
but hardcoding the path also works

~maxgyver83 1 year, 2 months ago

Thanks for all your answers and patches and sorry for my late reply. I have tested the master branch and it works when I add a device profile for my Nexus 5. I have created this patch for adding it: https://lists.sr.ht/~mil/sxmo-devel/patches/23640

~anjan FIXED REPORTED 1 year, 2 months ago

~anjan 1 year, 2 months ago

Please dont mark as fixed, we have to keep track of issues that are fixed in the git HEAD but not in a release.

~maxgyver83 1 year, 2 months ago

OK, I see!

~proycon REPORTED FIXED 1 year, 1 month ago

Fixed now after release

Register here or Log in to comment, or comment via email.