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:
- Safe to run (Default)
- Safe to run reporting
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")
}
SafeToRun.init(
configure {
// Root beer (detect root)
rootDetection {
tolerateRoot = false
tolerateBusyBox = true
}.error()
// Black list certain apps
blacklistConfiguration {
+"com.abc.def"
+"com.google.earth"
}.error()
verifySignatureConfig("cSP1O3JN/8+Ag14WAOeOEnwAnpY=")
.error()
// OS Blacklist version
osDetectionCheck(
conditionalBuilder {
with(minOsVersion(22))
and(notManufacturer("Abc"))
}
).warn()
debugCheck().warn()
installOriginCheckWithDefaults().error()
}
)
Then use like this
SafeToRun.safeToRun()
Errors or Warns​
The syntax above allows you to configure an 'error' or a 'warn' this simply impacts to type of response that is returned from safe to run. In practice, a response that would return an error message if configure to 'errorIf' will return
data class SafeToRunReportFailure(val failureReason: String, val failureMessage: String) : SafeToRunReport()
If set to warn it will return
data class SafeToRunWarning(val warnReason: String, val warningMessage: String) : SafeToRunReport()
The difference is simply to help your app to distinguish between the two