Skip to content

Commit

Permalink
updated crashlytics; added some non-fatal exceptions logging
Browse files Browse the repository at this point in the history
  • Loading branch information
truefedex committed Sep 3, 2020
1 parent f4f69d7 commit 5294c84
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.crashlytics'

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
Expand All @@ -16,8 +16,8 @@ android {
applicationId "com.phlox.tvwebbrowser"
minSdkVersion 21
targetSdkVersion 29
versionCode 40
versionName "1.5.6"
versionCode 41
versionName "1.5.7"

javaCompileOptions {
annotationProcessorOptions {
Expand Down Expand Up @@ -90,5 +90,5 @@ dependencies {
implementation 'de.halfbit:pinned-section-listview:1.0.0'

crashlyticsImplementation 'com.google.firebase:firebase-core:17.5.0'
crashlyticsImplementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
crashlyticsImplementation 'com.google.firebase:firebase-crashlytics-ktx:17.2.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.phlox.tvwebbrowser.activity.main.view.WebViewEx
import com.phlox.tvwebbrowser.model.*
import com.phlox.tvwebbrowser.service.downloads.DownloadService
import com.phlox.tvwebbrowser.singleton.AppDatabase
import com.phlox.tvwebbrowser.utils.LogUtils
import com.phlox.tvwebbrowser.utils.StringUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
Expand Down Expand Up @@ -86,6 +87,7 @@ class MainActivityViewModel: ViewModel() {
}
} catch (e: Exception) {
e.printStackTrace()
LogUtils.recordException(e)
}
}
}
Expand All @@ -106,6 +108,7 @@ class MainActivityViewModel: ViewModel() {
}
} catch (e: Exception) {
e.printStackTrace()
LogUtils.recordException(e)
}
tabsStates
}.await()
Expand All @@ -128,13 +131,15 @@ class MainActivityViewModel: ViewModel() {
}
} catch (e: Exception) {
e.printStackTrace()
LogUtils.recordException(e)
}

try {
val frequentlyUsedUrls = AppDatabase.db.historyDao().frequentlyUsedUrls()
jsInterface.setSuggestions(TVBro.instance, frequentlyUsedUrls)
} catch (e: Exception) {
e.printStackTrace()
LogUtils.recordException(e)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.webkit.WebView
import android.widget.FrameLayout
import android.widget.PopupMenu
import com.phlox.tvwebbrowser.R
import com.phlox.tvwebbrowser.utils.LogUtils

/**
* Created by fedex on 12.08.16.
Expand Down Expand Up @@ -175,10 +176,12 @@ class WebViewEx : WebView {
thumbnail = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
} catch (e: Throwable) {
e.printStackTrace()
LogUtils.recordException(e)
try {
thumbnail = Bitmap.createBitmap(width / 2, height / 2, Bitmap.Config.ARGB_8888)
} catch (e: OutOfMemoryError) {
e.printStackTrace()
LogUtils.recordException(e)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/phlox/tvwebbrowser/model/WebTabState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.webkit.WebChromeClient
import com.phlox.tvwebbrowser.TVBro

import com.phlox.tvwebbrowser.activity.main.view.WebViewEx
import com.phlox.tvwebbrowser.utils.LogUtils
import com.phlox.tvwebbrowser.utils.Utils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -70,6 +71,7 @@ data class WebTabState(var currentOriginalUrl: String? = null, var currentTitle:
}
} catch (e: JSONException) {
e.printStackTrace()
LogUtils.recordException(e)
}

}
Expand All @@ -96,6 +98,7 @@ data class WebTabState(var currentOriginalUrl: String? = null, var currentTitle:
}
} catch (e: JSONException) {
e.printStackTrace()
LogUtils.recordException(e)
}

return store
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/phlox/tvwebbrowser/utils/LogUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.phlox.tvwebbrowser.utils

object LogUtils {
//send exception info to crashlytics in case crashlytics included in current build
fun recordException(e: Throwable) {
try {
val clazz = Class.forName("com.google.firebase.crashlytics.FirebaseCrashlytics")
val method = clazz.getMethod("getInstance")
val crashlytics = method.invoke(null)
val clazz2 = crashlytics::class.java
val method2 = clazz2.getMethod("recordException", Throwable::class.java)
method2.invoke(crashlytics, e)
} catch (ex: ClassNotFoundException) {
//thats ok - not all builds include crashlytics
} catch (ex: Exception) {
ex.printStackTrace()
}
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.31.1'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit 5294c84

Please sign in to comment.