@@ -18,7 +18,7 @@ internal object ScreenProtector {
1818 private const val TAG = " TalsecScreenProtector"
1919 private const val SCREEN_CAPTURE_PERMISSION = " android.permission.DETECT_SCREEN_CAPTURE"
2020 private const val SCREEN_RECORDING_PERMISSION = " android.permission.DETECT_SCREEN_RECORDING"
21-
21+ private var registered = false
2222 private val screenCaptureCallback = ScreenCaptureCallback { Talsec .onScreenshotDetected() }
2323 private val screenRecordCallback: Consumer <Int > = Consumer <Int > { state ->
2424 if (state == SCREEN_RECORDING_STATE_VISIBLE ) {
@@ -34,7 +34,7 @@ internal object ScreenProtector {
3434 * granted for the app in the AndroidManifest.xml
3535 */
3636 internal fun register (activity : Activity ) {
37- if (! FreeraspPlugin .talsecStarted) {
37+ if (! FreeraspPlugin .talsecStarted || registered ) {
3838 return
3939 }
4040
@@ -45,7 +45,7 @@ internal object ScreenProtector {
4545 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
4646 registerScreenRecording(activity)
4747 }
48-
48+ registered = true
4949 }
5050
5151 /* *
@@ -108,7 +108,7 @@ internal object ScreenProtector {
108108 @SuppressLint(" MissingPermission" )
109109 @RequiresApi(Build .VERSION_CODES .UPSIDE_DOWN_CAKE )
110110 internal fun unregister (activity : Activity ) {
111- if (! FreeraspPlugin .talsecStarted) {
111+ if (! FreeraspPlugin .talsecStarted || ! registered ) {
112112 return
113113 }
114114
@@ -119,6 +119,7 @@ internal object ScreenProtector {
119119 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
120120 unregisterScreenRecording(activity)
121121 }
122+ registered = false
122123 }
123124
124125 // Missing permission is suppressed because the decision to use the screen capture API is made
0 commit comments