Skip to content

Commit d521c9e

Browse files
authored
Merge branch 'main' into rz/perf/faster-gesture-tracking
2 parents 43fb28f + cdfac96 commit d521c9e

File tree

29 files changed

+388
-23
lines changed

29 files changed

+388
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
### Fixes
1010

1111
- Fix TTFD measurement when API called too early ([#4297](https://github.com/getsentry/sentry-java/pull/4297))
12+
- Tag sockets traffic originating from Sentry's HttpConnection ([#4340](https://github.com/getsentry/sentry-java/pull/4340))
13+
- This should suppress the StrictMode's `UntaggedSocketViolation`
14+
- Reduce debug logs verbosity ([#4341](https://github.com/getsentry/sentry-java/pull/4341))
1215
- Fix unregister `SystemEventsBroadcastReceiver` when entering background ([#4338](https://github.com/getsentry/sentry-java/pull/4338))
1316
- This should reduce ANRs seen with this class in the stack trace for Android 14 and above
1417

scripts/toggle-codec-logs.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
# --- Functions ---
4+
5+
print_usage() {
6+
echo "Usage: $0 [enable|disable]"
7+
exit 1
8+
}
9+
10+
# Check for adb
11+
if ! command -v adb &> /dev/null; then
12+
echo "❌ adb not found. Please install Android Platform Tools and ensure adb is in your PATH."
13+
exit 1
14+
fi
15+
16+
# Check for connected device
17+
DEVICE_COUNT=$(adb devices | grep -w "device" | wc -l)
18+
if [ "$DEVICE_COUNT" -eq 0 ]; then
19+
echo "❌ No device connected. Please connect a device and enable USB debugging."
20+
exit 1
21+
fi
22+
23+
# --- Handle Argument ---
24+
25+
ACTION=$(echo "$1" | tr '[:upper:]' '[:lower:]')
26+
27+
case "$ACTION" in
28+
enable)
29+
echo "✅ Enabling native logs (DEBUG)..."
30+
adb shell setprop log.tag.MPEG4Writer D
31+
adb shell setprop log.tag.CCodec D
32+
adb shell setprop log.tag.VQApply D
33+
adb shell setprop log.tag.ColorUtils D
34+
adb shell setprop log.tag.MediaCodec D
35+
adb shell setprop log.tag.MediaCodecList D
36+
adb shell setprop log.tag.MediaWriter D
37+
adb shell setprop log.tag.CCodecConfig D
38+
adb shell setprop log.tag.Codec2Client D
39+
adb shell setprop log.tag.CCodecBufferChannel D
40+
adb shell setprop log.tag.CodecProperties D
41+
adb shell setprop log.tag.CodecSeeding D
42+
adb shell setprop log.tag.C2Store D
43+
adb shell setprop log.tag.C2NodeImpl D
44+
adb shell setprop log.tag.GraphicBufferSource D
45+
adb shell setprop log.tag.BufferQueueProducer D
46+
adb shell setprop log.tag.ReflectedParamUpdater D
47+
adb shell setprop log.tag.hw-BpHwBinder D
48+
echo "✅ Logs ENABLED"
49+
;;
50+
disable)
51+
echo "🚫 Disabling native logs (SILENT)..."
52+
adb shell setprop log.tag.MPEG4Writer SILENT
53+
adb shell setprop log.tag.CCodec SILENT
54+
adb shell setprop log.tag.VQApply SILENT
55+
adb shell setprop log.tag.ColorUtils SILENT
56+
adb shell setprop log.tag.MediaCodec SILENT
57+
adb shell setprop log.tag.MediaCodecList SILENT
58+
adb shell setprop log.tag.MediaWriter SILENT
59+
adb shell setprop log.tag.CCodecConfig SILENT
60+
adb shell setprop log.tag.Codec2Client SILENT
61+
adb shell setprop log.tag.CCodecBufferChannel SILENT
62+
adb shell setprop log.tag.CodecProperties SILENT
63+
adb shell setprop log.tag.CodecSeeding SILENT
64+
adb shell setprop log.tag.C2Store SILENT
65+
adb shell setprop log.tag.C2NodeImpl SILENT
66+
adb shell setprop log.tag.GraphicBufferSource SILENT
67+
adb shell setprop log.tag.BufferQueueProducer SILENT
68+
adb shell setprop log.tag.ReflectedParamUpdater SILENT
69+
adb shell setprop log.tag.hw-BpHwBinder SILENT
70+
echo "🚫 Logs DISABLED"
71+
;;
72+
*)
73+
echo "❓ Unknown or missing argument: '$1'"
74+
print_usage
75+
;;
76+
esac

sentry-android-core/api/sentry-android-core.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ public class io/sentry/android/core/AndroidProfiler$ProfileStartData {
111111
public fun <init> (JJLjava/util/Date;)V
112112
}
113113

114+
public final class io/sentry/android/core/AndroidSocketTagger : io/sentry/ISocketTagger {
115+
public static fun getInstance ()Lio/sentry/android/core/AndroidSocketTagger;
116+
public fun tagSockets ()V
117+
public fun untagSockets ()V
118+
}
119+
114120
public final class io/sentry/android/core/AnrIntegration : io/sentry/Integration, java/io/Closeable {
115121
public fun <init> (Landroid/content/Context;)V
116122
public fun close ()V

sentry-android-core/src/main/java/io/sentry/android/core/AndroidOptionsInitializer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.sentry.NoOpCompositePerformanceCollector;
1616
import io.sentry.NoOpConnectionStatusProvider;
1717
import io.sentry.NoOpContinuousProfiler;
18+
import io.sentry.NoOpSocketTagger;
1819
import io.sentry.NoOpTransactionProfiler;
1920
import io.sentry.NoopVersionDetector;
2021
import io.sentry.ScopeType;
@@ -238,6 +239,9 @@ static void initializeIntegrationsAndProcessors(
238239
if (options.getThreadChecker() instanceof NoOpThreadChecker) {
239240
options.setThreadChecker(AndroidThreadChecker.getInstance());
240241
}
242+
if (options.getSocketTagger() instanceof NoOpSocketTagger) {
243+
options.setSocketTagger(AndroidSocketTagger.getInstance());
244+
}
241245
if (options.getPerformanceCollectors().isEmpty()) {
242246
options.addPerformanceCollector(new AndroidMemoryCollector());
243247
options.addPerformanceCollector(new AndroidCpuCollector(options.getLogger()));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.sentry.android.core;
2+
3+
import android.net.TrafficStats;
4+
import io.sentry.ISocketTagger;
5+
import org.jetbrains.annotations.ApiStatus;
6+
7+
@ApiStatus.Internal
8+
public final class AndroidSocketTagger implements ISocketTagger {
9+
10+
// just a random number to tag outgoing traffic from the Sentry SDK
11+
private static final int SENTRY_TAG = 0xF001;
12+
13+
private static final AndroidSocketTagger instance = new AndroidSocketTagger();
14+
15+
private AndroidSocketTagger() {}
16+
17+
public static AndroidSocketTagger getInstance() {
18+
return instance;
19+
}
20+
21+
@Override
22+
public void tagSockets() {
23+
TrafficStats.setThreadStatsTag(SENTRY_TAG);
24+
}
25+
26+
@Override
27+
public void untagSockets() {
28+
TrafficStats.clearThreadStatsTag();
29+
}
30+
}

sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ final class ManifestMetadataReader {
109109

110110
static final String REPLAYS_MASK_ALL_IMAGES = "io.sentry.session-replay.mask-all-images";
111111

112+
static final String REPLAYS_DEBUG = "io.sentry.session-replay.debug";
113+
112114
static final String FORCE_INIT = "io.sentry.force-init";
113115

114116
static final String MAX_BREADCRUMBS = "io.sentry.max-breadcrumbs";
@@ -452,6 +454,8 @@ static void applyMetadata(
452454
.getSessionReplay()
453455
.setMaskAllImages(readBool(metadata, logger, REPLAYS_MASK_ALL_IMAGES, true));
454456

457+
options.getSessionReplay().setDebug(readBool(metadata, logger, REPLAYS_DEBUG, false));
458+
455459
options.setIgnoredErrors(readList(metadata, logger, IGNORED_ERRORS));
456460

457461
final @Nullable List<String> includes = readList(metadata, logger, IN_APP_INCLUDES);

sentry-android-core/src/main/java/io/sentry/android/core/internal/debugmeta/AssetsDebugMetaLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public AssetsDebugMetaLoader(final @NotNull Context context, final @NotNull ILog
4141
properties.load(is);
4242
return Collections.singletonList(properties);
4343
} catch (FileNotFoundException e) {
44-
logger.log(SentryLevel.INFO, e, "%s file was not found.", DEBUG_META_PROPERTIES_FILENAME);
44+
logger.log(SentryLevel.INFO, "%s file was not found.", DEBUG_META_PROPERTIES_FILENAME);
4545
} catch (IOException e) {
4646
logger.log(SentryLevel.ERROR, "Error getting Proguard UUIDs.", e);
4747
} catch (RuntimeException e) {

sentry-android-core/src/test/java/io/sentry/android/core/AndroidOptionsInitializerTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import io.sentry.DefaultCompositePerformanceCollector
1111
import io.sentry.IConnectionStatusProvider
1212
import io.sentry.IContinuousProfiler
1313
import io.sentry.ILogger
14+
import io.sentry.ISocketTagger
1415
import io.sentry.ITransactionProfiler
1516
import io.sentry.MainEventProcessor
1617
import io.sentry.NoOpContinuousProfiler
@@ -746,6 +747,13 @@ class AndroidOptionsInitializerTest {
746747
assertTrue { fixture.sentryOptions.threadChecker is AndroidThreadChecker }
747748
}
748749

750+
@Test
751+
fun `AndroidSocketTagger is set to options`() {
752+
fixture.initSut()
753+
754+
assertTrue { fixture.sentryOptions.socketTagger is AndroidSocketTagger }
755+
}
756+
749757
@Test
750758
fun `does not install ComposeGestureTargetLocator, if sentry-compose is not available`() {
751759
fixture.initSutWithClassLoader()
@@ -859,6 +867,7 @@ class AndroidOptionsInitializerTest {
859867
setModulesLoader(mock<IModulesLoader>())
860868
setDebugMetaLoader(mock<IDebugMetaLoader>())
861869
threadChecker = mock<IThreadChecker>()
870+
setSocketTagger(mock<ISocketTagger>())
862871
compositePerformanceCollector = mock<CompositePerformanceCollector>()
863872
})
864873

@@ -868,6 +877,7 @@ class AndroidOptionsInitializerTest {
868877
assertFalse { fixture.sentryOptions.modulesLoader is AssetsModulesLoader }
869878
assertFalse { fixture.sentryOptions.debugMetaLoader is AssetsDebugMetaLoader }
870879
assertFalse { fixture.sentryOptions.threadChecker is AndroidThreadChecker }
880+
assertFalse { fixture.sentryOptions.socketTagger is AndroidSocketTagger }
871881
assertFalse { fixture.sentryOptions.compositePerformanceCollector is DefaultCompositePerformanceCollector }
872882
}
873883
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ public class ReplayIntegration(
151151
} catch (e: Throwable) {
152152
options.logger.log(
153153
INFO,
154-
"ComponentCallbacks is not available, orientation changes won't be handled by Session replay",
155-
e
154+
"ComponentCallbacks is not available, orientation changes won't be handled by Session replay"
156155
)
157156
}
158157
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ internal class ScreenshotRecorder(
7272

7373
fun capture() {
7474
if (!isCapturing.get()) {
75-
options.logger.log(DEBUG, "ScreenshotRecorder is paused, not capturing screenshot")
75+
if (options.sessionReplay.isDebug) {
76+
options.logger.log(DEBUG, "ScreenshotRecorder is paused, not capturing screenshot")
77+
}
7678
return
7779
}
7880

7981
if (!contentChanged.get() && lastCaptureSuccessful.get()) {
80-
options.logger.log(DEBUG, "Content hasn't changed, repeating last known frame")
81-
8282
screenshotRecorderCallback?.onScreenshotRecorded(screenshot)
8383
return
8484
}

0 commit comments

Comments
 (0)