Skip to content

Commit

Permalink
#789 fix: try to ping the accessibility service multiple times when c…
Browse files Browse the repository at this point in the history
…hecking if it is crashed
  • Loading branch information
sds100 committed Nov 4, 2021
1 parent 9388051 commit 20a3cdc
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,19 @@ class AccessibilityServiceAdapter(
Timber.i("Accessibility service: checking if it is crashed")
val key = "check_is_crashed"

coroutineScope.launch {
delay(100)
serviceOutputEvents.emit(Ping(key))
val pingJob = coroutineScope.launch {
repeat(20) {
eventsToService.emit(Event.Ping(key))
delay(100)
}
}

val pong: Pong? = withTimeoutOrNull(2000L) {
eventReceiver.first { it == Pong(key) } as Pong?
}

pingJob.cancel()

if (pong == null) {
Timber.e("Accessibility service: is crashed")
}
Expand Down

0 comments on commit 20a3cdc

Please sign in to comment.