-
-
Notifications
You must be signed in to change notification settings - Fork 465
Add masking debug overlay #4357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
markushi
merged 13 commits into
main
from
markushi/feat/session-replay-masking-debug-mode
May 19, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d1a9c45
Add masking debug overlay
markushi 1b8d518
Merge branch 'main' into markushi/feat/session-replay-masking-debug-mode
markushi ac42ba6
Improve contrast for debug mode
markushi 5908fa8
Merge branch 'main' into markushi/feat/session-replay-masking-debug-mode
markushi 63940e0
Improve readability
markushi bee207e
Add ReplayIntegration.enableDebugMasking API, improve debug overlay
markushi c8b21fc
Merge branch 'main' into markushi/feat/session-replay-masking-debug-mode
markushi 5110b0f
Update Changelog
markushi 5d4cf78
Introduce IReplayApi
markushi effe222
Update Changelog
markushi bb574e8
Fix Sample app
markushi 502618d
Move replay API from SentryAndroid to Sentry
markushi e16fab5
Merge branch 'main' into markushi/feat/session-replay-masking-debug-mode
markushi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
sentry-android-replay/src/main/java/io/sentry/android/replay/util/DebugOverlayDrawable.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package io.sentry.android.replay.util | ||
|
|
||
| import android.graphics.Canvas | ||
| import android.graphics.Color | ||
| import android.graphics.ColorFilter | ||
| import android.graphics.Paint | ||
| import android.graphics.PixelFormat | ||
| import android.graphics.Rect | ||
| import android.graphics.drawable.Drawable | ||
|
|
||
| internal class DebugOverlayDrawable : Drawable() { | ||
|
|
||
| private val paint = Paint(Paint.ANTI_ALIAS_FLAG) | ||
| private val padding = 6f | ||
| private val tmpRect = Rect() | ||
| private var masks: List<Rect> = emptyList() | ||
|
|
||
| companion object { | ||
| private val maskBackgroundColor = Color.argb(32, 255, 20, 20) | ||
| private val maskBorderColor = Color.argb(128, 255, 20, 20) | ||
| private const val TEXT_COLOR = Color.BLACK | ||
| private const val TEXT_OUTLINE_COLOR = Color.WHITE | ||
|
|
||
| private const val STROKE_WIDTH = 6f | ||
| private const val TEXT_SIZE = 32f | ||
| } | ||
|
|
||
| override fun draw(canvas: Canvas) { | ||
| paint.textSize = TEXT_SIZE | ||
| paint.setColor(Color.BLACK) | ||
|
|
||
| paint.strokeWidth = STROKE_WIDTH | ||
|
|
||
| for (mask in masks) { | ||
| paint.setColor(maskBackgroundColor) | ||
| paint.style = Paint.Style.FILL | ||
| canvas.drawRect(mask, paint) | ||
|
|
||
| paint.setColor(maskBorderColor) | ||
| paint.style = Paint.Style.STROKE | ||
| canvas.drawRect(mask, paint) | ||
|
|
||
| val topLeftLabel = "${mask.left}/${mask.top}" | ||
| paint.getTextBounds(topLeftLabel, 0, topLeftLabel.length, tmpRect) | ||
| drawTextWithOutline( | ||
| canvas, | ||
| topLeftLabel, | ||
| mask.left.toFloat(), | ||
| mask.top.toFloat() | ||
| ) | ||
|
|
||
| val bottomRightLabel = "${mask.right}/${mask.bottom}" | ||
| paint.getTextBounds(bottomRightLabel, 0, bottomRightLabel.length, tmpRect) | ||
| drawTextWithOutline( | ||
| canvas, | ||
| bottomRightLabel, | ||
| mask.right.toFloat() - tmpRect.width(), | ||
| mask.bottom.toFloat() + tmpRect.height() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun drawTextWithOutline( | ||
| canvas: Canvas, | ||
| bottomRightLabel: String, | ||
markushi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| x: Float, | ||
| y: Float | ||
| ) { | ||
| paint.setColor(TEXT_OUTLINE_COLOR) | ||
| paint.style = Paint.Style.STROKE | ||
| canvas.drawText( | ||
| bottomRightLabel, | ||
| x, | ||
| y, | ||
| paint | ||
| ) | ||
|
|
||
| paint.setColor(TEXT_COLOR) | ||
| paint.style = Paint.Style.FILL | ||
| canvas.drawText( | ||
| bottomRightLabel, | ||
| x, | ||
| y, | ||
| paint | ||
| ) | ||
| } | ||
|
|
||
| override fun setAlpha(alpha: Int) { | ||
| // no-op | ||
| } | ||
|
|
||
| override fun setColorFilter(colorFilter: ColorFilter?) { | ||
| // no-op | ||
| } | ||
|
|
||
| @Deprecated("Deprecated in Java") | ||
| override fun getOpacity(): Int = PixelFormat.TRANSLUCENT | ||
|
|
||
| fun updateMasks(masks: List<Rect>) { | ||
| this.masks = masks | ||
| invalidateSelf() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package io.sentry; | ||
|
|
||
| public interface IReplayApi { | ||
|
|
||
| /** | ||
| * Draws a masking overlay on top of the screen to help visualize which parts of the screen are | ||
| * masked by Session Replay. This is only useful for debugging purposes and should not be used in | ||
| * production environments. | ||
| * | ||
| * <p>Expect the top level view to be invalidated more often than usual, as the overlay is drawn | ||
| * on top of it. | ||
| */ | ||
| void enableDebugMaskingOverlay(); | ||
|
|
||
| void disableDebugMaskingOverlay(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.