Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
only enable bugsnag in release-signed builds
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzz committed Jan 4, 2021
1 parent 655c910 commit 01c89b8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/src/main/java/utils/MyApp.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package utils

import android.app.Application
import android.content.pm.PackageManager
import android.os.Environment
import android.preference.PreferenceManager
import constants.Constants
import java.io.File
import android.util.Base64
import android.util.Log
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import com.libopenmw.openmw.BuildConfig
import constants.Constants
import java.io.File
import java.security.MessageDigest

class MyApp : Application() {

Expand All @@ -34,7 +38,7 @@ class MyApp : Application() {

// Enable bugsnag only when API key is provided and we have user consent
// Also don't enable bugsnag in debug builds
if (BugsnagApiKey.API_KEY.isNotEmpty() && !BuildConfig.DEBUG) {
if (isProductionBuild() && BugsnagApiKey.API_KEY.isNotEmpty() && !BuildConfig.DEBUG) {
haveBugsnagApiKey = true

val prefs = PreferenceManager.getDefaultSharedPreferences(this)
Expand All @@ -47,6 +51,14 @@ class MyApp : Application() {
}
}

private fun isProductionBuild(): Boolean {
val sig = applicationContext.packageManager.getPackageInfo(applicationContext.packageName, PackageManager.GET_SIGNATURES).signatures[0]
val digest: MessageDigest = MessageDigest.getInstance("SHA-256")
val hashBytes: ByteArray = digest.digest(sig.toByteArray())
val hash: String = Base64.encodeToString(hashBytes, Base64.NO_WRAP)
return hash == "cOqSYH3ucLraOQ7wyg/v8UKTGHlxP8N8JTN6UXO7rV0="
}

companion object {
var reportCrashes = false
var haveBugsnagApiKey = false
Expand Down

0 comments on commit 01c89b8

Please sign in to comment.