40

I'd like to find out various bits of information on an Android device's current status via ADB. Can it be done, and - if so - how?

ortisenderos
  • 370
  • 4
  • 15
HomerPlata
  • 1,687
  • 5
  • 22
  • 39

6 Answers6

71

Try this: adb shell dumpsys battery

It gives all the battery details.

julien_c
  • 4,942
  • 5
  • 39
  • 54
Vineeth Holla
  • 841
  • 7
  • 11
9

IF YOUR DEVICE IS ROOTED

You can use ADB almost like a remote shell, so you can get devices battery info using adb shell cat /sys/class/power_supply/battery/batt_attr_text where "level" is battery level or adb shell dumpsys battery.

adb shell <your command> will let you execute almost any linux command. Some commands are not available and must be installed (e.g. busybox).

Source

antoninkriz
  • 966
  • 4
  • 18
  • 36
6

Pretty simple and you don't need rooted device for this. adb shell dumpsys <option>

Subsitute options with any of these: battery diskstats wifi location usagestats cpuinfo iphonesubinfo telephony.registry meminfo netstat package

You may also try adb shell dumpsys | grep "DUMP OF SERVICE" This will list many other options available with dumpsys.

sziraqui
  • 5,763
  • 3
  • 28
  • 37
1

NO ROOTED NEED

Go straight forward

adb shell dumpsys battery
PYK
  • 3,674
  • 29
  • 17
1

Dump battery level

adb shell cmd battery get level

To customize the output:

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

Dump all settings for cmd battery (posix):

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

Output:

ac        : false
usb       : true
wireless  : false
status    : 5
level     : 100
temp      : 303
present   : true
counter   : 4512000
invalid   : 0

  • Confirmed: android 13/12 - no root reuqired.

Dumpsys:

  • equal to cmd
adb shell dumpsys battery get level

For the last command:


However, for your request the following example will do what you asking for:

adb logcat -d -s AODBatteryManager | tac | 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
    }
}'
  • Output
Estimated time until fully charged: 31 min 53 seconds

The command retrieves the log messages, reverses them, searches for the line containing "mRemainingChargeTime", extracts the relevant value, calculates the estimated time until fully charged in minutes and seconds, and prints the result. It ensures that only the first match is processed before exiting thats why I included "tac" so we skip the earlier messages since it is printed every ~10 seconds if monitoring the command, for doing that just add adb logcat -c; adb logcat -s ... and remove the tac and -d from the command:

# Clear old logs

adb logcat -c 

# Monitor remaining time

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
    }
}'
Time left to full: 29min 29seconds
Time left to full: 29min 22seconds
Time left to full: 29min 11seconds
Time left to full: 29min 4seconds
Time left to full: 28min 57seconds
Time left to full: 28min 46seconds
wuseman
  • 1,259
  • 12
  • 20
0

adb shell "dumpsys battery | grep level"

Oke Uwechue
  • 314
  • 4
  • 14