diff --git a/DeviceIdentifiersWrapper/build.gradle b/DeviceIdentifiersWrapper/build.gradle index 0a4ac26..98b3a42 100644 --- a/DeviceIdentifiersWrapper/build.gradle +++ b/DeviceIdentifiersWrapper/build.gradle @@ -10,7 +10,7 @@ android { compileSdkVersion 32 defaultConfig { - minSdkVersion 19 + minSdkVersion 28 targetSdkVersion 32 versionCode 4 versionName "0.4" @@ -25,6 +25,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } diff --git a/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/DIHelper.java b/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/DIHelper.java index d36a624..054b6b7 100644 --- a/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/DIHelper.java +++ b/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/DIHelper.java @@ -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; diff --git a/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/DIProfileManagerCommand.java b/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/DIProfileManagerCommand.java index f7b4435..5b636db 100644 --- a/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/DIProfileManagerCommand.java +++ b/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/DIProfileManagerCommand.java @@ -17,6 +17,7 @@ import java.io.StringReader; import java.util.ArrayList; +import java.util.Date; class DIProfileManagerCommand extends DICommandBase { public class ErrorHolder @@ -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 @@ -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; @@ -126,6 +132,7 @@ private void initializeEMDK() { logMessage("Error while requesting EMDKManager.\n" + e.getLocalizedMessage(), EMessageType.ERROR); e.printStackTrace(); + waitForEMDK(); return; } @@ -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 @@ -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; @@ -186,6 +217,7 @@ private void releaseManagers() private void onProfileManagerInitialized(ProfileManager profileManager) { mProfileManager = profileManager; + bInitializing = false; logMessage("Profile Manager retrieved.", EMessageType.DEBUG); processMXContent(); } diff --git a/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/RetrieveOEMInfoTask.java b/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/RetrieveOEMInfoTask.java index a13a4ff..8681321 100644 --- a/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/RetrieveOEMInfoTask.java +++ b/DeviceIdentifiersWrapper/src/main/java/com/zebra/deviceidentifierswrapper/RetrieveOEMInfoTask.java @@ -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; @@ -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; diff --git a/README.md b/README.md index d4fd336..3b59a93 100644 --- a/README.md +++ b/README.md @@ -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