Skip to content

Commit b4ed116

Browse files
authored
Merge pull request #7 from ltrudu/master
V0.8
2 parents 055ac23 + bf15b0f commit b4ed116

File tree

10 files changed

+191
-92
lines changed

10 files changed

+191
-92
lines changed

.idea/.name

Lines changed: 0 additions & 1 deletion
This file was deleted.

.idea/gradle.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
apply plugin: 'com.android.library'
2-
3-
ext {
4-
PUBLISH_GROUP_ID = 'com.zebra.deviceidentifierswrapper'
5-
PUBLISH_ARTIFACT_ID = 'deviceidentifierswrapper'
6-
PUBLISH_VERSION = '0.2'
1+
plugins {
2+
id 'com.android.library'
73
}
84

95
android {
@@ -12,8 +8,8 @@ android {
128
defaultConfig {
139
minSdkVersion 19
1410
targetSdkVersion 32
15-
versionCode 2
16-
versionName "0.2"
11+
versionCode 8
12+
versionName "0.8"
1713

1814
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1915

@@ -25,6 +21,10 @@ android {
2521
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2622
}
2723
}
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
2828

2929
}
3030

@@ -36,54 +36,3 @@ dependencies {
3636
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
3737
compileOnly 'com.symbol:emdk:+'
3838
}
39-
40-
/*
41-
Generate release files for publication and Zip them
42-
https://medium.com/@daniellevass/how-to-publish-your-android-studio-library-to-jcenter-5384172c4739
43-
https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle
44-
*/
45-
46-
// ./gradlew clean build generateRelease
47-
apply plugin: 'maven'
48-
49-
def version = project.PUBLISH_VERSION
50-
51-
def localReleaseDest = "${buildDir}/release/${version}"
52-
53-
task androidJavadocs(type: Javadoc) {
54-
failOnError = false
55-
source = android.sourceSets.main.java.srcDirs
56-
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
57-
classpath += files(ext.androidJar)
58-
}
59-
60-
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
61-
archiveClassifier = 'javadoc'
62-
from androidJavadocs.destinationDir
63-
}
64-
65-
task androidSourcesJar(type: Jar) {
66-
archiveClassifier = 'sources'
67-
from android.sourceSets.main.java.srcDirs
68-
}
69-
70-
task zipRelease(type: Zip) {
71-
from localReleaseDest
72-
destinationDir buildDir
73-
archiveBaseName = "release-${version}"
74-
}
75-
76-
task generateRelease {
77-
doLast {
78-
println "Release ${version} can be found at ${localReleaseDest}/"
79-
println "Release ${version} zipped can be found ${buildDir}/release-${version}.zip"
80-
}
81-
}
82-
83-
generateRelease.dependsOn(zipRelease)
84-
85-
86-
artifacts {
87-
archives androidSourcesJar
88-
archives androidJavadocsJar
89-
}

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

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,32 @@ 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 final long SEC_IN_MS = 1000;
31+
public static final long MIN_IN_MS = SEC_IN_MS * 60;
32+
public static long MAX_EMDK_TIMEOUT_IN_MS = 10 * MIN_IN_MS; // 10 minutes
33+
public static long WAIT_PERIOD_BEFORE_RETRY_EMDK_RETRIEVAL_IN_MS = 2 * SEC_IN_MS; // 2 seconds
34+
35+
public static void resetCachedValues()
36+
{
37+
sIMEI = null;
38+
sSerialNumber = null;
39+
}
40+
2741
// This method will return the serial number in the string passed through the onSuccess method
2842
public static void getSerialNumber(Context context, IDIResultCallbacks callbackInterface)
2943
{
44+
if(sSerialNumber != null)
45+
{
46+
if(callbackInterface != null)
47+
{
48+
callbackInterface.onDebugStatus("Serial number already in cache.");
49+
}
50+
callbackInterface.onSuccess(sSerialNumber);
51+
return;
52+
}
3053
if (android.os.Build.VERSION.SDK_INT < 29) {
3154
returnSerialUsingAndroidAPIs(context, callbackInterface);
3255
} else {
@@ -37,25 +60,54 @@ public static void getSerialNumber(Context context, IDIResultCallbacks callbackI
3760
@SuppressLint({"MissingPermission", "ObsoleteSdkInt", "HardwareIds"})
3861
private static void returnSerialUsingAndroidAPIs(Context context, IDIResultCallbacks callbackInterface) {
3962
if (android.os.Build.VERSION.SDK_INT < 26) {
63+
sSerialNumber = Build.SERIAL;
4064
callbackInterface.onSuccess(Build.SERIAL);
4165
} else {
4266
if (ContextCompat.checkSelfPermission(context, permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
67+
sSerialNumber = Build.getSerial();
4368
callbackInterface.onSuccess(Build.getSerial());
4469
} else {
4570
callbackInterface.onError("Please grant READ_PHONE_STATE permission");
4671
}
4772
}
4873
}
4974

50-
private static void returnSerialUsingZebraAPIs(Context context, IDIResultCallbacks callbackInterface) {
75+
private static void returnSerialUsingZebraAPIs(Context context, final IDIResultCallbacks callbackInterface) {
76+
IDIResultCallbacks tempCallbackInterface = new IDIResultCallbacks() {
77+
@Override
78+
public void onSuccess(String message) {
79+
sSerialNumber = message;
80+
callbackInterface.onSuccess(message);
81+
}
82+
83+
@Override
84+
public void onError(String message) {
85+
callbackInterface.onError(message);
86+
}
87+
88+
@Override
89+
public void onDebugStatus(String message) {
90+
callbackInterface.onDebugStatus(message);
91+
}
92+
};
93+
5194
new RetrieveOEMInfoTask()
5295
.execute(context, Uri.parse("content://oem_info/oem.zebra.secure/build_serial"),
53-
callbackInterface);
96+
tempCallbackInterface);
5497
}
5598

5699
// This method will return the imei number in the string passed through the onSuccess method
57100
public static void getIMEINumber(Context context, IDIResultCallbacks callbackInterface)
58101
{
102+
if(sIMEI != null)
103+
{
104+
if(callbackInterface != null)
105+
{
106+
callbackInterface.onDebugStatus("IMEI number already in cache.");
107+
}
108+
callbackInterface.onSuccess(sIMEI);
109+
return;
110+
}
59111
if (android.os.Build.VERSION.SDK_INT < 29) {
60112
returnImeiUsingAndroidAPIs(context, callbackInterface);
61113
} else {
@@ -68,6 +120,7 @@ private static void returnImeiUsingAndroidAPIs(Context context, IDIResultCallbac
68120
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
69121
if (android.os.Build.VERSION.SDK_INT < 26) {String imei = telephonyManager.getDeviceId();
70122
if (imei != null && !imei.isEmpty()) {
123+
sIMEI = imei;
71124
callbackInterface.onSuccess(imei);
72125
} else {
73126
callbackInterface.onError("Could not get IMEI number");
@@ -76,6 +129,7 @@ private static void returnImeiUsingAndroidAPIs(Context context, IDIResultCallbac
76129
if (ContextCompat.checkSelfPermission(context, permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
77130
String imei = telephonyManager.getImei();
78131
if (imei != null && !imei.isEmpty()) {
132+
sIMEI = imei;
79133
callbackInterface.onSuccess(imei);
80134
} else {
81135
callbackInterface.onError("Could not get IMEI number");
@@ -86,8 +140,26 @@ private static void returnImeiUsingAndroidAPIs(Context context, IDIResultCallbac
86140
}
87141
}
88142

89-
private static void returnImeiUsingZebraAPIs(Context context, IDIResultCallbacks callbackInterface) {
143+
private static void returnImeiUsingZebraAPIs(Context context, final IDIResultCallbacks callbackInterface) {
144+
IDIResultCallbacks tempCallbackInterface = new IDIResultCallbacks() {
145+
@Override
146+
public void onSuccess(String message) {
147+
sIMEI = message;
148+
callbackInterface.onSuccess(message);
149+
}
150+
151+
@Override
152+
public void onError(String message) {
153+
callbackInterface.onError(message);
154+
}
155+
156+
@Override
157+
public void onDebugStatus(String message) {
158+
callbackInterface.onDebugStatus(message);
159+
}
160+
};
161+
90162
new RetrieveOEMInfoTask().execute(context, Uri.parse("content://oem_info/wan/imei"),
91-
callbackInterface);
163+
tempCallbackInterface);
92164
}
93165
}

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

Lines changed: 40 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,9 @@ public class ErrorHolder
5556
// Provides full error description string
5657
public String msErrorString = "";
5758

59+
// To prevent multiple initializations at the same time
60+
private boolean bInitializing = false;
61+
5862
// Status Listener implementation (ensure that we retrieve the profile manager asynchronously
5963
EMDKManager.StatusListener mStatusListener = new EMDKManager.StatusListener() {
6064
@Override
@@ -114,6 +118,9 @@ public void execute(String mxProfile, String mxProfileName, IDIResultCallbacks r
114118

115119
private void initializeEMDK()
116120
{
121+
if(bInitializing)
122+
return;
123+
bInitializing = true;
117124
if(mEMDKManager == null)
118125
{
119126
EMDKResults results = null;
@@ -126,6 +133,7 @@ private void initializeEMDK()
126133
{
127134
logMessage("Error while requesting EMDKManager.\n" + e.getLocalizedMessage(), EMessageType.ERROR);
128135
e.printStackTrace();
136+
waitForEMDK();
129137
return;
130138
}
131139

@@ -134,6 +142,7 @@ private void initializeEMDK()
134142
logMessage("EMDKManager request command issued with success", EMessageType.DEBUG);
135143
}else {
136144
logMessage("EMDKManager request command error", EMessageType.ERROR);
145+
waitForEMDK();
137146
}
138147
}
139148
else
@@ -142,6 +151,36 @@ private void initializeEMDK()
142151
}
143152
}
144153

154+
private void waitForEMDK()
155+
{
156+
logMessage("EMDKManager error, this could be a BOOT_COMPLETED issue.", EMessageType.DEBUG);
157+
logMessage("Starting watcher thread to wait for EMDK initialization.", EMessageType.DEBUG);
158+
Thread t = new Thread(new Runnable() {
159+
@Override
160+
public void run() {
161+
long startDate = new Date().getTime();
162+
long delta = 0;
163+
while(mEMDKManager == null || delta < DIHelper.MAX_EMDK_TIMEOUT_IN_MS ) {
164+
// Try to initialize EMDK
165+
logMessage("Calling EMDK Initialization method", EMessageType.DEBUG);
166+
initializeEMDK();
167+
try {
168+
logMessage("Waiting " + DIHelper.WAIT_PERIOD_BEFORE_RETRY_EMDK_RETRIEVAL_IN_MS + " milliseconds before retrying.", EMessageType.DEBUG);
169+
Thread.sleep(DIHelper.WAIT_PERIOD_BEFORE_RETRY_EMDK_RETRIEVAL_IN_MS);
170+
} catch (InterruptedException e) {
171+
e.printStackTrace();
172+
}
173+
delta = new Date().getTime() - startDate;
174+
logMessage("Delta in ms since first EMDK retrieval try: " + delta + "ms stops at " + DIHelper.MAX_EMDK_TIMEOUT_IN_MS + "ms", EMessageType.DEBUG);
175+
}
176+
bInitializing = false;
177+
logMessage("Could not retrieve EMDK Manager after waiting " + DIHelper.WAIT_PERIOD_BEFORE_RETRY_EMDK_RETRIEVAL_IN_MS/DIHelper.SEC_IN_MS + " seconds. Please contact your administrator or check logcat for any EMDK related error.", EMessageType.ERROR);
178+
}
179+
});
180+
t.setPriority(Thread.MIN_PRIORITY);
181+
t.start();
182+
}
183+
145184
private void onEMDKManagerRetrieved(EMDKManager emdkManager)
146185
{
147186
mEMDKManager = emdkManager;
@@ -186,6 +225,7 @@ private void releaseManagers()
186225
private void onProfileManagerInitialized(ProfileManager profileManager)
187226
{
188227
mProfileManager = profileManager;
228+
bInitializing = false;
189229
logMessage("Profile Manager retrieved.", EMessageType.DEBUG);
190230
processMXContent();
191231
}

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

Lines changed: 10 additions & 3 deletions
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;
@@ -106,7 +107,10 @@ private static void registerCurrentApplication(Context context, Uri serviceIdent
106107
// You can copy/paste this snippet if you want to provide your own
107108
// certificate
108109
// TODO: use the following code snippet to extract your custom certificate if necessary
109-
final Signature[] arrSignatures = packageInfo.signingInfo.getApkContentsSigners();
110+
Signature[] arrSignatures = null;
111+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
112+
arrSignatures = packageInfo.signingInfo.getApkContentsSigners();
113+
}
110114
if(arrSignatures == null || arrSignatures.length == 0)
111115
{
112116
if(callbackInterface != null)
@@ -124,7 +128,10 @@ private static void registerCurrentApplication(Context context, Uri serviceIdent
124128
final byte[] rawCert = sig.toByteArray();
125129

126130
// Get the certificate as a base64 string
127-
String encoded = Base64.getEncoder().encodeToString(rawCert);
131+
String encoded = null;
132+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
133+
encoded = Base64.getEncoder().encodeToString(rawCert);
134+
}
128135

129136
profileData =
130137
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
@@ -163,7 +170,7 @@ private static void getURIValue(Cursor cursor, Uri uri, IDIResultCallbacks resul
163170
else{
164171
for (int i = 0; i < cursor.getColumnCount(); i++) {
165172
try {
166-
String data = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(i)));
173+
@SuppressLint("Range") String data = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(i)));
167174
resultCallbacks.onSuccess(data);
168175
cursor.close();
169176
return;

0 commit comments

Comments
 (0)