MachineUtil.java
2.65 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.hjx.personalcenter.util;
import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
public class MachineUtil {
public static String getMachineCode(Context context) {
String cpuAddress = null;
try{
// PmpsManager pmps = new PmpsManager();
// cpuAddress = pmps.getDeviceId(context);
}catch(Exception e){
com.hjx.personalcenter.util.LogUtil.Instance().WriteLog("mac地址获取失败");
}catch(NoClassDefFoundError e){
com.hjx.personalcenter.util.LogUtil.Instance().WriteLog("设备不是好记星");
}
if(!TextUtils.isEmpty(cpuAddress) && !"A818A81800".equals(cpuAddress)){
//Log.e("=========.MACHINE.=========", "function 1 get device id:"+cpuAddress);
return cpuAddress;
}
try{
cpuAddress = android.provider.Settings.System.getString(context.getContentResolver(), "serial_number").trim();
}catch(Exception e){
com.hjx.personalcenter.util.LogUtil.Instance().WriteLog("=========.MACHINE.=========function 2 get device id error");
}
if(!TextUtils.isEmpty(cpuAddress)){
//Log.e("=========.MACHINE.=========", "function 2 get device id:"+cpuAddress);
return cpuAddress;
}
try {
if("Top".equals(Build.MODEL)){
String str = "", strCPU = "";
// 读取CPU信息
Process pp = Runtime.getRuntime().exec("cat/proc/cpuinfo");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
// 查找CPU序列号
for (int i = 1; i < 100; i++) {
str = input.readLine();
if (str != null) {
// 查找到序列号所在行
if (str.indexOf("Serial") > -1) {
// 提取序列号
strCPU = str.substring(str.indexOf(":") + 1, str.length());
cpuAddress = strCPU.trim();
break;
}
} else {
break;
}
}
}
} catch (Exception e) {
com.hjx.personalcenter.util.LogUtil.Instance().WriteLog("=========.MACHINE.=========function 3 get device id error");
}
if(!TextUtils.isEmpty(cpuAddress)){
//Log.e("=========.MACHINE.=========", "function 3 get device id:"+cpuAddress);
return cpuAddress;
}
try{
cpuAddress = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
}catch(Exception e){
com.hjx.personalcenter.util.LogUtil.Instance().WriteLog("=========.MACHINE.=========function 4 get device id error");
}
if(!TextUtils.isEmpty(cpuAddress)){
//Log.e("=========.MACHINE.=========", "function 4 get device id:"+cpuAddress);
return cpuAddress;
}
cpuAddress = "unknown";
return cpuAddress;
}
}