Sensor Crashes (#819)

* Ensure that location isn't null.

* Ensure a single sensor can't stop the rest.
This commit is contained in:
Justin Bassett 2020-08-25 23:14:02 -04:00 committed by GitHub
parent 9cae26b771
commit 0a17e8e09b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -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)

View file

@ -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)