Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fingerprint/connect/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ dependencies {
implementation(project(":fingerprint:infra:scanner"))

testImplementation(project(":fingerprint:infra:scannermock"))
// Uncomment the line below to use the mock scanner implementation
// implementation(project(":fingerprint:infra:scannermock"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.simprints.fingerprint.connect

import android.bluetooth.BluetoothAdapter
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothAdapter
import com.simprints.fingerprint.infra.scanner.component.bluetooth.android.AndroidBluetoothAdapter
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ScannerConnectModule {

/*
* This is the simulated implementation of the BluetoothAdapter
* uncomment this and the import of the scanner mock module in the build.gradle.kts
*/
/*
@Provides
@Singleton
fun provideComponentBluetoothAdapter(@ApplicationContext ctx: Context): ComponentBluetoothAdapter =
SimulatedBluetoothAdapter(SimulatedScannerManager(
simulationMode = SimulationMode.V2,
isAdapterNull = false,
isAdapterEnabled = true,
isDeviceBonded = true,
deviceName = "Simulated Scanner",
outgoingStreamObservers = setOf(),
context = ctx,
))
*/

/*
* This is the real implementation of the BluetoothAdapter
*/
@Provides
@Singleton
fun provideComponentBluetoothAdapter(): ComponentBluetoothAdapter =
AndroidBluetoothAdapter(BluetoothAdapter.getDefaultAdapter())
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.simprints.fingerprint.infra.scanner.exceptions.unexpected.UnknownScan
import com.simprints.fingerprint.infra.scanner.tools.SerialNumberConverter
import com.simprints.fingerprint.infra.scanner.wrapper.ScannerFactory
import com.simprints.fingerprint.infra.scanner.wrapper.ScannerWrapper
import com.simprints.fingerprint.scannermock.dummy.DummyBluetoothDevice
import com.simprints.fingerprint.infra.scannermock.dummy.DummyBluetoothDevice
import com.simprints.infra.config.store.models.FingerprintConfiguration
import com.simprints.infra.config.store.models.FingerprintConfiguration.BioSdk.SECUGEN_SIM_MATCHER
import com.simprints.infra.config.sync.ConfigManager
Expand Down
3 changes: 0 additions & 3 deletions fingerprint/infra/scanner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ dependencies {
// RxJava
api(libs.rxJava2.core)
implementation(libs.rxJava2.kotlin)

// If mock/dummy BT adapter is required test implementation can be switched to regular one
testImplementation(project(":fingerprint:infra:scannermock"))
//implementation(project(":fingerprint:infra:scannermock"))

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.simprints.fingerprint.infra.scanner

import android.bluetooth.BluetoothAdapter
import android.content.Context
import android.nfc.NfcAdapter
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothAdapter
import com.simprints.fingerprint.infra.scanner.component.bluetooth.android.AndroidBluetoothAdapter
import com.simprints.fingerprint.infra.scanner.nfc.ComponentNfcAdapter
import com.simprints.fingerprint.infra.scanner.nfc.android.AndroidNfcAdapter
import dagger.Binds
Expand All @@ -13,7 +10,6 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module(
includes = [
Expand All @@ -35,18 +31,4 @@ object FingerprintDependenciesModule {
@Provides
fun provideNfcAdapter(@ApplicationContext context: Context): ComponentNfcAdapter =
AndroidNfcAdapter(NfcAdapter.getDefaultAdapter(context))

/**
* To provide alternative implementation for BT adapter replace
* returned instance with any of the mock implementations:
* - DummyBluetoothAdapter()
* - AndroidRecordBluetoothAdapter()
* - SimulatedBluetoothAdapter(SimulatedScannerManager(...))
*
* Also change the dependency declaration in build.gradle.kts
*/
@Provides
@Singleton
fun provideComponentBluetoothAdapter(): ComponentBluetoothAdapter =
AndroidBluetoothAdapter(BluetoothAdapter.getDefaultAdapter())
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.bluetooth.BluetoothAdapter
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothAdapter
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothDevice

internal class AndroidBluetoothAdapter(private val adapter: BluetoothAdapter?) : ComponentBluetoothAdapter {
class AndroidBluetoothAdapter(private val adapter: BluetoothAdapter?) : ComponentBluetoothAdapter {

override fun isNull(): Boolean = adapter == null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.simprints.fingerprint.infra.scanner.exceptions.safe.MultiplePossibleS
import com.simprints.fingerprint.infra.scanner.exceptions.safe.ScannerNotPairedException
import com.simprints.fingerprint.infra.scanner.tools.ScannerGenerationDeterminer
import com.simprints.fingerprint.infra.scanner.tools.SerialNumberConverter
import com.simprints.fingerprint.scannermock.dummy.DummyBluetoothDevice
import com.simprints.fingerprint.infra.scannermock.dummy.DummyBluetoothDevice
import com.simprints.infra.config.store.ConfigRepository
import com.simprints.infra.config.store.models.FingerprintConfiguration
import com.simprints.infra.recent.user.activity.RecentUserActivityManager
Expand Down
60 changes: 47 additions & 13 deletions fingerprint/infra/scannermock/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
# Fingerprint Scanner Mock

This package contains alternatives for `android.bluetooth.BluetoothAdapter` and associated classes that are designed for
use with the Bluetooth Component Abstractions for mocking, debugging, and testing. The options are as follows:

- [Simulated Bluetooth Adapter](./src/main/java/com/simprints/fingerprint/scannermock/simulated/README.md)
\- This is for an elaborate mock of the Vero fingerprint scanner, that simulates responses and interaction faithful to how the real scanner would operate.
For use in integration testing or for manual testing/debugging code easily or where we want the scanner to always respond in a certain way.
- [Dummy Bluetooth Adapter](./src/main/java/com/simprints/fingerprint/scannermock/dummy/README.md)
\- This is a very simple skeleton that can be used in tests where communication with the scanner does not occur,
but we just want something simple to pass as the `ComponentBluetoothAdapter` to allow code to compile.
- [Android Record Bluetooth Adapter](./src/main/java/com/simprints/fingerprint/scannermock/record/README.md)
\- This uses the actual `android.bluetooth.BluetoothAdapter` but with ability to record the received byte streams into a file for debugging purposes.
# Scanner Mock Module README

The Scanner Mock Module provides alternative Bluetooth adapters for replacing real Vero2 or Vero1 scanners in testing environments. This module includes adapters to simulate fingerprint capturing scenarios, record Bluetooth data for debugging, or serve as simple placeholders in basic tests. This README provides guidance on setting up and using each of these mock adapters in your testing environment.

---

## 1. Replacing the Real Android Bluetooth Adapter

To replace the real `AndroidBluetoothAdapter` with one of the mock adapters, select the appropriate adapter for your test case:
- Substitute the real `AndroidBluetoothAdapter` with `SimulatedBluetoothAdapter` in your DI setup. [Example](../../connect/src/main/java/com/simprints/fingerprint/connect/ScannerConnectModule.kt).
### A. **SimulatedBluetoothAdapter**

Use the `SimulatedBluetoothAdapter` to fully simulate the fingerprint capturing scenario in NEC or SimMatcher flows. This adapter is designed to emulate the complete scanning and capturing process, providing success and error responses similar to those from real scanners.

#### Setup
- Configure the test data in `SimulatedUn20ResponseHelper` to match your test case needs. This helper currently contains all necessary data for a successful fingerprint collection flow, but you can adjust it for specific scenarios or errors.

#### Reference
More details on using the `SimulatedBluetoothAdapter` can be found in the [README](../scannermock/src/main/java/com/simprints/fingerprint/infra/scannermock/simulated/README.md).

### B. **AndroidRecordBluetoothAdapter**

The `AndroidRecordBluetoothAdapter` mimics the real Android Bluetooth components with the added functionality of recording incoming data bytes from the scanner to a file. This is particularly useful for debugging purposes, allowing you to analyze the exact data transmitted during the fingerprint scanning process.
More details on using the `AndroidRecordBluetoothAdapter` can be found in the [README](../scannermock/src/main/java/com/simprints/fingerprint/infra/scannermock/record/README.md).
### C. **DummyBluetoothAdapter**

The `DummyBluetoothAdapter` serves as a simple placeholder adapter, useful in tests that require a Bluetooth component but do not involve actual data transmission or device communication.

- This adapter is beneficial when:
- You need a `ComponentBluetoothAdapter` instance that is enabled.
- You need access to the MAC address of the `ComponentBluetoothDevice`.

> **Note**: Attempts to connect or communicate with the `DummyBluetoothAdapter` will throw an `UnsupportedOperationException`.

---

## Summary

Each mock adapter provides specific functionality suited to different test requirements:

| Adapter | Purpose |
|----------------------------|-------------------------------------------------------|
| **SimulatedBluetoothAdapter** | Full simulation of the fingerprint capture process |
| **AndroidRecordBluetoothAdapter** | Real Bluetooth functionality with data recording |
| **DummyBluetoothAdapter** | Basic placeholder with minimal Bluetooth properties|

Choose the adapter that best fits your test scenario to effectively mock the scanner behavior and ensure accurate and efficient testing.
7 changes: 2 additions & 5 deletions fingerprint/infra/scannermock/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest />
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.dummy
package com.simprints.fingerprint.infra.scannermock.dummy

import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothAdapter
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothDevice
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.dummy
package com.simprints.fingerprint.infra.scannermock.dummy

import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothDevice
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothSocket
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.record
package com.simprints.fingerprint.infra.scannermock.record

import android.bluetooth.BluetoothAdapter
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothAdapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.record
package com.simprints.fingerprint.infra.scannermock.record

import android.bluetooth.BluetoothDevice
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothDevice
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.record
package com.simprints.fingerprint.infra.scannermock.record

import android.bluetooth.BluetoothSocket
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothSocket
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.simprints.fingerprint.scannermock.simulated

import com.simprints.fingerprint.scannermock.simulated.common.SimulatedFinger
import com.simprints.fingerprint.scannermock.simulated.common.SimulatedScanner
import com.simprints.fingerprint.scannermock.simulated.common.SimulatedScannerState
import com.simprints.fingerprint.scannermock.simulated.common.SimulationSpeedBehaviour
import com.simprints.fingerprint.scannermock.simulated.component.SimulatedBluetoothDevice
import com.simprints.fingerprint.scannermock.simulated.tools.OutputStreamInterceptor
import com.simprints.fingerprint.scannermock.simulated.v1.SimulatedScannerStateV1
import com.simprints.fingerprint.scannermock.simulated.v1.SimulatedScannerV1
import com.simprints.fingerprint.scannermock.simulated.v2.SimulatedScannerStateV2
import com.simprints.fingerprint.scannermock.simulated.v2.SimulatedScannerV2
package com.simprints.fingerprint.infra.scannermock.simulated

import android.content.Context
import com.simprints.fingerprint.infra.scannermock.simulated.common.SimulatedFinger
import com.simprints.fingerprint.infra.scannermock.simulated.common.SimulatedScanner
import com.simprints.fingerprint.infra.scannermock.simulated.common.SimulatedScannerState
import com.simprints.fingerprint.infra.scannermock.simulated.common.SimulationSpeedBehaviour
import com.simprints.fingerprint.infra.scannermock.simulated.component.SimulatedBluetoothDevice
import com.simprints.fingerprint.infra.scannermock.simulated.tools.OutputStreamInterceptor
import com.simprints.fingerprint.infra.scannermock.simulated.v1.SimulatedScannerStateV1
import com.simprints.fingerprint.infra.scannermock.simulated.v1.SimulatedScannerV1
import com.simprints.fingerprint.infra.scannermock.simulated.v2.SimulatedScannerStateV2
import com.simprints.fingerprint.infra.scannermock.simulated.v2.SimulatedScannerV2
import io.reactivex.Observer
import io.reactivex.observers.DisposableObserver
import java.io.PipedInputStream
Expand All @@ -26,7 +27,8 @@ class SimulatedScannerManager(
var isAdapterEnabled: Boolean = true,
var isDeviceBonded: Boolean = true,
var deviceName: String = "",
var outgoingStreamObservers: Set<Observer<ByteArray>> = setOf()) {
var outgoingStreamObservers: Set<Observer<ByteArray>> = setOf(),
var context: Context?,) {

private var simulatedScanner: SimulatedScanner? = null

Expand Down Expand Up @@ -97,6 +99,6 @@ class SimulatedScannerManager(
}

companion object {
const val DEFAULT_MAC_ADDRESS: String = "F0:AC:D7:CE:E3:B5"
const val DEFAULT_MAC_ADDRESS: String = "F0:AC:D7:C0:03:B5"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.simprints.fingerprint.infra.scannermock.simulated

enum class SimulationMode {
V1, V2
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.simulated.common
package com.simprints.fingerprint.infra.scannermock.simulated.common

enum class SimulatedFinger {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.simprints.fingerprint.scannermock.simulated.common
package com.simprints.fingerprint.infra.scannermock.simulated.common

import com.simprints.fingerprint.scannermock.simulated.SimulatedScannerManager
import com.simprints.fingerprint.scannermock.simulated.common.SimulationSpeedBehaviour.INSTANT
import com.simprints.fingerprint.scannermock.simulated.common.SimulationSpeedBehaviour.REALISTIC
import com.simprints.fingerprint.infra.scannermock.simulated.SimulatedScannerManager
import com.simprints.fingerprint.infra.scannermock.simulated.common.SimulationSpeedBehaviour.INSTANT
import com.simprints.fingerprint.infra.scannermock.simulated.common.SimulationSpeedBehaviour.REALISTIC
import java.io.OutputStream

abstract class SimulatedScanner(val scannerManager: SimulatedScannerManager) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.simprints.fingerprint.scannermock.simulated.common
package com.simprints.fingerprint.infra.scannermock.simulated.common

abstract class SimulatedScannerState(val eventQueue: MutableList<SimulatedScanner.() -> Unit> = mutableListOf())
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.simulated.common
package com.simprints.fingerprint.infra.scannermock.simulated.common

enum class SimulationSpeedBehaviour {
INSTANT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.simprints.fingerprint.scannermock.simulated.component
package com.simprints.fingerprint.infra.scannermock.simulated.component

import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothAdapter
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothDevice
import com.simprints.fingerprint.scannermock.simulated.SimulatedScannerManager
import com.simprints.fingerprint.infra.scannermock.simulated.SimulatedScannerManager


class SimulatedBluetoothAdapter(private val simulatedScannerManager: SimulatedScannerManager) : ComponentBluetoothAdapter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.simprints.fingerprint.scannermock.simulated.component
package com.simprints.fingerprint.infra.scannermock.simulated.component

import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothDevice
import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothSocket
import com.simprints.fingerprint.scannermock.simulated.SimulatedScannerManager
import com.simprints.fingerprint.infra.scannermock.simulated.SimulatedScannerManager
import java.util.UUID


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.simprints.fingerprint.scannermock.simulated.component
package com.simprints.fingerprint.infra.scannermock.simulated.component

import com.simprints.fingerprint.infra.scanner.component.bluetooth.ComponentBluetoothSocket
import com.simprints.fingerprint.scannermock.simulated.SimulatedScannerManager
import com.simprints.fingerprint.infra.scannermock.simulated.SimulatedScannerManager
import java.io.InputStream
import java.io.OutputStream

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.simulated.tools
package com.simprints.fingerprint.infra.scannermock.simulated.tools

/** @throws IndexOutOfBoundsException if odd number of hex characters */
fun hexStringToByteArray(string: String): ByteArray {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.simulated.tools
package com.simprints.fingerprint.infra.scannermock.simulated.tools

import io.reactivex.Observer
import java.io.OutputStream
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.simulated.v1
package com.simprints.fingerprint.infra.scannermock.simulated.v1

import com.simprints.fingerprint.infra.scanner.v1.Message
import com.simprints.fingerprint.infra.scanner.v1.enums.MESSAGE_TYPE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.simprints.fingerprint.scannermock.simulated.v1
package com.simprints.fingerprint.infra.scannermock.simulated.v1

import com.simprints.fingerprint.infra.scanner.v1.Message
import java.io.PipedInputStream
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.simprints.fingerprint.scannermock.simulated.v1
package com.simprints.fingerprint.infra.scannermock.simulated.v1

import com.simprints.fingerprint.scannermock.simulated.common.SimulatedFinger
import com.simprints.fingerprint.infra.scannermock.simulated.common.SimulatedFinger


enum class SimulatedFingerV1(val imageQualityResponse: String = "fa fa fa fa 0e 00 8b 00 63 00 f5 f5 f5 f5 ", // Quality score 99
Expand Down
Loading