Skip to content

Crashlytics: report previous-run ANRs in didCrashOnPreviousExecution()#8250

Open
jrodiz wants to merge 3 commits into
firebase:feature/didCrashAnrfrom
jrodiz:feature/jrc--Issue4201-2.API.to.check.previous.ANR
Open

Crashlytics: report previous-run ANRs in didCrashOnPreviousExecution()#8250
jrodiz wants to merge 3 commits into
firebase:feature/didCrashAnrfrom
jrodiz:feature/jrc--Issue4201-2.API.to.check.previous.ANR

Conversation

@jrodiz

@jrodiz jrodiz commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Report previous-run ANRs in didCrashOnPreviousExecution()

Implements #4201.

FirebaseCrashlytics.didCrashOnPreviousExecution() now returns true when the previous run ended with an ANR, in addition to JVM and native crashes. ANR detection requires API 30+ (ApplicationExitInfo); on older devices the ANR contribution is always false. No new public API.

How

On the next launch, Crashlytics already runs finalizeSessions()writeApplicationExitInfoEventIfRelevant() on a background worker to attach any ANR from the previous session. This records that result in a didPreviousExecutionEndWithAnr flag (via the new SessionReportingCoordinator.didRelevantAnrOccur(...)) and ORs it into didCrashOnPreviousExecution() — no main-thread blocking and no extra system query.

Tests

  • Unit (Robolectric): didRelevantAnrOccur across four branches; finalizeSessions sets / leaves the flag; no-ANR onPreExecutedidCrashOnPreviousExecution() is false.

  • Verified on a physical device (Galaxy S25 Ultra, API 36): clean launch → false; after a real ANR (OS records reason=6 (ANR)), relaunch → true. Reproducible end-to-end with the sample app at jrodiz/repro4201 (tap-to-ANR, then relaunch).

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@jrodiz

jrodiz commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates didCrashOnPreviousExecution() to return true if the previous run ended with an Application Not Responding (ANR) event on Android API level 30 or above. Feedback on these changes highlights a potential race condition where asynchronous background initialization might cause didCrashOnPreviousExecution() to return a false negative during early app startup; performing the ANR check synchronously on the background worker thread is suggested as a remedy. Additionally, it is recommended to replace Thread.sleep() in the newly added unit tests with robust synchronization (such as awaiting a Future or using a CountDownLatch) to avoid test flakiness.

@jrodiz jrodiz requested a review from mrober June 2, 2026 23:28
Replaced "e.g." and "i.e." with "for example" and "that is" throughout
the documentation comments to improve readability and style.

NO_RELEASE_CHANGE
mrober
mrober previously approved these changes Jun 26, 2026

@mrober mrober left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just 1 question. But please merge this into feature/didCrashAnr branch because this is a change to the behaviour of a public api


// Set during initialization's session finalization when the previous session ended with an ANR,
// so didCrashOnPreviousExecution() reports ANRs alongside JVM and native crashes.
private volatile boolean didPreviousExecutionEndWithAnr = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be volatile?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Written on background worker (finalizeSessions), read on caller/main thread via public didCrashOnPreviousExecution(), so volatile is needed for visibility

rlazo and others added 2 commits June 26, 2026 17:28
Replace the abbreviation "e.g." with "for example" in the Javadoc for
the experimentInfoMap parameter to improve readability.

NO_RELEASE_CHANGE
Detect ANRs during the existing non-blocking finalizeSessions flow and fold the
result into didCrashOnPreviousExecution(), so it returns true for ANRs alongside
JVM and native crashes (API 30+). Implements firebase#4201.
@jrodiz jrodiz force-pushed the feature/jrc--Issue4201-2.API.to.check.previous.ANR branch from 472ec56 to e6689fd Compare June 26, 2026 21:36
@jrodiz jrodiz changed the base branch from main to feature/didCrashAnr June 26, 2026 21:37
@jrodiz jrodiz requested a review from mrober June 26, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants