Skip to content

Commit d242084

Browse files
runningcodeclaude
andcommitted
fix(replay): Unmask Compose painters by type, not by class name
isMaskable() left any Painter unmasked whose class name contained Vector, Color, or Brush. Once R8 renames an app's painter, that check gave different results in debug and release. Checking the three AndroidX types directly behaves the same in both, and drops their keep rules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ef9f369 commit d242084

4 files changed

Lines changed: 68 additions & 14 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
### Fixes
1515

16+
- Session Replay: Mask Compose images the same way in debug and release builds. Only `VectorPainter`, `ColorPainter`, and `BrushPainter` are left unmasked, instead of any Painter whose class name contains `Vector`, `Color`, or `Brush` ([#6779](https://github.com/getsentry/sentry-java/pull/6779))
1617
- Session Replay: Mask Compose images loaded with Coil 3.1+ `AsyncImage` when `maskAllImages` is enabled ([#6759](https://github.com/getsentry/sentry-java/pull/6759))
1718
- Profiling: No longer crash on API 35+ devices whose framework can't load `ProfilingManager`. Perfetto profiling is turned off on those devices instead ([#6742](https://github.com/getsentry/sentry-java/pull/6742))
1819
- Android: Out-of-process crash reporting now supports Android 5.0 (API level 21) and later, previously required Android 11 (API level 30) ([#6614](https://github.com/getsentry/sentry-java/pull/6614))

‎sentry-android-replay/proguard-rules.pro‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
# Rules to detect Images/Icons and mask them
66
-dontwarn androidx.compose.ui.graphics.painter.Painter
7-
# isMaskable() leaves these Painters unmasked by name and masks every other one
8-
-keepnames class androidx.compose.ui.graphics.vector.VectorPainter
9-
-keepnames class androidx.compose.ui.graphics.painter.ColorPainter
10-
-keepnames class androidx.compose.ui.graphics.painter.BrushPainter
7+
-dontwarn androidx.compose.ui.graphics.painter.ColorPainter
8+
-dontwarn androidx.compose.ui.graphics.painter.BrushPainter
9+
-dontwarn androidx.compose.ui.graphics.vector.VectorPainter
1110
-keepclasseswithmembernames class * {
1211
androidx.compose.ui.graphics.painter.Painter painter;
1312
}

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ import androidx.compose.ui.geometry.Offset
2828
import androidx.compose.ui.geometry.Rect
2929
import androidx.compose.ui.graphics.Color
3030
import androidx.compose.ui.graphics.ColorProducer
31+
import androidx.compose.ui.graphics.painter.BrushPainter
32+
import androidx.compose.ui.graphics.painter.ColorPainter
3133
import androidx.compose.ui.graphics.painter.Painter
34+
import androidx.compose.ui.graphics.vector.VectorPainter
3235
import androidx.compose.ui.layout.LayoutCoordinates
3336
import androidx.compose.ui.layout.findRootCoordinates
3437
import androidx.compose.ui.node.LayoutNode
@@ -111,20 +114,14 @@ internal fun LayoutNode.isMaskableImage(): Boolean? {
111114
}
112115

113116
/**
114-
* We heuristically check the known classes that are coming from local assets usually:
115-
* [androidx.compose.ui.graphics.vector.VectorPainter]
116-
* [androidx.compose.ui.graphics.painter.ColorPainter]
117-
* [androidx.compose.ui.graphics.painter.BrushPainter]
117+
* Only [VectorPainter], [ColorPainter], and [BrushPainter] are left unmasked, because they draw
118+
* local vectors and fills. Every other Painter may draw a remote image, so it is masked.
118119
*
119120
* In theory, [androidx.compose.ui.graphics.painter.BitmapPainter] can also come from local assets,
120121
* but it can as well come from a network resource, so we preemptively mask it.
121122
*/
122-
internal fun Painter.isMaskable(): Boolean {
123-
val className = this::class.java.name
124-
return !className.contains("Vector") &&
125-
!className.contains("Color") &&
126-
!className.contains("Brush")
127-
}
123+
internal fun Painter.isMaskable(): Boolean =
124+
this !is VectorPainter && this !is ColorPainter && this !is BrushPainter
128125

129126
/**
130127
* This method is necessary to mask text in Compose.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
2+
3+
package io.sentry.android.replay.util
4+
5+
import android.graphics.Bitmap
6+
import androidx.compose.ui.geometry.Size
7+
import androidx.compose.ui.graphics.Color
8+
import androidx.compose.ui.graphics.SolidColor
9+
import androidx.compose.ui.graphics.asImageBitmap
10+
import androidx.compose.ui.graphics.drawscope.DrawScope
11+
import androidx.compose.ui.graphics.painter.BitmapPainter
12+
import androidx.compose.ui.graphics.painter.BrushPainter
13+
import androidx.compose.ui.graphics.painter.ColorPainter
14+
import androidx.compose.ui.graphics.painter.Painter
15+
import androidx.compose.ui.graphics.vector.VectorPainter
16+
import androidx.test.ext.junit.runners.AndroidJUnit4
17+
import com.google.common.truth.Truth.assertThat
18+
import kotlin.test.Test
19+
import org.junit.runner.RunWith
20+
import org.robolectric.annotation.Config
21+
22+
@RunWith(AndroidJUnit4::class)
23+
@Config(sdk = [35])
24+
class NodesTest {
25+
26+
@Test
27+
fun `VectorPainter is not maskable`() {
28+
assertThat(VectorPainter().isMaskable()).isFalse()
29+
}
30+
31+
@Test
32+
fun `ColorPainter is not maskable`() {
33+
assertThat(ColorPainter(Color.Red).isMaskable()).isFalse()
34+
}
35+
36+
@Test
37+
fun `BrushPainter is not maskable`() {
38+
assertThat(BrushPainter(SolidColor(Color.Red)).isMaskable()).isFalse()
39+
}
40+
41+
@Test
42+
fun `BitmapPainter is maskable`() {
43+
val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888).asImageBitmap()
44+
assertThat(BitmapPainter(bitmap).isMaskable()).isTrue()
45+
}
46+
47+
@Test
48+
fun `a custom Painter is maskable even when its name contains Color, Vector, or Brush`() {
49+
assertThat(ColorVectorBrushPainter().isMaskable()).isTrue()
50+
}
51+
52+
private class ColorVectorBrushPainter : Painter() {
53+
override val intrinsicSize: Size = Size.Unspecified
54+
55+
override fun DrawScope.onDraw() = Unit
56+
}
57+
}

0 commit comments

Comments
 (0)