mirror of
https://github.com/home-assistant/android
synced 2024-10-15 12:32:54 +00:00
Sensor Crashes (#819)
* Ensure that location isn't null. * Ensure a single sensor can't stop the rest.
This commit is contained in:
parent
9cae26b771
commit
0a17e8e09b
|
@ -5,6 +5,7 @@ import android.content.Context
|
|||
import android.location.Address
|
||||
import android.location.Geocoder
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import com.google.android.gms.location.LocationServices
|
||||
|
||||
class GeocodeSensorManager : SensorManager {
|
||||
|
@ -45,6 +46,11 @@ class GeocodeSensorManager : SensorManager {
|
|||
return
|
||||
val locApi = LocationServices.getFusedLocationProviderClient(context)
|
||||
locApi.lastLocation.addOnSuccessListener { location ->
|
||||
if (location == null) {
|
||||
Log.e(TAG, "Somehow location is null even though it was successful")
|
||||
return@addOnSuccessListener
|
||||
}
|
||||
|
||||
var address: Address? = null
|
||||
if (location.accuracy <= LocationBroadcastReceiver.MINIMUM_ACCURACY)
|
||||
address = Geocoder(context)
|
||||
|
|
|
@ -86,13 +86,17 @@ class SensorReceiver : BroadcastReceiver() {
|
|||
val enabledRegistrations = mutableListOf<SensorRegistration<Any>>()
|
||||
|
||||
MANAGERS.forEach { manager ->
|
||||
manager.requestSensorUpdate(context)
|
||||
try {
|
||||
manager.requestSensorUpdate(context)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Issue requesting updates for ${manager.name}", e)
|
||||
}
|
||||
manager.availableSensors.forEach { basicSensor ->
|
||||
val fullSensor = sensorDao.getFull(basicSensor.id)
|
||||
val sensor = fullSensor?.sensor
|
||||
|
||||
// Register Sensors if needed
|
||||
if (sensor?.enabled == true && !sensor.registered && !sensor.type.isNullOrBlank()) {
|
||||
if (sensor?.enabled == true && !sensor.registered && !sensor.type.isBlank()) {
|
||||
val reg = fullSensor.toSensorRegistration()
|
||||
try {
|
||||
integrationUseCase.registerSensor(reg)
|
||||
|
|
Loading…
Reference in a new issue