sdk

Oz Liveness SDK is a complementary part to Oz API. It serves several purposes:

  1. Implements a user-friendly interface for capturing video.

  2. Supports quality criteria for video for better accuracy of liveness and biometry.

  3. Provides convenience methods for calling Oz API.

SDK usage

  1. SDK contains Activity that implements user-friendly interface for capturing videos with selected gestures (smile, nod etc).

  2. SDK facilitates communication with Oz API, including login, file upload, and checks/analysis initiation. It is necessary to set config before using any SDK methods:

OzLivenessSDK.config.licenseResourceId = R.raw.forensics

```

### Capturing selfie-video

Start the activity.

```kotlin
val actions = listOf(OzAction.Smile, OzAction.Scan)
val intent = OzLivenessSDK.createStartIntent(actions)
startActivityForResult(intent, REQUEST_CODE)
```

* `actions` - list of requested action objects

Get Liveness SDK results.

```kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE) {
sdkMediaResult = OzLivenessSDK.getResultFromIntent(data)
sdkErrorString = OzLivenessSDK.getErrorFromIntent(data)
}
}
```

* `sdkMediaResult` - an object with activity results (media files and meta information) that can be passed on
API for analysis.
* `sdkErrorString` - error description (if any).

### Login to API

Before calling Oz API for the first time you need to either login...

```kotlin
val loginListener = object : StatusListener<String> {
override fun onSuccess(token: String) {
/* Save token */
}

override fun onError(errorCode: OzException) {
}
}
OzLivenessSDK.login(USER_NAME, PASSWORD, loginListener)
```

...or set URL and token manually if you have a service (permanent) token.

```kotlin
OzLivenessSDK.config.baseURL = SOME_SERVER_URL
OzLivenessSDK.config.permanentAccessToken = RECEIVED_TOKEN
```

### 3. Calling Oz API with the recorded media-files

Then you use OzMedia object with all the media to upload files and initiate analyses. You can use the object
constructed by the SDK as described above, or create your own, or combine both methods.

```kotlin
private val statusListener = object : StatusListener<List<OzAnalysisResult>> {
override fun onStatusChanged(status: String?) {
/* Your code for showing status message */
}

override fun onSuccess(result: List<OzAnalysisResult>) {
/* Your code to handle analysis result */
}

override fun onError(error: OzException) {
}
}
OzLivenessSDK.uploadMediaAndAnalyze(sdkMediaResult, statusListener)
```

1. "quality" (liveness) analysis will be requested for all video files.
2. "biometry" analysis will be requested for an object with `photo_id_front` tag and videos.
3. "documents" analysis will be requested for objects with tags `photo_id_front` and/or `photo_id_back`.

Analysis take time and are invoked asynchronously. You can check status and results in `UploadAndAnalyzeStatusListener`.

### 4. Local Analysis with the recorded media-files

You can make liveness and biometry analyses without uploading to server.
```kotlin
val biometryResult = OzLivenessSDK.localBiometryAnalyse(VIDEO_1, VIDEO_2)
val livenessResult = OzLivenessSDK.localLivenessAnalyse(VIDEO)
```

## Oz Liveness SDK customization

### 1. Look and feel

You can customize look-and-feel of Oz Liveness interface using OzCustomization class and its subclasses.

```kotlin
OzLivenessSDK.config.customization = OzCustomization(
OzCancelButtonCustomization(R.drawable.ic_arrow),
OzCenterHintCustomization(16f, Typeface.MONOSPACE, Color.CYAN, 1.3f),
OzDialogCustomization(R.style.Custom_Dialog_Theme),
OzFaceFrameCustomization(GeometryType.RECTANGLE, 8f),
OzVersionTextCustomization()
)
```

### 2. Locale

By default, SDK uses device locale for all the messages. You can override it by invoking the following
before SDK starts:

```kotlin
OzLivenessSDK.config.localizationCode = OzLocalizationCode.RU
```

## Working with server API

### 1. Retrofit API-interface

SDK contains `OzForensicsAPI` interface which describes the API communication.
It can be used to create a Retrofit instance.

The interface uses gson-converter and works with classes from [com.ozforensics.liveness.sdk.api.model] package.

Besides, the interface provides a static method to create default Retrofit instance (without logging, interceptors,
or anything else; timeouts are set to 15 seconds), to communicate with the server with given URL.

```kotlin
val service = OzForensicsAPI.create(URL)
```

### 2. OzForensicsService class

SDK contains `OzForensicsService` class, which uses Retrofit instance created by `OzForensicsAPI.create`.
This class wraps network calls from Retrofit interface and uses auth token when available. The token is saved after
successful auth call. Besides, this class automatically adds metadata when necessary (like creating a folder,
uploading media for analysis, etc). This class is async (uses `StatusListener` interface) and thread-safe.

The instance of the class can be obtained using this code.

```kotlin
val service = OzForensicsService(URL, TOKEN)
```

You'll need to perform auth if the specified token is NULL in order to make API calls.

```kotlin
service.auth(EMAIL, PASSWORD, listener)
```

The resulting `AuthToken` with the token will be passed to `onSuccess` of specified `listener`.

## SDK settings

* `OzConfig.baseURL` - server URL used by SDK.
* `OzConfig.permanentAccessToken` - permanent server access token.
* `OzConfig.licenseResourceId` - resource ID for Oz Liveness license.
* `OzConfig.attemptSettings` - amount of attempts to detect actions.
* `OzConfig.allowDebugVisualization` - display additional information for debugging
(after pressing on SDK version text).
* `OzConfig.logging` - logging settings.
* `OzConfig.useMainCamera` - use main camera instead front camera for liveness.

## Get logs from SDK

If your App needs logs from SDK (e.g. Action started, Record finished, and so on) use this:

```kotlin
OzLivenessSDK.logging.journalObserver = object : JournalObserver {
override fun update(event: String) {
/* Handle event string */
}
}
```

## Other SDK methods

```kotlin
OzLivenessSDK.logout()
```

```kotlin
OzLivenessSDK.isLoggedIn()

Packages

com.ozforensics.liveness.sdk.analyzers
Link copied to clipboard
com.ozforensics.liveness.sdk.api
Link copied to clipboard
Classes for communicating with Oz API.
com.ozforensics.liveness.sdk.api.model
Link copied to clipboard
Data structures for communicating with Oz API.
com.ozforensics.liveness.sdk.core
Link copied to clipboard
Core classes of SDK.
Exception classes of SDK.
com.ozforensics.liveness.sdk.core.model
Link copied to clipboard
Data structures of SDK.
Customization of SDK look-and-feel.
com.ozforensics.liveness.sdk.logging
Link copied to clipboard
Classes for logging.
com.ozforensics.liveness.sdk.media
Link copied to clipboard