Problem

루팅된 디바이스에서 앱이 실행 될 경우 정적 분석이나 코드 변조, 임의로 코드의 흐름을 조작하는 등 보안 문제를 일으킬 수 있다. 이를 방지하고자 루팅된 디바이스 실행 여부를 확인하는 코드가 필요하다.

Solution

private fun isRootedDevice(): Boolean {
    val buildTags = Build.TAGS
    if (buildTags != null && buildTags.contains("test-keys")) {
        return true
    }

    if (File("/system/app/Superuser.apk").exists()) {
        return true
    }

    try {
        Runtime.getRuntime().exec("su")
        return true
    } catch (e: Exception) {
    }

    return false
}
if(isRootedDevice()) {
    Notifications.alert(R.string.error_rooted_device)
    finishAffinity()

}else {
...
}

만약 애뮬레이터의 실행까지 차단하고자 한다면 buildTagsdev-keys까지 포함하여 확인해야 한다.