Skip to content

Commit 1dea9b5

Browse files
committed
Asynced everything
1 parent 29d4923 commit 1dea9b5

File tree

6 files changed

+215
-171
lines changed

6 files changed

+215
-171
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class DICommandBase {
1313
/*
1414
A TAG if we want to log something
1515
*/
16-
protected static String TAG = "DIWrapper";
16+
protected static String TAG = "DIWrapperMX";
1717

1818
/*
1919
A context to work with intents

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

Lines changed: 3 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.pm.Signature;
77
import android.database.Cursor;
88
import android.net.Uri;
9+
import android.os.AsyncTask;
910
import android.util.Log;
1011

1112
import java.util.Base64;
@@ -21,173 +22,12 @@ public class DIHelper {
2122
// This method will return the serial number in the string passed through the onSuccess method
2223
public static void getSerialNumber(Context context, IDIResultCallbacks callbackInterface)
2324
{
24-
registerCurrentApplication(context, Uri.parse("content://oem_info/oem.zebra.secure/build_serial"), new IDIResultCallbacks() {
25-
@Override
26-
public void onSuccess(String message) {
27-
String test = message;
28-
}
29-
30-
@Override
31-
public void onError(String message) {
32-
String test = message;
33-
34-
}
35-
36-
@Override
37-
public void onDebugStatus(String message) {
38-
String test = message;
39-
40-
}
41-
});
42-
RetrieveOEMInfo(context, Uri.parse("content://oem_info/oem.zebra.secure/build_serial"), callbackInterface);
25+
new RetrieveOEMInfoTask().execute(context, Uri.parse("content://oem_info/oem.zebra.secure/build_serial"), callbackInterface);
4326
}
4427

4528
// This method will return the imei number in the string passed through the onSuccess method
4629
public static void getIMEINumber(Context context, IDIResultCallbacks callbackInterface)
4730
{
48-
RetrieveOEMInfo(context, Uri.parse("content://oem_info/wan/imei"), callbackInterface);
49-
}
50-
51-
private static void registerCurrentApplication(Context context, Uri serviceIdentifier, IDIResultCallbacks callbackInterface)
52-
{
53-
String profileName = "AccessMgr-1";
54-
String profileData = "";
55-
try {
56-
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNING_CERTIFICATES);
57-
String path = context.getApplicationInfo().sourceDir;
58-
final String strName = packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString();
59-
final String strVendor = packageInfo.packageName;
60-
Signature sig = apkCertificate;
61-
62-
// Let's check if we have a custom certificate
63-
if(sig == null)
64-
{
65-
// Nope, we will get the first apk signing certificate that we find
66-
// You can copy/paste this snippet if you want to provide your own
67-
// certificate
68-
// TODO: use the following code snippet to extract your custom certificate if necessary
69-
final Signature[] arrSignatures = packageInfo.signingInfo.getApkContentsSigners();
70-
if(arrSignatures == null || arrSignatures.length == 0)
71-
{
72-
if(callbackInterface != null)
73-
{
74-
callbackInterface.onError("Error : Package has no signing certificates... how's that possible ?");
75-
return;
76-
}
77-
}
78-
sig = arrSignatures[0];
79-
}
80-
81-
/*
82-
* Get the X.509 certificate.
83-
*/
84-
final byte[] rawCert = sig.toByteArray();
85-
86-
// Get the certificate as a base64 string
87-
String encoded = Base64.getEncoder().encodeToString(rawCert);
88-
89-
profileData =
90-
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
91-
"<characteristic type=\"Profile\">" +
92-
"<parm name=\"ProfileName\" value=\"" + profileName + "\"/>" +
93-
"<characteristic type=\"AccessMgr\" version=\"9.2\">" +
94-
"<parm name=\"OperationMode\" value=\"1\" />" +
95-
"<parm name=\"ServiceAccessAction\" value=\"4\" />" +
96-
"<parm name=\"ServiceIdentifier\" value=\"" + serviceIdentifier + "\" />" +
97-
"<parm name=\"CallerPackageName\" value=\"" + context.getPackageName().toString() + "\" />" +
98-
"<parm name=\"CallerSignature\" value=\"" + encoded + "\" />" +
99-
"</characteristic>"+
100-
"</characteristic>";
101-
DIProfileManagerCommand profileManagerCommand = new DIProfileManagerCommand(context);
102-
profileManagerCommand.execute(profileData, profileName, callbackInterface);
103-
//}
104-
} catch (Exception e) {
105-
e.printStackTrace();
106-
if(callbackInterface != null)
107-
{
108-
callbackInterface.onError("Error on profile: " + profileName + "\nError:" + e.getLocalizedMessage() + "\nProfileData:" + profileData);
109-
}
110-
}
111-
}
112-
113-
private static void RetrieveOEMInfo(final Context context, final Uri uri, final IDIResultCallbacks callbackInterface) {
114-
// For clarity, this code calls ContentResolver.query() on the UI thread but production code should perform queries asynchronously.
115-
// See https://developer.android.com/guide/topics/providers/content-provider-basics.html for more information
116-
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
117-
if (cursor == null || cursor.getCount() < 1)
118-
{
119-
if(callbackInterface != null)
120-
{
121-
callbackInterface.onDebugStatus("App not registered to call OEM Service:" + uri.toString()+"\nRegistering current application using profile manger, this may take a couple of seconds...");
122-
}
123-
// Let's register the application
124-
registerCurrentApplication(context, uri, new IDIResultCallbacks() {
125-
@Override
126-
public void onSuccess(String message) {
127-
// The app has been registered
128-
// Let's try again to get the identifier
129-
Cursor cursor2 = context.getContentResolver().query(uri, null, null, null, null);
130-
if (cursor2 == null || cursor2.getCount() < 1) {
131-
if(callbackInterface != null)
132-
{
133-
callbackInterface.onError("Fail to register the app for OEM Service call:" + uri + "\nIt's time to debug this app ;)");
134-
return;
135-
}
136-
}
137-
getURIValue(cursor2, uri, callbackInterface);
138-
return;
139-
}
140-
141-
@Override
142-
public void onError(String message) {
143-
if(callbackInterface != null)
144-
{
145-
callbackInterface.onError(message);
146-
return;
147-
}
148-
}
149-
150-
@Override
151-
public void onDebugStatus(String message) {
152-
if(callbackInterface != null)
153-
{
154-
callbackInterface.onDebugStatus(message);
155-
}
156-
}
157-
});
158-
}
159-
else
160-
{
161-
// We have the right to call this service, and we obtained some data to parse...
162-
getURIValue(cursor, uri, callbackInterface);
163-
}
164-
}
165-
166-
private static void getURIValue(Cursor cursor, Uri uri, IDIResultCallbacks resultCallbacks)
167-
{
168-
while (cursor.moveToNext()) {
169-
if (cursor.getColumnCount() == 0)
170-
{
171-
// No data in the cursor. I have seen this happen on non-WAN devices
172-
String errorMsg = "Error: " + uri + " does not exist on this device";
173-
resultCallbacks.onDebugStatus(errorMsg);
174-
}
175-
else{
176-
for (int i = 0; i < cursor.getColumnCount(); i++) {
177-
try {
178-
String data = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(i)));
179-
resultCallbacks.onSuccess(data);
180-
cursor.close();
181-
return;
182-
}
183-
catch (Exception e)
184-
{
185-
resultCallbacks.onDebugStatus(e.getLocalizedMessage());
186-
}
187-
}
188-
}
189-
}
190-
cursor.close();
191-
resultCallbacks.onError("Data not found in Uri:" + uri);
31+
new RetrieveOEMInfoTask().execute(context, Uri.parse("content://oem_info/wan/imei"), callbackInterface);
19232
}
19333
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ private void onEMDKManagerRetrieved(EMDKManager emdkManager)
162162
}
163163

