@regulaforensics/cordova-plugin-document-reader-api 5.4.0 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/example/config.xml +1 -1
- package/example/package.json +7 -5
- package/example/www/index.html +6 -1
- package/example/www/js/index.js +61 -7
- package/package.json +1 -1
- package/plugin.xml +5 -4
- package/src/android/DocumentReader.java +227 -20
- package/src/android/Helpers.java +146 -0
- package/src/android/JSONConstructor.java +1830 -507
- package/src/android/RegulaConfig.java +85 -18
- package/src/android/build.gradle +11 -11
- package/src/ios/RGLDocumentReader.h +8 -3
- package/src/ios/RGLDocumentReader.m +163 -12
- package/src/ios/RGLWJSONConstructor.h +60 -0
- package/src/ios/RGLWJSONConstructor.m +918 -0
- package/src/ios/RegulaConfig.h +2 -0
- package/src/ios/RegulaConfig.m +128 -33
- package/www/DocumentReader.js +902 -667
- package/src/ios/JSONConstructor.h +0 -33
- package/src/ios/JSONConstructor.m +0 -821
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package cordova.plugin.documentreader;
|
|
2
2
|
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
3
4
|
import android.app.Activity;
|
|
4
5
|
import android.app.PendingIntent;
|
|
5
6
|
import android.content.Context;
|
|
@@ -8,16 +9,25 @@ import android.content.IntentFilter;
|
|
|
8
9
|
import android.graphics.Bitmap;
|
|
9
10
|
import android.nfc.NfcAdapter;
|
|
10
11
|
import android.nfc.tech.IsoDep;
|
|
12
|
+
import android.support.annotation.NonNull;
|
|
11
13
|
import android.util.Base64;
|
|
12
14
|
|
|
13
15
|
import com.regula.documentreader.api.completions.IDocumentReaderCompletion;
|
|
14
16
|
import com.regula.documentreader.api.completions.IDocumentReaderInitCompletion;
|
|
15
17
|
import com.regula.documentreader.api.completions.IDocumentReaderPrepareCompletion;
|
|
18
|
+
import com.regula.documentreader.api.completions.IRfidNotificationCompletion;
|
|
19
|
+
import com.regula.documentreader.api.completions.IRfidPKDCertificateCompletion;
|
|
20
|
+
import com.regula.documentreader.api.completions.IRfidReaderRequest;
|
|
21
|
+
import com.regula.documentreader.api.completions.IRfidTASignatureCompletion;
|
|
16
22
|
import com.regula.documentreader.api.enums.DocReaderAction;
|
|
23
|
+
import com.regula.documentreader.api.errors.DocumentReaderException;
|
|
24
|
+
import com.regula.documentreader.api.params.DocReaderConfig;
|
|
17
25
|
import com.regula.documentreader.api.params.ImageInputParam;
|
|
18
26
|
import com.regula.documentreader.api.params.rfid.PKDCertificate;
|
|
27
|
+
import com.regula.documentreader.api.params.rfid.authorization.PAResourcesIssuer;
|
|
28
|
+
import com.regula.documentreader.api.params.rfid.authorization.TAChallenge;
|
|
19
29
|
import com.regula.documentreader.api.results.DocumentReaderResults;
|
|
20
|
-
import com.regula.documentreader.api.
|
|
30
|
+
import com.regula.documentreader.api.parser.DocReaderResultsJsonParser;
|
|
21
31
|
|
|
22
32
|
import org.apache.cordova.CallbackContext;
|
|
23
33
|
import org.apache.cordova.CordovaPlugin;
|
|
@@ -26,6 +36,9 @@ import org.json.JSONArray;
|
|
|
26
36
|
import org.json.JSONObject;
|
|
27
37
|
import org.json.JSONException;
|
|
28
38
|
|
|
39
|
+
import java.io.File;
|
|
40
|
+
import java.io.IOException;
|
|
41
|
+
import java.io.InputStream;
|
|
29
42
|
import java.util.ArrayList;
|
|
30
43
|
import java.util.List;
|
|
31
44
|
|
|
@@ -37,6 +50,13 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
37
50
|
private boolean backgroundRFIDEnabled = false;
|
|
38
51
|
private Activity activity;
|
|
39
52
|
JSONArray data;
|
|
53
|
+
private IRfidPKDCertificateCompletion paCertificateCompletion;
|
|
54
|
+
private IRfidPKDCertificateCompletion taCertificateCompletion;
|
|
55
|
+
private IRfidTASignatureCompletion taSignatureCompletion;
|
|
56
|
+
private final static String rfidNotificationCompletionEvent = "rfidNotificationCompletionEvent";
|
|
57
|
+
private final static String paCertificateCompletionEvent = "paCertificateCompletionEvent";
|
|
58
|
+
private final static String taCertificateCompletionEvent = "taCertificateCompletionEvent";
|
|
59
|
+
private final static String taSignatureCompletionEvent = "taSignatureCompletionEvent";
|
|
40
60
|
private static int databaseDownloadProgress = 0;
|
|
41
61
|
|
|
42
62
|
private Context getContext() {
|
|
@@ -82,12 +102,42 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
82
102
|
callbackContext.sendPluginResult(pluginResult);
|
|
83
103
|
}
|
|
84
104
|
|
|
85
|
-
private void sendCompletion(int action, DocumentReaderResults results,
|
|
105
|
+
private void sendCompletion(int action, DocumentReaderResults results, DocumentReaderException error) {
|
|
86
106
|
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, JSONConstructor.generateCompletion(action, results, error, getContext()).toString());
|
|
87
107
|
pluginResult.setKeepCallback(true);
|
|
88
108
|
callbackContext.sendPluginResult(pluginResult);
|
|
89
109
|
}
|
|
90
110
|
|
|
111
|
+
private void sendVideoEncoderCompletion(String sessionId, File file) {
|
|
112
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, JSONConstructor.generateVideoEncoderCompletion(sessionId, file).toString());
|
|
113
|
+
pluginResult.setKeepCallback(true);
|
|
114
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private void sendIRfidNotificationCompletion(int notification) {
|
|
118
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, rfidNotificationCompletionEvent + notification);
|
|
119
|
+
pluginResult.setKeepCallback(true);
|
|
120
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private void sendPACertificateCompletion(byte[] serialNumber, PAResourcesIssuer issuer) {
|
|
124
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, paCertificateCompletionEvent + JSONConstructor.generatePACertificateCompletion(serialNumber, issuer).toString());
|
|
125
|
+
pluginResult.setKeepCallback(true);
|
|
126
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private void sendTACertificateCompletion(String keyCAR) {
|
|
130
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, taCertificateCompletionEvent + keyCAR);
|
|
131
|
+
pluginResult.setKeepCallback(true);
|
|
132
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
133
|
+
}
|
|
134
|
+
private void sendTASignatureCompletion(TAChallenge challenge) {
|
|
135
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, taSignatureCompletionEvent + JSONConstructor.generateTAChallenge(challenge).toString());
|
|
136
|
+
pluginResult.setKeepCallback(true);
|
|
137
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
91
141
|
@Override
|
|
92
142
|
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
|
|
93
143
|
this.callbackContext = callbackContext;
|
|
@@ -112,6 +162,9 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
112
162
|
};
|
|
113
163
|
try {
|
|
114
164
|
switch (action) {
|
|
165
|
+
case "initializeReaderAutomatically":
|
|
166
|
+
initializeReaderAutomatically(callback);
|
|
167
|
+
break;
|
|
115
168
|
case "getAPIVersion":
|
|
116
169
|
getAPIVersion(callback);
|
|
117
170
|
break;
|
|
@@ -217,6 +270,9 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
217
270
|
case "getRfidSessionStatus":
|
|
218
271
|
getRfidSessionStatus(callback);
|
|
219
272
|
break;
|
|
273
|
+
case "setRfidDelegate":
|
|
274
|
+
setRfidDelegate(callback, args(0));
|
|
275
|
+
break;
|
|
220
276
|
case "setEnableCoreLogs":
|
|
221
277
|
setEnableCoreLogs(callback, args(0));
|
|
222
278
|
break;
|
|
@@ -256,9 +312,24 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
256
312
|
case "setRfidSessionStatus":
|
|
257
313
|
setRfidSessionStatus(callback, args(0));
|
|
258
314
|
break;
|
|
315
|
+
case "providePACertificates":
|
|
316
|
+
providePACertificates(callback, args(0));
|
|
317
|
+
break;
|
|
318
|
+
case "provideTACertificates":
|
|
319
|
+
provideTACertificates(callback, args(0));
|
|
320
|
+
break;
|
|
321
|
+
case "provideTASignature":
|
|
322
|
+
provideTASignature(callback, args(0));
|
|
323
|
+
break;
|
|
324
|
+
case "parseCoreResults":
|
|
325
|
+
parseCoreResults(callback, args(0));
|
|
326
|
+
break;
|
|
259
327
|
case "initializeReaderWithDatabasePath":
|
|
260
328
|
initializeReaderWithDatabasePath(callback, args(0), args(1));
|
|
261
329
|
break;
|
|
330
|
+
case "initializeReaderWithDatabase":
|
|
331
|
+
initializeReaderWithDatabase(callback, args(0), args(1));
|
|
332
|
+
break;
|
|
262
333
|
case "recognizeImageFrame":
|
|
263
334
|
recognizeImageFrame(callback, args(0), args(1));
|
|
264
335
|
break;
|
|
@@ -293,6 +364,7 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
293
364
|
};
|
|
294
365
|
Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
|
|
295
366
|
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
367
|
+
@SuppressLint("UnspecifiedImmutableFlag")
|
|
296
368
|
PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
|
|
297
369
|
NfcAdapter.getDefaultAdapter(getActivity()).enableForegroundDispatch(activity, pendingIntent, filters, techList);
|
|
298
370
|
}
|
|
@@ -304,8 +376,30 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
304
376
|
backgroundRFIDEnabled = false;
|
|
305
377
|
}
|
|
306
378
|
|
|
379
|
+
private void initializeReaderAutomatically(Callback callback) {
|
|
380
|
+
if (!Instance().isReady())
|
|
381
|
+
try {
|
|
382
|
+
InputStream is = getContext().getAssets().open("regula.license");
|
|
383
|
+
byte[] license = new byte[is.available()];
|
|
384
|
+
//noinspection ResultOfMethodCallIgnored
|
|
385
|
+
is.read(license);
|
|
386
|
+
Instance().initializeReader(getContext(), new DocReaderConfig(license), getInitCompletion(callback));
|
|
387
|
+
is.close();
|
|
388
|
+
} catch (IOException e) {
|
|
389
|
+
e.printStackTrace();
|
|
390
|
+
callback.error("problem reading license(see logs)");
|
|
391
|
+
}
|
|
392
|
+
else
|
|
393
|
+
callback.success("already initialized");
|
|
394
|
+
}
|
|
395
|
+
|
|
307
396
|
private void getAvailableScenarios(Callback callback) throws JSONException {
|
|
308
|
-
callback.success(JSONConstructor.generateList(Instance().availableScenarios, JSONConstructor::generateDocumentReaderScenario
|
|
397
|
+
callback.success(JSONConstructor.generateList(Instance().availableScenarios, JSONConstructor::generateDocumentReaderScenario).toString());
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
private void parseCoreResults(Callback callback, String json) {
|
|
401
|
+
DocumentReaderResults results = (DocumentReaderResults) DocReaderResultsJsonParser.parseCoreResults(json).get("docReaderResults");
|
|
402
|
+
callback.success(JSONConstructor.generateDocumentReaderResults(results, getContext()).toString());
|
|
309
403
|
}
|
|
310
404
|
|
|
311
405
|
private void getAPIVersion(Callback callback) {
|
|
@@ -354,19 +448,19 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
354
448
|
}
|
|
355
449
|
|
|
356
450
|
private void getConfig(Callback callback) throws JSONException {
|
|
357
|
-
callback.success(RegulaConfig.getConfig(Instance()
|
|
451
|
+
callback.success(RegulaConfig.getConfig(Instance()).toString());
|
|
358
452
|
}
|
|
359
453
|
|
|
360
454
|
private void getRfidScenario(Callback callback) {
|
|
361
455
|
callback.success(Instance().rfidScenario().toJson());
|
|
362
456
|
}
|
|
363
457
|
|
|
364
|
-
private void selectedScenario(Callback callback)
|
|
365
|
-
callback.success(JSONConstructor.
|
|
458
|
+
private void selectedScenario(Callback callback) {
|
|
459
|
+
callback.success(JSONConstructor.generateDocumentReaderScenarioFull(Instance().getScenario(Instance().processParams().getScenario())).toString());
|
|
366
460
|
}
|
|
367
461
|
|
|
368
|
-
private void getScenario(Callback callback, String scenario)
|
|
369
|
-
callback.success(JSONConstructor.
|
|
462
|
+
private void getScenario(Callback callback, String scenario) {
|
|
463
|
+
callback.success(JSONConstructor.generateDocumentReaderScenarioFull(Instance().getScenario(scenario)).toString());
|
|
370
464
|
}
|
|
371
465
|
|
|
372
466
|
private void getLicenseExpiryDate(Callback callback) {
|
|
@@ -388,11 +482,11 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
388
482
|
}
|
|
389
483
|
|
|
390
484
|
private void getDocumentReaderIsReady(Callback callback) {
|
|
391
|
-
callback.success(Instance().
|
|
485
|
+
callback.success(Instance().isReady());
|
|
392
486
|
}
|
|
393
487
|
|
|
394
488
|
private void getDocumentReaderStatus(Callback callback) {
|
|
395
|
-
callback.success(Instance().
|
|
489
|
+
callback.success(Instance().isReady());
|
|
396
490
|
}
|
|
397
491
|
|
|
398
492
|
private void isRFIDAvailableForUse(Callback callback) {
|
|
@@ -400,8 +494,15 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
400
494
|
}
|
|
401
495
|
|
|
402
496
|
private void initializeReader(Callback callback, Object license) {
|
|
403
|
-
if (!Instance().
|
|
404
|
-
Instance().initializeReader(getContext(), Base64.decode(license.toString(), Base64.DEFAULT), getInitCompletion(callback));
|
|
497
|
+
if (!Instance().isReady())
|
|
498
|
+
Instance().initializeReader(getContext(), new DocReaderConfig(Base64.decode(license.toString(), Base64.DEFAULT)), getInitCompletion(callback));
|
|
499
|
+
else
|
|
500
|
+
callback.success("already initialized");
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
private void initializeReaderWithDatabase(Callback callback, Object license, Object db) {
|
|
504
|
+
if (!Instance().isReady())
|
|
505
|
+
Instance().initializeReader(getContext(), new DocReaderConfig(Base64.decode(license.toString(), Base64.DEFAULT), Base64.decode(db.toString(), Base64.DEFAULT)), getInitCompletion(callback));
|
|
405
506
|
else
|
|
406
507
|
callback.success("already initialized");
|
|
407
508
|
}
|
|
@@ -417,7 +518,7 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
417
518
|
}
|
|
418
519
|
|
|
419
520
|
private void recognizeImageWithImageInputParams(@SuppressWarnings("unused") Callback callback, String base64Image, final JSONObject params) throws JSONException {
|
|
420
|
-
Instance().recognizeImage(
|
|
521
|
+
Instance().recognizeImage(Helpers.bitmapFromBase64(base64Image), new ImageInputParam(params.getInt("width"), params.getInt("height"), params.getInt("type")), getCompletion());
|
|
421
522
|
}
|
|
422
523
|
|
|
423
524
|
private void recognizeImageWithOpts(Callback callback, String base64Image, final JSONObject opts) throws JSONException {
|
|
@@ -427,14 +528,14 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
427
528
|
|
|
428
529
|
private void recognizeImage(@SuppressWarnings("unused") Callback callback, String base64Image) {
|
|
429
530
|
stopBackgroundRFID();
|
|
430
|
-
Instance().recognizeImage(
|
|
531
|
+
Instance().recognizeImage(Helpers.bitmapFromBase64(base64Image), getCompletion());
|
|
431
532
|
}
|
|
432
533
|
|
|
433
534
|
private void recognizeImages(@SuppressWarnings("unused") Callback callback, JSONArray base64Images) throws JSONException {
|
|
434
535
|
stopBackgroundRFID();
|
|
435
536
|
Bitmap[] images = new Bitmap[base64Images.length()];
|
|
436
537
|
for (int i = 0; i < images.length; i++)
|
|
437
|
-
images[i] =
|
|
538
|
+
images[i] = Helpers.bitmapFromBase64(base64Images.getString(i));
|
|
438
539
|
Instance().recognizeImages(images, getCompletion());
|
|
439
540
|
}
|
|
440
541
|
|
|
@@ -472,7 +573,7 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
472
573
|
}
|
|
473
574
|
|
|
474
575
|
private void recognizeImageFrame(@SuppressWarnings("unused") Callback callback, String base64Image, final JSONObject opts) throws JSONException {
|
|
475
|
-
Instance().recognizeImageFrame(
|
|
576
|
+
Instance().recognizeImageFrame(Helpers.bitmapFromBase64(base64Image), new ImageInputParam(opts.getInt("width"), opts.getInt("height"), opts.getInt("type")), getCompletion());
|
|
476
577
|
}
|
|
477
578
|
|
|
478
579
|
private void recognizeVideoFrame(@SuppressWarnings("unused") Callback callback, String byteString, final JSONObject opts) throws JSONException {
|
|
@@ -502,7 +603,12 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
502
603
|
|
|
503
604
|
private void startRFIDReader(@SuppressWarnings("unused") Callback callback) {
|
|
504
605
|
stopBackgroundRFID();
|
|
505
|
-
|
|
606
|
+
IRfidReaderRequest delegate = null;
|
|
607
|
+
if (rfidDelegate == RFIDDelegate.NO_PA)
|
|
608
|
+
delegate = getIRfidReaderRequestNoPA();
|
|
609
|
+
if (rfidDelegate == RFIDDelegate.FULL)
|
|
610
|
+
delegate = getIRfidReaderRequest();
|
|
611
|
+
Instance().startRFIDReader(getContext(), getCompletion(), delegate, getIRfidNotificationCompletion());
|
|
506
612
|
}
|
|
507
613
|
|
|
508
614
|
private void stopRFIDReader(Callback callback) {
|
|
@@ -538,10 +644,52 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
538
644
|
startForegroundDispatch(getActivity());
|
|
539
645
|
}
|
|
540
646
|
|
|
647
|
+
private void providePACertificates(Callback callback, JSONArray certificatesJSON) throws JSONException {
|
|
648
|
+
if (paCertificateCompletion == null) {
|
|
649
|
+
callback.error("paCertificateCompletion is null");
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
PKDCertificate[] certificates = new PKDCertificate[certificatesJSON.length()];
|
|
653
|
+
for (int i = 0; i < certificatesJSON.length(); i++) {
|
|
654
|
+
JSONObject certificate = certificatesJSON.getJSONObject(i);
|
|
655
|
+
certificates[i] = new PKDCertificate(Base64.decode(certificate.get("binaryData").toString(), Base64.DEFAULT), certificate.getInt("resourceType"), certificate.has("privateKey") ? Base64.decode(certificate.get("privateKey").toString(), Base64.DEFAULT) : null);
|
|
656
|
+
}
|
|
657
|
+
paCertificateCompletion.onCertificatesReceived(certificates);
|
|
658
|
+
callback.success();
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
private void provideTACertificates(Callback callback, JSONArray certificatesJSON) throws JSONException {
|
|
662
|
+
if (taCertificateCompletion == null) {
|
|
663
|
+
callback.error("taCertificateCompletion is null");
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
PKDCertificate[] certificates = new PKDCertificate[certificatesJSON.length()];
|
|
667
|
+
for (int i = 0; i < certificatesJSON.length(); i++) {
|
|
668
|
+
JSONObject certificate = certificatesJSON.getJSONObject(i);
|
|
669
|
+
certificates[i] = new PKDCertificate(Base64.decode(certificate.get("binaryData").toString(), Base64.DEFAULT), certificate.getInt("resourceType"), certificate.has("privateKey") ? Base64.decode(certificate.get("privateKey").toString(), Base64.DEFAULT) : null);
|
|
670
|
+
}
|
|
671
|
+
taCertificateCompletion.onCertificatesReceived(certificates);
|
|
672
|
+
callback.success();
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
private void provideTASignature(Callback callback, Object signature) {
|
|
676
|
+
if (taSignatureCompletion == null) {
|
|
677
|
+
callback.error("taSignatureCompletion is null");
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
taSignatureCompletion.onSignatureReceived(Base64.decode(signature.toString(), Base64.DEFAULT));
|
|
681
|
+
callback.success();
|
|
682
|
+
}
|
|
683
|
+
|
|
541
684
|
private void setCameraSessionIsPaused(Callback callback, @SuppressWarnings("unused") boolean ignored) {
|
|
542
685
|
callback.error("setCameraSessionIsPaused() is an ios-only method");
|
|
543
686
|
}
|
|
544
687
|
|
|
688
|
+
private void setRfidDelegate(Callback callback, int delegate) {
|
|
689
|
+
rfidDelegate = delegate;
|
|
690
|
+
callback.success();
|
|
691
|
+
}
|
|
692
|
+
|
|
545
693
|
private void getCameraSessionIsPaused(Callback callback) {
|
|
546
694
|
callback.error("getCameraSessionIsPaused() is an ios-only method");
|
|
547
695
|
}
|
|
@@ -595,10 +743,69 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
595
743
|
|
|
596
744
|
private IDocumentReaderInitCompletion getInitCompletion(Callback callback) {
|
|
597
745
|
return (success, error) -> {
|
|
598
|
-
if (success)
|
|
746
|
+
if (success) {
|
|
747
|
+
Instance().setVideoEncoderCompletion(this::sendVideoEncoderCompletion);
|
|
599
748
|
callback.success("init completed");
|
|
600
|
-
else
|
|
749
|
+
} else
|
|
601
750
|
callback.error("Init failed:" + error);
|
|
602
751
|
};
|
|
603
752
|
}
|
|
604
|
-
|
|
753
|
+
|
|
754
|
+
private IRfidReaderRequest getIRfidReaderRequest() {
|
|
755
|
+
return new IRfidReaderRequest() {
|
|
756
|
+
@Override
|
|
757
|
+
public void onRequestPACertificates(byte[] serialNumber, PAResourcesIssuer issuer, @NonNull IRfidPKDCertificateCompletion completion) {
|
|
758
|
+
paCertificateCompletion = completion;
|
|
759
|
+
completion.onCertificatesReceived(new PKDCertificate[0]);
|
|
760
|
+
sendPACertificateCompletion(serialNumber, issuer);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
@Override
|
|
764
|
+
public void onRequestTACertificates(String keyCAR, @NonNull IRfidPKDCertificateCompletion completion) {
|
|
765
|
+
taCertificateCompletion = completion;
|
|
766
|
+
sendTACertificateCompletion(keyCAR);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
@Override
|
|
770
|
+
public void onRequestTASignature(TAChallenge challenge, @NonNull IRfidTASignatureCompletion completion) {
|
|
771
|
+
taSignatureCompletion = completion;
|
|
772
|
+
sendTASignatureCompletion(challenge);
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
private IRfidReaderRequest getIRfidReaderRequestNoPA() {
|
|
778
|
+
return new IRfidReaderRequest() {
|
|
779
|
+
@Override
|
|
780
|
+
public void onRequestPACertificates(byte[] serialNumber, PAResourcesIssuer issuer, @NonNull IRfidPKDCertificateCompletion completion) {
|
|
781
|
+
paCertificateCompletion = null;
|
|
782
|
+
completion.onCertificatesReceived(new PKDCertificate[0]);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
@Override
|
|
786
|
+
public void onRequestTACertificates(String keyCAR, @NonNull IRfidPKDCertificateCompletion completion) {
|
|
787
|
+
taCertificateCompletion = completion;
|
|
788
|
+
sendTACertificateCompletion(keyCAR);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
@Override
|
|
792
|
+
public void onRequestTASignature(TAChallenge challenge, @NonNull IRfidTASignatureCompletion completion) {
|
|
793
|
+
taSignatureCompletion = completion;
|
|
794
|
+
sendTASignatureCompletion(challenge);
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
private static int rfidDelegate = RFIDDelegate.NULL;
|
|
800
|
+
|
|
801
|
+
private static class RFIDDelegate {
|
|
802
|
+
public static final int NULL = 0;
|
|
803
|
+
public static final int NO_PA = 1;
|
|
804
|
+
public static final int FULL = 2;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
private IRfidNotificationCompletion getIRfidNotificationCompletion() {
|
|
809
|
+
return (notificationType, value) -> sendIRfidNotificationCompletion(notificationType);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
package cordova.plugin.documentreader;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.graphics.Bitmap;
|
|
5
|
+
import android.graphics.BitmapFactory;
|
|
6
|
+
import android.graphics.Canvas;
|
|
7
|
+
import android.graphics.Matrix;
|
|
8
|
+
import android.graphics.drawable.BitmapDrawable;
|
|
9
|
+
import android.graphics.drawable.Drawable;
|
|
10
|
+
import android.util.Base64;
|
|
11
|
+
|
|
12
|
+
import com.regula.documentreader.api.enums.BarcodeType;
|
|
13
|
+
import com.regula.documentreader.api.params.FaceMetaData;
|
|
14
|
+
import com.regula.documentreader.api.results.Bounds;
|
|
15
|
+
|
|
16
|
+
import org.json.JSONArray;
|
|
17
|
+
import org.json.JSONException;
|
|
18
|
+
import org.json.JSONObject;
|
|
19
|
+
|
|
20
|
+
import java.io.ByteArrayOutputStream;
|
|
21
|
+
import java.util.ArrayList;
|
|
22
|
+
import java.util.List;
|
|
23
|
+
|
|
24
|
+
class Helpers {
|
|
25
|
+
static Bitmap bitmapFromBase64(String base64) {
|
|
26
|
+
byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
|
|
27
|
+
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
28
|
+
options.inPreferredConfig = Bitmap.Config.RGB_565;
|
|
29
|
+
Bitmap result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length, options);
|
|
30
|
+
int sizeMultiplier = result.getByteCount() / 5000000;
|
|
31
|
+
if (result.getByteCount() > 5000000)
|
|
32
|
+
result = Bitmap.createScaledBitmap(result, result.getWidth() / (int) Math.sqrt(sizeMultiplier), result.getHeight() / (int) Math.sqrt(sizeMultiplier), false);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static BitmapDrawable drawableFromBase64(String base64, Context context)
|
|
37
|
+
{
|
|
38
|
+
byte[] decodedByte = Base64.decode(base64, 0);
|
|
39
|
+
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
|
|
40
|
+
float density = context.getResources().getDisplayMetrics().density;
|
|
41
|
+
int width = (int)(bitmap.getWidth()*density);
|
|
42
|
+
int height = (int)(bitmap.getHeight()*density);
|
|
43
|
+
return new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, width, height, false));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static Bitmap bitmapFromDrawable(Drawable drawable) {
|
|
47
|
+
Bitmap bitmap;
|
|
48
|
+
|
|
49
|
+
if (drawable instanceof BitmapDrawable) {
|
|
50
|
+
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
|
|
51
|
+
if (bitmapDrawable.getBitmap() != null) {
|
|
52
|
+
return bitmapDrawable.getBitmap();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
|
|
57
|
+
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
|
|
58
|
+
} else {
|
|
59
|
+
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
Canvas canvas = new Canvas(bitmap);
|
|
63
|
+
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
|
64
|
+
drawable.draw(canvas);
|
|
65
|
+
return bitmap;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static String bitmapToBase64String(Bitmap bitmap) {
|
|
69
|
+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
70
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
|
|
71
|
+
byte[] byteArray = byteArrayOutputStream.toByteArray();
|
|
72
|
+
|
|
73
|
+
return Base64.encodeToString(byteArray, Base64.DEFAULT);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static Matrix matrixFromFloatArray(float[] floats) {
|
|
77
|
+
Matrix matrix = new Matrix();
|
|
78
|
+
matrix.setValues(floats);
|
|
79
|
+
return matrix;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static float[] floatArrayFromJson(JSONArray jsonArray) throws JSONException {
|
|
83
|
+
float[] result = new float[jsonArray.length()];
|
|
84
|
+
for (int i = 0; i < jsonArray.length(); i++)
|
|
85
|
+
result[i] = (float) jsonArray.getDouble(i);
|
|
86
|
+
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static int[] intArrayFromJson(JSONArray jsonArray) throws JSONException {
|
|
91
|
+
int[] result = new int[jsonArray.length()];
|
|
92
|
+
for (int i = 0; i < jsonArray.length(); i++)
|
|
93
|
+
result[i] = jsonArray.getInt(i);
|
|
94
|
+
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static String[] barcodeTypeArrayFromJson(JSONArray jsonArray) throws JSONException {
|
|
99
|
+
String[] result = new String[jsonArray.length()];
|
|
100
|
+
for (int i = 0; i < jsonArray.length(); i++)
|
|
101
|
+
result[i] = BarcodeType.valueOf(jsonArray.getInt(i));
|
|
102
|
+
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static FaceMetaData[] faceMetaDataArrayFromJson(JSONArray jsonArray) throws JSONException {
|
|
107
|
+
FaceMetaData[] result = new FaceMetaData[jsonArray.length()];
|
|
108
|
+
for (int i = 0; i < jsonArray.length(); i++)
|
|
109
|
+
result[i] = faceMetaDataFromJson(jsonArray.getJSONObject(i));
|
|
110
|
+
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static FaceMetaData faceMetaDataFromJson(JSONObject object) throws JSONException {
|
|
115
|
+
FaceMetaData result = new FaceMetaData();
|
|
116
|
+
result.ID = object.getInt("ID");
|
|
117
|
+
result.rollAngle = object.getInt("rollAngle");
|
|
118
|
+
result.bounds = boundsFromJson(object.getJSONObject("bounds"));
|
|
119
|
+
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static Bounds boundsFromJson(JSONObject object) throws JSONException {
|
|
124
|
+
Bounds result = new Bounds();
|
|
125
|
+
result.height = object.getInt("height");
|
|
126
|
+
result.width = object.getInt("width");
|
|
127
|
+
result.x = object.getInt("x");
|
|
128
|
+
result.y = object.getInt("y");
|
|
129
|
+
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static List<String> stringListFromJson(JSONArray jsonArray) {
|
|
134
|
+
List<String> result = new ArrayList<>();
|
|
135
|
+
for (int i = 0; i < jsonArray.length(); i++)
|
|
136
|
+
result.add(jsonArray.optString(i));
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static String[] stringArrayFromJson(JSONArray jsonArray) {
|
|
141
|
+
String[] result = new String[jsonArray.length()];
|
|
142
|
+
for (int i = 0; i < jsonArray.length(); i++)
|
|
143
|
+
result[i] = jsonArray.optString(i);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
}
|