Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Get Processor Model

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..

like image 577
Rakesh Yadav Avatar asked Aug 03 '15 08:08

Rakesh Yadav


People also ask

What is the processor of my phone?

RELATED: How to See How Much RAM Your Android Phone Has You'll be greeted with the “Dashboard” tab, which is an overview of your device's status. We'll switch over to the “Hardware” tab. At the top, you'll see the name of your processor.

How do I find hardware info on Android?

1. For Android 7 : go to "Settings" > "About" > "Hardware information". 2. The screen of "Hardware information" includes the information as below picture.

How do I know my phone processor architecture?

For the Android version, look at the OS version under the Device section. This explicitly displays the version number. For architecture info, slide over to the System tab and check out the CPU Architecture and Instruction Sets entries under the Processor tab.


2 Answers

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;

    }
like image 198
Acuna Avatar answered Sep 25 '22 07:09

Acuna


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;
                }
            }
like image 20
tim687 Avatar answered Sep 22 '22 07:09

tim687