Sony Nagara (Xperia 1IV and 5IV) port

As I kept having problems with the recharging limit which at some point just broke and I couldn’t make it work again, for my own use I modified BatteryBuddy 4.3.2-1 (which seems to be the latest release version) to work with the 1 & 5 IV. It is 100% functional now, including the upper and lower limits, current limit, notifications, etc. If someone wants either the modified source code (project ready to build in the SDK) or the rpm package, please let me know.

Or if someone would prefer to modify it oneself, here’s the information so that you don’t have to rediscover it:

  • the charging control file on Nagara is /sys/class/qcom-battery/charging_enabled (writing 1 to that file enables charging, 0 stops it)
  • to make current limitation work, one needs to control two files: write max current (in microamps) to /sys/class/qcom-battery/restrict_curr and write 1 to /sys/class/qcom-battery/restrict_chg to enable the limit (it gets reverted to 0 on every reboot, so in order for the current limit to work it has to be rewritten with 1 each time)
  • /sys/class/power_supply/usb/online informs whether usb charger is connected (0 or 1)
  • all the remaining files are already supported by BatteryBuddy as they remain the same as on some other devices, so there’s no need to modify anything to make those functions work, e.g. /sys/class/power_supply/battery/capacity (holds current charge level in %), /sys/class/power_supply/battery/temp (temperature), /sys/class/power_supply/battery/current_now (reports the charging current in uA), /sys/class/power_supply/battery/status (current status, e.g. charging, discharging, full, empty, etc.), /sys/power_supply/battery/health, and so on.
  • In addition to adding the 1/5 IV specific control files to application/src/battery.cpp and service/src/battery.cpp, one also needs to remember to include them in set-write-permissions.sh and restore-write-permissions.sh scripts so that write permissions are correctly set on boot (e.g. chmod 666 /sys/class/qcom-battery/charging_enabled 2>/dev/null), otherwise the control files won’t be writable for BatteryBuddy. I also used that script to write 1 to the file enabling to limit the charging current (echo 1 > /sys/class/qcom-battery/restrict_chg) so that it is re-enabled on each boot. Well, and that’s it….

I will contact @direc85 and ask him if he would like to officially include those Xperia 1 & 5 Mk IV specific control files in Battery Buddy, but for now we can easily make it work ourselves, as indicated above. I’ve been testing it for a couple of days now and it works 100% OK.

5 Likes