Skip to content

Commit a36c1e5

Browse files
committed
fix(android): Bind the NDK crash service as important
Without `BIND_IMPORTANT`, a foreground app raises its bound crash service process only to the visible oom adj (100), so lmkd would kill the service before the app under memory pressure. The flag gives the service the app's own adj (0) while the app is on top, without lowering the app's priority the way `BIND_ABOVE_CLIENT` would.
1 parent 390f348 commit a36c1e5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎sentry-android-ndk-outproc/src/main/java/io/sentry/android/ndk/SentryNdkCrashService.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,13 @@ public void onBindingDied(final @NotNull ComponentName name) {
304304
}
305305
};
306306

307+
// a foreground app raises the service process only to visible without BIND_IMPORTANT
308+
final int flags = Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT;
307309
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
308310
// deliver callbacks on the binder thread, the caller blocks on the latch
309-
bound[0] = context.bindService(intent, Context.BIND_AUTO_CREATE, Runnable::run, connection);
311+
bound[0] = context.bindService(intent, flags, Runnable::run, connection);
310312
} else {
311-
bound[0] = context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
313+
bound[0] = context.bindService(intent, connection, flags);
312314
}
313315
if (!bound[0]) {
314316
return null;

0 commit comments

Comments
 (0)