import java.io.File
public class RootChecker {
private fun isRooted(): Boolean {
return findBinary("su")
}
private fun findBinary(binaryName: String): Boolean {
var found = false
if (!found) {
val places = arrayOf(
"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/",
"/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"
)
for (where in places) {
if (File(where + binaryName).exists()) {
found = true
break
}
}
}
return found
}
public fun check(context: Context) {
val activity = context as Activity?
if (RootChecker().isRooted() && activity != null) {
AlertDialog.Builder(context)
.setTitle("Found rooted system")
.setMessage("Please install on an android which isn't rooted")
.setPositiveButton("Okay.") { _, _ ->
finishAffinity(activity)
}
.setOnDismissListener {
finishAffinity(activity)
}
.setIcon(android.R.drawable.ic_dialog_alert)
.show()
}
}
}