@@ -2,26 +2,15 @@ package com.aheaditec.talsec.demoapp
22
33import android.app.Activity
44import android.app.Application
5- import android.os.Build
65import android.os.Bundle
7- import android.util.Log
8- import android.view.WindowManager.SCREEN_RECORDING_STATE_VISIBLE
6+ import com.aheaditec.talsec_security.security.api.ScreenProtector
97import com.aheaditec.talsec_security.security.api.SuspiciousAppInfo
108import com.aheaditec.talsec_security.security.api.Talsec
119import com.aheaditec.talsec_security.security.api.TalsecConfig
1210import com.aheaditec.talsec_security.security.api.ThreatListener
13- import java.util.function.Consumer
1411
1512class TalsecApplication : Application (), ThreatListener.ThreatDetected {
1613
17- private var currentActivity: Activity ? = null
18- private var screenCaptureCallback: Activity .ScreenCaptureCallback ? = null
19- private val screenRecordCallback: Consumer <Int > = Consumer <Int > { state ->
20- if (state == SCREEN_RECORDING_STATE_VISIBLE ) {
21- Talsec .onScreenRecordingDetected()
22- }
23- }
24-
2514 override fun onCreate () {
2615 super .onCreate()
2716
@@ -35,68 +24,33 @@ class TalsecApplication : Application(), ThreatListener.ThreatDetected {
3524 .watcherMail(watcherMail)
3625 .supportedAlternativeStores(supportedAlternativeStores)
3726 .prod(isProd)
27+ .killOnBypass(true ) // determines if the app should be killed within the SDK if the callbacks are hooked/modified by an attacker
3828 .build()
3929
40- ThreatListener (this , deviceStateListener).registerListener(this )
30+ ThreatListener (this , deviceStateListener, raspExecutionStateListener ).registerListener(this )
4131 Talsec .start(this , config)
4232
4333 registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
4434 override fun onActivityCreated (activity : Activity , bundle : Bundle ? ) {
45-
46- // Set to 'true' to block screen capture
4735 Talsec .blockScreenCapture(activity, false )
4836 }
4937
50- override fun onActivityStarted (activity : Activity ) {
51- unregisterCallbacks()
52- currentActivity = activity
53- registerCallbacks(activity)
54- }
55-
56- override fun onActivityResumed (activity : Activity ) {}
57- override fun onActivityPaused (activity : Activity ) {}
38+ override fun onActivityStarted (activity : Activity ) {}
5839
59- override fun onActivityStopped (activity : Activity ) {
60- if (activity == currentActivity) {
61- unregisterCallbacks()
62- currentActivity = null
63- }
40+ override fun onActivityResumed (activity : Activity ) {
41+ ScreenProtector .INSTANCE .registerScreenCallbacks(activity)
6442 }
6543
66- override fun onActivitySaveInstanceState (activity : Activity , bundle : Bundle ) {}
67- override fun onActivityDestroyed (activity : Activity ) {}
68- })
69- }
70-
71- private fun registerCallbacks (activity : Activity ) {
72- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
73- screenCaptureCallback = Activity .ScreenCaptureCallback {
74- Talsec .onScreenshotDetected()
44+ override fun onActivityPaused (activity : Activity ) {
45+ ScreenProtector .INSTANCE .unregisterScreenCallbacks(activity)
7546 }
76- activity.registerScreenCaptureCallback(
77- baseContext.mainExecutor, screenCaptureCallback!!
78- )
79- }
8047
81- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
82- val initialState = activity.windowManager.addScreenRecordingCallback(
83- mainExecutor, screenRecordCallback
84- )
85- screenRecordCallback.accept(initialState)
86- }
87- }
48+ override fun onActivityStopped (activity : Activity ) {}
8849
89- private fun unregisterCallbacks () {
90- currentActivity?.let { activity ->
91- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE && screenCaptureCallback != null ) {
92- activity.unregisterScreenCaptureCallback(screenCaptureCallback!! )
93- screenCaptureCallback = null
94- }
50+ override fun onActivitySaveInstanceState (activity : Activity , bundle : Bundle ) {}
9551
96- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
97- activity.windowManager.removeScreenRecordingCallback(screenRecordCallback)
98- }
99- }
52+ override fun onActivityDestroyed (activity : Activity ) {}
53+ })
10054 }
10155
10256 override fun onRootDetected () {
@@ -143,23 +97,41 @@ class TalsecApplication : Application(), ThreatListener.ThreatDetected {
14397 println (" onObfuscationIssuesDetected" )
14498 }
14599
146- override fun onMalwareDetected (p0 : MutableList <SuspiciousAppInfo >? ) {
100+ override fun onMalwareDetected (p0 : MutableList <SuspiciousAppInfo >) {
147101 // Set your reaction
148102 println (" onMalwareDetected" )
149103 }
150104
151105 override fun onScreenshotDetected () {
106+ // Set your reaction
152107 println (" onScreenshotDetected" )
153108 }
154109
155110 override fun onScreenRecordingDetected () {
111+ // Set your reaction
156112 println (" onScreenRecordingDetected" )
157113 }
158114
159115 override fun onMultiInstanceDetected () {
116+ // Set your reaction
160117 println (" onMultiInstanceDetected" )
161118 }
162119
120+ override fun onUnsecureWifiDetected () {
121+ // Set your reaction
122+ println (" onUnsecureWifiDetected" )
123+ }
124+
125+ override fun onTimeSpoofingDetected () {
126+ // Set your reaction
127+ println (" onTimeSpoofingDetected" )
128+ }
129+
130+ override fun onLocationSpoofingDetected () {
131+ // Set your reaction
132+ println (" onLocationSpoofingDetected" )
133+ }
134+
163135 // This is optional. Use only if you are interested in device state information like device lock and HW backed keystore state
164136 private val deviceStateListener = object : ThreatListener .DeviceState {
165137 override fun onUnlockedDeviceDetected () {
@@ -173,18 +145,28 @@ class TalsecApplication : Application(), ThreatListener.ThreatDetected {
173145 }
174146
175147 override fun onDeveloperModeDetected () {
148+ // Set your reaction
176149 println (" onDeveloperModeDetected" )
177150 }
178151
179152 override fun onADBEnabledDetected () {
153+ // Set your reaction
180154 println (" onADBEnabledDetected" )
181155 }
182156
183157 override fun onSystemVPNDetected () {
158+ // Set your reaction
184159 println (" onSystemVPNDetected" )
185160 }
186161 }
187162
163+ // This is optional. Use only if you are interested in RASP execution state information
164+ private val raspExecutionStateListener = object : ThreatListener .RaspExecutionState () {
165+ override fun onAllChecksFinished () {
166+ println (" onAllChecksFinished" )
167+ }
168+ }
169+
188170 companion object {
189171 private const val expectedPackageName = " com.aheaditec.talsec.demoapp" // Don't use Context.getPackageName!
190172 private val expectedSigningCertificateHashBase64 = arrayOf(
@@ -196,6 +178,6 @@ class TalsecApplication : Application(), ThreatListener.ThreatDetected {
196178 // Google Play Store and Huawei AppGallery are supported out of the box, you can pass empty array or null or add other stores like the Samsung's one:
197179 " com.sec.android.app.samsungapps" // Samsung Store
198180 )
199- private val isProd = true
181+ private const val isProd = true
200182 }
201183}
0 commit comments