Android CPU序列号(CPU id)

 

一.使用

1.1.root 权限

1.2.cat proc/cpuinfo | grep Seria

	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

Build.SERIAL

 从build.prop 获取系统属性

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 @ 2021-01-14 11:40  CrushGirl  阅读(1624)  评论(0编辑  收藏  举报