Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable battery charging during ADB connection?

Tags:

android

adb

usb

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

like image 676
frank Avatar asked Jun 09 '15 12:06

frank


People also ask

How do I stop charging when USB is connected?

As per my experience you can't disable that charging, your device will always receive that voltage from USB port and you can't stop it(unless you plug your device out).

How do I stop charging my phone when connected to a laptop?

There are a few ways to do this: 1. Use the phone's settings to disable charging when connected to a computer. 2. Unplug the phone from the computer.

How do you stop Android Auto charging?

Android Auto has no control over the charging of your phone - this is how all vehicle USBs are wired. However, you're free to modify a USB cable - remove (aka cut) the voltage wire (Google a wiring diagram of a USB cable), then you will not charge the phone.


5 Answers

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.

like image 97
francis duvivier Avatar answered Oct 16 '22 20:10

francis duvivier


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

like image 42
frank Avatar answered Oct 16 '22 22:10

frank


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
like image 24
Fuad All Avatar answered Oct 16 '22 21:10

Fuad All


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/

like image 42
Nicolas Bossard Avatar answered Oct 16 '22 21:10

Nicolas Bossard


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
like image 36
Sudhir Sinha Avatar answered Oct 16 '22 21:10

Sudhir Sinha