Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Fixes

- 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))
- 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

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,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 = "1.0.0-beta.2" }
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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -290,13 +293,30 @@ 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) {
if (!new io.sentry.util.LoadClass()
.isClassAvailable(NdkIntegration.SENTRY_NDK_OUTPROC_CLASS_NAME, (ILogger) null)) {
return false;
}
final @Nullable String processName = Application.getProcessName();
final @Nullable String processName =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
? Application.getProcessName()
: readProcessName();
Comment thread
jpnurmi marked this conversation as resolved.
Resolved
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -580,12 +582,35 @@ 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<ILogger>(),
),
)
.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 {
it.dsn = "https://[email protected]/123"
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()
Expand Down
3 changes: 0 additions & 3 deletions sentry-android-ndk-outproc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Loading
Loading