Android CPU序列号(CPU id)

 

一.使用

1.1.root 权限

1.2.cat proc/cpuinfo | grep Seria

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
public String getCPUinfo() {
    String cpuAddress = "0000000000000000";
    String cmd = "cat /proc/cpuinfo";
    try {
        Process p = Runtime.getRuntime().exec(cmd);
 
        String data = null;
        BufferedReader ie = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String error = null;
 
        while ((error = ie.readLine()) != null && !error.equals("null")) {
            data += error + "\n";
        }
 
        String line = null;
 
        while ((line = in.readLine()) != null && !line.equals("null")) {
            data += line + "\n";
            // Log.d("gatsby", "CPUinfo line->" + line);
            if (line.contains("Serial\t\t:")) {
                String[] SerialStr = line.split(":");
                if (SerialStr.length == 2) {
                    String mSerial = SerialStr[1];
                    // Cpu 序列号
                    // Log.d("gatsby", "CPUinfo mSerial ->" + mSerial.trim());
                    cpuAddress = mSerial.trim();
                    return cpuAddress;
                }
            }
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    return cpuAddress;
}

1.3.Android 标准api

1
Build.SERIAL

 从build.prop 获取系统属性

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
55
56
57
58
59
60
61
62
63
64
private static final String TAG = "Build";
/**当构建属性未知时使用的值。*/
public static final String UNKNOWN = "未知";
/**一个变更列表号,或者一个像“M4-rc20”这样的标签。*/
public static final String ID = getString("ro.build.id");
/**一个用于显示给用户的构建ID字符串*/
public static final String DISPLAY = getString("ro.build.display.id");
/**整体产品的名称。*/
public static final String PRODUCT = getString("ro.product.name");
/**工业设计名称。*/
public static final String DEVICE = getString("ro.product.device");
/**底层板的名称,如“金鱼”。*/
public static final String BOARD = getString("ro.product.board");
/**
*本机代码的指令集名称(CPU类型+ ABI约定)。
使用{@link #SUPPORTED_ABIS}代替。
*/
@Deprecated
public static final String CPU_ABI;
/**
*本机代码的第二个指令集(CPU类型+ ABI约定)的名称。
使用{@link #SUPPORTED_ABIS}代替。
*/
@Deprecated
public static final String CPU_ABI2;
/**产品/五金的制造商。*/
public static final String MANUFACTURER = getString("ro.product.manufacturer");
/**与产品或硬件相关的消费者可见品牌。*/
public static final String BRAND = getString("ro.product.brand");
/**最终用户可见的最终产品名称。*/
public static final String MODEL = getString("ro.product.model");
/**系统引导程序版本号。*/
public static final String BOOTLOADER = getString("ro.bootloader");
/**
*无线电固件版本号。
* @deprecated无线电固件版本通常不
*当该类初始化时可用,导致一个空白或
这个字符串的未知值。使用
* {@link #getRadioVersion}代替。
*/
@Deprecated
public static final String RADIO = getString(TelephonyProperties.PROPERTY_BASEBAND_VERSION);
/**硬件的名称(从内核命令行或/proc)。*/
public static final String HARDWARE = getString("ro.hardware");
/**
*此构建是否为模拟器设备。
* @hide
*/
@TestApi
public static final boolean IS_EMULATOR = getString("ro.kernel.qemu").equals("1");
/**
*硬件序列号(如果可用)。字母,不区分大小写的。
*此字段总是设置为{@link Build#UNKNOWN}。
使用{@link #getSerial()}代替。
* * /
@Deprecated
// IMPORTANT:这个字段应该通过函数调用来初始化
//在编译过程中防止它的值被内联到应用程序中
//稍后我们将根据应用程序的目标SDK设置它的值。
public static final String SERIAL = getString("no.such.thing");

  

  

  

posted @   CrushGirl  阅读(1945)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示