For #13959: comment about duplication in logic in StrictMode.

I had to drop a commit that addressed the issue because it was too hard
to fix.
pull/184/head
Michael Comella 4 years ago committed by Michael Comella
parent e1bd6191c7
commit a92356fe00

@ -11,6 +11,10 @@ import androidx.fragment.app.FragmentManager
/**
* Manages strict mode settings for the application.
*
* Due to the static dependencies in this class, it's getting hard to test: if this class takes any
* many more static dependencies, consider switching it, and other code that uses [StrictMode] like
* [StrictMode.ThreadPolicy].resetPoliciesAfter, to a class with dependency injection.
*/
object StrictModeManager {
@ -19,6 +23,9 @@ object StrictModeManager {
* @param setPenaltyDeath boolean value to decide setting the penaltyDeath as a penalty.
*/
fun enableStrictMode(setPenaltyDeath: Boolean) {
// The expression in this if is duplicated in StrictMode.ThreadPolicy.resetPoliciesAfter
// because the tests break in unexpected ways if the value is shared as a constant in this
// class. It wasn't worth the time to address it.
if (Config.channel.isDebug) {
val threadPolicy = StrictMode.ThreadPolicy.Builder()
.detectAll()

@ -17,6 +17,9 @@ import org.mozilla.fenix.Config
inline fun <R> StrictMode.ThreadPolicy.resetPoliciesAfter(functionBlock: () -> R): R {
// Calling resetAfter takes 1-2ms (unknown device) so we only execute it if StrictMode can
// actually be enabled. https://github.com/mozilla-mobile/fenix/issues/11617
//
// The expression in this if is duplicated in StrictModeManager.enableStrictMode: see that method
// for details.
return if (Config.channel.isDebug) {
resetAfter { functionBlock() }
} else {

Loading…
Cancel
Save