Skip to content

Commit fbc04cf

Browse files
authored
Merge 1ee7610 into b5c443f
2 parents b5c443f + 1ee7610 commit fbc04cf

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed

scripts/toggle-codec-logs.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ case "$ACTION" in
4545
adb shell setprop log.tag.BufferQueueProducer D
4646
adb shell setprop log.tag.ReflectedParamUpdater D
4747
adb shell setprop log.tag.hw-BpHwBinder D
48+
adb shell setprop log.tag.ACodec D
49+
adb shell setprop log.tag.VideoCapabilities D
50+
adb shell setprop log.tag.OMXUtils D
51+
adb shell setprop log.tag.OMXClient D
4852
echo "✅ Logs ENABLED"
4953
;;
5054
disable)
@@ -67,6 +71,10 @@ case "$ACTION" in
6771
adb shell setprop log.tag.BufferQueueProducer SILENT
6872
adb shell setprop log.tag.ReflectedParamUpdater SILENT
6973
adb shell setprop log.tag.hw-BpHwBinder SILENT
74+
adb shell setprop log.tag.ACodec SILENT
75+
adb shell setprop log.tag.VideoCapabilities SILENT
76+
adb shell setprop log.tag.OMXUtils SILENT
77+
adb shell setprop log.tag.OMXClient SILENT
7078
echo "🚫 Logs DISABLED"
7179
;;
7280
*)

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.compose.ui.semantics.SemanticsActions
1414
import androidx.compose.ui.semantics.SemanticsProperties
1515
import androidx.compose.ui.semantics.getOrNull
1616
import androidx.compose.ui.text.TextLayoutResult
17+
import androidx.compose.ui.unit.TextUnit
1718
import io.sentry.SentryLevel
1819
import io.sentry.SentryOptions
1920
import io.sentry.SentryReplayOptions
@@ -100,14 +101,19 @@ internal object ComposeViewHierarchyNode {
100101
?.invoke(textLayoutResults)
101102

102103
val (color, hasFillModifier) = node.findTextAttributes()
103-
var textColor = textLayoutResults.firstOrNull()?.layoutInput?.style?.color
104+
val textLayoutResult = textLayoutResults.firstOrNull()
105+
var textColor = textLayoutResult?.layoutInput?.style?.color
104106
if (textColor?.isUnspecified == true) {
105107
textColor = color
106108
}
107-
// TODO: support multiple text layouts
109+
val isLaidOut = textLayoutResult?.layoutInput?.style?.fontSize != TextUnit.Unspecified
108110
// TODO: support editable text (currently there's a way to get @Composable's padding only via reflection, and we can't reliably mask input fields based on TextLayout, so we mask the whole view instead)
109111
TextViewHierarchyNode(
110-
layout = if (textLayoutResults.isNotEmpty() && !isEditable) ComposeTextLayout(textLayoutResults.first(), hasFillModifier) else null,
112+
layout = if (textLayoutResult != null && !isEditable && isLaidOut) {
113+
ComposeTextLayout(textLayoutResult, hasFillModifier)
114+
} else {
115+
null
116+
},
111117
dominantColor = textColor?.toArgb()?.toOpaque(),
112118
x = visibleRect.left.toFloat(),
113119
y = visibleRect.top.toFloat(),

sentry-android-replay/src/test/java/io/sentry/android/replay/viewhierarchy/ComposeMaskingOptionsTest.kt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import androidx.compose.ui.platform.testTag
1919
import androidx.compose.ui.semantics.invisibleToUser
2020
import androidx.compose.ui.semantics.semantics
2121
import androidx.compose.ui.text.input.TextFieldValue
22+
import androidx.compose.ui.unit.TextUnit
2223
import androidx.compose.ui.unit.dp
24+
import androidx.compose.ui.unit.sp
2325
import androidx.test.ext.junit.runners.AndroidJUnit4
2426
import coil.compose.AsyncImage
2527
import io.sentry.SentryOptions
@@ -41,6 +43,7 @@ import java.io.File
4143
import kotlin.test.Test
4244
import kotlin.test.assertEquals
4345
import kotlin.test.assertFalse
46+
import kotlin.test.assertNull
4447
import kotlin.test.assertTrue
4548

4649
@RunWith(AndroidJUnit4::class)
@@ -53,6 +56,7 @@ class ComposeMaskingOptionsTest {
5356
System.setProperty("robolectric.pixelCopyRenderMode", "hardware")
5457
ComposeMaskingOptionsActivity.textModifierApplier = null
5558
ComposeMaskingOptionsActivity.containerModifierApplier = null
59+
ComposeMaskingOptionsActivity.fontSizeApplier = null
5660
}
5761

5862
@Test
@@ -67,8 +71,23 @@ class ComposeMaskingOptionsTest {
6771
val textNodes = activity.get().collectNodesOfType<TextViewHierarchyNode>(options)
6872
assertEquals(4, textNodes.size) // [TextField, Text, Button, Activity Title]
6973
assertTrue(textNodes.all { it.shouldMask })
70-
// just a sanity check for parsing the tree
71-
assertEquals("Random repo", (textNodes[1].layout as ComposeTextLayout).layout.layoutInput.text.text)
74+
// no fontSize specified - we don't use the text layout
75+
assertNull(textNodes.first().layout)
76+
}
77+
78+
@Test
79+
fun `when text is laid out nodes use it`() {
80+
ComposeMaskingOptionsActivity.fontSizeApplier = { 20.sp }
81+
val activity = buildActivity(ComposeMaskingOptionsActivity::class.java).setup()
82+
shadowOf(Looper.getMainLooper()).idle()
83+
84+
val options = SentryOptions().apply {
85+
sessionReplay.maskAllText = true
86+
}
87+
88+
val textNodes = activity.get().collectNodesOfType<TextViewHierarchyNode>(options)
89+
// the text should be laid out when fontSize is specified
90+
assertEquals("Random repo", (textNodes.first().layout as? ComposeTextLayout)?.layout?.layoutInput?.text?.text)
7291
}
7392

7493
@Test
@@ -213,6 +232,7 @@ private class ComposeMaskingOptionsActivity : ComponentActivity() {
213232
companion object {
214233
var textModifierApplier: (() -> Modifier)? = null
215234
var containerModifierApplier: (() -> Modifier)? = null
235+
var fontSizeApplier: (() -> TextUnit)? = null
216236
}
217237

218238
override fun onCreate(savedInstanceState: Bundle?) {
@@ -232,11 +252,11 @@ private class ComposeMaskingOptionsActivity : ComponentActivity() {
232252
contentDescription = null,
233253
modifier = Modifier.padding(vertical = 16.dp)
234254
)
255+
Text("Random repo", fontSize = fontSizeApplier?.invoke() ?: TextUnit.Unspecified)
235256
TextField(
236257
value = TextFieldValue("Placeholder"),
237258
onValueChange = { _ -> }
238259
)
239-
Text("Random repo")
240260
Button(
241261
onClick = {},
242262
modifier = Modifier

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/compose/ComposeActivity.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ fun Github(
106106
val scope = rememberCoroutineScope()
107107

108108
LaunchedEffect(perPage) {
109-
result = GithubAPI.service.listReposAsync(user.text, perPage).random().full_name
109+
result = try {
110+
GithubAPI.service.listReposAsync(user.text, perPage).random().full_name
111+
} catch (e: Throwable) {
112+
"error"
113+
}
110114
}
111115

112116
SentryTraced("github-$user") {
@@ -133,12 +137,15 @@ fun Github(
133137
user = newText
134138
}
135139
)
136-
Text("Random repo $result")
140+
Text("Random repo: $result")
137141
Button(
138142
onClick = {
139143
scope.launch {
140-
result =
144+
result = try {
141145
GithubAPI.service.listReposAsync(user.text, perPage).random().full_name
146+
} catch (e: Throwable) {
147+
"error"
148+
}
142149
}
143150
},
144151
modifier = Modifier

0 commit comments

Comments
 (0)