Skip to content

Commit b11dc42

Browse files
committed
Added basic cache mechanism.
1 parent 5e30bd2 commit b11dc42

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

DeviceIdentifiersWrapper/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
defaultConfig {
1313
minSdkVersion 19
1414
targetSdkVersion 32
15-
versionCode 2
16-
versionName "0.2"
15+
versionCode 4
16+
versionName "0.4"
1717

1818
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1919

DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/DIHelper.java

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,23 @@ public class DIHelper {
2424
// TODO: Put your custom certificate in the apkCertificate member for MX AccessMgr registering (only if necessary and if you know what you are doing)
2525
public static Signature apkCertificate = null;
2626

27+
protected static String sIMEI = null;
28+
protected static String sSerialNumber = null;
29+
30+
public static void resetCachedValues()
31+
{
32+
sIMEI = null;
33+
sSerialNumber = null;
34+
}
35+
2736
// This method will return the serial number in the string passed through the onSuccess method
2837
public static void getSerialNumber(Context context, IDIResultCallbacks callbackInterface)
2938
{
39+
if(sSerialNumber != null)
40+
{
41+
callbackInterface.onSuccess(sSerialNumber);
42+
return;
43+
}
3044
if (android.os.Build.VERSION.SDK_INT < 29) {
3145
returnSerialUsingAndroidAPIs(context, callbackInterface);
3246
} else {
@@ -37,25 +51,50 @@ public static void getSerialNumber(Context context, IDIResultCallbacks callbackI
3751
@SuppressLint({"MissingPermission", "ObsoleteSdkInt", "HardwareIds"})
3852
private static void returnSerialUsingAndroidAPIs(Context context, IDIResultCallbacks callbackInterface) {
3953
if (android.os.Build.VERSION.SDK_INT < 26) {
54+
sSerialNumber = Build.SERIAL;
4055
callbackInterface.onSuccess(Build.SERIAL);
4156
} else {
4257
if (ContextCompat.checkSelfPermission(context, permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
58+
sSerialNumber = Build.getSerial();
4359
callbackInterface.onSuccess(Build.getSerial());
4460
} else {
4561
callbackInterface.onError("Please grant READ_PHONE_STATE permission");
4662
}
4763
}
4864
}
4965

50-
private static void returnSerialUsingZebraAPIs(Context context, IDIResultCallbacks callbackInterface) {
66+
private static void returnSerialUsingZebraAPIs(Context context, final IDIResultCallbacks callbackInterface) {
67+
IDIResultCallbacks tempCallbackInterface = new IDIResultCallbacks() {
68+
@Override
69+
public void onSuccess(String message) {
70+
sSerialNumber = message;
71+
callbackInterface.onSuccess(message);
72+
}
73+
74+
@Override
75+
public void onError(String message) {
76+
callbackInterface.onError(message);
77+
}
78+
79+
@Override
80+
public void onDebugStatus(String message) {
81+
callbackInterface.onDebugStatus(message);
82+
}
83+
};
84+
5185
new RetrieveOEMInfoTask()
5286
.execute(context, Uri.parse("content://oem_info/oem.zebra.secure/build_serial"),
53-
callbackInterface);
87+
tempCallbackInterface);
5488
}
5589

5690
// This method will return the imei number in the string passed through the onSuccess method
5791
public static void getIMEINumber(Context context, IDIResultCallbacks callbackInterface)
5892
{
93+
if(sIMEI != null)
94+
{
95+
callbackInterface.onSuccess(sIMEI);
96+
return;
97+
}
5998
if (android.os.Build.VERSION.SDK_INT < 29) {
6099
returnImeiUsingAndroidAPIs(context, callbackInterface);
61100
} else {
@@ -68,6 +107,7 @@ private static void returnImeiUsingAndroidAPIs(Context context, IDIResultCallbac
68107
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
69108
if (android.os.Build.VERSION.SDK_INT < 26) {String imei = telephonyManager.getDeviceId();
70109
if (imei != null && !imei.isEmpty()) {
110+
sIMEI = imei;
71111
callbackInterface.onSuccess(imei);
72112
} else {
73113
callbackInterface.onError("Could not get IMEI number");
@@ -76,6 +116,7 @@ private static void returnImeiUsingAndroidAPIs(Context context, IDIResultCallbac
76116
if (ContextCompat.checkSelfPermission(context, permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
77117
String imei = telephonyManager.getImei();
78118
if (imei != null && !imei.isEmpty()) {
119+
sIMEI = imei;
79120
callbackInterface.onSuccess(imei);
80121
} else {
81122
callbackInterface.onError("Could not get IMEI number");
@@ -86,8 +127,26 @@ private static void returnImeiUsingAndroidAPIs(Context context, IDIResultCallbac
86127
}
87128
}
88129

89-
private static void returnImeiUsingZebraAPIs(Context context, IDIResultCallbacks callbackInterface) {
130+
private static void returnImeiUsingZebraAPIs(Context context, final IDIResultCallbacks callbackInterface) {
131+
IDIResultCallbacks tempCallbackInterface = new IDIResultCallbacks() {
132+
@Override
133+
public void onSuccess(String message) {
134+
sIMEI = message;
135+
callbackInterface.onSuccess(message);
136+
}
137+
138+
@Override
139+
public void onError(String message) {
140+
callbackInterface.onError(message);
141+
}
142+
143+
@Override
144+
public void onDebugStatus(String message) {
145+
callbackInterface.onDebugStatus(message);
146+
}
147+
};
148+
90149
new RetrieveOEMInfoTask().execute(context, Uri.parse("content://oem_info/wan/imei"),
91-
callbackInterface);
150+
tempCallbackInterface);
92151
}
93152
}

0 commit comments

Comments
 (0)