Skip to content

Commit d29cfcf

Browse files
committed
feat(Android): add device state listener
1 parent 9bf9a0e commit d29cfcf

File tree

3 files changed

+22
-28
lines changed

3 files changed

+22
-28
lines changed

README.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -238,29 +238,21 @@ const actions = {
238238
'device binding': () => {
239239
console.log('device binding');
240240
},
241-
// iOS only
242-
'deviceID': () => {
243-
console.log('deviceID');
244-
},
245-
// iOS only
246-
'missingSecureEnclave': () => {
247-
console.log('missingSecureEnclave');
241+
// Android & iOS
242+
'passcode': () => {
243+
console.log('passcode');
248244
},
245+
// Android & iOS
246+
'hardwareBackedKeystoreNotAvailable': () => {
247+
console.log('hardwareBackedKeystoreNotAvailable');
248+
}
249249
// iOS only
250250
'passcodeChange': () => {
251251
console.log('passcodeChange');
252252
},
253253
// iOS only
254-
'passcode': () => {
255-
console.log('passcode');
256-
}
257-
// Android only
258-
'onUnlockedDevice': () => {
259-
console.log('onUnlockedDeviceDetected');
260-
},
261-
// Android only
262-
'onHardwareBackedKeystoreNotAvailable': () => {
263-
console.log('onHardwareBackedKeystoreNotAvailableDetected');
254+
'deviceID': () => {
255+
console.log('deviceID');
264256
}
265257
};
266258

android/src/main/java/com/freeraspreactnative/FreeraspReactNativeModule.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,23 @@ 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+
}
90+
}
91+
8192
private fun sendOngoingPluginResult(eventName: String, params: WritableMap?) {
8293
reactContext
8394
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
8495
.emit(eventName, params)
8596
}
8697

87-
// This is optional. Use only if you are interested in device state information like device lock and HW backed keystore state
88-
private val deviceStateListener = object : ThreatListener.DeviceState {
89-
override fun onUnlockedDeviceDetected() {
90-
sendOngoingPluginResult("onUnlockedDeviceDetected", null)
91-
}
92-
93-
override fun onHardwareBackedKeystoreNotAvailableDetected() {
94-
// Set your reaction
95-
sendOngoingPluginResult("onHardwareBackedKeystoreNotAvailableDetected", null)
96-
}
97-
}
9898

9999
private fun parseTalsecConfig(config: ReadableMap): TalsecConfig {
100100
val androidConfig = config.getMap("androidConfig")!!

src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type NativeEventEmitterActions = {
3030
'missingSecureEnclave'?: () => any;
3131
'passcodeChange'?: () => any;
3232
'passcode'?: () => any;
33+
'unlockedDevice'?: () => any;
34+
'hardwareBackedKeystoreNotAvailable'?: () => any;
3335
'started'?: () => any;
3436
'initializationError'?: (reason: { message: string }) => any;
3537
};

0 commit comments

Comments
 (0)