@@ -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,44 @@ class TalsecApplication : Application(), ThreatListener.ThreatDetected {
14397 println (" onObfuscationIssuesDetected" )
14498 }
14599
146- override fun onMalwareDetected (p0 : MutableList <SuspiciousAppInfo >? ) {
100+ override fun onMalwareDetected (suspiciousApps : List <SuspiciousAppInfo >) {
147101 // Set your reaction
148102 println (" onMalwareDetected" )
103+ suspiciousApps.forEach {
104+ println (" Suspicious app: ${it.packageInfo.packageName} , reason: ${it.reason} " )
105+ }
149106 }
150107
151108 override fun onScreenshotDetected () {
109+ // Set your reaction
152110 println (" onScreenshotDetected" )
153111 }
154112
155113 override fun onScreenRecordingDetected () {
114+ // Set your reaction
156115 println (" onScreenRecordingDetected" )
157116 }
158117
159118 override fun onMultiInstanceDetected () {
119+ // Set your reaction
160120 println (" onMultiInstanceDetected" )
161121 }
162122
123+ override fun onUnsecureWifiDetected () {
124+ // Set your reaction
125+ println (" onUnsecureWifiDetected" )
126+ }
127+
128+ override fun onTimeSpoofingDetected () {
129+ // Set your reaction
130+ println (" onTimeSpoofingDetected" )
131+ }
132+
133+ override fun onLocationSpoofingDetected () {
134+ // Set your reaction
135+ println (" onLocationSpoofingDetected" )
136+ }
137+
163138 // This is optional. Use only if you are interested in device state information like device lock and HW backed keystore state
164139 private val deviceStateListener = object : ThreatListener .DeviceState {
165140 override fun onUnlockedDeviceDetected () {
@@ -173,18 +148,28 @@ class TalsecApplication : Application(), ThreatListener.ThreatDetected {
173148 }
174149
175150 override fun onDeveloperModeDetected () {
151+ // Set your reaction
176152 println (" onDeveloperModeDetected" )
177153 }
178154
179155 override fun onADBEnabledDetected () {
156+ // Set your reaction
180157 println (" onADBEnabledDetected" )
181158 }
182159
183160 override fun onSystemVPNDetected () {
161+ // Set your reaction
184162 println (" onSystemVPNDetected" )
185163 }
186164 }
187165
166+ // This is optional. Use only if you are interested in RASP execution state information
167+ private val raspExecutionStateListener = object : ThreatListener .RaspExecutionState () {
168+ override fun onAllChecksFinished () {
169+ println (" onAllChecksFinished" )
170+ }
171+ }
172+
188173 companion object {
189174 private const val expectedPackageName = " com.aheaditec.talsec.demoapp" // Don't use Context.getPackageName!
190175 private val expectedSigningCertificateHashBase64 = arrayOf(
@@ -196,6 +181,6 @@ class TalsecApplication : Application(), ThreatListener.ThreatDetected {
196181 // 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:
197182 " com.sec.android.app.samsungapps" // Samsung Store
198183 )
199- private val isProd = true
184+ private const val isProd = true
200185 }
201186}
0 commit comments