Skip to content

Commit

Permalink
Added a wait for EMDK mechanism.
Browse files Browse the repository at this point in the history
This can become handy when your app respond to the BOOT_COMPLETED event.
Changed the architecture of the sample.
  • Loading branch information
ltrudu committed Nov 7, 2022
1 parent 1219784 commit 4acda07
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
6 changes: 5 additions & 1 deletion DeviceIdentifiersWrapper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
compileSdkVersion 32

defaultConfig {
minSdkVersion 19
minSdkVersion 28
targetSdkVersion 32
versionCode 4
versionName "0.4"
Expand All @@ -25,6 +25,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class DIHelper {
protected static String sIMEI = null;
protected static String sSerialNumber = null;

private static final long MIN_IN_MS = 1000 * 60;
public static long MAX_EMDK_TIMEOUT_IN_MS = 10 * MIN_IN_MS; // 10 minutes

public static void resetCachedValues()
{
sIMEI = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.StringReader;
import java.util.ArrayList;
import java.util.Date;

class DIProfileManagerCommand extends DICommandBase {
public class ErrorHolder
Expand Down Expand Up @@ -55,6 +56,8 @@ public class ErrorHolder
// Provides full error description string
public String msErrorString = "";

private boolean bInitializing = false;

// Status Listener implementation (ensure that we retrieve the profile manager asynchronously
EMDKManager.StatusListener mStatusListener = new EMDKManager.StatusListener() {
@Override
Expand Down Expand Up @@ -114,6 +117,9 @@ public void execute(String mxProfile, String mxProfileName, IDIResultCallbacks r

private void initializeEMDK()
{
if(bInitializing)
return;
bInitializing = true;
if(mEMDKManager == null)
{
EMDKResults results = null;
Expand All @@ -126,6 +132,7 @@ private void initializeEMDK()
{
logMessage("Error while requesting EMDKManager.\n" + e.getLocalizedMessage(), EMessageType.ERROR);
e.printStackTrace();
waitForEMDK();
return;
}

Expand All @@ -134,6 +141,7 @@ private void initializeEMDK()
logMessage("EMDKManager request command issued with success", EMessageType.DEBUG);
}else {
logMessage("EMDKManager request command error", EMessageType.ERROR);
waitForEMDK();
}
}
else
Expand All @@ -142,6 +150,29 @@ private void initializeEMDK()
}
}

private void waitForEMDK()
{
Thread t = new Thread(new Runnable() {
@Override
public void run() {
long startDate = new Date().getTime();
long delta = 0;
long maxWait = 1000 * 60 * 10; // We will try for 10 mns... before stopping
while(mEMDKManager == null || delta < DIHelper.MAX_EMDK_TIMEOUT_IN_MS ) {
initializeEMDK();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
delta = new Date().getTime() - startDate;
}
}
});
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}

private void onEMDKManagerRetrieved(EMDKManager emdkManager)
{
mEMDKManager = emdkManager;
Expand Down Expand Up @@ -186,6 +217,7 @@ private void releaseManagers()
private void onProfileManagerInitialized(ProfileManager profileManager)
{
mProfileManager = profileManager;
bInitializing = false;
logMessage("Profile Manager retrieved.", EMessageType.DEBUG);
processMXContent();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.zebra.deviceidentifierswrapper;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -163,7 +164,7 @@ private static void getURIValue(Cursor cursor, Uri uri, IDIResultCallbacks resul
else{
for (int i = 0; i < cursor.getColumnCount(); i++) {
try {
String data = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(i)));
@SuppressLint("Range") String data = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(i)));
resultCallbacks.onSuccess(data);
cursor.close();
return;
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
## Sample Repository
https://github.com/ltrudu/DeviceIdentifiersWrapper-Sample


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

0 comments on commit 4acda07

Please sign in to comment.