From 521001ea05f6d17d7750c3a9a797c5d149e5bfd2 Mon Sep 17 00:00:00 2001 From: Denys M Date: Sun, 12 May 2019 08:01:41 +0300 Subject: [PATCH] [fenix] Closes https://github.com/mozilla-mobile/fenix/issues/1083. Don't print sensitive data to logs in the production app. (https://github.com/mozilla-mobile/fenix/pull/2437) --- .../main/java/org/mozilla/fenix/ext/Log.kt | 44 +++++++++++++++++++ .../search/awesomebar/AwesomeBarComponent.kt | 4 +- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/org/mozilla/fenix/ext/Log.kt diff --git a/app/src/main/java/org/mozilla/fenix/ext/Log.kt b/app/src/main/java/org/mozilla/fenix/ext/Log.kt new file mode 100644 index 0000000000..e2950a7983 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/ext/Log.kt @@ -0,0 +1,44 @@ +package org.mozilla.fenix.ext + +import android.util.Log +import org.mozilla.fenix.BuildConfig + +/** + * Will print to `Log.d()` only when [BuildConfig.DEBUG] is enabled. + * + * 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) +} + +/** + * Will print to `Log.w()` only when [BuildConfig.DEBUG] is enabled. + * + * 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) +} + +/** + * Will print to `Log.w()` only when [BuildConfig.DEBUG] is enabled. + * + * 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) +} + +/** + * Will print to `Log.e()` only when [BuildConfig.DEBUG] is enabled. + * + * 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) +} diff --git a/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarComponent.kt b/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarComponent.kt index 0bdd46a34a..81099c02fa 100644 --- a/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarComponent.kt +++ b/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarComponent.kt @@ -4,7 +4,6 @@ package org.mozilla.fenix.search.awesomebar 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/. */ -import android.util.Log import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModel @@ -12,6 +11,7 @@ import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProviders import io.reactivex.Observable import mozilla.components.browser.search.SearchEngine +import org.mozilla.fenix.ext.logDebug import org.mozilla.fenix.mvi.Action import org.mozilla.fenix.mvi.ActionBusFactory import org.mozilla.fenix.mvi.Change @@ -77,7 +77,7 @@ class AwesomeBarViewModel(initialState: AwesomeBarState, changesObservable: Obse companion object { val reducer: Reducer = { state, change -> - Log.d("IN_REDUCER", change.toString()) + logDebug("IN_REDUCER", change.toString()) when (change) { is AwesomeBarChange.SearchShortcutEngineSelected -> state.copy(suggestionEngine = change.engine, showShortcutEnginePicker = false)