valheru
valheru

Reputation: 2562

Unable to open log device '/dev/log/main': Permission denied

I've seen other solutions for this but none of them seem to apply.

I'm trying to read from a process executing "logcat -d" and I'm receiving the error in the title.

My AndroidManifest.xml includes:

<uses-permission android:name="android.permission.READ_LOGS" />

Using adb shell, I can execute the command just fine.

This is a code snippet:

            ProcessBuilder procBuilder = new ProcessBuilder();
            procBuilder.redirectErrorStream(true);
            procBuilder.command("logcat", "-d");
            procBuilder.directory(new File("/"));
            Process process = procBuilder.start();
            //Process process = Runtime.getRuntime().exec("logcat -d");

            process.waitFor();

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            StringBuilder log = new StringBuilder();
            String line = "";
            while ((line = bufferedReader.readLine()) != null) {
                log.append(line + "\n");
            }

When executed, I see the first line as the error in the title and that is all.

I've read online that logcat cannot be executed without su and yet there are plenty of articles of code just like this...working just fine.

Any other ideas of what I might be doing wrong or could try?

Upvotes: 2

Views: 2000

Answers (1)

Smile2Life
Smile2Life

Reputation: 1921

It's classified on top 10 bad permissions and turned off in jellybean, the answer from google:

Dan Galpin: Read system log. Now, I've got bad news for you guys. If you haven't watched some of our other presentations, read system log actually is gone as of J. There is no more read system log that you can get. However allows you, without a permission, to read the system log for your own app. So the good news is no creepy spying on what the user is doing by turning on their read system log permission. And at the same time you can still get to the useful logs you need to help your debugging if the crash recording and all the stuff we have on Google Play isn't enough.

Ref: http://youtu.be/WDDgoxvQsrQ?t=22m3s

Upvotes: 2

Related Questions