Disable USB charging For some reasons not related to the battery life, I need to disable the battery charging when a USB host is connected to my phone (a rooted Nexus 4). Taking a look around on the internet (link1, link2), it looks like I should modify a system file. I have found a series of interesting files located in /sys/class/power_supply/battery and /sys/class/power_supply/usb, that could be the right ones to be modified in order to achieve the usb charging disabling (e.g. /sys/class/power_supply/usb/present 0/1). 

Has anyone tried something like that (control the usb charging via software and modify such system files)? Which is the best way to modify those system files? Should I use the adb shell or another tool?

I tried the "root explore" app in order to modify those files, however when I modified a file (after changing its permissions), it was automatically kept back to its original value.
I just tried and found that you need to modify a file:
sys/class/power_supply/usb/device/charge

its default content is '1' which means 'enable charging'
you need to set it to '0' to 'disable charging'

$ su

$ echo 0 &gt; /sys/class/power_supply/usb/device/charge


I tested on Nexus 4 and it's working successfully.