getsentry / getsentry/sentry-java
Session Replay: consolidate window size detection onto OnLayoutChangeListener
- Linguagem predominante
- Kotlin
- Estrelas
- 1.4k
- Forks
- 478
- Merge médio
- 3d 4h
- PRs com merge (30d)
- 72
Descrição
## Summary
`WindowRecorder.determineWindowSize` currently has two detection paths for window size changes:
1. **Synchronous**: if the root already has size at registration time, compare and emit immediately.
2. **Deferred** (`OnPreDrawListener`): if the root has no size yet (typical — Curtains fires `onRootViewsChanged` before the first traversal), register a listener that re-checks on every pre-draw and removes itself once size is known.
[#5333](https://github.com/getsentry/sentry-java/pull/5333) added a third path — an `OnLayoutChangeListener` per tracked root — to detect same-root resizes for activities with `configChanges` (Unity, video players). This listener strictly subsumes the `OnPreDrawListener` path: it fires on the first `View.layout(0, 0, W, H)` (bounds differ from the initial 0/0/0/0), which happens on the same Choreographer frame but before draw.
## Proposed change
Replace the `OnPreDrawListener` path with the `OnLayoutChangeListener`, keeping the synchronous check for the rare case where the root already has size at add time. This would:
- Remove the dual-listener setup (simpler code, one mechanism instead of two).
- Eliminate the per-preDraw iteration that checks `hasSize()` and `root == currentRoot` on every draw until size is known.
- Unify initial detection and subsequent resize detection into a single listener.
The `OnLayoutChangeListener` already has the latest-root guard (`v != rootViews.lastOrNull()?.get()` → skip), matching the `OnPreDrawListener`'s existing `root != currentRoot` guard.
## Why it wasn't done in #5333
The refactor changes behavior for all apps, not just `configChanges` activities. It was kept out of scope to limit regression risk in the SurfaceView capture PR.
Guia de contribuição
Direção de pesquisa
Localize WindowRecorder.determineWindowSize e leia os caminhos existentes de OnPreDrawListener e OnLayoutChangeListener, incluindo o latest-root guard. Verifique se a verificação síncrona do tamanho permanece; em seguida, consolide a detecção inicial adiada no listener de layout e confirme que a iteração de pre-draw seja removida sem alterar a detecção subsequente de redimensionamentos.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- android, kotlin
- Domínio
- mobile
- Tipo de issue
- Refatoração
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Pouca atividade
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 52/100