12

I want to get Processor Model similar to DU Booster. CPU model contains ARM processor version and revision. For Example: ARMv7 Processor rev 3 (v7l)

I have tried this System.getProperty("os.arch") which returns only architecture

and

String[] args = {"/system/bin/cat", "/proc/cpuinfo"}; 

to get CPU info. I am able to get the right information in some of the devices but not in all.

I tried this in Asus Fonepad 7 which doesn't return the property of the Processor(but returns processor(small p)

It returns like

processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 53
model name  : Intel(R) Atom(TM) CPU Z2520  @ 1.20GHz
stepping    : 1
microcode   : 0x10e
cpu MHz     : 800.000
cache size  : 512 KB
physical id : 0
siblings    : 4

I want to get result like "ARMv7 Processor rev 3 (v7l)". Thanks in Advance..

Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42
Rakesh Yadav
  • 1,966
  • 2
  • 21
  • 35

2 Answers2

16

You don't need to implement separated methods to work with differ processors types, just simply replace the model_name key to cpu_model when it needed while getting /proc/cpuinfo file:

    public static Map<String, String> getCPUInfo () throws IOException {

        BufferedReader br = new BufferedReader (new FileReader ("/proc/cpuinfo"));

        String str;

        Map<String, String> output = new HashMap<> ();

        while ((str = br.readLine ()) != null) {

            String[] data = str.split (":");

            if (data.length > 1) {

                String key = data[0].trim ().replace (" ", "_");
                if (key.equals ("model_name")) key = "cpu_model";

                output.put (key, data[1].trim ());

            }

        }

        br.close ();

        return output;

    }
Acuna
  • 1,741
  • 17
  • 20
  • Not working on recent devices, any other options to get the info? – 3c71 Jul 16 '23 at 15:49
  • @3c71 only to get rooted device and check that `/system/bin/cat` and `/proc/cpuinfo` (may be another ones) files contains strings related CPU info (which can be differ). – Acuna Jul 19 '23 at 10:46
  • Take any recent devices running Qualcomm CPU and you won't find anything useful in /proc/cpuinfo. I've got 2 atm, and by recent I mean years. Otherwise I know how to read answers and have been using that file for more than 10 years. – 3c71 Jul 20 '23 at 16:40
  • So you can download any Device Info app and check if it show CPU info on newer devices, because something are impossible unfortunately. – Acuna Aug 04 '23 at 12:34
  • Some apps are able to give exact processor models using a C library or I believe they use a remote server to query CPU names based on actual serial or model numbers. – 3c71 Aug 24 '23 at 15:16
1

This is an easy way to do so, you can do it with Patterns but that would require alot of TaE (Trial and Error)

String unparsed_CPU_INFO;

onCreate{

        // cpu info
                    String result = null;
                    CMDExecute cmdexe = new CMDExecute();
                    try {
                        String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
                        result = cmdexe.run(args, "/system/bin/");
                        Log.i("result", "result=" + result);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }


                    unparsed_CPU_INFO = result;

System.out.println("Your cpu model is: " ++ getCPUName());
}

    public synchronized String getCPUName() {
                if (cpuName == null) {
                    String CPUName = "";

                    String[] lines = unparsed_CPU_INFO.split("\n");

                    for (int i = 0; i < lines.length; i++) {

                        String temp = lines[i];

                        if (lines[i].contains("Processor\t:")) {

                            CPUName = lines[i].replace("Processor\t: ", "");
                            break;
                        }
                    }
                    cpuName = CPUName;
                    return CPUName;
                } else {
                    return cpuName;
                }
            }
tim687
  • 2,256
  • 2
  • 17
  • 28
  • As mentioned in my question I have used both String[] args = {"/system/bin/cat", "/proc/cpuinfo"}; But there is not "Processor" string in the result. – Rakesh Yadav Aug 03 '15 at 09:25
  • @AndroidProgrammer The example in your question is that the real value of the string? Then I'll change it accordingly – tim687 Aug 03 '15 at 09:26
  • That is the value of the line behind the Processor\t: . If your example in the question is the exact value you should change Processor to model name – tim687 Aug 03 '15 at 09:30
  • This is no longer working on recent devices, for a few years, any other way? – 3c71 Jul 16 '23 at 15:49