mirror of
https://github.com/home-assistant/android
synced 2024-07-22 10:54:12 +00:00
Restart health services if no updates received in 30 minutes (#3126)
* Restart health services if no updates received in 30 minutes * Only update activity state if the state changes or an update needs to be forced
This commit is contained in:
parent
49849d4587
commit
5780f1492b
|
@ -31,6 +31,7 @@ class HealthServicesSensorManager : SensorManager {
|
|||
companion object {
|
||||
|
||||
private const val TAG = "HealthServices"
|
||||
private var callbackLastUpdated = 0L
|
||||
private val userActivityState = SensorManager.BasicSensor(
|
||||
"activity_state",
|
||||
"sensor",
|
||||
|
@ -171,7 +172,7 @@ class HealthServicesSensorManager : SensorManager {
|
|||
.setDataTypes(dataTypes)
|
||||
.build()
|
||||
|
||||
if (dataTypesRegistered != dataTypes || activityStateRegistered != activityStateEnabled) {
|
||||
if (dataTypesRegistered != dataTypes || activityStateRegistered != activityStateEnabled || callbackLastUpdated + 1800000 < System.currentTimeMillis()) {
|
||||
clearHealthServicesCallBack()
|
||||
}
|
||||
|
||||
|
@ -181,6 +182,8 @@ class HealthServicesSensorManager : SensorManager {
|
|||
val passiveListenerCallback: PassiveListenerCallback = object : PassiveListenerCallback {
|
||||
override fun onUserActivityInfoReceived(info: UserActivityInfo) {
|
||||
Log.d(TAG, "User activity state: ${info.userActivityState.name}")
|
||||
callbackLastUpdated = System.currentTimeMillis()
|
||||
val forceUpdate = info.userActivityState == UserActivityState.USER_ACTIVITY_EXERCISE
|
||||
onSensorUpdated(
|
||||
latestContext,
|
||||
userActivityState,
|
||||
|
@ -195,14 +198,18 @@ class HealthServicesSensorManager : SensorManager {
|
|||
"time" to info.stateChangeTime,
|
||||
"exercise_type" to info.exerciseInfo?.exerciseType?.name
|
||||
),
|
||||
forceUpdate = info.userActivityState == UserActivityState.USER_ACTIVITY_EXERCISE
|
||||
forceUpdate = forceUpdate
|
||||
)
|
||||
val sensorDao = AppDatabase.getInstance(latestContext).sensorDao()
|
||||
val sensorData = sensorDao.get(userActivityState.id)
|
||||
|
||||
SensorReceiver.updateAllSensors(latestContext)
|
||||
if (sensorData?.state != sensorData?.lastSentState || forceUpdate)
|
||||
SensorReceiver.updateAllSensors(latestContext)
|
||||
}
|
||||
|
||||
override fun onNewDataPointsReceived(dataPoints: DataPointContainer) {
|
||||
Log.d(TAG, "New data point received: ${dataPoints.dataTypes}")
|
||||
callbackLastUpdated = System.currentTimeMillis()
|
||||
val floorsDaily = dataPoints.getData(DataType.FLOORS_DAILY)
|
||||
val distanceDaily = dataPoints.getData(DataType.DISTANCE_DAILY)
|
||||
val caloriesDaily = dataPoints.getData(DataType.CALORIES_DAILY)
|
||||
|
|
Loading…
Reference in a new issue