File tree Expand file tree Collapse file tree
sentry-android-core/src/main/java/io/sentry/android/core
sentry-android-ndk-outproc
main/java/io/sentry/android/ndk/outproc
test/java/io/sentry/android/ndk/outproc Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020import io .sentry .android .fragment .FragmentLifecycleIntegration ;
2121import io .sentry .android .timber .SentryTimberIntegration ;
2222import io .sentry .util .AutoClosableReentrantLock ;
23+ import io .sentry .util .FileUtils ;
24+ import java .io .File ;
25+ import java .io .IOException ;
2326import java .lang .reflect .InvocationTargetException ;
2427import java .util .ArrayList ;
2528import java .util .List ;
@@ -291,13 +294,26 @@ private static void deduplicateIntegrations(
291294 }
292295 }
293296
294- // the crash service only runs on API 30+
295297 @ SuppressLint ("NewApi" )
296298 private static boolean isNdkCrashServiceProcess () {
297- if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . P ) {
298- return false ;
299- }
300- final @ Nullable String processName = Application . getProcessName ();
299+ final @ Nullable String processName =
300+ Build . VERSION . SDK_INT >= Build . VERSION_CODES . P
301+ ? Application . getProcessName ()
302+ : readProcessName ();
301303 return processName != null && processName .endsWith (NDK_CRASH_SERVICE_PROCESS_SUFFIX );
302304 }
305+
306+ // argv[0] of an app process is its process name
307+ private static @ Nullable String readProcessName () {
308+ try {
309+ final @ Nullable String cmdline = FileUtils .readText (new File ("/proc/self/cmdline" ));
310+ if (cmdline == null ) {
311+ return null ;
312+ }
313+ final int end = cmdline .indexOf ('\0' );
314+ return end >= 0 ? cmdline .substring (0 , end ) : cmdline ;
315+ } catch (IOException e ) {
316+ return null ;
317+ }
318+ }
303319}
Original file line number Diff line number Diff line change @@ -16,6 +16,3 @@ configurations.configureEach {
1616```
1717
1818Otherwise, the build fails because it contains both native backends.
19-
20- The crash service needs API 30+. On older versions, native crash reporting is
21- disabled.
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ protected boolean onTransact(
140140 return null ;
141141 }
142142
143- final int shmFd = io .sentry .ndk .SentryNdk .createCrashShm ();
143+ final int shmFd = io .sentry .ndk .SentryNdk .createCrashShm (nativeDatabaseDir . getPath () );
144144 if (shmFd < 0 ) {
145145 options .getLogger ().log (SentryLevel .DEBUG , "Failed to create NDK crash shared memory." );
146146 return null ;
Original file line number Diff line number Diff line change 33import android .annotation .SuppressLint ;
44import android .content .Context ;
55import android .content .ServiceConnection ;
6- import android .os .Build ;
76import io .sentry .SentryIntegrationPackageStorage ;
87import io .sentry .android .core .NdkHandlerStrategy ;
98import io .sentry .android .core .SentryAndroidOptions ;
@@ -68,8 +67,8 @@ public static void init(@NotNull final SentryAndroidOptions options) {
6867 public static void init (
6968 @ Nullable final Context context , @ NotNull final SentryAndroidOptions options ) {
7069 // no fork/exec fallback, the native crash daemon only runs in the crash service
71- if (context == null || Build . VERSION . SDK_INT < Build . VERSION_CODES . R ) {
72- throw new IllegalStateException ("The NDK crash service needs a context and API 30+ " );
70+ if (context == null ) {
71+ throw new IllegalStateException ("The NDK crash service needs a context" );
7372 }
7473
7574 addPackage (options .getSdkVersion ());
Original file line number Diff line number Diff line change @@ -52,12 +52,6 @@ class NativeBackendTest {
5252 assertFailsWith<IllegalStateException > { SentryNdkOutproc .init (options()) }
5353 }
5454
55- @Test
56- @Config(sdk = [29 ])
57- fun `fails below API 30` () {
58- assertFailsWith<IllegalStateException > { SentryNdkOutproc .init (mock<Context >(), options()) }
59- }
60-
6155 private fun options () =
6256 SentryAndroidOptions ().apply {
6357 dsn = " https://key@sentry.io/proj"
Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ class SentryNdkCrashServiceTest {
223223 fun `init fails without shared memory` () {
224224 configure(true )
225225 Mockito .mockStatic(io.sentry.ndk.SentryNdk ::class .java).use { native ->
226- native.`when `<Int > { io.sentry.ndk.SentryNdk .createCrashShm() }.thenReturn(- 1 )
226+ native.`when `<Int > { io.sentry.ndk.SentryNdk .createCrashShm(any< String >() ) }.thenReturn(- 1 )
227227
228228 assertFailsWith<IllegalStateException > { SentryNdkOutproc .init (app, options) }
229229
You can’t perform that action at this time.
0 commit comments