7

I found some references and ended up with the following code:

String[] args = { "/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" };

cmd = new ProcessBuilder(args);

Process process = cmd.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();

The above code works pretty well but not all the time. I've gotten some reports that it reports higher than the frequency set by SetCPU at max setting on some phones.

Is there a more reliable way to find the clock speed of Android phones?

Bob
  • 111
  • 1
  • 4
  • 4
    Are you sure that it is not `SetCPU` that is "telling lies"? – Stephen C Feb 09 '11 at 00:58
  • 2
    Also this might be me being naive, but why use a process(not that it is the issue, just wondering for performance reasons)? why not just get the inputstream from the file directly? I assume the same permissions are needed to exec cat as there is to read the proc dir. – Greg Giacovelli Feb 17 '11 at 07:42

1 Answers1

1

If you want to get the current frequency you can read from:

/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
Chris
  • 7,864
  • 1
  • 27
  • 38
  • That's exactly what he does - only a lot more complicated! – Zordid Feb 23 '11 at 11:46
  • @Zordid: Yes, it's the same priciple. But I suggested "scaling_cur_freq" while he is reading from "cpuinfo_max_freq", thus he would get the current frequency. The current frequency should be more reliable than the max frequency, which may be set by different tools in different ways. – Chris Feb 23 '11 at 12:34