Android 系统获取 CPU 位数信息
2018-01-15 16:37:43 法迪 阅读数 2678更多
分类专栏: Android系统
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/su749520/article/details/79066156
系统获取 CPU 位数
adb shell “cat /proc/cpuinfo”
processor : 0
Processor : AArch64 Processor rev 4 (aarch64)
model name : AArch64 Processor rev 4 (aarch64)
BogoMIPS : 26.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Processor : AArch64 Processor rev 4 (aarch64) 可以查看位数信息,包含aarch64即为64位
编码如下
public static boolean isCPU64(){
boolean result = false;
String mProcessor = null;
List<String > list = null;
try {
mProcessor = getFieldFromCpuinfo("Processor");
} catch (IOException e) {
e.printStackTrace();
}
if (mProcessor != null) {
// D/CpuUtils: isCPU64 mProcessor = AArch64 Processor rev 4 (aarch64)
Log.d(TAG, "isCPU64 mProcessor = " + mProcessor);
//list = Arrays.asList(mProcessor.split("\\s"));
if (mProcessor.contains("aarch64")) {
result = true;
}
}
return result;
}
/* cat /proc/cpuinfo
processor : 0
Processor : AArch64 Processor rev 4 (aarch64)
model name : AArch64 Processor rev 4 (aarch64)
BogoMIPS : 26.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
*/
public static String getFieldFromCpuinfo(String field) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("/proc/cpuinfo"));
Pattern p = Pattern.compile(field + "\\s*:\\s*(.*)");
try {
String line;
while ((line = br.readLine()) != null) {
Matcher m = p.matcher(line);
if (m.matches()) {
return m.group(1);
}
}
} finally {
br.close();
}
return null;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54