Skip to content

[Android] Implement exit info extraction and process crash parsing - #5454

Open
IvanBM18 wants to merge 5 commits into
feature/android-exit-code-constantsfrom
feature/android-exit-code-core
Open

[Android] Implement exit info extraction and process crash parsing#5454
IvanBM18 wants to merge 5 commits into
feature/android-exit-code-constantsfrom
feature/android-exit-code-core

Conversation

@IvanBM18

@IvanBM18 IvanBM18 commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Bug: b/553141628

Overview

Since Android API level 30 (and all apps targeting Android 11+), Android introduced ApplicationExitInfo to report process exit reasons and historical diagnostic metadata via dumpsys activity exit-info.

Testcase execution using am start almost 99% of the time returns exit code 0 regardless of whether the activity crashed or failed. To overcome this, this PR introduces core helper utilities to fetch dumpsys activity exit-info via ADB, extract process PIDs from ActivityManager logcat output, parse termination metadata, and evaluate activity crashes.

Learn more:
https://developer.android.com/reference/android/app/ApplicationExitInfo

Changes

  • src/clusterfuzz/_internal/platforms/android/adb.py: Added get_activity_exit_info() to fetch dumpsys exit metadata for a package.
  • src/clusterfuzz/_internal/platforms/android/logger.py: Added log_activity_manager_output() helper to read ActivityManager logcat entries.
  • src/clusterfuzz/_internal/platforms/android/util.py: Implemented get_latest_pid_for_package(), get_exit_info_for_pid(), activity_crashed(), and activity_crashed_by_package().
  • src/clusterfuzz/_internal/tests/core/platforms/android/util_test.py: Added comprehensive unit tests for PID retrieval, exit-info parsing, and crash evaluation.

Tests performed

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-core branch from 2ee401b to 06ad0cc Compare September 3, 2026 20:59
@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-core branch 2 times, most recently from 0d0746c to 0081f44 Compare September 3, 2026 21:20
@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-core branch from 0081f44 to 4e5b219 Compare September 3, 2026 21:26
@IvanBM18 IvanBM18 self-assigned this Sep 3, 2026
@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-core branch from 1c4eb3d to 926e938 Compare September 3, 2026 21:50
Comment thread src/clusterfuzz/_internal/platforms/android/adb.py
PID of the package's latest process if found, None otherwise.
"""
if not app_package:
return None

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.

it might be helpful to log these cases. When would you expect app_package or logcat_output to be None?

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.

Sure, adding log!

the app's package should never be empty in a blackbox android fuzzing session, its catched very early into the session execution(top of my mind, in bad build check)

But i added this validations if someone ever calls this method in a CG fuzzing session.

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.

on the contrary logcat output shouldn't be empty if we are launching activities... but again in CG fuzzing this may not be the case, would have to monitor this changes for CG once they land

ProcessExitInfo object if metadata for target_pid is found and parsed,
None otherwise.
"""
if not app_package or target_pid is None:

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.

same question here

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.

Dito ^.

BUT worth noting that if a pkg doesn't have exit info it means that is still running

Comment thread src/clusterfuzz/_internal/platforms/android/util.py Outdated
Comment thread src/clusterfuzz/_internal/platforms/android/util.py Outdated
Comment thread src/clusterfuzz/_internal/platforms/android/util.py
Returns:
Dumpsys output for the application package.
"""
dumpsys_output = run_shell_command(

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.

how long is the dumpsys activity kept around? And is it written to immediately following a crash?

This approach seems like it would work but it's a bit indirect

@IvanBM18 IvanBM18 Sep 4, 2026

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.

Is persistent in the disk, but it can be deleted using:
adb shell am clear-exit-info [<PACKAGE>]
adb uninstall <app>

@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-core branch from 926e938 to 52bdb16 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, same question about checking with GOSST for the Android instance

Comment thread src/clusterfuzz/_internal/platforms/android/adb.py
try:
return enum_cls(int(raw_value))
except (ValueError, TypeError):
return None

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: add a log so that this doesn't silently lose the input

Comment thread src/clusterfuzz/_internal/tests/core/platforms/android/util_test.py Outdated
@IvanBM18
IvanBM18 force-pushed the feature/android-exit-code-core branch from c3e42ea to 756a828 Compare September 8, 2026 17:39
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