Skip to content

Battery


Freezing Battery State

adb shell cmd battery unplug -f

Unfreeze Battery State

adb shell cmd battery reset -f

Dump Battery Level

adb shell cmd battery get level | sed 's/.*/Battery:&%/'

Dump all settings for cmd battery (posix)

#!/bin/bash
# Author: wuseman

batstats="ac usb wireless status level temp present counter invalid"

for batstat in $batstats; do
  value=$(adb shell cmd battery get "$batstat")
  printf "%-8s: %s\n" "$batstat" "$value"
done

Simple examlpe of how to monitor the battery charging

#!/bin/bash
# Author: wuseman

adb logcat -c 

adb logcat -s AODBatteryManager  | awk -F' ' '/mRemainingChargeTime/ {
    split($15, arr, "=")
    gsub(",", "", arr[2])
    minutes = int(arr[2] / 60000)
    seconds = int((arr[2] % 60000) / 1000)
    if (!found) {
        print "Estimated time until fully charged: " minutes " min " seconds " seconds"
        found=1
        exit
    }
}'