通过ADB拔出设备的电源:“找不到服务” [英] Unplugging the device via ADB: "can't find service"

查看:138
本文介绍了通过ADB拔出设备的电源:“找不到服务”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须测试我的应用在打ze模式下的行为。根据文档,我首先必须通过在终端中输入以下命令,设备认为已将其拔出:

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

我该怎么办?

推荐答案

日志中没有指出电池服务(这可能是特定于设备的。)

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]

管理电池应该使用 batterymanager

$ adb shell dumpsys batterymanager

输出(如果已插入已充电的USB)

outputs (in case the usb charged is plugged)

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

然后,当您键入

$ 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

验证您应该使用 batterymanager 服务而不是 battery

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

这篇关于通过ADB拔出设备的电源:“找不到服务”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