Skip to content

Commit 30abe89

Browse files
committed
fix: detection when app launched during active recording
1 parent 65e7925 commit 30abe89

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

android/src/main/kotlin/com/aheaditec/freerasp/FreeraspPlugin.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter
1616
/** FreeraspPlugin */
1717
class FreeraspPlugin : FlutterPlugin, ActivityAware, LifecycleEventObserver {
1818
private var streamHandler: StreamHandler = StreamHandler()
19-
private var methodCallHandler: MethodCallHandler = MethodCallHandler()
2019
private var screenProtector: ScreenProtector? =
2120
if (Build.VERSION.SDK_INT >= 34) ScreenProtector() else null
21+
private var methodCallHandler: MethodCallHandler = MethodCallHandler(screenProtector)
2222

2323
private var context: Context? = null
2424
private var lifecycle: Lifecycle? = null
2525

2626
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
2727
val messenger = flutterPluginBinding.binaryMessenger
2828
context = flutterPluginBinding.applicationContext
29-
screenProtector?.enable()
3029
methodCallHandler.createMethodChannel(messenger, flutterPluginBinding.applicationContext)
3130
streamHandler.createEventChannel(messenger)
3231
}

android/src/main/kotlin/com/aheaditec/freerasp/ScreenProtector.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ internal class ScreenProtector : DefaultLifecycleObserver {
3636
internal fun enable() {
3737
if (isEnabled) return
3838
isEnabled = true
39+
activity?.let { register(it) }
3940
}
4041

4142
override fun onStart(owner: LifecycleOwner) {

android/src/main/kotlin/com/aheaditec/freerasp/handlers/MethodCallHandler.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import android.os.Looper
88
import androidx.lifecycle.Lifecycle
99
import androidx.lifecycle.LifecycleEventObserver
1010
import androidx.lifecycle.LifecycleOwner
11-
import com.aheaditec.freerasp.runResultCatching
11+
import com.aheaditec.freerasp.ScreenProtector
1212
import com.aheaditec.freerasp.Utils
1313
import com.aheaditec.freerasp.generated.TalsecPigeonApi
14+
import com.aheaditec.freerasp.runResultCatching
1415
import com.aheaditec.freerasp.toPigeon
1516
import com.aheaditec.talsec_security.security.api.SuspiciousAppInfo
1617
import com.aheaditec.talsec_security.security.api.Talsec
@@ -23,7 +24,8 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler
2324
/**
2425
* A method handler that creates and manages an [MethodChannel] for freeRASP methods.
2526
*/
26-
internal class MethodCallHandler : MethodCallHandler, LifecycleEventObserver {
27+
internal class MethodCallHandler(private val screenProtector: ScreenProtector?) : MethodCallHandler,
28+
LifecycleEventObserver {
2729
private var context: Context? = null
2830
private var methodChannel: MethodChannel? = null
2931
private var pigeonApi: TalsecPigeonApi? = null
@@ -137,6 +139,7 @@ internal class MethodCallHandler : MethodCallHandler, LifecycleEventObserver {
137139
val talsecConfig = Utils.toTalsecConfigThrowing(config)
138140
context?.let {
139141
TalsecThreatHandler.start(it, talsecConfig)
142+
screenProtector?.enable()
140143
} ?: throw IllegalStateException("Unable to run Talsec - context is null")
141144
result.success(null)
142145
}

0 commit comments

Comments
 (0)