new: enable StrictMode in debug builds
This commit is contained in:
@@ -1,5 +1,39 @@
|
||||
package bzh.ajaury.chombev
|
||||
|
||||
import android.app.Application
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.os.StrictMode
|
||||
|
||||
class ChomBevApp : Application()
|
||||
class ChomBevApp : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
if (isDebuggable()) {
|
||||
enableStrictMode()
|
||||
}
|
||||
}
|
||||
|
||||
private fun isDebuggable(): Boolean =
|
||||
applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0
|
||||
|
||||
/**
|
||||
* Enables StrictMode for debug builds only. All violations are logged
|
||||
* ([StrictMode.ThreadPolicy.Builder.penaltyLog]) so problems surface in Logcat
|
||||
* without ever crashing the app (no `penaltyDeath`).
|
||||
*/
|
||||
private fun enableStrictMode() {
|
||||
StrictMode.setThreadPolicy(
|
||||
StrictMode.ThreadPolicy
|
||||
.Builder()
|
||||
.detectAll()
|
||||
.penaltyLog()
|
||||
.build(),
|
||||
)
|
||||
StrictMode.setVmPolicy(
|
||||
StrictMode.VmPolicy
|
||||
.Builder()
|
||||
.detectAll()
|
||||
.penaltyLog()
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user