Skip to content

Commit cd315a3

Browse files
author
Jenkins
committed
7.1.578
1 parent ae6b476 commit cd315a3

24 files changed

Lines changed: 3260 additions & 2188 deletions

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
# Regula Face API (React Native version)
1+
# Deprecated
2+
This plugin is deprecated and `7.1` is the last release. We kindly recommend migrating to our new plugin `@regulaforensics/face-sdk`:
3+
* [github](https://github.com/regulaforensics/npm-face-sdk)
4+
* [npmjs](https://www.npmjs.com/package/@regulaforensics/face-sdk)
5+
6+
## Regula Face API (React Native version)
27
Face API is a framework that is used for face matching, recognition and liveness detection.
38

4-
# Contents
9+
## Contents
510
* [How to build the demo application](#how-to-build-the-demo-application)
611
* [How to use offine match](#how-to-use-offine-match)
712
* [Documentation](#documentation)
@@ -27,7 +32,7 @@ $ pod install
2732
4. iOS:
2833
* Run `npx react-native run-ios` inside `example` folder - this is just one way to run the app. You can also run it directly from within Xcode.
2934

30-
## How to use offine match
35+
## How to use offline match
3136
1. Place a license that supports offline match at `android/app/src/main/assets/regula.license` and `ios/license/regula.license`.
3237
2. Change android and iOS bundle id if required by your license with the following commands(replace `ANDROID_ID` and `IOS_ID` with actual ids):
3338
```bash

RNFaceApi.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ Pod::Spec.new do |s|
1515
s.source = { http: "file:#{source}" }
1616
s.ios.deployment_target = '13.0'
1717
s.source_files = 'ios/**/*.{h,m}'
18-
s.dependency 'FaceSDK', '6.4.2494'
18+
s.dependency 'FaceSDK', '7.1.2736'
1919
s.dependency 'React'
2020
end

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies {
4141
//noinspection GradleDynamicVersion
4242
implementation 'com.facebook.react:react-native:+'
4343
//noinspection GradleDependency
44-
implementation('com.regula.face:api:6.4.3632'){
44+
implementation('com.regula.face:api:7.1.3784'){
4545
transitive = true
4646
}
4747
}

android/src/main/java/com/reactlibrary/Config.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fun setFaceCaptureConfig(builder: FaceCaptureConfiguration.Builder, config: JSON
2121
"torchButtonEnabled" -> builder.setTorchButtonEnabled(v as Boolean)
2222
"vibrateOnSteps" -> builder.setVibrateOnStep(v as Boolean)
2323
"detectOcclusion" -> builder.setDetectOcclusion(v as Boolean)
24+
"showFaceAnimation" -> builder.setShowFaceAnimation(v as Boolean)
2425
"cameraPositionAndroid" -> builder.setCameraId(v.toInt())
2526
"screenOrientation" -> builder.setScreenOrientation(*screenOrientationArrayFromJSON(v as JSONArray))
2627
"timeout" -> builder.setTimeout(v.toFloat())
@@ -35,6 +36,7 @@ fun getFaceCaptureConfig(input: FaceCaptureConfiguration) = mapOf(
3536
"torchButtonEnabled" to input.isTorchButtonEnabled,
3637
"vibrateOnSteps" to input.isVibrateOnSteps,
3738
"detectOcclusion" to input.isDetectOcclusion,
39+
"showFaceAnimation" to input.isShowFaceAnimation,
3840
"cameraPositionAndroid" to input.cameraId,
3941
"screenOrientation" to generateScreenOrientationArray(input.screenOrientation),
4042
"timeout" to input.timeout,

android/src/main/java/com/reactlibrary/JSONConstructor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ fun faceCaptureImageFromJSON(input: JSONObject?) = input?.let {
312312
Image(
313313
it.getInt("imageType").toImageType(),
314314
it.getStringOrNull("tag"),
315-
it.getString("image").toBitmap(),
315+
it.getString("image").toBitmap()!!,
316316
)
317317
}
318318

@@ -376,7 +376,7 @@ fun generateLivenessNotification(it: LivenessNotification) = mapOf(
376376

377377
fun matchFacesImageFromJSON(input: JSONObject?) = input?.let {
378378
val result = MatchFacesImage(
379-
it.getString("image").toBitmap(),
379+
it.getString("image").toBitmap()!!,
380380
it.getInt("imageType").toImageType(),
381381
it.optBoolean("detectAll", false)
382382
)
@@ -635,7 +635,7 @@ fun generateDetectFacesConfig(input: DetectFacesConfiguration?) = input?.let {
635635
fun detectFacesRequestFromJSON(input: JSONObject) = input.let {
636636
val image = it.getString("image").toBitmap()!!
637637
it.getStringOrNull("scenario")?.let { scenario ->
638-
DetectFacesRequest::class.constructor(Bitmap::class, String::class).instantiate(image, scenario)
638+
DetectFacesRequest::class.java.getDeclaredConstructor(Bitmap::class.java, String::class.java).instantiate(image, scenario)
639639
} ?: DetectFacesRequest(
640640
image,
641641
detectFacesConfigFromJSON(it.getJSONObjectOrNull("configuration")),
@@ -674,7 +674,7 @@ fun detectFacesAttributeResultFromJSON(it: JSONObject) = DetectFacesAttributeRes
674674
)
675675

676676
fun generateDetectFacesAttributeResult(it: DetectFacesAttributeResult) = mapOf(
677-
"attribute" to it.attribute.value,
677+
"attribute" to it.attribute?.value,
678678
"value" to it.value,
679679
"confidence" to it.confidence,
680680
"range" to generateImageQualityRange(it.range)

android/src/main/java/com/reactlibrary/RNFaceApiModule.kt

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import com.regula.facesdk.callback.DetectFacesCompletion
1515
import com.regula.facesdk.callback.FaceCaptureCallback
1616
import com.regula.facesdk.callback.FaceCaptureNotificationCallback
1717
import com.regula.facesdk.callback.FaceInitializationCompletion
18-
import com.regula.facesdk.callback.ICameraSwitchCallback
1918
import com.regula.facesdk.callback.LivenessCallback
2019
import com.regula.facesdk.callback.LivenessNotificationCallback
2120
import com.regula.facesdk.callback.MatchFaceCallback
22-
import com.regula.facesdk.callback.NotificationCallback
2321
import com.regula.facesdk.callback.PersonDBCallback
22+
import com.regula.facesdk.configuration.InitializationBleDeviceConfiguration
23+
import com.regula.facesdk.enums.InitErrorCode
24+
import com.regula.facesdk.exception.InitException
2425
import com.regula.facesdk.listener.NetworkInterceptorListener
2526
import com.regula.facesdk.model.LivenessNotification
2627
import com.regula.facesdk.model.results.matchfaces.MatchFacesSimilarityThresholdSplit
@@ -149,9 +150,16 @@ fun setCustomization(config: JSONObject) = setCustomization(Instance().customiza
149150

150151
fun isInitialized(callback: Callback) = callback(Instance().isInitialized)
151152

152-
fun initialize(callback: Callback, config: JSONObject?) = config?.let {
153-
Instance().initialize(context, initConfigFromJSON(it), initCompletion(callback))
154-
} ?: Instance().initialize(context, initCompletion(callback))
153+
@SuppressLint("MissingPermission")
154+
fun initialize(callback: Callback, config: JSONObject?) =
155+
if (config == null)
156+
Instance().initialize(context, initCompletion(callback))
157+
else if (config.getBooleanOrNull("useBleDevice") != true)
158+
Instance().initialize(context, initConfigFromJSON(config), initCompletion(callback))
159+
else
160+
getBleWrapper()?.let {
161+
Instance().initialize(context, InitializationBleDeviceConfiguration(it), initCompletion(callback))
162+
} ?: callback(generateInitCompletion(false, InitException(InitErrorCode.LICENSE_IS_NULL)))
155163

156164
fun deinitialize() = Instance().deinitialize()
157165

@@ -187,11 +195,13 @@ fun stopLiveness() = Instance().stopLivenessProcessing(context)
187195

188196
fun matchFaces(callback: Callback, request: JSONObject, config: JSONObject?) = config?.let {
189197
Instance().matchFaces(
198+
context,
190199
matchFacesRequestFromJSON(request),
191200
matchFacesConfigFromJSON(it),
192201
matchFacesCompletion(callback)
193202
)
194203
} ?: Instance().matchFaces(
204+
context,
195205
matchFacesRequestFromJSON(request),
196206
matchFacesCompletion(callback)
197207
)
@@ -203,55 +213,58 @@ fun splitComparedFaces(callback: Callback, faces: JSONArray, similarity: Double)
203213
}
204214

205215
fun detectFaces(callback: Callback, request: JSONObject) = Instance().detectFaces(
216+
context,
206217
detectFacesRequestFromJSON(request),
207218
detectFacesCompletion(callback)
208219
)
209220

221+
val db get() = Instance().personDatabase(context)!!
222+
210223
fun createPerson(
211224
callback: Callback,
212225
name: String,
213226
groupIds: JSONArray?,
214227
metadata: JSONObject?
215-
) = Instance().personDatabase().createPerson(
228+
) = db.createPerson(
216229
name,
217230
metadata,
218231
groupIds.toArray(),
219232
databaseItemCompletion(callback, ::generatePerson)
220233
)
221234

222235
fun updatePerson(callback: Callback, personJson: JSONObject) =
223-
Instance().personDatabase().getPerson(idFromJSON(personJson), object : PersonDBCallback<Person?> {
224-
override fun onSuccess(person: Person?) = Instance().personDatabase().updatePerson(
236+
db.getPerson(idFromJSON(personJson), object : PersonDBCallback<Person?> {
237+
override fun onSuccess(person: Person?) = db.updatePerson(
225238
updatePersonFromJSON(person!!, personJson),
226239
databaseItemCompletion(callback, null)
227240
)
228241

229242
override fun onFailure(error: String) = callback(generatePersonDBResponse(null, error))
230243
})
231244

232-
fun deletePerson(callback: Callback, personId: String) = Instance().personDatabase().deletePerson(
245+
fun deletePerson(callback: Callback, personId: String) = db.deletePerson(
233246
personId,
234247
databaseItemCompletion(callback, null)
235248
)
236249

237-
fun getPerson(callback: Callback, personId: String) = Instance().personDatabase().getPerson(
250+
fun getPerson(callback: Callback, personId: String) = db.getPerson(
238251
personId,
239252
databaseItemCompletion(callback, ::generatePerson)
240253
)
241254

242-
fun addPersonImage(callback: Callback, personId: String, image: JSONObject) = Instance().personDatabase().addPersonImage(
255+
fun addPersonImage(callback: Callback, personId: String, image: JSONObject) = db.addPersonImage(
243256
personId,
244257
imageUploadFromJSON(image),
245258
databaseItemCompletion(callback, ::generatePersonImage)
246259
)
247260

248-
fun deletePersonImage(callback: Callback, personId: String, imageId: String) = Instance().personDatabase().deletePersonImage(
261+
fun deletePersonImage(callback: Callback, personId: String, imageId: String) = db.deletePersonImage(
249262
personId,
250263
imageId,
251264
databaseItemCompletion(callback, null)
252265
)
253266

254-
fun getPersonImage(callback: Callback, personId: String, imageId: String) = Instance().personDatabase().getPersonImageById(
267+
fun getPersonImage(callback: Callback, personId: String, imageId: String) = db.getPersonImageById(
255268
personId,
256269
imageId,
257270
object : PersonDBCallback<ByteArray> {
@@ -260,7 +273,7 @@ fun getPersonImage(callback: Callback, personId: String, imageId: String) = Inst
260273
}
261274
)
262275

263-
fun getPersonImages(callback: Callback, personId: String) = Instance().personDatabase().getPersonImages(
276+
fun getPersonImages(callback: Callback, personId: String) = db.getPersonImages(
264277
personId,
265278
databasePageCompletion(callback, ::generatePersonImage)
266279
)
@@ -270,22 +283,22 @@ fun getPersonImagesForPage(
270283
personId: String,
271284
page: Int,
272285
size: Int
273-
) = Instance().personDatabase().getPersonImagesForPage(
286+
) = db.getPersonImagesForPage(
274287
personId,
275288
page,
276289
size,
277290
databasePageCompletion(callback, ::generatePersonImage)
278291
)
279292

280-
fun createGroup(callback: Callback, name: String, metadata: JSONObject?) = Instance().personDatabase().createGroup(
293+
fun createGroup(callback: Callback, name: String, metadata: JSONObject?) = db.createGroup(
281294
name,
282295
metadata,
283296
databaseItemCompletion(callback, ::generatePersonGroup)
284297
)
285298

286299
fun updateGroup(callback: Callback, groupJson: JSONObject) =
287-
Instance().personDatabase().getGroup(idFromJSON(groupJson), object : PersonDBCallback<PersonGroup?> {
288-
override fun onSuccess(group: PersonGroup?) = Instance().personDatabase().updateGroup(
300+
db.getGroup(idFromJSON(groupJson), object : PersonDBCallback<PersonGroup?> {
301+
override fun onSuccess(group: PersonGroup?) = db.updateGroup(
289302
updatePersonGroupFromJSON(group!!, groupJson),
290303
databaseItemCompletion(callback, null)
291304
)
@@ -294,32 +307,31 @@ fun updateGroup(callback: Callback, groupJson: JSONObject) =
294307
})
295308

296309
fun editPersonsInGroup(callback: Callback, groupId: String, editGroupPersonsRequest: JSONObject) =
297-
Instance().personDatabase().editPersonsInGroup(
310+
db.editPersonsInGroup(
298311
groupId,
299312
editGroupPersonsRequestFromJSON(editGroupPersonsRequest),
300313
databaseItemCompletion(callback, null)
301314
)
302315

303-
fun deleteGroup(callback: Callback, groupId: String) = Instance().personDatabase().deleteGroup(
316+
fun deleteGroup(callback: Callback, groupId: String) = db.deleteGroup(
304317
groupId,
305318
databaseItemCompletion(callback, null)
306319
)
307320

308-
fun getGroup(callback: Callback, groupId: String) = Instance().personDatabase().getGroup(
321+
fun getGroup(callback: Callback, groupId: String) = db.getGroup(
309322
groupId,
310323
databaseItemCompletion(callback, ::generatePersonGroup)
311324
)
312325

313-
fun getGroups(callback: Callback) =
314-
Instance().personDatabase().getGroups(databasePageCompletion(callback, ::generatePersonGroup))
326+
fun getGroups(callback: Callback) = db.getGroups(databasePageCompletion(callback, ::generatePersonGroup))
315327

316-
fun getGroupsForPage(callback: Callback, page: Int, size: Int) = Instance().personDatabase().getGroupsForPage(
328+
fun getGroupsForPage(callback: Callback, page: Int, size: Int) = db.getGroupsForPage(
317329
page,
318330
size,
319331
databasePageCompletion(callback, ::generatePersonGroup)
320332
)
321333

322-
fun getPersonGroups(callback: Callback, personId: String) = Instance().personDatabase().getPersonGroups(
334+
fun getPersonGroups(callback: Callback, personId: String) = db.getPersonGroups(
323335
personId,
324336
databasePageCompletion(callback, ::generatePersonGroup)
325337
)
@@ -329,14 +341,14 @@ fun getPersonGroupsForPage(
329341
personId: String,
330342
page: Int,
331343
size: Int
332-
) = Instance().personDatabase().getPersonGroupsForPage(
344+
) = db.getPersonGroupsForPage(
333345
personId,
334346
page,
335347
size,
336348
databasePageCompletion(callback, ::generatePersonGroup)
337349
)
338350

339-
fun getPersonsInGroup(callback: Callback, groupId: String) = Instance().personDatabase().getPersonsInGroup(
351+
fun getPersonsInGroup(callback: Callback, groupId: String) = db.getPersonsInGroup(
340352
groupId,
341353
databasePageCompletion(callback, ::generatePerson)
342354
)
@@ -346,14 +358,14 @@ fun getPersonsInGroupForPage(
346358
groupId: String,
347359
page: Int,
348360
size: Int
349-
) = Instance().personDatabase().getPersonsInGroupForPage(
361+
) = db.getPersonsInGroupForPage(
350362
groupId,
351363
page,
352364
size,
353365
databasePageCompletion(callback, ::generatePerson)
354366
)
355367

356-
fun searchPerson(callback: Callback, searchPersonRequest: JSONObject) = Instance().personDatabase().searchPerson(
368+
fun searchPerson(callback: Callback, searchPersonRequest: JSONObject) = db.searchPerson(
357369
searchPersonRequestFromJSON(searchPersonRequest),
358370
object : PersonDBCallback<List<SearchPerson>> {
359371
override fun onSuccess(data: List<SearchPerson>?) = callback(generatePersonDBResponse(data.toJsonNullable(::generateSearchPerson)!!, null))
@@ -418,4 +430,4 @@ fun <T : DbBaseItem?> databasePageCompletion(callback: Callback, toJson: (T?) ->
418430

419431
// Weak references
420432
var localizationCallbacks: LocalizationCallbacks? = null
421-
var networkInterceptorListener: NetworkInterceptorListener? = null
433+
var networkInterceptorListener: NetworkInterceptorListener? = null

android/src/main/java/com/reactlibrary/Utils.kt

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@file:Suppress("UNCHECKED_CAST")
1+
@file:Suppress("UNCHECKED_CAST", "EnumValuesSoftDeprecate", "UseKtx")
22

33
package com.reactlibrary
44

@@ -10,6 +10,8 @@ import android.graphics.Typeface
1010
import android.graphics.drawable.BitmapDrawable
1111
import android.graphics.drawable.Drawable
1212
import android.util.Base64
13+
import android.util.Log
14+
import com.regula.common.ble.BLEWrapper
1315
import com.regula.facesdk.configuration.Customization
1416
import com.regula.facesdk.enums.CustomizationColor
1517
import com.regula.facesdk.enums.CustomizationFont
@@ -248,7 +250,12 @@ fun <T : Any> T.setPrivateProperty(clazz: Class<T>, varName: String, data: Any?)
248250
//}
249251

250252
internal object Convert {
251-
fun String?.toByteArray() = this?.let { Base64.decode(it, Base64.NO_WRAP) }
253+
fun String?.toByteArray(): ByteArray? {
254+
var str = this ?: return null
255+
if (str.startsWith("data")) str = str.substring(str.indexOf(",") + 1)
256+
return Base64.decode(str, Base64.NO_WRAP)
257+
}
258+
252259
fun ByteArray?.toBase64() = this?.let { Base64.encodeToString(it, Base64.NO_WRAP) }
253260

254261
fun String?.toBitmap() = this?.let {
@@ -279,4 +286,32 @@ internal object Convert {
279286
val height = (bitmap.height * density).toInt()
280287
BitmapDrawable(context.resources, Bitmap.createScaledBitmap(bitmap, width, height, false))
281288
}
282-
}
289+
}
290+
291+
fun getBleWrapper(): BLEWrapper? {
292+
listOf(
293+
"io.flutter.plugins.regula.documentreader.flutter_document_reader_api",
294+
"cordova.plugin.documentreader",
295+
"com.regula.documentreader"
296+
).forEach { packageName ->
297+
getVarFromClass<BLEWrapper>(
298+
packageName,
299+
"BluetoothUtilKt",
300+
"bluetooth"
301+
)?.let { return it }
302+
}
303+
Log.e("REGULA", "Failed to get BLEWrapper from DocumentReader plugin")
304+
return null
305+
}
306+
307+
fun <T> getVarFromClass(packageName: String, className: String, varName: String): T? {
308+
try {
309+
val targetClass = Class.forName("$packageName.$className")
310+
val field = targetClass.getDeclaredField(varName)
311+
field.isAccessible = true
312+
val result = field.get(null) as BLEWrapper?
313+
return result as T?
314+
} catch (_: Exception) {
315+
return null
316+
}
317+
}

0 commit comments

Comments
 (0)