Skip to content

AppStartMetrics crashes in isolated process (WebView) on API 35+ #5596

Description

@michaelchai-sentry

AppStartMetrics.registerLifecycleCallbacks calls ActivityManager.getHistoricalProcessStartReasons() unconditionally on API 35+ (Android 15). When the app uses a WebView, Android spawns an isolated WebView process and calls Application.onCreate within it. Isolated processes are sandboxed and cannot make this IPC call, resulting in a fatal SecurityException that crashes the app before Sentry can capture it.

Root cause

registerLifecycleCallbacks (introduced for ApplicationStartInfo support on API 35+) does not guard against the isolated-process context:

// AppStartMetrics.java
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
    final ActivityManager activityManager =
        (ActivityManager) application.getSystemService(Context.ACTIVITY_SERVICE);
    if (activityManager != null) {
        // Throws SecurityException in isolated processes (e.g. WebView process)
        final List<ApplicationStartInfo> historicalProcessStartReasons =
            activityManager.getHistoricalProcessStartReasons(1);
        ...
    }
}

Android enforces that isolated processes (see ActivityManagerService.enforceNotIsolatedCaller) cannot call getHistoricalProcessStartReasons. The WebView process runs Application.onCreate in this isolated context, triggering the crash.

Stack trace (sanitized)

java.lang.RuntimeException
  at android.app.ActivityThread.handleBindApplication
  ...
Caused by java.lang.SecurityException: Isolated process not allowed to call getHistoricalProcessStartReasons
  at android.app.ActivityManager.getHistoricalProcessStartReasons
  at io.sentry.android.core.performance.AppStartMetrics.registerLifecycleCallbacks (AppStartMetrics.java:346)
  at io.sentry.android.core.performance.AppStartMetrics.onApplicationCreate (AppStartMetrics.java:307)
  at android.app.ActivityThread.handleBindApplication
  ...
Caused by android.os.RemoteException: Remote stack trace:
  at com.android.server.am.ActivityManagerService.enforceNotIsolatedCaller
  at com.android.server.am.ActivityManagerService.getHistoricalProcessStartReasons
  ...

Reproduction

  1. Initialize Sentry Android SDK on API 35+ (Android 15) in an app that uses WebView.
  2. Launch the app — Android spins up an isolated WebView process.
  3. AppStartMetrics.registerLifecycleCallbacks fires inside the isolated process and crashes on getHistoricalProcessStartReasons.

Expected behavior

SDK should skip the getHistoricalProcessStartReasons call (and ideally all app-start tracking) when running in an isolated process.

Workaround

Guard Sentry initialization to the main process only:

if (!android.os.Process.isIsolated()) {
    SentryAndroid.init(context) { options -> ... }
}

Affected versions

Confirmed present in sentry-java 8.37.1 (shipped with @sentry/react-native 8.7.0) and verified unpatched in current main (8.44.1). No existing issue or PR found tracking this.

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

Status
Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions