2

I have to test how my app behaves in doze mode. According to the documentation, I first must make the device think it's unplugged by entering the following command in the terminal:

$ adb shell dumpsys battery unplug

However, nothing happens and it logs:

Can't find service: battery

What should I do?

1 Answer 1

9

There is no battery service as the log points out (this may be device specific).

Enter the following command to find existing battery related services:

$ adb shell service list | grep battery

it will result in something like this

$ adb shell service list | grep battery
88      batterymanager: [android.app.IBatteryService]
107     batterystats: [com.android.internal.app.IBatteryStats]
114     batteryproperties: [android.os.IBatteryPropertiesRegistrar]

It makes sense that to manage the battery, you should use the batterymanager.

$ adb shell dumpsys batterymanager

outputs (in case the usb charged is plugged)

Current Battery Service state:
  (UPDATES STOPPED -- use 'reset' to restart)
  AC powered: false
  USB powered: true

then, when you type

$ adb shell dumpsys batterymanager unplug

and run the previous command again, it outputs

Current Battery Service state:
  (UPDATES STOPPED -- use 'reset' to restart)
  AC powered: false
  USB powered: false

Which validates that you should use the batterymanager service instead of battery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.