Skip to content

Commit

Permalink
Improve sensor re-registration on app version change for offline serv…
Browse files Browse the repository at this point in the history
…er (#3380)

- Prevent the sensor worker runs from taking a long time when the app version changes if a server is offline due to reregistration of all servers (~15 min), by skipping these re-registrations if it fails with an exception that indicates offline/network issues.

Co-authored-by: Justin Bassett <[email protected]>
  • Loading branch information
jpelgrom and JBassett authored Mar 1, 2023
1 parent ac02e85 commit f5d2b97
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.IOException
import java.net.ConnectException
import java.net.SocketTimeoutException
import java.util.Locale
import javax.inject.Inject

Expand Down Expand Up @@ -213,6 +215,7 @@ abstract class SensorReceiverBase : BroadcastReceiver() {
null
}

var serverIsReachable = true
val enabledRegistrations = mutableListOf<SensorRegistration<Any>>()

managers.forEach { manager ->
Expand Down Expand Up @@ -296,6 +299,7 @@ abstract class SensorReceiverBase : BroadcastReceiver() {
}
} else if (
canBeRegistered &&
serverIsReachable &&
(sensor.enabled || supportsDisabledSensors) &&
(currentAppVersion != sensor.appRegistration || currentHAversion != sensor.coreRegistration)
) {
Expand All @@ -309,6 +313,10 @@ abstract class SensorReceiverBase : BroadcastReceiver() {
sensorDao.update(sensor)
} catch (e: Exception) {
Log.e(tag, "Issue re-registering sensor ${basicSensor.id}", e)
if (e is IntegrationException && (e.cause is ConnectException || e.cause is SocketTimeoutException)) {
Log.w(tag, "Server can't be reached, skipping other registrations for sensors due to version change")
serverIsReachable = false
}
}
}

Expand Down

0 comments on commit f5d2b97

Please sign in to comment.