I am trying to get info about smartphone's CPU. I can get that from displaying /proc/cpuinfo file. However its output is poor and unreadable. I would like to have output like from "lscpu" command but when I execute command "lscpu" from my app I have no permissions to do that (however I can do that from Termux console on my phone and output is readable). Do you have any ideas how to get human readable?
Here is code to view /proc/cpuinfo file:
static class CMDExecute {
synchronized String run(String[] cmd)
throws IOException {
String result = "";
try {
ProcessBuilder builder = new ProcessBuilder(cmd);
builder.redirectErrorStream(true);
Process process = builder.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while (in.read(re) != -1) {
System.out.println(new String(re));
result = result + new String(re);
}
in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
}
private static StringBuffer buffer;
public static void fetch_cpu_info() {
String result = null;
CMDExecute cmdexe = new CMDExecute();
try {
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
result = cmdexe.run(args);
System.out.println("RESULT\n" + result);
} catch (IOException ex) {
ex.printStackTrace();
}
}
and its output:
I/System.out: RESULT
processor : 0
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt lpae evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 1
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt lpae evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 2
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt lpae evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 3
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt lpae evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
As you can see it's very poor output. When I try to perform "lscpu" command from my code, changing only one line:
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
to
String[] args = {"lscpu"};
I am getting error:
W/System.err: java.io.IOException: Cannot run program "lscpu": error=13, Permission denied
However, I have application Termux on my phone. It's shell console and I don't know why but I can perform "lscpu" in this console (I cannot from app code). Check this out:
I would like to get that output into my app. Do you have any ideas how to get that nice human readable output about CPU info?
I'd appreciate any help!