Skip to main content

Getting started

Gradle:

implementation "io.github.dllewellyn.safetorun:safetorun:$latest_version"
implementation "io.github.dllewellyn.safetorun:safeToRunCore:$latest_version"

An example of a configuration, done in App class:

private inline fun canIRun(actionOnFailure: () -> Unit) {
if (safeToRun(buildSafeToRunCheckList {
add {
banAvdEmulatorCheck()
}

add {
blacklistedAppCheck()
}

add {
rootDetectionCheck()
}

add {
banGenymotionEmulatorCheck()
}

add {
banBluestacksEmulatorCheck()
}

add {
safeToRunCombinedCheck(
listOf(
{ bannedHardwareCheck("hardware") },
{ bannedBoardCheck("board") }
) // Only one list to the combined check - fail if either condition is true
)
}

add {
safeToRunCombinedCheck(
listOf { installOriginCheckWithDefaultsCheck() }, // Fail if the install origin check fails
listOf { !BuildConfig.DEBUG } // Unless this is a debug application
)
}

add {
verifySignatureCheck("Abc")
}
}).invoke()) {
actionOnFailure()
}
}

Then use like this

canIRun {
throw RuntimeException("Def")
}