1
0
Fork 0

No issue: Enable Strict Mode in Debug Builds (#4014)

master
Colin Lee 2019-07-12 00:23:28 -05:00 committed by GitHub
parent 7cea2ed048
commit 2feddc9bd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -26,7 +26,6 @@ import java.io.File
class DebugFenixApplication : FenixApplication() {
override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
if (FlipperUtils.shouldEnableFlipper(this)) {
@ -39,6 +38,8 @@ class DebugFenixApplication : FenixApplication() {
start()
}
}
super.onCreate()
}
private var heapDumper: ToggleableHeapDumper? = null

View File

@ -8,6 +8,7 @@ import android.annotation.SuppressLint
import android.app.Application
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.StrictMode
import androidx.appcompat.app.AppCompatDelegate
import io.reactivex.plugins.RxJavaPlugins
import kotlinx.coroutines.Deferred
@ -55,6 +56,7 @@ open class FenixApplication : Application() {
setupLogging(megazordEnabled)
registerRxExceptionHandling()
setupCrashReporting()
enableStrictMode()
if (!isMainProcess()) {
// If this is not the main process then do not continue with the initialization here. Everything that
@ -237,4 +239,25 @@ open class FenixApplication : Application() {
}
}
}
private fun enableStrictMode() {
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build()
)
var builder = StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.detectLeakedRegistrationObjects()
.detectActivityLeaks()
.detectFileUriExposure()
.penaltyLog()
if (SDK_INT >= Build.VERSION_CODES.O) builder = builder.detectContentUriWithoutPermission()
if (SDK_INT >= Build.VERSION_CODES.P) builder = builder.detectNonSdkApiUsage()
StrictMode.setVmPolicy(builder.build())
}
}
}