5

I am trying to obtain the dumpsys statistics [like dumpsys cpuinfo, dumpsys battery]. I executing these in java and writing it to a file. But I am getting,

2012.06.20 07:32:19
Permission Denial: can't dump cpuinfo from from pid=862, uid=10040 without permission android.permission.DUMP
for all dumpsys commands.

I have added the permission "android.permission.DUMP" and "android.permission.BATTERY_STATS" in android.manifest. But, not obtaining the resulyPlease help as its critical.The code I use is as below where cmd contains dumpsys cpuinfo or dumpsys battery [anyone]

Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
System.setOut(new PrintStream(new FileOutputStream("/sdcard/Monitor/"+file+".txt",false)));
System.out.println("\n\n"+sdf.format(cal.getTime()));           
Log.w("cmd-fn", cmd);
process=Runtime.getRuntime().exec(cmd);
process.waitFor();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String buffer="";

while((buffer=bufferedReader.readLine())!=null)
      {
    //fileobj.write(buffer);
    System.out.println(buffer);
    //output.write(buffer);
}
    buffer="";
    BufferedReader buffered = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    while((buffer=buffered.readLine())!=null)
        {
        Log.w("exception",buffer);
        }

Below is my manifest entries

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.DUMP" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Vipul
  • 27,808
  • 7
  • 60
  • 75
vinod
  • 8,350
  • 9
  • 32
  • 36

5 Answers5

11

The DUMP permission is defined as android:protectionLevel="signatureOrSystem" so you can't get it unless your app is signed with the platform key, or installed in the system partition.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • How to accomplish that? Please help – vinod Jun 20 '12 at 09:32
  • @Nick Is there anyother way like changing the android:protectionLevel to someother value like normal and make it work? Else how to make your app is signed with the platform key? – vinod Jun 20 '12 at 09:39
  • If you are not building a custom firmware (ROM), the only way is to root the phone. – Nikolay Elenkov Jun 20 '12 at 11:21
  • @Nikolas I am new to android. Is there any programming way to do this? Please explain with code how to root phone or the steps. THanks. Please help – vinod Jun 20 '12 at 11:58
  • the only way to get your app installed as a system app is to own the ROM yourself, and install it there when the ROM is built (or via a ROM OTA). – Jeffrey Blattman Dec 03 '13 at 01:38
  • Actually, it is possible to grant this permission using adb (device being connected to the PC), but for some reason using dumpsys still doesn't work, even though checking that this permission is granted -returns that it is. – android developer Oct 29 '16 at 13:01
  • Is it possible to use the dump permission using root? If so, how? – android developer Apr 24 '17 at 14:28
2

The android dev team decided to stop granting these permissions to third-party apps. Only system apps can now get them.

more details:https://code.google.com/p/acra/issues/detail?id=100

1

You can provide DUMP permission from adb

adb shell pm grant <your-package-name> android.permission.DUMP
Chetan Tak
  • 11
  • 1
0

You can access some memory information by checking /proc/meminfo file, there is also other intersting files under /proc/. Hopefully these files will be readable in future releases

Code example to fetch meminfo:

    public static String showMemInfo() {
    StringBuilder meminfo = new StringBuilder();
    try {
        ArrayList<String> commandLine = new ArrayList<String>();
        commandLine.add("cat");
        commandLine.add("/proc/meminfo");

        Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[commandLine.size()]));
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

        String line;
        while ((line = bufferedReader.readLine()) != null) {
            meminfo.append(line);
            meminfo.append("\n");
        }

    } catch (IOException e) {
        Log.e(LOG_TAG, "Could not read /proc/meminfo", e);
    }

    return meminfo.toString();
}

PS: I know it's not verbose like dumpsys ;)

flegare
  • 684
  • 7
  • 9
-1

There are two other ways you can use to get cpu information

  1. use top command int adb shell, get most information

    top -n 1
    
  2. You also can cat information in /proc/stat and /proc/pid/stat to get the cpu information

    cat /proc/stat
    

    If you wanna details, check Get Memeory Usage

Community
  • 1
  • 1
Wednesday
  • 74
  • 4