Skip to content

Instantly share code, notes, and snippets.

@vnu
Created August 4, 2012 16:07
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vnu/3258553 to your computer and use it in GitHub Desktop.
Save vnu/3258553 to your computer and use it in GitHub Desktop.
Android dumpsys denial to access programmatically

How to log the dumpsys information periodically?

What is dumpsys and what are its benefits?

Dumpsys is a very interesting android shell command that dumps the state of various running services and also other system information on std output.

Benefits :

Retrieve various system information in a simple string representation Analyse the various stats like cpuinfo, batteryinfo, meminfo, wifi, location etc., to analyze the overall performance of the device and also the individual performance of various application and services. Syntax : $ adb shell dumpsys

It takes either no arguments, to list all the dumpsys information or one argument of the specific to list. However, based on the service you can have multiple arguments to the dumpsys command followed by the <servicename>

To List all the services : $ adb shell dumpsys | grep DUMP

Android application needs, android.permission.DUMP permission added to android manifest to access dumpsys programmatically.

Although dumpsys is a very useful tool that can be used to view the system information on an adb shell, these information cannot be retrieved programmatically by a normal application. Executing this shell command, through android Runtime.getRuntime().exec() sometimes causes error or unexpected stopping of your application.

If you try to write the output to DataOutputStream, it shows Permission Denial : cannot dump <servicename>

This is because dumpsys has android:protectionLevel="signatureOrSystem". Unless your application is signed with a platform key or built as a system application, dumpsys information cannot be retrieved programmatically.

Solution : One has to either root the phone or install the application as a system application or change the protection level of DUMP permission and create a new build.

@Leaking
Copy link

Leaking commented Apr 2, 2017

Mark

@AndroidDeveloperLB
Copy link

It seems that on Android O, even if you have root and get the DUMP permission, you get an error by using "adb shell dumpsys" :

Error dumping service info: (Unknown error -2147483646) activity

Any alternative to this on Android O ?

@flyer88
Copy link

flyer88 commented Dec 28, 2017

mark

@mohit008
Copy link

mohit008 commented Mar 9, 2018

If you are root user you can achieve it easily,

  1. Firstly get root privilege in console with Process process = Runtime.getRuntime().exec("su").
  2. Then write your command with root access su

My this https://stackoverflow.com/a/48885488/2553431 might help you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment