|
|
@ -17,6 +17,9 @@
|
|
|
|
package com.google.samples.apps.nowinandroid
|
|
|
|
package com.google.samples.apps.nowinandroid
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Application
|
|
|
|
import android.app.Application
|
|
|
|
|
|
|
|
import android.content.pm.ApplicationInfo
|
|
|
|
|
|
|
|
import android.os.StrictMode
|
|
|
|
|
|
|
|
import android.os.StrictMode.ThreadPolicy.Builder
|
|
|
|
import coil.ImageLoader
|
|
|
|
import coil.ImageLoader
|
|
|
|
import coil.ImageLoaderFactory
|
|
|
|
import coil.ImageLoaderFactory
|
|
|
|
import com.google.samples.apps.nowinandroid.sync.initializers.Sync
|
|
|
|
import com.google.samples.apps.nowinandroid.sync.initializers.Sync
|
|
|
@ -37,10 +40,34 @@ class NiaApplication : Application(), ImageLoaderFactory {
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate() {
|
|
|
|
override fun onCreate() {
|
|
|
|
super.onCreate()
|
|
|
|
super.onCreate()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setStrictModePolicy()
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize Sync; the system responsible for keeping data in the app up to date.
|
|
|
|
// Initialize Sync; the system responsible for keeping data in the app up to date.
|
|
|
|
Sync.initialize(context = this)
|
|
|
|
Sync.initialize(context = this)
|
|
|
|
profileVerifierLogger()
|
|
|
|
profileVerifierLogger()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun newImageLoader(): ImageLoader = imageLoader.get()
|
|
|
|
override fun newImageLoader(): ImageLoader = imageLoader.get()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Return true if the application is debuggable.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private fun isDebuggable(): Boolean {
|
|
|
|
|
|
|
|
return 0 != applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Set a thread policy that detects all potential problems on the main thread, such as network
|
|
|
|
|
|
|
|
* and disk access.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* If a problem is found, the offending call will be logged and the application will be killed.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private fun setStrictModePolicy() {
|
|
|
|
|
|
|
|
if (isDebuggable()) {
|
|
|
|
|
|
|
|
StrictMode.setThreadPolicy(
|
|
|
|
|
|
|
|
Builder().detectAll().penaltyLog().penaltyDeath().build(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|