From f532ea3fc4c667589d75b529ec86cf7ea59414b2 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 10 Nov 2026 13:11:01 +0100 Subject: [PATCH 01/12] fix(android): Start the NDK crash service without waiting for it `SentryNdkCrashService.start` waited up to 10 s for the service to connect and configure, on the thread that calls `SentryAndroid.init`, usually the main thread. It now hands the app's ends to native right away, and the service takes its ends when it connects. If it doesn't connect within 10 s, its ends are closed so that native sends and the crash handler fail at once, and a later connection reattaches. Native init in sentry-native 1.0.0-beta.1 still waits for the daemon. --- .../ndk/outproc/SentryNdkCrashService.java | 126 ++++++++++++------ .../ndk/outproc/SentryNdkCrashServiceTest.kt | 63 ++++++++- 2 files changed, 145 insertions(+), 44 deletions(-) diff --git a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java index 985e3b1af5..4842f772b3 100644 --- a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java +++ b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java @@ -17,6 +17,7 @@ import android.os.RemoteException; import io.sentry.DateUtils; import io.sentry.ILogger; +import io.sentry.ISentryExecutorService; import io.sentry.SentryEnvelope; import io.sentry.SentryEnvelopeItem; import io.sentry.SentryEvent; @@ -42,8 +43,9 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.concurrent.CountDownLatch; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -58,6 +60,7 @@ public final class SentryNdkCrashService extends Service { private static final @NotNull String MERGED_SUFFIX = ".merged"; private static final long POLL_INTERVAL_MILLIS = 250; private static final long MATCH_TOLERANCE_MILLIS = 30000; + private static final long CONNECT_TIMEOUT_MILLIS = 10000; private final @NotNull IBinder binder = new Binder() { @@ -150,6 +153,7 @@ protected boolean onTransact( ParcelFileDescriptor readyWrite = null; ParcelFileDescriptor messageWrite = null; ParcelFileDescriptor messageRead = null; + @Nullable ServiceEnds ends = null; try { final ParcelFileDescriptor[] notifyPipe = ParcelFileDescriptor.createPipe(); final ParcelFileDescriptor[] readyPipe = ParcelFileDescriptor.createPipe(); @@ -160,6 +164,10 @@ protected boolean onTransact( final ParcelFileDescriptor[] messageSocket = ParcelFileDescriptor.createSocketPair(); messageWrite = messageSocket[0]; messageRead = messageSocket[1]; + ends = new ServiceEnds(shm.dup(), notifyRead, readyWrite, messageRead); + notifyRead = null; + readyWrite = null; + messageRead = null; final Intent intent = new Intent(context, SentryNdkCrashService.class); final @Nullable ServiceConnection connection = @@ -167,9 +175,9 @@ protected boolean onTransact( context, intent, options.getLogger(), + options.getExecutorService(), nativeDatabaseDir.getPath(), context.getApplicationInfo().nativeLibraryDir, - shm, Process.myPid(), Process.myTid(), options.isTombstoneEnabled() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S, @@ -177,25 +185,24 @@ protected boolean onTransact( options.getShutdownTimeoutMillis(), new ArrayList<>(options.getInAppIncludes()), new ArrayList<>(options.getInAppExcludes()), - notifyRead, - readyWrite, - messageRead); + ends); + ends = null; if (connection == null) { - options.getLogger().log(SentryLevel.DEBUG, "NDK crash service did not configure."); + options.getLogger().log(SentryLevel.DEBUG, "NDK crash service did not bind."); return null; } + // the daemon attaches once the service connects io.sentry.ndk.SentryNdk.initCrashDaemon( shm.detachFd(), notifyWrite.detachFd(), readyRead.detachFd(), messageWrite.detachFd()); return connection; - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - options.getLogger().log(SentryLevel.DEBUG, e, "Failed to start NDK crash service."); - return null; } catch (IOException | SecurityException e) { options.getLogger().log(SentryLevel.DEBUG, e, "Failed to start NDK crash service."); return null; } finally { + if (ends != null) { + ends.close(); + } closeQuietly(shm); closeQuietly(notifyRead); closeQuietly(notifyWrite); @@ -225,9 +232,9 @@ private static void closeQuietly(final @Nullable Closeable closeable) { final @NotNull Context context, final @NotNull Intent intent, final @NotNull ILogger logger, + final @NotNull ISentryExecutorService executorService, final @NotNull String nativeDatabasePath, final @Nullable String nativeLibraryDir, - final @NotNull ParcelFileDescriptor shm, final int appPid, final long appTid, final boolean tombstoneEnabled, @@ -235,24 +242,19 @@ private static void closeQuietly(final @Nullable Closeable closeable) { final long shutdownTimeoutMillis, final @NotNull ArrayList includes, final @NotNull ArrayList excludes, - final @NotNull ParcelFileDescriptor notifyRead, - final @NotNull ParcelFileDescriptor readyWrite, - final @NotNull ParcelFileDescriptor messageRead) - throws InterruptedException { - final CountDownLatch latch = new CountDownLatch(1); - final boolean[] configured = new boolean[] {false}; + final @NotNull ServiceEnds ends) { // a foreground app raises the service process only to visible without BIND_IMPORTANT final int flags = Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT; final ServiceConnection connection = new ServiceConnection() { - private boolean connected; + private volatile boolean configured; @Override public void onServiceConnected( final @NotNull ComponentName name, final @NotNull IBinder service) { - if (connected) { - // a restarted service process has no daemon for this app + if (!ends.take()) { + // a restarted or late service process has no daemon for this app reattach( service, logger, @@ -267,13 +269,12 @@ public void onServiceConnected( excludes); return; } - connected = true; - configured[0] = + configured = transactConfigure( service, nativeDatabasePath, nativeLibraryDir, - shm, + ends.shm, appPid, appTid, tombstoneEnabled, @@ -281,43 +282,57 @@ public void onServiceConnected( shutdownTimeoutMillis, includes, excludes, - notifyRead, - readyWrite, - messageRead); - latch.countDown(); + ends.notifyRead, + ends.readyWrite, + ends.messageRead); + ends.close(); + if (!configured) { + logger.log(SentryLevel.ERROR, "NDK crash service did not configure."); + } } @Override public void onServiceDisconnected(final @NotNull ComponentName name) { logger.log(SentryLevel.ERROR, "NDK crash service disconnected."); - latch.countDown(); } @Override public void onBindingDied(final @NotNull ComponentName name) { logger.log(SentryLevel.ERROR, "NDK crash service binding died."); - latch.countDown(); // a dead binding does not reconnect, it must be bound again - if (configured[0]) { + if (configured) { context.unbindService(this); bind(context, intent, flags, this); } } }; - if (!bind(context, intent, flags, connection)) { - return null; - } - boolean ready = false; + boolean bound = false; try { - ready = latch.await(10000, TimeUnit.MILLISECONDS) && configured[0]; - // stay bound, so the service process keeps the app's importance and is not frozen - return ready ? connection : null; + bound = bind(context, intent, flags, connection); } finally { - if (!ready) { - context.unbindService(connection); + if (!bound) { + ends.close(); } } + if (!bound) { + return null; + } + try { + executorService.schedule( + () -> { + if (ends.take()) { + // without a reader, native sends and the crash handler fail at once + ends.close(); + logger.log(SentryLevel.ERROR, "NDK crash service did not connect in time."); + } + }, + CONNECT_TIMEOUT_MILLIS); + } catch (RejectedExecutionException e) { + logger.log(SentryLevel.DEBUG, e, "Failed to schedule the NDK crash service timeout."); + } + // stay bound, so the service process keeps the app's importance and is not frozen + return connection; } private static boolean bind( @@ -326,7 +341,7 @@ private static boolean bind( final int flags, final @NotNull ServiceConnection connection) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - // deliver callbacks on the binder thread, the caller blocks on the latch + // deliver callbacks on the binder thread instead of the main thread return context.bindService(intent, flags, Runnable::run, connection); } return context.bindService(intent, connection, flags); @@ -810,4 +825,35 @@ private DaemonConfig( this.debug = debug; } } + + // the service's ends of the crash IPC, handed over on the first connection or closed + private static final class ServiceEnds { + private final @NotNull AtomicBoolean taken = new AtomicBoolean(); + private final @NotNull ParcelFileDescriptor shm; + private final @NotNull ParcelFileDescriptor notifyRead; + private final @NotNull ParcelFileDescriptor readyWrite; + private final @NotNull ParcelFileDescriptor messageRead; + + private ServiceEnds( + final @NotNull ParcelFileDescriptor shm, + final @NotNull ParcelFileDescriptor notifyRead, + final @NotNull ParcelFileDescriptor readyWrite, + final @NotNull ParcelFileDescriptor messageRead) { + this.shm = shm; + this.notifyRead = notifyRead; + this.readyWrite = readyWrite; + this.messageRead = messageRead; + } + + private boolean take() { + return taken.compareAndSet(false, true); + } + + private void close() { + closeQuietly(shm); + closeQuietly(notifyRead); + closeQuietly(readyWrite); + closeQuietly(messageRead); + } + } } diff --git a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt index b8bf6f31e2..228a145356 100644 --- a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt +++ b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt @@ -4,6 +4,9 @@ import android.app.ActivityManager import android.app.ApplicationExitInfo import android.content.ComponentName import android.content.Context +import android.content.ContextWrapper +import android.content.Intent +import android.content.ServiceConnection import android.os.Binder import android.os.Parcel import android.os.ParcelFileDescriptor @@ -15,10 +18,12 @@ import io.sentry.android.core.SentryAndroidOptions import io.sentry.android.core.cache.AndroidEnvelopeCache import io.sentry.ndk.NdkOptions import io.sentry.ndk.SentryNdk.CrashDaemon +import io.sentry.test.DeferredExecutorService import java.io.File import java.io.InputStream import java.util.Date import java.util.concurrent.CountDownLatch +import java.util.concurrent.Executor import java.util.concurrent.LinkedBlockingQueue import java.util.concurrent.TimeUnit import java.util.zip.GZIPInputStream @@ -66,13 +71,48 @@ class SentryNdkCrashServiceTest { } @Test - fun `unbinds when the service does not configure`() { + fun `stays bound when the service does not configure`() { configure(false) Mockito.mockStatic(io.sentry.ndk.SentryNdk::class.java).use { - assertThat(SentryNdkCrashService.start(app, options)).isNull() + val connection = SentryNdkCrashService.start(app, options) - assertThat(shadowOf(app).boundServiceConnections).isEmpty() - assertThat(shadowOf(app).unboundServiceConnections).hasSize(1) + assertThat(connection).isNotNull() + assertThat(shadowOf(app).boundServiceConnections).containsExactly(connection) + assertThat(shadowOf(app).unboundServiceConnections).isEmpty() + } + } + + @Test + fun `starts before the service connects`() { + val context = UnconnectedContext() + options.executorService = DeferredExecutorService() + Mockito.mockStatic(io.sentry.ndk.SentryNdk::class.java).use { native -> + val connection = SentryNdkCrashService.start(context, options) + + assertThat(connection).isNotNull() + assertThat(context.connections).containsExactly(connection) + native.verify { io.sentry.ndk.SentryNdk.initCrashDaemon(any(), any(), any(), any()) } + } + } + + @Test + fun `reattaches a service that connects after the timeout`() { + val binder = configure(true) + val context = UnconnectedContext() + val executor = DeferredExecutorService() + options.executorService = executor + Mockito.mockStatic(io.sentry.ndk.SentryNdk::class.java).use { native -> + native.`when` { io.sentry.ndk.SentryNdk.dupCrashShmFd() }.thenReturn(42) + native + .`when` { io.sentry.ndk.SentryNdk.reattachCrashDaemon(any(), any(), any()) } + .thenReturn(true) + val connection = SentryNdkCrashService.start(context, options)!! + + executor.runAll() + connection.onServiceConnected(component, binder) + + assertThat(binder.transactions).isEqualTo(1) + native.verify { io.sentry.ndk.SentryNdk.reattachCrashDaemon(any(), any(), any()) } } } @@ -439,6 +479,21 @@ class SentryNdkCrashServiceTest { private fun descriptor(fd: Int): ParcelFileDescriptor = mock { on { detachFd() } doReturn fd } + // binds without connecting, as a service process that is still starting + private inner class UnconnectedContext : ContextWrapper(app) { + val connections = mutableListOf() + + override fun bindService( + service: Intent, + flags: Int, + executor: Executor, + conn: ServiceConnection, + ): Boolean { + connections += conn + return true + } + } + private fun configure(configured: Boolean) = object : Binder() { var transactions = 0 From 397fe29c9bb7780d2be16d895265c8e09eb47f26 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 11 Nov 2026 13:39:30 +0100 Subject: [PATCH 02/12] fix(android): Run the NDK crash service below API 30 Nothing in the crash service needs API 30. Drop the check in `SentryNdkOutproc.init()`, and pass the database directory to `SentryNdk.createCrashShm()` so that the crash IPC falls back to a file on kernels without memfd. `Application.getProcessName()` needs API 28, so read the process name from `/proc/self/cmdline` on older versions to skip SDK init in the crash service process. --- .../io/sentry/android/core/SentryAndroid.java | 26 +++++++++++++++---- sentry-android-ndk-outproc/README.md | 3 --- .../ndk/outproc/SentryNdkCrashService.java | 2 +- .../android/ndk/outproc/SentryNdkOutproc.java | 5 ++-- .../android/ndk/outproc/NativeBackendTest.kt | 6 ----- .../ndk/outproc/SentryNdkCrashServiceTest.kt | 2 +- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java b/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java index 7439de759d..d553c4815f 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java @@ -20,6 +20,9 @@ import io.sentry.android.fragment.FragmentLifecycleIntegration; import io.sentry.android.timber.SentryTimberIntegration; import io.sentry.util.AutoClosableReentrantLock; +import io.sentry.util.FileUtils; +import java.io.File; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; @@ -291,13 +294,26 @@ private static void deduplicateIntegrations( } } - // the crash service only runs on API 30+ @SuppressLint("NewApi") private static boolean isNdkCrashServiceProcess() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { - return false; - } - final @Nullable String processName = Application.getProcessName(); + final @Nullable String processName = + Build.VERSION.SDK_INT >= Build.VERSION_CODES.P + ? Application.getProcessName() + : readProcessName(); return processName != null && processName.endsWith(NDK_CRASH_SERVICE_PROCESS_SUFFIX); } + + // argv[0] of an app process is its process name + private static @Nullable String readProcessName() { + try { + final @Nullable String cmdline = FileUtils.readText(new File("/proc/self/cmdline")); + if (cmdline == null) { + return null; + } + final int end = cmdline.indexOf('\0'); + return end >= 0 ? cmdline.substring(0, end) : cmdline; + } catch (IOException e) { + return null; + } + } } diff --git a/sentry-android-ndk-outproc/README.md b/sentry-android-ndk-outproc/README.md index fefcd96da8..7ad125367e 100644 --- a/sentry-android-ndk-outproc/README.md +++ b/sentry-android-ndk-outproc/README.md @@ -16,6 +16,3 @@ configurations.configureEach { ``` Otherwise, the build fails because it contains both native backends. - -The crash service needs API 30+. On older versions, native crash reporting is -disabled. diff --git a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java index 4842f772b3..75b0b88cbd 100644 --- a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java +++ b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java @@ -140,7 +140,7 @@ protected boolean onTransact( return null; } - final int shmFd = io.sentry.ndk.SentryNdk.createCrashShm(); + final int shmFd = io.sentry.ndk.SentryNdk.createCrashShm(nativeDatabaseDir.getPath()); if (shmFd < 0) { options.getLogger().log(SentryLevel.DEBUG, "Failed to create NDK crash shared memory."); return null; diff --git a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java index 0a18bf1966..f7c642ef35 100644 --- a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java +++ b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java @@ -3,7 +3,6 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.ServiceConnection; -import android.os.Build; import io.sentry.SentryIntegrationPackageStorage; import io.sentry.android.core.NdkHandlerStrategy; import io.sentry.android.core.SentryAndroidOptions; @@ -68,8 +67,8 @@ public static void init(@NotNull final SentryAndroidOptions options) { public static void init( @Nullable final Context context, @NotNull final SentryAndroidOptions options) { // no fork/exec fallback, the native crash daemon only runs in the crash service - if (context == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { - throw new IllegalStateException("The NDK crash service needs a context and API 30+"); + if (context == null) { + throw new IllegalStateException("The NDK crash service needs a context"); } addPackage(options.getSdkVersion()); diff --git a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/NativeBackendTest.kt b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/NativeBackendTest.kt index 96a68c1960..58957a7920 100644 --- a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/NativeBackendTest.kt +++ b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/NativeBackendTest.kt @@ -52,12 +52,6 @@ class NativeBackendTest { assertFailsWith { SentryNdkOutproc.init(options()) } } - @Test - @Config(sdk = [29]) - fun `fails below API 30`() { - assertFailsWith { SentryNdkOutproc.init(mock(), options()) } - } - private fun options() = SentryAndroidOptions().apply { dsn = "https://key@sentry.io/proj" diff --git a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt index 228a145356..19a4d7b62e 100644 --- a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt +++ b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt @@ -223,7 +223,7 @@ class SentryNdkCrashServiceTest { fun `init fails without shared memory`() { configure(true) Mockito.mockStatic(io.sentry.ndk.SentryNdk::class.java).use { native -> - native.`when` { io.sentry.ndk.SentryNdk.createCrashShm() }.thenReturn(-1) + native.`when` { io.sentry.ndk.SentryNdk.createCrashShm(any()) }.thenReturn(-1) assertFailsWith { SentryNdkOutproc.init(app, options) } From 1eca50617ad6b7e0543ca956b67be560af6a8f0c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 11 Nov 2026 13:39:30 +0100 Subject: [PATCH 03/12] ci(temp): Publish sentry-native-ndk-outproc from the API 21 branch DO NOT MERGE (revert after releasing getsentry/sentry-native#2301) `SentryNdk.createCrashShm(String)` is not in a sentry-native release yet. Build `sentry-native-ndk-outproc` from the sentry-native branch and publish it to Maven Local under a version that Maven Central does not have, so that Gradle resolves the local build. --- .github/workflows/build.yml | 14 ++++++++++++++ gradle/libs.versions.toml | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 351dd6c3da..4764914a8d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,6 +30,20 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 + # DO NOT MERGE (remove after releasing getsentry/sentry-native#2301) + - name: Checkout sentry-native + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: getsentry/sentry-native + ref: jpnurmi/fix/native-android-21 + path: sentry-native + submodules: 'recursive' + + # DO NOT MERGE (remove after releasing getsentry/sentry-native#2301) + - name: Publish sentry-native-ndk-outproc to Maven Local + working-directory: sentry-native/ndk + run: ./gradlew --no-daemon -PversionName=0.0.0-local :sentry-native-ndk-outproc:publishToMavenLocal + - name: Run Tests and Lint run: make preMerge diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 962544c6dc..c803abb077 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -197,7 +197,7 @@ reactor-core = { module = "io.projectreactor:reactor-core", version = "3.5.3" } retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" } retrofit-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" } sentry-native-ndk = { module = "io.sentry:sentry-native-ndk", version = "0.17.6" } -sentry-native-ndk-outproc = { module = "io.sentry:sentry-native-ndk-outproc", version = "1.0.0-beta.1" } +sentry-native-ndk-outproc = { module = "io.sentry:sentry-native-ndk-outproc", version = "0.0.0-local" } servlet-api = { module = "javax.servlet:javax.servlet-api", version = "3.1.0" } servlet4-api = { module = "javax.servlet:javax.servlet-api", version = "4.0.1" } servlet-jakarta-api = { module = "jakarta.servlet:jakarta.servlet-api", version = "6.1.0" } From 6f5312c39b139a5e8b90c40090b94a8326c6f4e0 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 16 Nov 2026 10:02:38 +0100 Subject: [PATCH 04/12] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f6c22e1d5..8126e03a48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Nav3: Stop attributing errors and spans from an Activity or ViewPager2 page without a `SentryNavEffect` to the most recently visited Nav3 root ([#6483](https://github.com/getsentry/sentry-java/pull/6483)) - Android: Count deep sleep in breadcrumb, screenshot and view hierarchy debounce windows, so the first low-memory or battery breadcrumb after a long Doze is no longer dropped ([#6590](https://github.com/getsentry/sentry-java/pull/6590)) +- 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)) ### Dependencies From a0d588ddde180c0cc3a83f3572d85daa85910eb3 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 16 Nov 2026 10:45:13 +0100 Subject: [PATCH 05/12] fix(android): Rebind the NDK crash service after a late reattach A service that connected after the 10 s timeout reattached, but its connection never counted as configured, so `onBindingDied` didn't bind it again and out-of-process crash handling stayed down for the rest of the session. --- .../ndk/outproc/SentryNdkCrashService.java | 12 +++++++---- .../ndk/outproc/SentryNdkCrashServiceTest.kt | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java index 75b0b88cbd..b4c96b9fb4 100644 --- a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java +++ b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java @@ -255,7 +255,7 @@ public void onServiceConnected( final @NotNull ComponentName name, final @NotNull IBinder service) { if (!ends.take()) { // a restarted or late service process has no daemon for this app - reattach( + if (reattach( service, logger, nativeDatabasePath, @@ -266,7 +266,9 @@ public void onServiceConnected( debug, shutdownTimeoutMillis, includes, - excludes); + excludes)) { + configured = true; + } return; } configured = @@ -347,7 +349,7 @@ private static boolean bind( return context.bindService(intent, connection, flags); } - private static void reattach( + private static boolean reattach( final @NotNull IBinder service, final @NotNull ILogger logger, final @NotNull String nativeDatabasePath, @@ -362,7 +364,7 @@ private static void reattach( final int shmFd = io.sentry.ndk.SentryNdk.dupCrashShmFd(); if (shmFd < 0) { logger.log(SentryLevel.ERROR, "NDK crash service restarted, but the app can't reattach."); - return; + return false; } final ParcelFileDescriptor shm = ParcelFileDescriptor.adoptFd(shmFd); @@ -406,8 +408,10 @@ private static void reattach( } else { logger.log(SentryLevel.ERROR, "NDK crash service restarted, failed to reattach the app."); } + return reattached; } catch (IOException | SecurityException e) { logger.log(SentryLevel.ERROR, e, "Failed to reattach to the NDK crash service."); + return false; } finally { closeQuietly(shm); closeQuietly(notifyRead); diff --git a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt index 19a4d7b62e..3e9e63cbda 100644 --- a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt +++ b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt @@ -219,6 +219,27 @@ class SentryNdkCrashServiceTest { } } + @Test + fun `binds again when the binding of a late service died`() { + val binder = configure(true) + val context = UnconnectedContext() + val executor = DeferredExecutorService() + options.executorService = executor + Mockito.mockStatic(io.sentry.ndk.SentryNdk::class.java).use { native -> + native.`when` { io.sentry.ndk.SentryNdk.dupCrashShmFd() }.thenReturn(42) + native + .`when` { io.sentry.ndk.SentryNdk.reattachCrashDaemon(any(), any(), any()) } + .thenReturn(true) + val connection = SentryNdkCrashService.start(context, options)!! + executor.runAll() + connection.onServiceConnected(component, binder) + + connection.onBindingDied(component) + + assertThat(context.connections).containsExactly(connection, connection) + } + } + @Test fun `init fails without shared memory`() { configure(true) From 24398e27cb846033f210258cbfb887d953054be1 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 19 Nov 2026 13:04:54 +0100 Subject: [PATCH 06/12] fix(android): Skip the NDK crash service process check without outproc Below API 28, the check read `/proc/self/cmdline` on the thread that calls `SentryAndroid.init`, usually the main thread, for every app, which StrictMode flags as a disk read. Only apps with `sentry-android-ndk-outproc` have the crash service process, so check that its class is available first. --- .../io/sentry/android/core/SentryAndroid.java | 4 ++++ .../sentry/android/core/SentryAndroidTest.kt | 24 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java b/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java index d553c4815f..e5558d59c3 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java @@ -296,6 +296,10 @@ private static void deduplicateIntegrations( @SuppressLint("NewApi") private static boolean isNdkCrashServiceProcess() { + if (!new io.sentry.util.LoadClass() + .isClassAvailable(NdkIntegration.SENTRY_NDK_OUTPROC_CLASS_NAME, (ILogger) null)) { + return false; + } final @Nullable String processName = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? Application.getProcessName() diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt index 36a23bf368..bc8df051b3 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt @@ -49,6 +49,7 @@ import io.sentry.protocol.Contexts import io.sentry.spotlight.SpotlightIntegration import io.sentry.test.applyTestOptions import io.sentry.transport.NoOpEnvelopeCache +import io.sentry.util.LoadClass import io.sentry.util.StringUtils import java.io.ByteArrayOutputStream import java.io.File @@ -72,6 +73,7 @@ import org.junit.rules.TemporaryFolder import org.junit.runner.RunWith import org.mockito.Mockito import org.mockito.kotlin.any +import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.eq import org.mockito.kotlin.mock import org.mockito.kotlin.never @@ -580,12 +582,32 @@ class SentryAndroidTest { ShadowApplication.setProcessName("${context.packageName}.sentry_ndk_crash") var configured = false - fixture.initSut { configured = true } + Mockito.mockConstruction(LoadClass::class.java) { loadClass, _ -> + whenever( + loadClass.isClassAvailable( + eq(NdkIntegration.SENTRY_NDK_OUTPROC_CLASS_NAME), + anyOrNull(), + ) + ) + .thenReturn(true) + } + .use { fixture.initSut { configured = true } } assertFalse(configured) assertFalse(Sentry.isEnabled()) } + @Test + @Config(sdk = [30]) + fun `init runs in a process named like the NDK crash service without outproc`() { + ShadowApplication.setProcessName("${context.packageName}.sentry_ndk_crash") + var configured = false + + fixture.initSut { configured = true } + + assertTrue(configured) + } + private fun prefillScopeCache(options: SentryOptions, cacheDir: String) { val scopeDir = File(cacheDir, SCOPE_CACHE).also { it.mkdirs() } val queueFile = QueueFile.Builder(File(scopeDir, BREADCRUMBS_FILENAME)).build() From 0508dbc659ae58ad8e8efe5d51c0b28cc3432ec2 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 19 Nov 2026 13:04:54 +0100 Subject: [PATCH 07/12] fix(android): Use the timer executor for the NDK crash service timeout The connect timeout ran on the executor that also sends cached envelopes, so a slow send could delay it. The timer executor is dedicated to timeouts. --- .../sentry/android/ndk/outproc/SentryNdkCrashService.java | 2 +- .../sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java index b4c96b9fb4..3ae1996d9d 100644 --- a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java +++ b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java @@ -175,7 +175,7 @@ protected boolean onTransact( context, intent, options.getLogger(), - options.getExecutorService(), + options.getTimerExecutorService(), nativeDatabaseDir.getPath(), context.getApplicationInfo().nativeLibraryDir, Process.myPid(), diff --git a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt index 3e9e63cbda..44824b7faa 100644 --- a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt +++ b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt @@ -85,7 +85,7 @@ class SentryNdkCrashServiceTest { @Test fun `starts before the service connects`() { val context = UnconnectedContext() - options.executorService = DeferredExecutorService() + options.timerExecutorService = DeferredExecutorService() Mockito.mockStatic(io.sentry.ndk.SentryNdk::class.java).use { native -> val connection = SentryNdkCrashService.start(context, options) @@ -100,7 +100,7 @@ class SentryNdkCrashServiceTest { val binder = configure(true) val context = UnconnectedContext() val executor = DeferredExecutorService() - options.executorService = executor + options.timerExecutorService = executor Mockito.mockStatic(io.sentry.ndk.SentryNdk::class.java).use { native -> native.`when` { io.sentry.ndk.SentryNdk.dupCrashShmFd() }.thenReturn(42) native @@ -224,7 +224,7 @@ class SentryNdkCrashServiceTest { val binder = configure(true) val context = UnconnectedContext() val executor = DeferredExecutorService() - options.executorService = executor + options.timerExecutorService = executor Mockito.mockStatic(io.sentry.ndk.SentryNdk::class.java).use { native -> native.`when` { io.sentry.ndk.SentryNdk.dupCrashShmFd() }.thenReturn(42) native From 52342934774ab87ac825107a2f13599d880e54db Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 19 Nov 2026 13:06:56 +0000 Subject: [PATCH 08/12] Format code --- .../src/test/java/io/sentry/android/core/SentryAndroidTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt index 678df387e6..6f4a107306 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt @@ -587,7 +587,7 @@ class SentryAndroidTest { loadClass.isClassAvailable( eq(NdkIntegration.SENTRY_NDK_OUTPROC_CLASS_NAME), anyOrNull(), - ) + ), ) .thenReturn(true) } From c92297c5a9ab9421c1f3d0c6d34fec97934d8554 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 20 Nov 2026 09:05:02 +0100 Subject: [PATCH 09/12] Update CHANGELOG.md Move the future item into its own separate section to reduce changelog conflicts. --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 514ad71ebd..843957c43b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,18 @@ > - Java 8 support will be dropped. SDK 9.0.0 requires Java 11+. See [#6469](https://github.com/getsentry/sentry-java/issues/6469). > - The Android `minSdk` will be raised from 21 to 24. See [#5508](https://github.com/getsentry/sentry-java/issues/5508). +## Future (TODO: release sentry-native#2301) + +### Fixes + +- 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)) + ## Unreleased ### Fixes - Kotlin now sees `Attachment.getBytes()`, `Device.getArchs()`, `Spring.getActiveProfiles()` and `JsonSerializationUtils.bytesFrom(...)` as nullable, because `@Nullable` now annotates the returned array instead of its elements ([#6558](https://github.com/getsentry/sentry-java/pull/6558)) - Shake-to-report no longer leaks the first Activity that resumes after `Sentry.init` ([#6686](https://github.com/getsentry/sentry-java/pull/6686)) -- 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)) ## 8.65.0 From 97adebf4498832af74ffa65c1972b9ffb4e3d294 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 20 Nov 2026 09:34:27 +0100 Subject: [PATCH 10/12] fix(android): Close the NDK crash service ends on close `SentryNdkCrashService.start` returns before the service connects, so the service's ends of the crash IPC wait for the connection or the 10 s timeout. `SentryNdkOutproc.close` only unbound the service, and a non-restarting `Sentry.close` drops the pending timeout, which left the descriptors to the finalizer. Close the ends that no connection took when unbinding. --- .../ndk/outproc/SentryNdkCrashService.java | 23 +++++++++++++++---- .../android/ndk/outproc/SentryNdkOutproc.java | 8 +++---- .../android/ndk/outproc/NativeBackendTest.kt | 7 +++--- .../ndk/outproc/SentryNdkCrashServiceTest.kt | 16 +++++++++++++ 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java index 3ae1996d9d..0a08e8345f 100644 --- a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java +++ b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkCrashService.java @@ -113,7 +113,7 @@ protected boolean onTransact( } }; - static @Nullable ServiceConnection start( + static @Nullable Connection start( final @NotNull Context context, final @NotNull SentryAndroidOptions options) { // fail before binding, the crash daemon can't attach without the native libraries io.sentry.ndk.SentryNdk.loadNativeLibraries(); @@ -170,7 +170,7 @@ protected boolean onTransact( messageRead = null; final Intent intent = new Intent(context, SentryNdkCrashService.class); - final @Nullable ServiceConnection connection = + final @Nullable Connection connection = configureService( context, intent, @@ -228,7 +228,7 @@ private static void closeQuietly(final @Nullable Closeable closeable) { } } - private static @Nullable ServiceConnection configureService( + private static @Nullable Connection configureService( final @NotNull Context context, final @NotNull Intent intent, final @NotNull ILogger logger, @@ -246,8 +246,8 @@ private static void closeQuietly(final @Nullable Closeable closeable) { // a foreground app raises the service process only to visible without BIND_IMPORTANT final int flags = Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT; - final ServiceConnection connection = - new ServiceConnection() { + final Connection connection = + new Connection() { private volatile boolean configured; @Override @@ -307,6 +307,13 @@ public void onBindingDied(final @NotNull ComponentName name) { bind(context, intent, flags, this); } } + + @Override + public void close() { + if (ends.take()) { + ends.close(); + } + } }; boolean bound = false; @@ -830,6 +837,12 @@ private DaemonConfig( } } + // closes the service's ends of the crash IPC unless a connection took them + abstract static class Connection implements ServiceConnection, Closeable { + @Override + public abstract void close(); + } + // the service's ends of the crash IPC, handed over on the first connection or closed private static final class ServiceEnds { private final @NotNull AtomicBoolean taken = new AtomicBoolean(); diff --git a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java index f7c642ef35..d36a4a777e 100644 --- a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java +++ b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java @@ -2,7 +2,6 @@ import android.annotation.SuppressLint; import android.content.Context; -import android.content.ServiceConnection; import io.sentry.SentryIntegrationPackageStorage; import io.sentry.android.core.NdkHandlerStrategy; import io.sentry.android.core.SentryAndroidOptions; @@ -28,7 +27,7 @@ public final class SentryNdkOutproc { @SuppressLint("StaticFieldLeak") // the application context from NdkIntegration private static @Nullable Context serviceContext; - private static @Nullable ServiceConnection serviceConnection; + private static @Nullable SentryNdkCrashService.Connection serviceConnection; private SentryNdkOutproc() {} @@ -106,7 +105,7 @@ public static void init( ndkOptions.setEnableAppHangTracking(options.isEnableNdkAppHangTracking()); ndkOptions.setAppHangTimeoutMillis(options.getNdkAppHangTimeoutIntervalMillis()); - final @Nullable ServiceConnection connection = + final @Nullable SentryNdkCrashService.Connection connection = SentryNdkCrashService.start(context, options); if (connection == null) { throw new IllegalStateException("Failed to start the NDK crash service"); @@ -167,11 +166,12 @@ private static void addPackage(final @Nullable SdkVersion sdkVersion) { private static void unbindCrashService() { final @Nullable Context context = serviceContext; - final @Nullable ServiceConnection connection = serviceConnection; + final @Nullable SentryNdkCrashService.Connection connection = serviceConnection; serviceContext = null; serviceConnection = null; if (context != null && connection != null) { context.unbindService(connection); + connection.close(); } } } diff --git a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/NativeBackendTest.kt b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/NativeBackendTest.kt index 2a0be762fd..8169bbc197 100644 --- a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/NativeBackendTest.kt +++ b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/NativeBackendTest.kt @@ -1,7 +1,6 @@ package io.sentry.android.ndk.outproc import android.content.Context -import android.content.ServiceConnection import com.google.common.truth.Truth.assertThat import io.sentry.android.core.SentryAndroidOptions import io.sentry.ndk.NdkOptions @@ -73,8 +72,10 @@ class NativeBackendTest { .`when` { io.sentry.ndk.SentryNdk.init(any()) } .doAnswer { captured = it.arguments[0] as NdkOptions } service - .`when` { SentryNdkCrashService.start(context, options) } - .thenReturn(mock()) + .`when` { + SentryNdkCrashService.start(context, options) + } + .thenReturn(mock()) SentryNdkOutproc.init(context, options) diff --git a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt index 7f89a7a0b1..701fc4d896 100644 --- a/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt +++ b/sentry-android-ndk-outproc/src/test/java/io/sentry/android/ndk/outproc/SentryNdkCrashServiceTest.kt @@ -145,6 +145,22 @@ class SentryNdkCrashServiceTest { } } + @Test + fun `close releases the service ends before the service connects`() { + val binder = configure(true) + val context = UnconnectedContext() + options.timerExecutorService = DeferredExecutorService() + Mockito.mockStatic(io.sentry.ndk.SentryNdk::class.java).use { native -> + native.`when` { io.sentry.ndk.SentryNdk.dupCrashShmFd() }.thenReturn(-1) + val connection = SentryNdkCrashService.start(context, options)!! + + connection.close() + connection.onServiceConnected(component, binder) + + assertThat(binder.transactions).isEqualTo(0) + } + } + @Test fun `init unbinds when native init fails`() { configure(true) From da0f72912b19b03bdb10fc5f91be65097d6b9764 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 20 Nov 2026 09:47:00 +0100 Subject: [PATCH 11/12] fix(android): Close the NDK crash service ends if unbinding throws `Context.unbindService` throws for a connection that is not registered, which skipped closing the service's ends of the crash IPC. --- .../io/sentry/android/ndk/outproc/SentryNdkOutproc.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java index d36a4a777e..38c158ce14 100644 --- a/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java +++ b/sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/outproc/SentryNdkOutproc.java @@ -170,8 +170,11 @@ private static void unbindCrashService() { serviceContext = null; serviceConnection = null; if (context != null && connection != null) { - context.unbindService(connection); - connection.close(); + try { + context.unbindService(connection); + } finally { + connection.close(); + } } } } From 3d985d907be89849f2e96c1cdae9801ce32bbd13 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 20 Nov 2026 10:20:31 +0100 Subject: [PATCH 12/12] test(android): Set the DSN in the NDK crash service process name test The test relied on the manifest DSN, which `ContextUtils` caches statically per Robolectric SDK sandbox. When another test class had cached the app info without a DSN first, `SentryAndroid.init` failed. --- .../test/java/io/sentry/android/core/SentryAndroidTest.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt index 6f4a107306..08eecc00c4 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt @@ -603,7 +603,10 @@ class SentryAndroidTest { ShadowApplication.setProcessName("${context.packageName}.sentry_ndk_crash") var configured = false - fixture.initSut { configured = true } + fixture.initSut { + it.dsn = "https://key@sentry.io/123" + configured = true + } assertTrue(configured) }