From b9bd10d8b155d787e8552d13c44c4cdebb443e51 Mon Sep 17 00:00:00 2001 From: Aitor Viana Date: Tue, 11 Jun 2024 10:09:03 +0100 Subject: [PATCH] Enable strict mode in debug builds (#4635) --- .../app/global/DuckDuckGoApplication.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/com/duckduckgo/app/global/DuckDuckGoApplication.kt b/app/src/main/java/com/duckduckgo/app/global/DuckDuckGoApplication.kt index eaa4abc63da5..5271a4a1584c 100644 --- a/app/src/main/java/com/duckduckgo/app/global/DuckDuckGoApplication.kt +++ b/app/src/main/java/com/duckduckgo/app/global/DuckDuckGoApplication.kt @@ -16,6 +16,8 @@ package com.duckduckgo.app.global +import android.os.StrictMode +import android.os.StrictMode.ThreadPolicy import androidx.lifecycle.ProcessLifecycleOwner import com.duckduckgo.app.browser.BuildConfig import com.duckduckgo.app.di.AppComponent @@ -73,6 +75,7 @@ open class DuckDuckGoApplication : HasDaggerInjector, MultiProcessApplication() configureLogging() Timber.d("onMainProcessCreate $currentProcessName with pid=${android.os.Process.myPid()}") + configureStrictMode() configureDependencyInjection() setupActivityLifecycleCallbacks() configureUncaughtExceptionHandler() @@ -93,6 +96,7 @@ open class DuckDuckGoApplication : HasDaggerInjector, MultiProcessApplication() override fun onSecondaryProcessCreate(shortProcessName: String) { runInSecondaryProcessNamed(VPN_PROCESS_NAME) { configureLogging() + configureStrictMode() Timber.d("Init for secondary process $shortProcessName with pid=${android.os.Process.myPid()}") configureDependencyInjection() configureUncaughtExceptionHandler() @@ -135,6 +139,20 @@ open class DuckDuckGoApplication : HasDaggerInjector, MultiProcessApplication() daggerAppComponent.inject(this) } + private fun configureStrictMode() { + if (BuildConfig.DEBUG) { + StrictMode.setThreadPolicy( + ThreadPolicy.Builder() + .detectDiskReads() + .detectDiskWrites() + .detectNetwork() + .penaltyLog() + .penaltyDropBox() + .build(), + ) + } + } + // vtodo - Work around for https://crbug.com/558377 // AndroidInjection.inject(this) creates a new instance of the DuckDuckGoApplication (because we are in a new process) // This has several disadvantages: