Andriod obtains mobile phone CPU model device information

environment

  • Mac mini 2014(Intel)
  • Android Studio Bumblebee
  • android phone

Problem Description

When obtaining the CPU information of the mobile phone, Build.HARDWAREonly , without the CPU name.

problem solved

Note: The citation source of the article has been trying to cite the original, but the following citations did not find the original literature

Oriented to search engine programming, reference 1 introduces the shell command operation under Windows to obtain CPU information. Reference 2 introduces how to parse out the CPU name. It is similar on the Internet, but in fact, the name and model of the CPU are not obtained.

Shell command to get CPU information

There are two ways to obtain the CPU by shell commands under Mac (Intel), one is in the Mac terminal, the other is in the Terminal of Android Studio, both use the following command:

adb shell
cat /proc/cpuinfo

The results obtained are as follows:

Processor	: AArch64 Processor rev 2 (aarch64)
processor	: 0
BogoMIPS	: 3.84
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 1
BogoMIPS	: 3.84
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 2
BogoMIPS	: 3.84
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 3
BogoMIPS	: 3.84
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 4
BogoMIPS	: 3.84
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd09
CPU revision	: 2

processor	: 5
BogoMIPS	: 3.84
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd09
CPU revision	: 2

processor	: 6
BogoMIPS	: 3.84
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd09
CPU revision	: 2

processor	: 7
BogoMIPS	: 3.84
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd09
CPU revision	: 2

Hardware	: Hisilicon Kirin970

It can be seen that the CPU name and model are in the last line. It is definitely wrong to just get the first line in the existing article.

Parse CPU name model

To parse the CPU name and model, the following method should be used:

public static String getCpuName() {
    
    
 String str1 = "/proc/cpuinfo";
 String str2 = "";
 String cpuName = "";

 try {
    
    
     FileReader fileReader = new FileReader(str1);
     BufferedReader bufferedReader = new BufferedReader(fileReader);
     
     while ((str2 = bufferedReader.readLine()) != null) {
    
    
         if (TextUtils.isEmpty(str2)) {
    
    
             continue;
         }
         String[] arrayOfString = str2.split(":\\s+", 2);
         if (TextUtils.equals(arrayOfString[0].trim(), "Hardware")) {
    
    
             cpuName = arrayOfString[1];
             break;
         }
     }

     bufferedReader.close();
     fileReader.close();
 } catch (IOException e) {
    
    
     e.printStackTrace();
 }
 return cpuName;
}

references

[1] Android view cpu information
[2] Android obtain system cpu information

Guess you like

Origin blog.csdn.net/dpdcsdn/article/details/126782438