Skip to content

Commit

Permalink
recording: capture touch interaction off of main thread to avoid ANRs
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Aug 23, 2024
1 parent 51ce6ae commit 284edae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- recording: capture touch interaction off of main thread to avoid ANRs ([#154](https://github.com/PostHog/posthog-android/pull/154))

## 3.5.0 - 2024-08-08

- feat: add emulator detection property to static context ([#154](https://github.com/PostHog/posthog-android/pull/154))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,25 @@ public class PostHogReplayIntegration(

private val onTouchEventListener =
OnTouchEventListener { motionEvent ->
try {
if (!isSessionReplayEnabled) {
return@OnTouchEventListener
}
val timestamp = config.dateProvider.currentTimeMillis()
when (motionEvent.action.and(MotionEvent.ACTION_MASK)) {
MotionEvent.ACTION_DOWN -> {
generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchStart)
executor.submit {
try {
if (!isSessionReplayEnabled) {
return@submit
}
MotionEvent.ACTION_UP -> {
generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchEnd)
val timestamp = config.dateProvider.currentTimeMillis()
when (motionEvent.action.and(MotionEvent.ACTION_MASK)) {
MotionEvent.ACTION_DOWN -> {
generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchStart)
}
MotionEvent.ACTION_UP -> {
generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchEnd)
}
}
} catch (e: Throwable) {
config.logger.log("OnTouchEventListener $motionEvent failed: $e.")
}
} catch (e: Throwable) {
config.logger.log("OnTouchEventListener $motionEvent failed: $e.")
}
return@OnTouchEventListener
}

private fun generateMouseInteractions(
Expand Down

0 comments on commit 284edae

Please sign in to comment.