From f02db914bf60b545cecb5776a08e79450101c20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Wed, 2 Jun 2021 12:45:16 +0200 Subject: [PATCH] Fix treessence upgrade (#1361) --- .../github/wulkanowy/utils/CrashLogUtils.kt | 18 +------ .../io/github/wulkanowy/utils/LoggerUtils.kt | 53 ++++++++++++++++--- .../wulkanowy/utils/CrashlyticsUtils.kt | 11 +--- 3 files changed, 50 insertions(+), 32 deletions(-) diff --git a/app/src/hms/java/io/github/wulkanowy/utils/CrashLogUtils.kt b/app/src/hms/java/io/github/wulkanowy/utils/CrashLogUtils.kt index b5fb6ad71..b0c34f413 100644 --- a/app/src/hms/java/io/github/wulkanowy/utils/CrashLogUtils.kt +++ b/app/src/hms/java/io/github/wulkanowy/utils/CrashLogUtils.kt @@ -3,11 +3,6 @@ package io.github.wulkanowy.utils import android.util.Log import com.huawei.agconnect.crash.AGConnectCrash import fr.bipi.tressence.base.FormatterPriorityTree -import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException -import io.github.wulkanowy.sdk.scrapper.exception.FeatureDisabledException -import java.io.InterruptedIOException -import java.net.SocketTimeoutException -import java.net.UnknownHostException class CrashLogTree : FormatterPriorityTree(Log.VERBOSE) { @@ -20,21 +15,10 @@ class CrashLogTree : FormatterPriorityTree(Log.VERBOSE) { } } -class CrashLogExceptionTree : FormatterPriorityTree(Log.ERROR) { +class CrashLogExceptionTree : FormatterPriorityTree(Log.ERROR, ExceptionFilter) { private val connectCrash by lazy { AGConnectCrash.getInstance() } - override fun skipLog(priority: Int, tag: String?, message: String, t: Throwable?): Boolean { - return when (t) { - is FeatureDisabledException, - is FeatureNotAvailableException, - is UnknownHostException, - is SocketTimeoutException, - is InterruptedIOException -> true - else -> super.skipLog(priority, tag, message, t) - } - } - override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { if (skipLog(priority, tag, message, t)) return diff --git a/app/src/main/java/io/github/wulkanowy/utils/LoggerUtils.kt b/app/src/main/java/io/github/wulkanowy/utils/LoggerUtils.kt index 48d46892b..ee18453ff 100644 --- a/app/src/main/java/io/github/wulkanowy/utils/LoggerUtils.kt +++ b/app/src/main/java/io/github/wulkanowy/utils/LoggerUtils.kt @@ -7,7 +7,13 @@ import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager +import fr.bipi.tressence.common.filters.Filter +import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException +import io.github.wulkanowy.sdk.scrapper.exception.FeatureDisabledException import timber.log.Timber +import java.io.InterruptedIOException +import java.net.SocketTimeoutException +import java.net.UnknownHostException import javax.inject.Inject import javax.inject.Singleton @@ -18,7 +24,20 @@ class DebugLogTree : Timber.DebugTree() { } } -private fun Bundle?.checkSavedState() = if (this == null) "(STATE IS NULL)" else "(STATE IS NOT NULL)" +object ExceptionFilter : Filter { + + override fun isLoggable(priority: Int, tag: String?) = true + + override fun skipLog(priority: Int, tag: String?, message: String, t: Throwable?) = + when (t) { + is FeatureDisabledException, + is FeatureNotAvailableException, + is UnknownHostException, + is SocketTimeoutException, + is InterruptedIOException -> true + else -> false + } +} class ActivityLifecycleLogger : Application.ActivityLifecycleCallbacks { @@ -52,9 +71,15 @@ class ActivityLifecycleLogger : Application.ActivityLifecycleCallbacks { } @Singleton -class FragmentLifecycleLogger @Inject constructor() : FragmentManager.FragmentLifecycleCallbacks() { +class FragmentLifecycleLogger @Inject constructor() : + FragmentManager.FragmentLifecycleCallbacks() { - override fun onFragmentViewCreated(fm: FragmentManager, f: Fragment, v: View, savedInstanceState: Bundle?) { + override fun onFragmentViewCreated( + fm: FragmentManager, + f: Fragment, + v: View, + savedInstanceState: Bundle? + ) { Timber.d("${f::class.java.simpleName} VIEW CREATED ${savedInstanceState.checkSavedState()}") } @@ -62,7 +87,11 @@ class FragmentLifecycleLogger @Inject constructor() : FragmentManager.FragmentLi Timber.d("${f::class.java.simpleName} STOPPED") } - override fun onFragmentCreated(fm: FragmentManager, f: Fragment, savedInstanceState: Bundle?) { + override fun onFragmentCreated( + fm: FragmentManager, + f: Fragment, + savedInstanceState: Bundle? + ) { Timber.d("${f::class.java.simpleName} CREATED ${savedInstanceState.checkSavedState()}") } @@ -78,7 +107,11 @@ class FragmentLifecycleLogger @Inject constructor() : FragmentManager.FragmentLi Timber.d("${f::class.java.simpleName} DESTROYED") } - override fun onFragmentSaveInstanceState(fm: FragmentManager, f: Fragment, outState: Bundle) { + override fun onFragmentSaveInstanceState( + fm: FragmentManager, + f: Fragment, + outState: Bundle + ) { Timber.d("${f::class.java.simpleName} SAVED INSTANCE STATE") } @@ -90,7 +123,11 @@ class FragmentLifecycleLogger @Inject constructor() : FragmentManager.FragmentLi Timber.d("${f::class.java.simpleName} VIEW DESTROYED") } - override fun onFragmentActivityCreated(fm: FragmentManager, f: Fragment, savedInstanceState: Bundle?) { + override fun onFragmentActivityCreated( + fm: FragmentManager, + f: Fragment, + savedInstanceState: Bundle? + ) { Timber.d("${f::class.java.simpleName} ACTIVITY CREATED ${savedInstanceState.checkSavedState()}") } @@ -102,3 +139,7 @@ class FragmentLifecycleLogger @Inject constructor() : FragmentManager.FragmentLi Timber.d("${f::class.java.simpleName} DETACHED") } } + +private fun Bundle?.checkSavedState() = + if (this == null) "(STATE IS NULL)" else "(STATE IS NOT NULL)" + diff --git a/app/src/play/java/io/github/wulkanowy/utils/CrashlyticsUtils.kt b/app/src/play/java/io/github/wulkanowy/utils/CrashlyticsUtils.kt index b26f4f6ba..f8b805740 100644 --- a/app/src/play/java/io/github/wulkanowy/utils/CrashlyticsUtils.kt +++ b/app/src/play/java/io/github/wulkanowy/utils/CrashlyticsUtils.kt @@ -4,6 +4,7 @@ import android.util.Log import com.google.firebase.crashlytics.FirebaseCrashlytics import fr.bipi.tressence.base.FormatterPriorityTree import fr.bipi.tressence.common.StackTraceRecorder +import fr.bipi.tressence.common.filters.Filter import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException import io.github.wulkanowy.sdk.scrapper.exception.FeatureDisabledException import java.io.InterruptedIOException @@ -21,18 +22,10 @@ class CrashLogTree : FormatterPriorityTree(Log.VERBOSE) { } } -class CrashLogExceptionTree : FormatterPriorityTree(Log.ERROR) { +class CrashLogExceptionTree : FormatterPriorityTree(Log.ERROR, ExceptionFilter) { private val crashlytics by lazy { FirebaseCrashlytics.getInstance() } - override fun skipLog(priority: Int, tag: String?, message: String, t: Throwable?): Boolean { - if (t is FeatureDisabledException || t is FeatureNotAvailableException || t is UnknownHostException || t is SocketTimeoutException || t is InterruptedIOException) { - return true - } - - return super.skipLog(priority, tag, message, t) - } - override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { if (skipLog(priority, tag, message, t)) return