Android Shell. Part 1: Mocking Battery Status

This article starts a series of short posts describing some useful commands available in Android shell.

We’ll start with interacting with a system service responsible for providing information about device battery.

Android Shell.Mocking battery status

Using “dumpsys battery” we can get information about the device battery status.

First three lines show what charges are connected. To interpret the status and health values you can use corresponding constants in BatteryManager documentation. Here’s an extract from that doc. Values we got are highlighted.

 Status Health
4Not charging4Dead
5Full5Over voltage
6Unspecified failure

“scale” is the maximum value of “level”. Divide “temperature” by 10 to get value in Celsius.

We can make the system think that charger is disconnected with a command

In Android 6 a new “unplug” command is available. It’s an equivalent to setting all the chargers (usb, ac, wireless) to 0.

If you want to change battery level value, use “set level” command:

Also let’s set battery status to “discharging”:

At this moment our battery is in discharging state with level 5.

The first time you invoke one of “set” commands, device stops getting information from real hardware. Hence, do not forget to finish your gambling with “reset” command in order to get our device back to earth.

Now you have a good instrument to test how your app behaves in low battery conditions. Good luck!

Check out the next part of the series Android Shell Part 2: Activity Manager Client.

Give it a try. It only takes a click to unsubscribe.

Read more:


Need help with development of your Android application?

Contact Stanfy button


November 25, 2015
  • Thanks for the Great info.

  • You made my day!!!
    I was looking for this info for a long time.

  • Jabez Balaguer

    How to change the scale?

    • You cannot change the scale :)
      It’s a constant defined in Android battery service and provided more like a reference to help with level value interpretation.

      • Mali

        Can you pleaseee help? Do you know any way to disable usb charging on a nexus 5? There is a serious android bug. When the battery is full, tethering disconnects randomly and reconnects itself. I have tested this on different computers and it starts happening only after the battery level reaches 100 percent.

  • Shon Stewart

    Does anyone know the difference between how AC and USB is defined. Since a USB connection is required to read dump sys how does the device determine if it’s connected to a AC adapter or your terminal’s USB hub?

  • Mohiz Rahman

    can we send android battery status via usb to microcontroller

  • Pavel Machala

    Will device actually enter doze if I make it look that it is disconnected?

  • pierx

    Thanks for this, been looking for something like this for a while.

androidapp development