BaseConfig.java
3.54 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.hhmedic.android.sdk.base;
import android.os.Build;
import android.text.TextUtils;
import java.util.UUID;
public class BaseConfig {
public static boolean isTest = false;
public static boolean canPrintLog = false;
public static boolean isDebug = false;
private static String DEVICE_ID;
private static String mPId;
private static String mCoopId;
private static String mHardwareId;
private static String mSdkVersion;
private static String mAppVersion;
static {
DEVICE_ID = getUniqueID();
}
public static String getPid(){
if (TextUtils.isEmpty(mPId)){
mPId = "3001";
}
return mPId;
}
public static String getCoopId(){
if (TextUtils.isEmpty(mCoopId)){
mCoopId = "coopId";
}
return mCoopId;
}
public static String getDeviceId(){
return DEVICE_ID;
}
public static String getHardwareId(){
return mHardwareId;
}
public static void setPid(String pid) {
mPId = pid;
}
public static void setHardwareId(String id){
mHardwareId = id;
}
public static void setCoopId(String id) {
mCoopId = id;
}
public static void setSdkVersion(String version){
mSdkVersion = version;
}
public static void setAppVersion(String version){
mAppVersion = version;
}
public static String getAppVersion(){
if (TextUtils.isEmpty(mAppVersion)){
return getSdkVersion();
}
return mAppVersion;
}
public static String getSdkVersion(){
if (TextUtils.isEmpty(mSdkVersion)){
return "2.6.0";
}
return mSdkVersion;
}
private static String getUniqueID()
{
// If all else fails, if the user does have lower than API 9 (lower
// than Gingerbread), has reset their device or 'Secure.ANDROID_ID'
// returns 'null', then simply the ID returned will be solely based
// off their Android device information. This is where the collisions
// can happen.
// Thanks http://www.pocketmagic.net/?p=1662!
// Try not to use DISPLAY, HOST or ID - these items could change.
// If there are collisions, there will be overlapping data
String m_szDevIDShort = "35" + (Build.BOARD.length() % 10) + (Build.BRAND.length() % 10) + (Build.CPU_ABI.length() % 10) + (Build.DEVICE.length() % 10) + (Build.MANUFACTURER.length() % 10) + (Build.MODEL.length() % 10) + (Build.PRODUCT.length() % 10);
// Thanks to @Roman SL!
// http://stackoverflow.com/a/4789483/950427
// Only devices with API >= 9 have android.os.Build.SERIAL
// http://developer.android.com/reference/android/os/Build.html#SERIAL
// If a user upgrades software or roots their device, there will be a duplicate entry
String serial = null;
try {
serial = Build.class.getField("SERIAL").get(null).toString();
// Go ahead and return the serial for api => 9
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
} catch (Exception exception) {
// String needs to be initialized
serial = "serial"; // some value
}
// Thanks @Joe!
// http://stackoverflow.com/a/2853253/950427
// Finally, combine the values we have found by using the UUID class to create a unique identifier
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
}
}