Skip reporting ANR on zero pid process

Though currently the only case is from broadcast timeout
on a process forking by unresponsive webview_zygote, skip
the case to avoid noise reports.

Bug: 227349843
Test: AnrHelperTest
Change-Id: I433c4d33e14619bec764b99a1334ebe7c6137bb0
This commit is contained in:
Riddle Hsu
2022-03-30 16:02:12 +08:00
parent 525ddc37e4
commit 6de944c27a
2 changed files with 6 additions and 1 deletions

View File

@@ -79,6 +79,11 @@ class AnrHelper {
WindowProcessController parentProcess, boolean aboveSystem, String annotation) {
final int incomingPid = anrProcess.mPid;
synchronized (mAnrRecords) {
if (incomingPid == 0) {
// Extreme corner case such as zygote is no response to return pid for the process.
Slog.i(TAG, "Skip zero pid ANR, process=" + anrProcess.processName);
return;
}
if (mProcessingPid == incomingPid) {
Slog.i(TAG, "Skip duplicated ANR, pid=" + incomingPid + " " + annotation);
return;

View File

@@ -70,6 +70,7 @@ public class AnrHelperTest {
final Context context = getInstrumentation().getTargetContext();
runWithDexmakerShareClassLoader(() -> {
mAnrApp = mock(ProcessRecord.class);
mAnrApp.mPid = 12345;
final ProcessErrorStateRecord errorState = mock(ProcessErrorStateRecord.class);
setFieldValue(ProcessErrorStateRecord.class, errorState, "mProcLock",
new ActivityManagerProcLock());
@@ -130,7 +131,6 @@ public class AnrHelperTest {
}).when(mAnrApp.mErrorState).appNotResponding(anyString(), any(), any(), any(),
anyBoolean(), anyString(), anyBoolean());
final ApplicationInfo appInfo = new ApplicationInfo();
mAnrApp.mPid = 12345;
final Runnable reportAnr = () -> mAnrHelper.appNotResponding(mAnrApp,
"activityShortComponentName", appInfo, "parentShortComponentName",
null /* parentProcess */, false /* aboveSystem */, "annotation");