Skip to content

Instantly share code, notes, and snippets.

@kibotu
Created July 22, 2019 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kibotu/ca82d594560180a11c135cff8b443527 to your computer and use it in GitHub Desktop.
Save kibotu/ca82d594560180a11c135cff8b443527 to your computer and use it in GitHub Desktop.
Strict Mode
/**
* https://developer.android.com/reference/android/os/StrictMode
*/
fun Application.initStrictMode() {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectCustomSlowCalls()
.detectNetwork()
.penaltyDeathOnNetwork()
.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
detectResourceMismatches()
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
detectUnbufferedIo()
}
}
//.detectDiskReads() // realm native libs
//.detectDiskWrites() // realm native libs
.penaltyLog()
// .penaltyDeath()
.build()
)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectActivityLeaks()
.detectFileUriExposure()
.detectLeakedClosableObjects()
.detectLeakedSqlLiteObjects()
.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
detectCleartextNetwork()
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
detectContentUriWithoutPermission()
// detectUntaggedSockets() // exoplayer
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// detectNonSdkApiUsage() // exoplayer
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
detectCredentialProtectedWhileLocked()
detectImplicitDirectBoot()
}
}
.penaltyLog()
// .penaltyDeath()
.build()
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment