Skip to content

[Android] Integrate exit code handling into process_handler - #5455

Merged
IvanBM18 merged 3 commits into
feature/android-exit-code-corefrom
feature/android-exit-code-process-handler
Sep 11, 2026
Merged

[Android] Integrate exit code handling into process_handler#5455
IvanBM18 merged 3 commits into
feature/android-exit-code-corefrom
feature/android-exit-code-process-handler

Conversation

@IvanBM18

@IvanBM18 IvanBM18 commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Bug: b/553141628

Overview

Since Android API level 30 (and apps targeting Android 11+), apps have scoped storage access. am start process execution does not report exit codes on activity crashes, returning 0 even when native crashes occur.

This PR integrates Android activity crash detection and reboot tracking into process_handler.run_process(), ensuring process return codes accurately reflect native crashes (e.g. SIGSEGV, SIGABRT) or device reboots at test case executions. We also correct an intermittent issue in which the time since the last reboot vs time since activity launched was calculated incorrectly.

Changes

  • src/clusterfuzz/_internal/system/process_handler.py: Integrated activity_crashed_by_package() check and reboot validation in run_process() for Android.
  • src/clusterfuzz/_internal/tests/core/system/process_handler_test.py: Added unit tests for Android activity crash and clean exit handling in run_process().

Tests performed

Basically the same as the parent PR

reason=2 (SIGNALED) subreason=0 (UNKNOWN) status=9

When this happen now CF correctly determines that the app crashed due to runtime issues not related to memory errors.

PR stack

  • master
    • #PR 2.1a feature/android-exit-code-constants
    • #PR 2.1b feature/android-exit-code-core
    • #PR 2.2 feature/android-exit-code-process-handler 👈
    • #PR 2.3 feature/android-bad-build-check

@IvanBM18
IvanBM18 requested a review from a team as a code owner September 3, 2026 20:47
@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-process-handler branch from 95569d8 to b5f8edb Compare September 3, 2026 20:59
@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-process-handler branch from b5f8edb to 1d4dda2 Compare September 3, 2026 21:12
@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-process-handler branch 2 times, most recently from 8f902fa to ac29a1f Compare September 3, 2026 21:26
@IvanBM18 IvanBM18 self-assigned this Sep 3, 2026
@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-process-handler branch from ac29a1f to 34c7b78 Compare September 3, 2026 21:50

@Xeicker Xeicker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't quite get why it is an issue that the uptime is calculated incorrectly and how it is related to the returning codes issue.
Not that it shouldn't be fixed, just curious why to integrate it in the stacked PRs

logs.warning(f'Activity Crashed with: {exit_info}')
return_code = exit_info.reason

elif android.constants.LOW_MEMORY_REGEX.search(output):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: I would use exit reason low memory. I'd consider that a bit more consistent

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Currently when memory on the device is low, CF performs a reset on the device and then continues the execution without marking the test case or the bad build check as a crash, returning a non 0 exit reason here would change that, so i don't think this one is feasable.

@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-process-handler branch from 34c7b78 to b6cfae0 Compare September 4, 2026 22:30

@dylanjew dylanjew left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Comment thread src/clusterfuzz/_internal/tests/core/system/process_handler_test.py Outdated
@IvanBM18

IvanBM18 commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

I don't quite get why it is an issue that the uptime is calculated incorrectly and how it is related to the returning codes issue. Not that it shouldn't be fixed, just curious why to integrate it in the stacked PRs

Answering your 'uptime calculation question' When testing this changes i performed quite a ton of tests, and i saw that intermittently CF marked the test case as a failure because of this, even though i was seeing the test case execution directly on the avd's screen, and since the fix was a small pretty straight forward one i figured that it might fit into this small pr of changes in this stack

@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-process-handler branch from a7adff5 to 15461cf Compare September 8, 2026 17:39

@decoNR decoNR 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.

Please resolve comments before merging.

if android.constants.LOW_MEMORY_REGEX.search(output):
if android.util.activity_crashed(exit_info):
logs.warning(f'Activity Crashed with: {exit_info}')
return_code = exit_info.reason

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.

Just to confirm, it seems that return_code can be overwritten, could this cause any issues?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Other than bringing more clarity it shouldn't bring any issues, actually in this method we usually change the return_code to tell callers if the invoked process crashed, see example:

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.

What I meant is that the value assigned to return_code here can be overwritten later in the function.

I just wanted to flag this to confirm if it is not a problem.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You are right, i see it can be overwritten to

return_code = 1

If there was a memory crash... this seems very delicate so I'll add a log there to note the dev that the return_code was modified midflight.
Thanks for catching that!

@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-process-handler branch from 1b60828 to 0a7db63 Compare September 11, 2026 20:33
@IvanBM18
IvanBM18 merged commit aa07871 into master Sep 11, 2026
13 checks passed
@IvanBM18
IvanBM18 deleted the feature/android-exit-code-process-handler branch September 11, 2026 20:34
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.

4 participants