Search code examples
androidadbdumpdumpsys

dumpsys battery only works when executed from PC


I've built a small app with the purpose of running dumpsys commands on device as a development helper. I've granted it the permission DUMP and PACKAGE_USAGE_STATS via adb and the app is installed as system app.

It runs commands just fine, but often it puts out a service not found error.

If I execute adb shell dumpsys battery on my PC I get infos about the battery. If I execute dumpsys battery on my device via my app I get the error

dumpsys battery  error Can't find service: battery

Running the command with adb shell in front obvioulsy wont work, because these interfaces are only needed to get the command from pc to the device in my understanding.

How can I run dumpsys commands on device without getting this error?


Solution

  • Your app won't have permission to connect to the batterystats service unlike adb.