Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

## Unreleased

### Improvements

- Android: Narrow consumer keep rules to the classes and members the SDK reads by reflection, so R8 can optimize more of your app ([#6779](https://github.com/getsentry/sentry-java/pull/6779))

### Fixes

- 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))
- Android: A crash long after `Sentry.init` is no longer marked as a startup crash when the device slept in between, because the time since init now counts deep sleep ([#6738](https://github.com/getsentry/sentry-java/pull/6738))

### Dependencies
Expand Down
10 changes: 3 additions & 7 deletions sentry-android-core/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
##---------------Begin: proguard configuration for android-core ----------

##---------------Begin: proguard configuration for androidx.core ----------
-keep class androidx.core.app.FrameMetricsAggregator { <init>(...); }
-keep interface androidx.core.view.ScrollingView { *; }
-keepnames class androidx.core.app.FrameMetricsAggregator
-keepnames interface androidx.core.view.ScrollingView
##---------------End: proguard configuration for androidx.core ----------

##---------------Begin: proguard configuration for androidx.lifecycle ----------
-keep interface androidx.lifecycle.DefaultLifecycleObserver { *; }
-keep class androidx.lifecycle.ProcessLifecycleOwner { <init>(...); }
-keepnames class androidx.lifecycle.ProcessLifecycleOwner
##---------------End: proguard configuration for androidx.lifecycle ----------

# To mitigate the issue on R8 site (https://issuetracker.google.com/issues/235733922)
Expand Down Expand Up @@ -45,9 +44,6 @@
# disagree. Unused Throwables may still be removed, and retained Throwables may still be obfuscated.
-keep,allowshrinking,allowobfuscation class * extends java.lang.Throwable

# Keep Classnames for integrations
-keepnames class * implements io.sentry.Integration

-dontwarn io.sentry.apollo.SentryApolloInterceptor
-keepnames class io.sentry.apollo.SentryApolloInterceptor

Expand Down
2 changes: 1 addition & 1 deletion sentry-android-fragment/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##---------------Begin: proguard configuration for Fragment ----------

# The Android SDK checks at runtime if these classes are available via Class.forName
-keep class io.sentry.android.fragment.FragmentLifecycleIntegration { <init>(...); }
-keepnames class io.sentry.android.fragment.FragmentLifecycleIntegration
-keepnames class androidx.fragment.app.FragmentManager$FragmentLifecycleCallbacks

# To ensure that stack traces is unambiguous
Expand Down
5 changes: 4 additions & 1 deletion sentry-android-ndk-outproc/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
##---------------Begin: proguard configuration for NDK outproc ----------

# The Android SDK checks at runtime if this class is available via Class.forName
-keep class io.sentry.android.ndk.outproc.SentryNdkOutproc { *; }
-keep class io.sentry.android.ndk.outproc.SentryNdkOutproc {
public static void init(...);
public static void close();
}

##---------------End: proguard configuration for NDK outproc ----------
5 changes: 4 additions & 1 deletion sentry-android-ndk/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
##---------------Begin: proguard configuration for NDK ----------

# The Android SDK checks at runtime if this class is available via Class.forName
-keep class io.sentry.android.ndk.SentryNdk { *; }
-keep class io.sentry.android.ndk.SentryNdk {
public static void init(...);
public static void close();
}

# The JNI layer uses this class through reflection
-keep class io.sentry.protocol.DebugImage { *; }
Expand Down
6 changes: 4 additions & 2 deletions sentry-android-replay/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

# Rules to detect Images/Icons and mask them
-dontwarn androidx.compose.ui.graphics.painter.Painter
-keepnames class * extends androidx.compose.ui.graphics.painter.Painter
-dontwarn androidx.compose.ui.graphics.painter.ColorPainter
-dontwarn androidx.compose.ui.graphics.painter.BrushPainter
-dontwarn androidx.compose.ui.graphics.vector.VectorPainter
-keepclasseswithmembernames class * {
androidx.compose.ui.graphics.painter.Painter painter;
}
Expand Down Expand Up @@ -32,7 +34,7 @@
-dontwarn androidx.camera.view.PreviewView
-keepnames class androidx.camera.view.PreviewView
# Rules to walk the Compose Node tree.
-keep class androidx.compose.ui.node.LayoutNode {
-keepclassmembers class androidx.compose.ui.node.LayoutNode {
*** getChildren*(...);
*** getOuterCoordinator*(...);
*** getCollapsedSemantics*(...);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorProducer
import androidx.compose.ui.graphics.painter.BrushPainter
import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.VectorPainter
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.findRootCoordinates
import androidx.compose.ui.node.LayoutNode
Expand Down Expand Up @@ -111,20 +114,14 @@ internal fun LayoutNode.isMaskableImage(): Boolean? {
}

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

/**
* This method is necessary to mask text in Compose.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")

package io.sentry.android.replay.util

import android.graphics.Bitmap
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.painter.BrushPainter
import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.VectorPainter
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config

@RunWith(AndroidJUnit4::class)
@Config(sdk = [35])
class NodesTest {

@Test
fun `VectorPainter is not maskable`() {
assertThat(VectorPainter().isMaskable()).isFalse()
}

@Test
fun `ColorPainter is not maskable`() {
assertThat(ColorPainter(Color.Red).isMaskable()).isFalse()
}

@Test
fun `BrushPainter is not maskable`() {
assertThat(BrushPainter(SolidColor(Color.Red)).isMaskable()).isFalse()
}

@Test
fun `BitmapPainter is maskable`() {
val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888).asImageBitmap()
assertThat(BitmapPainter(bitmap).isMaskable()).isTrue()
}

@Test
fun `a custom Painter is maskable even when its name contains Color, Vector, or Brush`() {
assertThat(ColorVectorBrushPainter().isMaskable()).isTrue()
}

private class ColorVectorBrushPainter : Painter() {
override val intrinsicSize: Size = Size.Unspecified

override fun DrawScope.onDraw() = Unit
}
}
2 changes: 1 addition & 1 deletion sentry-android-timber/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##---------------Begin: proguard configuration for Timber ----------

# The Android SDK checks at runtime if these classes are available via Class.forName
-keep class io.sentry.android.timber.SentryTimberIntegration { <init>(...); }
-keepnames class io.sentry.android.timber.SentryTimberIntegration
-keepnames class timber.log.Timber

# To ensure that stack traces is unambiguous
Expand Down
8 changes: 4 additions & 4 deletions sentry-compose/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
##---------------Begin: proguard configuration for Compose ----------

# The Android SDK checks at runtime if these classes are available via Class.forName
-keep class io.sentry.compose.gestures.ComposeGestureTargetLocator { <init>(...); }
-keep class io.sentry.compose.viewhierarchy.ComposeViewHierarchyExporter { <init>(...); }
-keepnames class io.sentry.compose.gestures.ComposeGestureTargetLocator
-keepnames class io.sentry.compose.viewhierarchy.ComposeViewHierarchyExporter

-keepnames interface androidx.compose.ui.node.Owner
-keepclassmembers class androidx.compose.ui.node.LayoutNode {
Expand All @@ -14,8 +14,8 @@
-keepnames class androidx.compose.foundation.ScrollingLayoutElement
-keepnames class androidx.compose.foundation.ScrollingContainerElement
-keepnames class androidx.compose.foundation.ScrollableAreaElement
-keepnames class androidx.compose.ui.platform.TestTagElement { *; }
-keepnames class io.sentry.compose.SentryModifier$SentryTagModifierNodeElement { *; }
-keepnames class androidx.compose.ui.platform.TestTagElement { java.lang.String tag; }
-keepnames class io.sentry.compose.SentryModifier$SentryTagModifierNodeElement { java.lang.String tag; }

# R8 will warn about missing classes if people don't have androidx.compose-navigation on their
# classpath, but this is fine, these classes are used in an internal class which is only used when
Expand Down
Loading