Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,30 @@ class HealthNotifier(
"wantrunning-false")

init {
// This roughly matches the iOS/macOS implementation in terms of debouncing, and ingoring
// health warnings in various states.
scope.launch {
healthStateFlow
.distinctUntilChanged { old, new -> old?.Warnings?.count() == new?.Warnings?.count() }
.combine(ipnStateFlow, ::Pair)
.debounce(5000)
.debounce(3000)
.collect { pair ->
val health = pair.first
val ipnState = pair.second
// When the client is Stopped, no warnings should get added, and any warnings added
// previously should be removed.
if (ipnState == Ipn.State.Stopped) {
TSLog.d(
TAG,
"Ignoring and dropping all pre-existing health messages in the Stopped state")
dropAllWarnings()
return@collect
} else {
TSLog.d(TAG, "Health updated: ${health?.Warnings?.keys?.sorted()}")
health?.Warnings?.let {
notifyHealthUpdated(it.values.mapNotNull { it }.toTypedArray())
// When the client is Stopped, requires Login or has no state, we should drop all
// existing warnings
when (val ipnState = pair.second) {
Ipn.State.NeedsLogin,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't relevant to Android, but what about InUseOtherUser?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the logic from the Apple notifier. InOtherUser isn't covered there - I don't think it's relevant on mobile (or at least, not relevant here). NeedsLogin was the state we weren't dealing with IIRC. I'll double check. It's possible we were just transitioning through NoState too - which dropped the warnings.

Ipn.State.Stopped,
Ipn.State.NoState -> {
TSLog.d(TAG, "Ignoring and dropping all health messages in state ${ipnState}")
dropAllWarnings()
return@collect
}
else -> {
TSLog.d(TAG, "Health updated: ${health?.Warnings?.keys?.sorted()}")
health?.Warnings?.let {
notifyHealthUpdated(it.values.mapNotNull { it }.toTypedArray())
}
}
}
}
Expand Down