164164
private void onEMDKManagerClosed()
165+
{
166+
releaseManagers();
167+
}
168+
169+
private void releaseManagers()
165170
{
166171
if(mProfileManager != null)
167172
{
@@ -187,18 +192,22 @@ private void onProfileManagerInitialized(ProfileManager profileManager)
187192

188193
private void onProfileExecutedWithSuccess()
189194
{
195+
releaseManagers();
190196
if(idiProfileManagerCommandResult != null)
191197
{
192198
idiProfileManagerCommandResult.onSuccess("Success applying profile:" + msProfileName + "\nProfileData:" + msProfileData);
193199
}
200+
194201
}
195202

196203
private void onProfileExecutedError(String message)
197204
{
205+
releaseManagers();
198206
if(idiProfileManagerCommandResult != null)
199207
{
200208
idiProfileManagerCommandResult.onError("Error on profile: " + msProfileName + "\nError:" + message + "\nProfileData:" + msProfileData);
201209
}
210+
202211
}
203212

204213
private void onProfileExecutedStatusChanged(String message)
@@ -261,6 +270,7 @@ else if(results.statusCode == EMDKResults.STATUS_CODE.SUCCESS)
261270
{
262271
logMessage("Profile executed with success: " + msProfileName, EMessageType.DEBUG);
263272
onProfileExecutedWithSuccess();
273+
return;
264274
}
265275
else
266276
{
@@ -279,12 +289,12 @@ private void parseXML(XmlPullParser myParser) {
279289
event = myParser.getEventType();
280290
// An object that will store a temporary error holder if an error characteristic is found
281291
ErrorHolder tempErrorHolder = null;
282-
logMessage("XML document", EMessageType.VERBOSE);
292+
//logMessage("XML document", EMessageType.VERBOSE);
283293
while (event != XmlPullParser.END_DOCUMENT) {
284294
String name = myParser.getName();
285295
switch (event) {
286296
case XmlPullParser.START_TAG:
287-
logMessage("XML Element:<" + myParser.getText()+">", EMessageType.VERBOSE);
297+
//logMessage("XML Element:<" + myParser.getText()+">", EMessageType.VERBOSE);
288298
if (name.equals("characteristic-error"))
289299
{
290300
if(tempErrorHolder == null)
@@ -312,7 +322,7 @@ else if (name.equals("parm-error"))
312322
}
313323
break;
314324
case XmlPullParser.END_TAG:
315-
logMessage("XML Element:<//" + myParser.getText()+">", EMessageType.VERBOSE);
325+
//logMessage("XML Element:<//" + myParser.getText()+">", EMessageType.VERBOSE);
316326
break;
317327
}
318328
event = myParser.next();

0 commit comments

Comments
 (0)