mirror of
https://github.com/ev-map/EVMap.git
synced 2026-04-23 07:36:59 -04:00
ACRA: introduce AAOS-friendly crash reporting screen
This commit is contained in:
@@ -247,7 +247,7 @@ dependencies {
|
||||
googleImplementation "com.android.billingclient:billing-ktx:$billing_version"
|
||||
|
||||
// ACRA (crash reporting)
|
||||
def acraVersion = "5.8.4"
|
||||
def acraVersion = "5.11.1"
|
||||
implementation("ch.acra:acra-mail:$acraVersion")
|
||||
implementation("ch.acra:acra-dialog:$acraVersion")
|
||||
implementation("ch.acra:acra-limiter:$acraVersion")
|
||||
|
||||
@@ -45,6 +45,9 @@ class EvMapApplication : Application(), Configuration.Provider {
|
||||
commentPrompt = getString(R.string.crash_report_comment_prompt)
|
||||
resIcon = R.drawable.ic_launcher_foreground
|
||||
resTheme = R.style.AppTheme
|
||||
if (BuildConfig.FLAVOR_automotive == "automotive") {
|
||||
reportDialogClass = androidx.car.app.activity.CarAppActivity::class.java
|
||||
}
|
||||
}
|
||||
|
||||
limiter {
|
||||
|
||||
@@ -34,6 +34,7 @@ import net.vonforst.evmap.location.LocationEngine
|
||||
import net.vonforst.evmap.location.Priority
|
||||
import net.vonforst.evmap.storage.PreferenceDataSource
|
||||
import net.vonforst.evmap.utils.checkFineLocationPermission
|
||||
import org.acra.interaction.DialogInteraction
|
||||
|
||||
|
||||
interface LocationAwareScreen {
|
||||
@@ -122,11 +123,13 @@ class EVMapSession(val cas: CarAppService) : Session(), DefaultLifecycleObserver
|
||||
}
|
||||
|
||||
override fun onCreateScreen(intent: Intent): Screen {
|
||||
handleActionsIntent(intent)
|
||||
|
||||
val mapScreen = MapScreen(carContext, this)
|
||||
val screens = mutableListOf<Screen>(mapScreen)
|
||||
|
||||
handleActionsIntent(intent)?.let {
|
||||
screens.add(it)
|
||||
}
|
||||
if (!prefs.dataSourceSet) {
|
||||
screens.add(
|
||||
ChooseDataSourceScreen(
|
||||
@@ -154,6 +157,9 @@ class EVMapSession(val cas: CarAppService) : Session(), DefaultLifecycleObserver
|
||||
AcceptPrivacyScreen(carContext)
|
||||
)
|
||||
}
|
||||
handleACRAIntent(intent)?.let {
|
||||
screens.add(it)
|
||||
}
|
||||
|
||||
if (screens.size > 1) {
|
||||
val screenManager = carContext.getCarService(ScreenManager::class.java)
|
||||
@@ -165,7 +171,13 @@ class EVMapSession(val cas: CarAppService) : Session(), DefaultLifecycleObserver
|
||||
return screens.last()
|
||||
}
|
||||
|
||||
private fun handleActionsIntent(intent: Intent): Boolean {
|
||||
private fun handleACRAIntent(intent: Intent): Screen? {
|
||||
return if (intent.hasExtra(DialogInteraction.EXTRA_REPORT_CONFIG)) {
|
||||
CrashReportScreen(carContext, intent)
|
||||
} else null
|
||||
}
|
||||
|
||||
private fun handleActionsIntent(intent: Intent): Screen? {
|
||||
intent.data?.let {
|
||||
if (it.host == "find_charger") {
|
||||
val lat = it.getQueryParameter("latitude")?.toDouble()
|
||||
@@ -174,15 +186,14 @@ class EVMapSession(val cas: CarAppService) : Session(), DefaultLifecycleObserver
|
||||
if (lat != null && lon != null) {
|
||||
prefs.placeSearchResultAndroidAuto = LatLng(lat, lon)
|
||||
prefs.placeSearchResultAndroidAutoName = name ?: "%.4f,%.4f".format(lat, lon)
|
||||
return true
|
||||
return null
|
||||
} else if (name != null) {
|
||||
val screenManager = carContext.getCarService(ScreenManager::class.java)
|
||||
screenManager.push(PlaceSearchScreen(carContext, this, name))
|
||||
return true
|
||||
val screen = PlaceSearchScreen(carContext, this, name)
|
||||
return screen
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.vonforst.evmap.auto
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.car.app.CarContext
|
||||
import androidx.car.app.Screen
|
||||
import androidx.car.app.model.Action
|
||||
import androidx.car.app.model.CarColor
|
||||
import androidx.car.app.model.CarIcon
|
||||
import androidx.car.app.model.MessageTemplate
|
||||
import androidx.car.app.model.Template
|
||||
import net.vonforst.evmap.R
|
||||
import org.acra.dialog.CrashReportDialogHelper
|
||||
|
||||
/**
|
||||
* ACRA-compatible crash reporting screen for the Car App Library
|
||||
*
|
||||
* only used on Android Automotive OS
|
||||
*/
|
||||
class CrashReportScreen(ctx: CarContext, intent: Intent) : Screen(ctx) {
|
||||
val helper = CrashReportDialogHelper(ctx, intent)
|
||||
override fun onGetTemplate(): Template {
|
||||
return MessageTemplate.Builder(carContext.getString(R.string.crash_report_text)).apply {
|
||||
setHeaderAction(Action.APP_ICON)
|
||||
setTitle(carContext.getString(R.string.app_name))
|
||||
addAction(
|
||||
Action.Builder()
|
||||
.setTitle(carContext.getString(R.string.ok))
|
||||
.setFlags(Action.FLAG_PRIMARY)
|
||||
.setBackgroundColor(CarColor.PRIMARY)
|
||||
.setOnClickListener {
|
||||
helper.sendCrash(null, null)
|
||||
screenManager.pop()
|
||||
}.build()
|
||||
)
|
||||
addAction(
|
||||
Action.Builder()
|
||||
.setTitle(carContext.getString(R.string.cancel))
|
||||
.setOnClickListener {
|
||||
helper.cancelReports()
|
||||
screenManager.pop()
|
||||
}.build()
|
||||
)
|
||||
}.build()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user