Fix Android Auto connected sensor intent crash (#3434)

- The CarConnection class registers for intents using the provided context, so switch to application context instead
This commit is contained in:
Joris Pelgröm 2023-04-01 04:57:40 +02:00 committed by GitHub
parent 3c0145eed3
commit f89d3c7c78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,13 +46,13 @@ class AndroidAutoSensorManager : SensorManager, Observer<Int> {
private var carConnection: CarConnection? = null
override fun requestSensorUpdate(context: Context) {
this.context = context
this.context = context.applicationContext
if (!isEnabled(context, androidAutoConnected)) {
return
}
CoroutineScope(Dispatchers.Main + Job()).launch {
if (carConnection == null) {
carConnection = CarConnection(context)
carConnection = CarConnection(context.applicationContext)
}
carConnection?.type?.observeForever(this@AndroidAutoSensorManager)
}