Skip to content

Commit

Permalink
Set StrictMode for the sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
ninovanhooff committed Sep 20, 2021
1 parent 3677438 commit fb45542
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/src/main/java/com/q42/q42stats/sample/SampleApplication.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.q42.q42stats.sample

import android.app.Application
import android.os.Build
import android.os.StrictMode
import android.os.StrictMode.ThreadPolicy
import android.os.StrictMode.VmPolicy
import androidx.annotation.RequiresApi
import com.q42.q42stats.library.Q42Stats
import com.q42.q42stats.library.Q42StatsConfig


@Suppress("unused") // SampleApplication is referenced from manifest only
class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setStrictMode()
}
Q42Stats(
Q42StatsConfig(
firebaseProjectId = "theProject",
Expand All @@ -17,4 +26,28 @@ class SampleApplication : Application() {
)
).runAsync(this.applicationContext)
}

@RequiresApi(Build.VERSION_CODES.O)
private fun setStrictMode() {
StrictMode.setThreadPolicy(
ThreadPolicy.Builder()
.detectAll() // or .detectAll() for all detectable problems
.penaltyLog()
.build()
)
StrictMode.setVmPolicy(
VmPolicy.Builder()
.detectActivityLeaks()
.detectFileUriExposure()
//.detectUntaggedSockets() exclude okhttp bug
.detectContentUriWithoutPermission()
.detectLeakedRegistrationObjects()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
//.detectNonSdkApiUsage() // exclude triggerÅed by AppCompatActivity
.detectCleartextNetwork()
.penaltyLog()
.build()
)
}
}

0 comments on commit fb45542

Please sign in to comment.