diff --git a/mobile/build.gradle b/mobile/build.gradle index d4577318..c5d7a76c 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -84,7 +84,7 @@ dependencies { implementation 'com.github.topjohnwu.libsu:core:2.5.1' implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0' implementation 'com.google.android.material:material:1.1.0' - implementation 'com.google.firebase:firebase-analytics:17.3.0' + implementation 'com.google.firebase:firebase-analytics-ktx:17.3.0' implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta04' implementation 'com.google.zxing:core:3.4.0' implementation 'com.jakewharton.timber:timber:4.7.1' diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt index 99f0e229..e7ce96f3 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt @@ -8,7 +8,6 @@ import android.content.res.Configuration import android.net.ConnectivityManager import android.net.wifi.WifiManager import android.os.Build -import android.os.Bundle import android.util.Log import androidx.annotation.Size import androidx.browser.customtabs.CustomTabColorSchemeParams @@ -23,9 +22,11 @@ import be.mygod.vpnhotspot.net.DhcpWorkaround import be.mygod.vpnhotspot.room.AppDatabase import be.mygod.vpnhotspot.util.DeviceStorageApp import be.mygod.vpnhotspot.util.RootSession -import com.google.firebase.FirebaseApp -import com.google.firebase.analytics.FirebaseAnalytics +import com.google.firebase.analytics.ktx.ParametersBuilder +import com.google.firebase.analytics.ktx.analytics import com.google.firebase.crashlytics.FirebaseCrashlytics +import com.google.firebase.ktx.Firebase +import com.google.firebase.ktx.initialize import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import timber.log.Timber @@ -46,15 +47,15 @@ class App : Application() { deviceStorage.moveSharedPreferencesFrom(this, PreferenceManager(this).sharedPreferencesName) deviceStorage.moveDatabaseFrom(this, AppDatabase.DB_NAME) } else deviceStorage = this - FirebaseApp.initializeApp(deviceStorage) + Firebase.initialize(deviceStorage) Timber.plant(object : Timber.DebugTree() { override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { if (t == null) { if (priority != Log.DEBUG || BuildConfig.DEBUG) Log.println(priority, tag, message) - crashlytics.log("${"XXVDIWEF".getOrElse(priority) { 'X' }}/$tag: $message") + FirebaseCrashlytics.getInstance().log("${"XXVDIWEF".getOrElse(priority) { 'X' }}/$tag: $message") } else { if (priority >= Log.WARN || priority == Log.DEBUG) Log.println(priority, tag, message) - if (priority >= Log.INFO) crashlytics.recordException(t) + if (priority >= Log.INFO) FirebaseCrashlytics.getInstance().recordException(t) } } }) @@ -88,14 +89,14 @@ class App : Application() { * This method is used to log "expected" and well-handled errors, i.e. we care less about logs, etc. * logException is inappropriate sometimes because it flushes all logs that could be used to investigate other bugs. */ - fun logEvent(@Size(min = 1L, max = 40L) event: String, extras: Bundle? = null) { - Timber.i(if (extras == null) event else "$event, extras: $extras") - analytics.logEvent(event, extras) + fun logEvent(@Size(min = 1L, max = 40L) event: String, block: ParametersBuilder.() -> Unit = { }) { + val builder = ParametersBuilder() + builder.block() + Timber.i(if (builder.bundle.isEmpty) event else "$event, extras: ${builder.bundle}") + Firebase.analytics.logEvent(event, builder.bundle) } lateinit var deviceStorage: Application - private val analytics by lazy { FirebaseAnalytics.getInstance(app.deviceStorage) } - val crashlytics by lazy { FirebaseCrashlytics.getInstance() } val english by lazy { createConfigurationContext(Configuration(resources.configuration).apply { setLocale(Locale.ENGLISH) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt index c6d4cfc0..f9e4e8d9 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt @@ -14,7 +14,6 @@ import android.provider.Settings import android.view.View import android.widget.Toast import androidx.core.content.getSystemService -import androidx.core.os.bundleOf import androidx.recyclerview.widget.RecyclerView import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.LocalOnlyHotspotService @@ -61,7 +60,7 @@ class LocalOnlyHotspotManager(private val parent: TetheringFragment) : Manager() context.startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) Toast.makeText(context, R.string.tethering_temp_hotspot_location, Toast.LENGTH_LONG).show() } catch (e: ActivityNotFoundException) { - app.logEvent("location_settings", bundleOf("message" to e.message)) + app.logEvent("location_settings") { param("message", e.message.toString()) } SmartSnackbar.make(R.string.tethering_temp_hotspot_location).show() } return diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt index bd949a54..727bc3fc 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt @@ -37,9 +37,12 @@ object ManageBar : Manager() { } catch (e1: RuntimeException) { try { context.startActivity(Intent().setClassName(SETTINGS_PACKAGE, SETTINGS_2)) - app.logEvent(TAG, bundleOf(SETTINGS_1 to e1.message)) + app.logEvent(TAG) { param(SETTINGS_1, e1.message.toString()) } } catch (e2: RuntimeException) { - app.logEvent(TAG, bundleOf(SETTINGS_1 to e1.message, SETTINGS_2 to e2.message)) + app.logEvent(TAG) { + param(SETTINGS_1, e1.message.toString()) + param(SETTINGS_2, e2.message.toString()) + } } } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt index e3bda0c5..124eb952 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt @@ -48,7 +48,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), "package:${mainActivity.packageName}".toUri())) return } catch (e: RuntimeException) { - app.logEvent("manage_write_settings", bundleOf("message" to e.message)) + app.logEvent("manage_write_settings") { param("message", e.message.toString()) } } val started = manager.isStarted try { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/configuration/P2pSupplicantConfiguration.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/configuration/P2pSupplicantConfiguration.kt index d03e8c05..a03e3066 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/configuration/P2pSupplicantConfiguration.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/configuration/P2pSupplicantConfiguration.kt @@ -5,6 +5,7 @@ import android.os.Build import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.RepeaterService import be.mygod.vpnhotspot.util.RootSession +import com.google.firebase.crashlytics.FirebaseCrashlytics import java.io.File /** @@ -108,9 +109,11 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress: } Triple(result, target!!, shell.err.isNotEmpty()) } catch (e: RuntimeException) { - app.crashlytics.setCustomKey(TAG, parser.lines.joinToString("\n")) - app.crashlytics.setCustomKey("$TAG.ownerAddress", ownerAddress.toString()) - app.crashlytics.setCustomKey("$TAG.p2pGroup", group.toString()) + FirebaseCrashlytics.getInstance().apply { + setCustomKey(TAG, parser.lines.joinToString("\n")) + setCustomKey("$TAG.ownerAddress", ownerAddress.toString()) + setCustomKey("$TAG.p2pGroup", group.toString()) + } throw e } }