Safe to run
Search
⌃K

Getting started - Resilience

From emulators, to rooted phones from out of date android versions to devices with malware - if your app stores sensitive information, make sure you're not running on an unsafe device
First, add the dependency
implementation "com.safetorun:safetorun:$latest_version"
Then, try add the following configuration to your Application.kt file in startup(), or any other place that gets called on startup
private inline fun canIRun(actionOnFailure: () -> Unit) {
val hasCheckFailed = safeToRun(
{
banAvdEmulatorCheck()
},
{
blacklistedAppCheck()
},
{
rootDetectionCheck()
},
{
banGenymotionEmulatorCheck()
},
{
banBluestacksEmulatorCheck()
},
{
safeToRunCombinedCheck(
listOf(
{ bannedHardwareCheck("hardware") },
{ bannedBoardCheck("board") }
) // Only one list to the combined check - fail if either condition is true
)
},
{
safeToRunCombinedCheck(
listOf { installOriginCheckWithDefaultsCheck() }, // Fail if the install origin check fails
listOf { !BuildConfig.DEBUG } // Unless this is a debug application
)
}
).invoke()
if (hasCheckFailed) {
throw Exception("Cannot start. Safe to run check failed.")
}
}
This code will throw an exception (almost definitely - given the verify signature check) on startup due to the failure of the check and the 'action on failure'