1

Why is writing to /sys/class/power_supply/battery/status having no effect?

Accessed manually via adb shell as root, eg echo "Discharging" > /sys/class/power_supply/battery/status does not change the file's contents. vi does not want to save any changes. touch also fails to create a test file in the same directory.

Permissions were 444 originally, but changed to 644 with chmod.

The goal is to use Battery Charge Limit to limit how much the phone's battery is charged, and that app writes to a control file to achieve this. Since the app isn't working on this phone I tried to test writing manually to diagnose.

The phone is a Samsung Gio GT-S5660M running Cyanogenmod 11 which is the most recent ROM I found for it.

File system and memory:

root@gio:/ # df
Filesystem               Size     Used     Free   Blksize
/dev                   136.9M   136.0K   136.7M   4096
/sys/fs/cgroup         136.9M     0.0K   136.9M   4096
/mnt/asec              136.9M     0.0K   136.9M   4096
/mnt/obb               136.9M     0.0K   136.9M   4096
/mnt/fuse              136.9M     0.0K   136.9M   4096
/system                206.4M   185.2M    21.3M   4096
/data                  178.4M   114.7M    63.7M   4096
/cache                  24.8M     4.2M    20.6M   4096
/mnt/media_rw/sdcard0     1.8G     4.3M     1.8G   32768
/mnt/secure/asec         1.8G     4.3M     1.8G   32768
/storage/sdcard0         1.8G     4.3M     1.8G   32768
root@gio:/ # free
             total         used         free       shared      buffers
Mem:        280276       267796        12480            0         3672
-/+ buffers:             264124        16152
Swap:        49148         4580        44568
root@gio:/ # mount
rootfs / rootfs ro,relatime 0 0
tmpfs /dev tmpfs rw,seclabel,nosuid,relatime,mode=755 0 0
devpts /dev/pts devpts rw,seclabel,relatime,mode=600 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,seclabel,relatime 0 0
selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0
none /acct cgroup rw,relatime,cpuacct 0 0
none /sys/fs/cgroup tmpfs rw,seclabel,relatime,mode=750,gid=1000 0 0
none /sys/fs/cgroup/memory cgroup rw,relatime,memory 0 0
tmpfs /mnt/asec tmpfs rw,seclabel,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,seclabel,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/fuse tmpfs rw,seclabel,relatime,mode=775,gid=1000 0 0
none /dev/cpuctl cgroup rw,relatime,cpu 0 0
/dev/block/stl12 /system ext4 ro,seclabel,relatime,user_xattr,acl,barrier=1,data=ordered 0 0
/dev/block/stl13 /data ext4 rw,seclabel,nosuid,nodev,relatime,user_xattr,acl,barrier=1,data=ordered 0 0
/dev/block/stl14 /cache ext4 rw,seclabel,nosuid,nodev,relatime,user_xattr,acl,barrier=1,data=ordered 0 0
/sys/kernel/debug /sys/kernel/debug debugfs rw,relatime 0 0
/dev/block/vold/179:1 /mnt/media_rw/sdcard0 vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/block/vold/179:1 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/fuse /storage/sdcard0 fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
adatum
  • 113
  • 5
  • @beeshyams If writing to the status file does not work, it could explain why BCL is not working. Even though BCL is no longer maintained, it is simple and works well on another phone. The Samsung Gio is very old and limited in storage (178MB internal). And I don't know if ACCA or Magisk still support android 4.4.4. Maybe I could try the ACC install on its own, but I would like to figure out why writing is failing on this ROM. Am I missing something simple? – adatum Jun 02 '21 at 14:33
  • Also the file is not identical in all devices, that is what I tried to explain in answer here https://android.stackexchange.com/q/167260/131553 – beeshyams Jun 02 '21 at 14:46
  • 1
    @beeshyams To clarify, the file does exist and cat /sys/class/power_supply/battery/status always shows Charging even when fully charged. But I cannot write to it with echo or vi, even when root has write permissions to the file, and I can't create a file in the same directory with touch. I'm trying to understand why writing is not working and how to have it succeed before looking further about control files or charge limiting apps. – adatum Jun 02 '21 at 16:17
  • Similar problem I had way back and alternative that worked due me here https://android.stackexchange.com/a/127286/131553. I have no idea as to why this approach worked and yours doesn't – beeshyams Jun 02 '21 at 16:31
  • According to this, it's read only in some cases, while in others it can be used as you intend to/Maybe your's falls in that category? – beeshyams Jun 03 '21 at 09:51
  • @beeshyams Is read/write access in that documentation referring to file permissions? If so, as mentioned the permissions for the status file were 444 (read only) but I changed them temporarily with chmod to 644 but still could not write. – adatum Jun 03 '21 at 13:36
  • @beeshyams I just checked and SELinux is in permissive mode by default. I updated the question to include the output of df, free, and mount. Note that the phone's internal storage is only 178MB, so maybe the issue is with how sysfs or tmpfs is used? I don't know, just speculating. – adatum Jun 04 '21 at 19:45
  • The 1.8G comes from the 2GB microSD card that is installed. – adatum Jun 04 '21 at 23:05

1 Answers1

1

By default, the /sys directory tree is read-only and maintained by Android's Linux kernel. Using it to control charging would require a customised kernel, and AFAIK Cynogenmod had a pretty generic kernel.

John Dallman
  • 1,091
  • 9
  • 24