Skip to content

Commit

Permalink
Enable strict mode in debug builds (#4635)
Browse files Browse the repository at this point in the history
  • Loading branch information
aitorvs authored Jun 11, 2024
1 parent 9355a91 commit b9bd10d
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,6 +75,7 @@ open class DuckDuckGoApplication : HasDaggerInjector, MultiProcessApplication()
configureLogging()
Timber.d("onMainProcessCreate $currentProcessName with pid=${android.os.Process.myPid()}")

configureStrictMode()
configureDependencyInjection()
setupActivityLifecycleCallbacks()
configureUncaughtExceptionHandler()
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b9bd10d

Please sign in to comment.