From cf143489e1aa026c2a552b0d832e531bfd63dd2a Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Fri, 20 Dec 2019 13:27:05 -0800 Subject: [PATCH] For #6464: Replace use of BuildConfig.DEBUG with ReleaseChannel.channel.isDebug. This fixes performance issues where StrictMode would greatly slow down startup in the forPerformanceTest variants. --- .../org/mozilla/fenix/engine/GeckoProvider.kt | 4 ++-- .../org/mozilla/fenix/engine/GeckoProvider.kt | 4 ++-- .../java/org/mozilla/fenix/FenixApplication.kt | 2 +- app/src/main/java/org/mozilla/fenix/ext/Log.kt | 18 +++++++++--------- .../test/java/org/mozilla/fenix/ext/LogTest.kt | 7 +++++-- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/src/geckoBeta/java/org/mozilla/fenix/engine/GeckoProvider.kt b/app/src/geckoBeta/java/org/mozilla/fenix/engine/GeckoProvider.kt index 197104aa3..76b91849e 100644 --- a/app/src/geckoBeta/java/org/mozilla/fenix/engine/GeckoProvider.kt +++ b/app/src/geckoBeta/java/org/mozilla/fenix/engine/GeckoProvider.kt @@ -6,7 +6,7 @@ import android.content.Context import android.os.Bundle import mozilla.components.browser.engine.gecko.glean.GeckoAdapter import mozilla.components.lib.crash.handler.CrashHandlerService -import org.mozilla.fenix.BuildConfig +import org.mozilla.fenix.Config import org.mozilla.fenix.utils.Settings import org.mozilla.geckoview.GeckoRuntime import org.mozilla.geckoview.GeckoRuntimeSettings @@ -36,7 +36,7 @@ object GeckoProvider { .crashHandler(CrashHandlerService::class.java) .useContentProcessHint(true) .telemetryDelegate(GeckoAdapter()) - .debugLogging(BuildConfig.DEBUG) + .debugLogging(Config.channel.isDebug) .build() if (!Settings.getInstance(context).shouldUseAutoSize) { diff --git a/app/src/geckoNightly/java/org/mozilla/fenix/engine/GeckoProvider.kt b/app/src/geckoNightly/java/org/mozilla/fenix/engine/GeckoProvider.kt index d653b2b7e..4bd5311ff 100644 --- a/app/src/geckoNightly/java/org/mozilla/fenix/engine/GeckoProvider.kt +++ b/app/src/geckoNightly/java/org/mozilla/fenix/engine/GeckoProvider.kt @@ -6,7 +6,7 @@ import android.content.Context import android.os.Bundle import mozilla.components.browser.engine.gecko.glean.GeckoAdapter import mozilla.components.lib.crash.handler.CrashHandlerService -import org.mozilla.fenix.BuildConfig +import org.mozilla.fenix.Config import org.mozilla.fenix.utils.Settings import org.mozilla.geckoview.GeckoRuntime import org.mozilla.geckoview.GeckoRuntimeSettings @@ -36,7 +36,7 @@ object GeckoProvider { .crashHandler(CrashHandlerService::class.java) .useContentProcessHint(true) .telemetryDelegate(GeckoAdapter()) - .debugLogging(BuildConfig.DEBUG) + .debugLogging(Config.channel.isDebug) .aboutConfigEnabled(true) .build() diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index 5edd19b34..a9efc08a5 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -278,7 +278,7 @@ open class FenixApplication : Application() { } private fun enableStrictMode() { - if (BuildConfig.DEBUG) { + if (Config.channel.isDebug) { StrictMode.setThreadPolicy( StrictMode.ThreadPolicy.Builder() .detectAll() diff --git a/app/src/main/java/org/mozilla/fenix/ext/Log.kt b/app/src/main/java/org/mozilla/fenix/ext/Log.kt index 854246a67..63eca07ac 100644 --- a/app/src/main/java/org/mozilla/fenix/ext/Log.kt +++ b/app/src/main/java/org/mozilla/fenix/ext/Log.kt @@ -5,44 +5,44 @@ package org.mozilla.fenix.ext import android.util.Log -import org.mozilla.fenix.BuildConfig +import org.mozilla.fenix.Config /** - * Will print to `Log.d()` only when [BuildConfig.DEBUG] is enabled. + * Will print to `Log.d()` only for debug release channels. * * Meant to be used for logs that should not be visible in the production app. */ @Suppress("NOTHING_TO_INLINE") inline fun logDebug(tag: String, message: String) { - if (BuildConfig.DEBUG) Log.d(tag, message) + if (Config.channel.isDebug) Log.d(tag, message) } /** - * Will print to `Log.w()` only when [BuildConfig.DEBUG] is enabled. + * Will print to `Log.w()` only for debug release channels. * * Meant to be used for logs that should not be visible in the production app. */ @Suppress("NOTHING_TO_INLINE") inline fun logWarn(tag: String, message: String) { - if (BuildConfig.DEBUG) Log.w(tag, message) + if (Config.channel.isDebug) Log.w(tag, message) } /** - * Will print to `Log.w()` only when [BuildConfig.DEBUG] is enabled. + * Will print to `Log.w()` only for debug release channels. * * Meant to be used for logs that should not be visible in the production app. */ @Suppress("NOTHING_TO_INLINE") inline fun logWarn(tag: String, message: String, err: Throwable) { - if (BuildConfig.DEBUG) Log.w(tag, message, err) + if (Config.channel.isDebug) Log.w(tag, message, err) } /** - * Will print to `Log.e()` only when [BuildConfig.DEBUG] is enabled. + * Will print to `Log.e()` only for debug release channels. * * Meant to be used for logs that should not be visible in the production app. */ @Suppress("NOTHING_TO_INLINE") inline fun logErr(tag: String, message: String, err: Throwable) { - if (BuildConfig.DEBUG) Log.e(tag, message, err) + if (Config.channel.isDebug) Log.e(tag, message, err) } diff --git a/app/src/test/java/org/mozilla/fenix/ext/LogTest.kt b/app/src/test/java/org/mozilla/fenix/ext/LogTest.kt index 7e270cc20..5831829a7 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/LogTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/LogTest.kt @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + package org.mozilla.fenix.ext import org.mozilla.fenix.TestApplication @@ -10,14 +14,13 @@ import io.mockk.mockkStatic import io.mockk.verify import android.util.Log import org.junit.Before -import org.mozilla.fenix.BuildConfig @RunWith(RobolectricTestRunner::class) @Config(application = TestApplication::class) class LogTest { - val numCalls = if (BuildConfig.DEBUG) 1 else 0 + val numCalls = if (org.mozilla.fenix.Config.channel.isDebug) 1 else 0 @Before fun setup() {