From a92356fe00c4f89f755e8d53231a7cf8ccb11b3d Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Thu, 24 Sep 2020 14:20:41 -0700 Subject: [PATCH] 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. --- app/src/main/java/org/mozilla/fenix/StrictModeManager.kt | 7 +++++++ app/src/main/java/org/mozilla/fenix/ext/StrictMode.kt | 3 +++ 2 files changed, 10 insertions(+) diff --git a/app/src/main/java/org/mozilla/fenix/StrictModeManager.kt b/app/src/main/java/org/mozilla/fenix/StrictModeManager.kt index a64e1598e..25944f7d6 100644 --- a/app/src/main/java/org/mozilla/fenix/StrictModeManager.kt +++ b/app/src/main/java/org/mozilla/fenix/StrictModeManager.kt @@ -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() diff --git a/app/src/main/java/org/mozilla/fenix/ext/StrictMode.kt b/app/src/main/java/org/mozilla/fenix/ext/StrictMode.kt index 634482c31..54985108f 100644 --- a/app/src/main/java/org/mozilla/fenix/ext/StrictMode.kt +++ b/app/src/main/java/org/mozilla/fenix/ext/StrictMode.kt @@ -17,6 +17,9 @@ import org.mozilla.fenix.Config inline fun 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 {