vinod
vinod

Reputation: 8420

Dumpsys permission denial in java

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" />

Upvotes: 5

Views: 13509

Answers (5)

Chetan Tak
Chetan Tak

Reputation: 31

You can provide DUMP permission from adb

adb shell pm grant <your-package-name> android.permission.DUMP

Upvotes: 3

Wednesday
Wednesday

Reputation: 74

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

Upvotes: -1

cinesex solo
cinesex solo

Reputation: 31

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

Upvotes: 2

flegare
flegare

Reputation: 704

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 ;)

Upvotes: 0

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52956

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.

Upvotes: 11

Related Questions