Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- recording: `OnTouchEventListener` try catch guard to swallow unexpected errors ([#147](https://github.com/PostHog/posthog-android/pull/147))

## 3.4.0 - 2024-06-20

- chore: screenshot masking ([#145](https://github.com/PostHog/posthog-android/pull/145))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,21 @@ public class PostHogReplayIntegration(

private val onTouchEventListener =
OnTouchEventListener { motionEvent ->
if (!isSessionReplayEnabled) {
return@OnTouchEventListener
}
motionEvent.eventTime
val timestamp = config.dateProvider.currentTimeMillis()
when (motionEvent.action.and(MotionEvent.ACTION_MASK)) {
MotionEvent.ACTION_DOWN -> {
generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchStart)
try {

@marandaneto marandaneto Jun 27, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't see how this could throw but I recall a lot of strange dispatchTouchEvent errors in the past so let's just be super careful.
Better to lose the touch than crashing.

if (!isSessionReplayEnabled) {
return@OnTouchEventListener
}
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)
}
}
// TODO: ACTION_MOVE requires the positions arrays caching since it triggers multiple times
// MotionEvent.ACTION_MOVE -> {
// generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchMoveDeparted)
// }
} catch (e: Throwable) {
config.logger.log("OnTouchEventListener $motionEvent failed: $e.")
}
}

Expand Down