How to disable battery charging during ADB connection?
Asked Answered
R

6

14

Problem description: Each time wen I connect USB cable between PC and my mobile phone the battery automatically is charged. I want to use ADB protocol but I don't want to charge my battery during ADB connection. Is it possible to to turn off this charging? And ofcourse how can I do this?

Environment: Mobile phone with Android os 4 and higher

I need only mention that my referential device working on android 5 so there is no /sys/class/power_supply/battery/force_usb_charging file

Ringer answered 9/6, 2015 at 12:21 Comment(5)
I don't think it's possible to do so.Angellaangelle
There is no link between android version and BSP it runs on top of on some device (i.e. your last sentence makes no sense). To answer your question - it can be done but the instructions will be device specific.Girdler
@ Bidhan A - Thank you for your reply but refering to this article forum.xda-developers.com/showthread.php?t=1662337 I think it should be possible (but of course you can have right)Ringer
@ CommonsWare - Thank you for you reply. Sure the wifi it is the way :-) but I need to use USB connectionRinger
@Alex P - Thank you for your reply - refering to above link there was some informations thah someone make it on android 4 (if I remember well) and that was the reason why I mention about my os version and this file. Of course I agree with your opinion that it depends of device.Ringer
R
4

Probably it can be done via (root privileges):

/sys/devices/battery.XX/power_supply/battery/hv_charger_set

0 - Disable USB Charging

1 - Enable USB Charging

Ringer answered 10/6, 2015 at 8:1 Comment(3)
Never thought that something like this will be possible. What will happen if your run out will this setting is onRedundancy
Then I hope you have wireless charging on your phone :)Henpeck
Thanks! This was in a different location on my phone but the hv_charger_set was the thing I needed as well. Works great! Thank youBelay
I
22

BEWARE: adb shell dumpsys battery unplug only MOCKS the battery status. I checked with a current indicator on my usb cable and this does not change the amount of flowing current at all so the battery is still charging. It only changes what applications think about the state, so for example google play would not start updating if you have configured that it can only update when charging...

Changing the value of a file like /sys/devices/battery.XX/power_supply/battery/hv_charger_set to 0 does really work but its a different file for every device. For example, for my yotaphone 2 with a snapdragon 805 there is a file: /sys/devices/qpnp-charger-14/power_supply/battery/charging_enabled

So you could make a script that you can use in tasker(if you have root):

echo $1 > /sys/devices/qpnp-charger-14/power_supply/battery/charging_enabled

if you write that to an executable file /data/setcharging.sh then you could call the script like /data/setcharging.sh 0 to disable or /data/setcharging.sh 1 to enable.

This works, I checked with my current metering usb cable, but it does not show that it works in the battery status icon. So you could use a combination of this and adb shell dumpsys battery unplug / reset to make it look better, but the problem is that then apps like tasker don't know whether you have ac power or not, so you can not put triggers for that when you've set it to unplugged...

One more thing, I also tested what it does in recovery (twrp) and during boot. And it turns out that during boot and in recovery, the charging just works. So its not like your device will end up dead if you forget to turn on charging again. You can always charge it in recovery mode and then boot up and change the value again (or change it while in recovery if your recovery gives access to adb).

Lastly, there are apps on the play store that are made exactly for this, but I would recommend getting such a current indicating usb-cable and checking if they really do what they say and are not just mocking.

Interlaken answered 23/7, 2017 at 15:58 Comment(0)
F
9

You can make the system think it is not loading th battery using

adb shell dumpsys battery unplug

Refer to this good article : https://stanfy.com/blog/android-shell-part-1-mocking-battery-status/

Frangible answered 24/8, 2016 at 13:55 Comment(2)
I can see the charging icon becomes to general battery icon on status bar, but why the level of battery still shows 100% after a long time ?Too
@Too See francis duvivier's answer. It answers your question. How did you miss it as a start xD.Nodular
D
7

Try this for rooted device:

To enable battery Charging:

    adb shell dumpsys battery set ac 1
    adb shell dumpsys battery set usb 1
    adb shell dumpsys battery set wireless 1

To disable battery Charging:

    adb shell dumpsys battery set ac 0
    adb shell dumpsys battery set usb 0
    adb shell dumpsys battery set wireless 0
Disconsolate answered 12/9, 2018 at 7:4 Comment(2)
Do you know if this actually stop charging? Like frank's answer? Or it only stops apps from seeing it's charging like francis duvivier said of another command?Nodular
Battery on my Pixel 3a stays charged after adb shell dumpsys battery set ac 0. So the answer doesn't really work, only emulatesImplicatory
B
5

if android os version is more than 6 use unplug and reset to revert back.

adb shell dumpsys battery unplug
adb shell dumpsys battery reset
Begay answered 3/7, 2020 at 22:51 Comment(0)
R
4

Probably it can be done via (root privileges):

/sys/devices/battery.XX/power_supply/battery/hv_charger_set

0 - Disable USB Charging

1 - Enable USB Charging

Ringer answered 10/6, 2015 at 8:1 Comment(3)
Never thought that something like this will be possible. What will happen if your run out will this setting is onRedundancy
Then I hope you have wireless charging on your phone :)Henpeck
Thanks! This was in a different location on my phone but the hv_charger_set was the thing I needed as well. Works great! Thank youBelay
T
0

Copied from perfetto.dev

On rooted phones the power management IC driver allows to disconnect the USB charging while keeping the USB data link active. This feature is SoC-specific, is undocumented and not exposed through any HAL. For instance on a Pixel 2 this can be achieved running, as root: echo 1 > /sys/devices/soc/800f000.qcom,spmi/spmi-0/spmi0-02/800f000.qcom,spmi:qcom,pmi8998@2:qcom,qpnp-smb2/power_supply/battery/input_suspend. Note that in most devices the kernel USB driver holds a wakelock to keep the USB data link active, so the device will never fully suspend even when turning the screen off.

Tiercel answered 6/9, 2021 at 12:34 Comment(1)
An easier way is probably just use wireless debugging, in which case you have adb, and you are not charging.Tiercel

© 2022 - 2024 — McMap. All rights reserved.