Unplugging the device via ADB: “can't find service”

岁酱吖の 提交于 2019-12-06 09:17:47

问题


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:


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.



来源:https://stackoverflow.com/questions/39162535/unplugging-the-device-via-adb-cant-find-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!