Don't crash on sensor update on on/off/setting change (#2391)

* Don't crash on sensor update on on/off/setting change

* Update logging message, also for Wear OS
This commit is contained in:
Joris Pelgröm 2022-03-23 01:17:17 +01:00 committed by GitHub
parent ead6a9377f
commit 965ee61b11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View file

@ -141,7 +141,11 @@ class SensorDetailViewModel @Inject constructor(
}
updateSensorEntity(isEnabled)
if (isEnabled) sensorManager?.requestSensorUpdate(app)
if (isEnabled) try {
sensorManager?.requestSensorUpdate(app)
} catch (e: Exception) {
Log.e(TAG, "Exception while requesting update for sensor $sensorId", e)
}
}
fun onSettingWithDialogPressed(setting: SensorSetting) {
@ -181,7 +185,11 @@ class SensorDetailViewModel @Inject constructor(
fun setSetting(setting: SensorSetting) {
sensorDao.add(setting)
sensorManager?.requestSensorUpdate(app)
try {
sensorManager?.requestSensorUpdate(app)
} catch (e: Exception) {
Log.e(TAG, "Exception while requesting update for sensor $sensorId", e)
}
refreshSensorData()
}

View file

@ -261,8 +261,11 @@ class MainViewModel @Inject constructor(application: Application) : AndroidViewM
.first { basicSensor -> basicSensor.id == sensorId }
updateSensorEntity(sensorsDao, basicSensor, isEnabled)
if (isEnabled)
if (isEnabled) try {
sensorManager.requestSensorUpdate(app)
} catch (e: Exception) {
Log.e(TAG, "Exception while requesting update for sensor $sensorId", e)
}
}
}