Skip to content

Commit 4acda07

Browse files
committed
Added a wait for EMDK mechanism.
This can become handy when your app respond to the BOOT_COMPLETED event. Changed the architecture of the sample.
1 parent 1219784 commit 4acda07

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

DeviceIdentifiersWrapper/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010
compileSdkVersion 32
1111

1212
defaultConfig {
13-
minSdkVersion 19
13+
minSdkVersion 28
1414
targetSdkVersion 32
1515
versionCode 4
1616
versionName "0.4"
@@ -25,6 +25,10 @@ android {
2525
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2626
}
2727
}
28+
compileOptions {
29+
sourceCompatibility JavaVersion.VERSION_1_8
30+
targetCompatibility JavaVersion.VERSION_1_8
31+
}
2832

2933
}
3034

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public class DIHelper {
2727
protected static String sIMEI = null;
2828
protected static String sSerialNumber = null;
2929

30+
private static final long MIN_IN_MS = 1000 * 60;
31+
public static long MAX_EMDK_TIMEOUT_IN_MS = 10 * MIN_IN_MS; // 10 minutes
32+
3033
public static void resetCachedValues()
3134
{
3235
sIMEI = null;

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.StringReader;
1919
import java.util.ArrayList;
20+
import java.util.Date;
2021

2122
class DIProfileManagerCommand extends DICommandBase {
2223
public class ErrorHolder
@@ -55,6 +56,8 @@ public class ErrorHolder
5556
// Provides full error description string
5657
public String msErrorString = "";
5758

59+
private boolean bInitializing = false;
60+
5861
// Status Listener implementation (ensure that we retrieve the profile manager asynchronously
5962
EMDKManager.StatusListener mStatusListener = new EMDKManager.StatusListener() {
6063
@Override
@@ -114,6 +117,9 @@ public void execute(String mxProfile, String mxProfileName, IDIResultCallbacks r
114117

115118
private void initializeEMDK()
116119
{
120+
if(bInitializing)
121+
return;
122+
bInitializing = true;
117123
if(mEMDKManager == null)
118124
{
119125
EMDKResults results = null;
@@ -126,6 +132,7 @@ private void initializeEMDK()
126132
{
127133
logMessage("Error while requesting EMDKManager.\n" + e.getLocalizedMessage(), EMessageType.ERROR);
128134
e.printStackTrace();
135+
waitForEMDK();
129136
return;
130137
}
131138

@@ -134,6 +141,7 @@ private void initializeEMDK()
134141
logMessage("EMDKManager request command issued with success", EMessageType.DEBUG);
135142
}else {
136143
logMessage("EMDKManager request command error", EMessageType.ERROR);
144+
waitForEMDK();
137145
}
138146
}
139147
else
@@ -142,6 +150,29 @@ private void initializeEMDK()
142150
}
143151
}
144152

153+
private void waitForEMDK()
154+
{
155+
Thread t = new Thread(new Runnable() {
156+
@Override
157+
public void run() {
158+
long startDate = new Date().getTime();
159+
long delta = 0;
160+
long maxWait = 1000 * 60 * 10; // We will try for 10 mns... before stopping
161+
while(mEMDKManager == null || delta < DIHelper.MAX_EMDK_TIMEOUT_IN_MS ) {
162+
initializeEMDK();
163+
try {
164+
Thread.sleep(5000);
165+
} catch (InterruptedException e) {
166+
e.printStackTrace();
167+
}
168+
delta = new Date().getTime() - startDate;
169+
}
170+
}
171+
});
172+
t.setPriority(Thread.MIN_PRIORITY);
173+
t.start();
174+
}
175+
145176
private void onEMDKManagerRetrieved(EMDKManager emdkManager)
146177
{
147178
mEMDKManager = emdkManager;
@@ -186,6 +217,7 @@ private void releaseManagers()
186217
private void onProfileManagerInitialized(ProfileManager profileManager)
187218
{
188219
mProfileManager = profileManager;
220+
bInitializing = false;
189221
logMessage("Profile Manager retrieved.", EMessageType.DEBUG);
190222
processMXContent();
191223
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.zebra.deviceidentifierswrapper;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Context;
45
import android.content.pm.PackageInfo;
56
import android.content.pm.PackageManager;
@@ -163,7 +164,7 @@ private static void getURIValue(Cursor cursor, Uri uri, IDIResultCallbacks resul
163164
else{
164165
for (int i = 0; i < cursor.getColumnCount(); i++) {
165166
try {
166-
String data = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(i)));
167+
@SuppressLint("Range") String data = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(i)));
167168
resultCallbacks.onSuccess(data);
168169
cursor.close();
169170
return;

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111
## Sample Repository
1212
https://github.com/ltrudu/DeviceIdentifiersWrapper-Sample
1313

14-
15-
## Update for A11
14+
## V0.4 : Basic cache mechanism
15+
```text
16+
Added basic cache mechanism.
17+
The IMei and the Serial number will be cached once they get retrieved.
18+
The cache can be reset with the method:
19+
DIHelper.resetCachedValues()
20+
Added a mechanism to wait for the EMDK if it is not available (when responding to the BOOT_COMPLETED event for ex.
21+
To be tested... feel free to report any issue regarding this feature.
22+
```
23+
## V0.3 : Update for A11
1624
```text
1725
Update your graddle distribution to >= 7.3.3
1826
update your compileSdkVersion to 30

0 commit comments

Comments
 (0)