@@ -12,9 +12,9 @@ import com.facebook.react.bridge.ReadableMap
1212import com.facebook.react.modules.core.DeviceEventManagerModule
1313
1414class FreeraspReactNativeModule (val reactContext : ReactApplicationContext ) :
15- ReactContextBaseJavaModule (reactContext), ThreatListener .ThreatDetected {
15+ ReactContextBaseJavaModule (reactContext), ThreatListener .ThreatDetected , FreeraspDeviceStateListener . DeviceStateListener {
1616
17- private val listener = ThreatListener (this )
17+ private val listener = ThreatListener (this , FreeraspDeviceStateListener )
1818
1919 override fun getName (): String {
2020 return NAME
@@ -27,8 +27,8 @@ class FreeraspReactNativeModule(val reactContext: ReactApplicationContext) :
2727
2828 try {
2929 val config = parseTalsecConfig(options)
30+ FreeraspDeviceStateListener .listener = this
3031 listener.registerListener(reactContext)
31- ThreatListener ( this ,deviceStateListener).registerListener(reactContext)
3232 Talsec .start(reactContext, config)
3333 sendOngoingPluginResult(" started" , null )
3434
@@ -78,15 +78,8 @@ class FreeraspReactNativeModule(val reactContext: ReactApplicationContext) :
7878 sendOngoingPluginResult(" device binding" , null )
7979 }
8080
81- // This is optional. Use only if you are interested in device state information like device lock and HW backed keystore state
82- private val deviceStateListener = object : ThreatListener .DeviceState {
83- override fun onUnlockedDeviceDetected () {
84- sendOngoingPluginResult(" unlockedDevice" , null )
85- }
86-
87- override fun onHardwareBackedKeystoreNotAvailableDetected () {
88- sendOngoingPluginResult(" hardwareBackedKeystoreNotAvailable" , null )
89- }
81+ override fun deviceStateChangeDetected (threatType : String ) {
82+ sendOngoingPluginResult(threatType, null )
9083 }
9184
9285 private fun sendOngoingPluginResult (eventName : String , params : WritableMap ? ) {
@@ -95,7 +88,6 @@ class FreeraspReactNativeModule(val reactContext: ReactApplicationContext) :
9588 .emit(eventName, params)
9689 }
9790
98-
9991 private fun parseTalsecConfig (config : ReadableMap ): TalsecConfig {
10092 val androidConfig = config.getMap(" androidConfig" )!!
10193 val packageName = androidConfig.getString(" packageName" )!!
0 commit comments