🤖Android
📝 Prerequisites
freeRASP requires a minimum SDK level of 23. To update the minimum SDK level of the application, follow these steps:
From the root of your project (or module level), go to the
build.gradle.Update
minSdkVersionto at least 23 (Android 6.0) or higher.
buildscript {
ext {
minSdkVersion 23
}
}Add permissions for checks
Some checks require additional permissions in order to work properly. If your app already has these permissions, you don't need to add them again.
Screenshot and Screen Recording Detection
To detect screenshots and screen recordings , add the following permissions to your AndroidManifest.xml file inside the <manifest> root tag:
<uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" />
<uses-permission android:name="android.permission.DETECT_SCREEN_RECORDING" />Screenshot Detection is supported on Android 14 (API level 34) and higher. Screen Recording Detection is supported on Android 15 (API level 35) and higher.
Location Spoofing Detection
To detect location spoofing, add the following permissions to your AndroidManifest.xml file inside the <manifest> root tag:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />Unsecure WiFi Detection
To detect unsecure WiFi, add the following permissions to your AndroidManifest.xml file inside the <manifest> root tag:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />📦 Add the dependency
Set Talsec's Artifact Registry in your project's settings.gradle (or build.gradle). You should comment out the relevant section in settings.gradle, if you want to use build.gradle, as settings.gradle is preferred:
Config via settings.gradle:
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url "https://europe-west3-maven.pkg.dev/talsec-artifact-repository/freerasp" }
}repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
maven { url = uri("https://europe-west3-maven.pkg.dev/talsec-artifact-repository/freerasp") }
}Config via build.gradle:
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url "https://europe-west3-maven.pkg.dev/talsec-artifact-repository/freerasp" }
}repositories {
google()
mavenCentral()
maven { url = uri ("https://jitpack.io") }
maven { url = uri ("https://europe-west3-maven.pkg.dev/talsec-artifact-repository/freerasp") }
}Make sure that Talsec's maven dependency is at the last position.
Set dependencies in your :app module's build.gradle:
dependencies {
// freeRASP SDK
implementation 'com.aheaditec.talsec.security:TalsecSecurity-Community:17.0.0'
}⚙️ Setup the Configuration for your App
To ensure freeRASP functions correctly, you need to provide the necessary configuration. All required values must be filled in for the plugin to operate properly. Use the following template to configure the plugin. Detailed descriptions of the configuration options are provided on the API page.
Create an arbitrary subclass of
Application(), override itsonCreate()method, and implementThreatListener.ThreatDetectedinterface. You can, of course, use yourApplicationsubclass if you already have one in your project. If you encounter issues importingThreatListener.ThreatDetected, please use 'Sync Project with Gradle Files' to resolve them.“class TalsecApplication : Application(), ThreatListener.ThreatDetected { override fun onCreate() { super.onCreate() } }Add a new subclass to
AndroidManifest.xml, inside<application>tag:<application android:name=".TalsecApplication" />Set up the Configuration for your app with your values, which are explained in more detail in API.
companion object { private const val expectedPackageName = "com.aheaditec.talsec.demoapp" // don't use Context.getPackageName! private val expectedSigningCertificateHashBase64 = arrayOf( "mVr/qQLO8DKTwqlL+B1qigl9NoBnbiUs8b4c2Ewcz0k=" ) // replace with your release (!) signing certificate hash(es) private const val watcherMail = "[email protected]" // for Security Reports, Talsec Portal, Updates private val supportedAlternativeStores = arrayOf( "com.sec.android.app.samsungapps" // add other stores, such as the Samsung Galaxy Store ) private val = true private val killOnBypass = true }override fun onCreate() { ... val config = TalsecConfig.Builder( expectedPackageName, expectedSigningCertificateHashBase64) .watcherMail(watcherMail) .supportedAlternativeStores(supportedAlternativeStores) .prod(isProd) .killOnBypass(killOnBypass) .build() }
👷 Handle detected threats
You can handle the detected threats using listeners. For example, you can log the event, show a window to the user or kill the application. See the Threat detection to learn more details about the performed checks and their importance for app security.
Implement methods of
ThreatListener.ThreatDetectedinterface:override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun (suspiciousApps: List<SuspiciousAppInfo>) { println("onMalwareDetected") }Optionally, you can use a device state listener to get additional information about the device state, like passcode lock and HW-backed Keystore state:
private val deviceStateListener = object : ThreatListener.DeviceState { override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } override fun () { TODO("Not yet implemented") } }Optionally, you can use the
RaspExecutionStatelistener, to get information about state of check execution:private val raspExecutionListener = object : ThreatListener.RaspExecutionState() { override fun onAllChecksFinished() { println("onAllChecksFinished") } }Modify initialization of
ThreatListener:override fun onCreate() { ... // listens only for threats detected // ThreatListener(this).registerListener(this) // listens for threats detected, and device state // ThreatListener(this, deviceStateListener).registerListener(this) // listens for all threats detected, device state, and execution state ThreatListener(this, deviceStateListener, raspExecutionListener).registerListener(this) }(Optional) You can integrate the screen capture methods to detect threats like screenshots - onScreenshotDetected() or screen recording - onScreenRecordingDetected(). If you do not implement the steps below, these detections will not work, in that case, you can just leave the implementations empty.
To use onScreenshotDetected() you have to be on Android 14+ (API 34+). Also, the application needs the following permission:
<uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" />To use onScreenRecordingDetected() you have to be on Android 15+ (API 35+). Also, the application needs the following permission:
<uses-permission android:name="android.permission.DETECT_SCREEN_RECORDING" />To utilize active protection, you can use Talsec.blockScreenCapture(activity, true). To receive whether the screen capture is blocked, you can use the Talsec.isScreenCaptureBlocked(). For more details about all these screen capture methods, see Screen Capture. Integration of all these methods should be performed at the Application level to best address the Android lifecycle:
class TalsecApplication : Application(), ThreatListener.ThreatDetected { override fun onCreate() { ... registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks { override fun onActivityCreated(activity: Activity, bundle: Bundle?) { Talsec.blockScreenCapture(activity, false) } override fun onActivityStarted(activity: Activity) {} override fun onActivityResumed(activity: Activity) { ScreenProtector.INSTANCE.registerScreenCallbacks(activity) } override fun onActivityPaused(activity: Activity) { ScreenProtector.INSTANCE.unregisterScreenCallbacks(activity) } override fun onActivityStopped(activity: Activity) {} override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {} override fun onActivityDestroyed(activity: Activity) {} }) } }
🛡️ Start freeRASP
override fun onCreate() {
...
Talsec.start(this, config)
}🌁 Enable source code obfuscation
You can make sure that the obfuscation is enabled by checking the value of minifyEnabled property in your module's build.gradle file.
Read more about why this is important in the wiki.
android {
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}☢️ (Optionally) Integrate freeMalwareDetection
freeMalwareDetection is a powerful feature designed to enhance the security of your Android application by quickly and efficiently scanning for malicious or suspicious applications (e.g. Android malware) based on various blacklists and security policies.
It helps to detect apps with suspicious package names, hashes, or potentially dangerous permissions.
Visit the freeMalwareDetection repository to learn more about this feature! For the integration, refer to the integration guide for the Android platform.
🖥️ Check Talsec Portal
Check out Data Visualisation Portal and register using your watcherMail to see your data. If you integrated the SDK successfully, the application will be present after a few hours. The visualisations will be active later due to the bucketing mechanism.
You have to use the same email for the Portal as you used for the watcherMail parameter.
Last updated

