File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
app/src/main/kotlin/com/google/samples/apps/nowinandroid Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 1717package com.google.samples.apps.nowinandroid
1818
1919import android.app.Application
20+ import android.content.pm.ApplicationInfo
21+ import android.os.StrictMode
2022import coil.ImageLoader
2123import coil.ImageLoaderFactory
2224import com.google.samples.apps.nowinandroid.sync.initializers.Sync
@@ -37,10 +39,25 @@ class NiaApplication : Application(), ImageLoaderFactory {
3739
3840 override fun onCreate () {
3941 super .onCreate()
42+
43+ // Kill NiA if there are main thread policy violations and log the offending call.
44+ if (isDebuggable()) {
45+ StrictMode .setThreadPolicy(
46+ StrictMode .ThreadPolicy .Builder ().detectAll().penaltyLog().penaltyDeath().build(),
47+ )
48+ }
49+
4050 // Initialize Sync; the system responsible for keeping data in the app up to date.
4151 Sync .initialize(context = this )
4252 profileVerifierLogger()
4353 }
4454
4555 override fun newImageLoader (): ImageLoader = imageLoader.get()
56+
57+ /* *
58+ * Check if the application is debuggable.
59+ */
60+ private fun isDebuggable (): Boolean {
61+ return 0 != applicationInfo.flags and ApplicationInfo .FLAG_DEBUGGABLE
62+ }
4663}
You can’t perform that action at this time.
0 commit comments