Skip to content

Commit 762eced

Browse files
authored
Merge c8a1689 into 3565c96
2 parents 3565c96 + c8a1689 commit 762eced

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

sentry-android-replay/src/main/java/io/sentry/android/replay/ScreenshotRecorder.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import io.sentry.SentryReplayOptions
2626
import io.sentry.android.replay.util.MainLooperHandler
2727
import io.sentry.android.replay.util.getVisibleRects
2828
import io.sentry.android.replay.util.gracefullyShutdown
29+
import io.sentry.android.replay.util.submitSafely
2930
import io.sentry.android.replay.viewhierarchy.ViewHierarchyNode
3031
import io.sentry.android.replay.viewhierarchy.ViewHierarchyNode.ImageViewHierarchyNode
3132
import io.sentry.android.replay.viewhierarchy.ViewHierarchyNode.TextViewHierarchyNode
@@ -122,7 +123,7 @@ internal class ScreenshotRecorder(
122123
val viewHierarchy = ViewHierarchyNode.fromView(root, null, 0, options)
123124
root.traverse(viewHierarchy)
124125

125-
recorder.submit {
126+
recorder.submitSafely(options, "screenshot_recorder.redact") {
126127
val canvas = Canvas(bitmap)
127128
canvas.setMatrix(prescaledMatrix)
128129
viewHierarchy.traverse { node ->

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/SessionCaptureStrategy.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ internal class SessionCaptureStrategy(
124124
}
125125

126126
override fun onConfigurationChanged(recorderConfig: ScreenshotRecorderConfig) {
127-
val currentSegmentTimestamp = segmentTimestamp ?: return
128127
createCurrentSegment("onConfigurationChanged") { segment ->
129128
if (segment is ReplaySegment.Created) {
130129
segment.capture(hub)

sentry-android-replay/src/main/java/io/sentry/android/replay/util/Views.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import android.os.Build.VERSION
1414
import android.os.Build.VERSION_CODES
1515
import android.text.Layout
1616
import android.view.View
17+
import android.widget.TextView
18+
import java.lang.NullPointerException
1719

1820
/**
1921
* Adapted copy of AccessibilityNodeInfo from https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/view/View.java;l=10718
@@ -26,7 +28,7 @@ internal fun View.isVisibleToUser(): Pair<Boolean, Rect?> {
2628
}
2729
// An invisible predecessor or one with alpha zero means
2830
// that this view is not visible to the user.
29-
var current: Any = this
31+
var current: Any? = this
3032
while (current is View) {
3133
val view = current
3234
val transitionAlpha = if (VERSION.SDK_INT >= VERSION_CODES.Q) view.transitionAlpha else 1f
@@ -53,7 +55,10 @@ internal fun Drawable?.isRedactable(): Boolean {
5355
// TODO: otherwise maybe check for the bitmap size and don't redact those that take a lot of height (e.g. a background of a whatsapp chat)
5456
return when (this) {
5557
is InsetDrawable, is ColorDrawable, is VectorDrawable, is GradientDrawable -> false
56-
is BitmapDrawable -> !bitmap.isRecycled && bitmap.height > 10 && bitmap.width > 10
58+
is BitmapDrawable -> {
59+
val bmp = bitmap ?: return false
60+
return !bmp.isRecycled && bmp.height > 10 && bmp.width > 10
61+
}
5762
else -> true
5863
}
5964
}
@@ -84,3 +89,15 @@ internal fun Layout?.getVisibleRects(globalRect: Rect, paddingLeft: Int, padding
8489
}
8590
return rects
8691
}
92+
93+
/**
94+
* [TextView.getVerticalOffset] which is used by [TextView.getTotalPaddingTop] may throw an NPE on
95+
* some devices (Redmi), so we try-catch it specifically for an NPE and then fallback to
96+
* [TextView.getExtendedPaddingTop]
97+
*/
98+
internal val TextView.totalPaddingTopSafe: Int
99+
get() = try {
100+
totalPaddingTop
101+
} catch (e: NullPointerException) {
102+
extendedPaddingTop
103+
}

sentry-android-replay/src/main/java/io/sentry/android/replay/viewhierarchy/ViewHierarchyNode.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.widget.TextView
99
import io.sentry.SentryOptions
1010
import io.sentry.android.replay.util.isRedactable
1111
import io.sentry.android.replay.util.isVisibleToUser
12+
import io.sentry.android.replay.util.totalPaddingTopSafe
1213

1314
@TargetApi(26)
1415
sealed class ViewHierarchyNode(
@@ -245,7 +246,7 @@ sealed class ViewHierarchyNode(
245246
layout = view.layout,
246247
dominantColor = view.currentTextColor.toOpaque(),
247248
paddingLeft = view.totalPaddingLeft,
248-
paddingTop = view.totalPaddingTop,
249+
paddingTop = view.totalPaddingTopSafe,
249250
x = view.x,
250251
y = view.y,
251252
width = view.width,

0 commit comments

Comments
 (0)