From 221c72ded1eff65a8f8ae6346315972501998f23 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Tue, 22 Feb 2022 23:21:15 +0800 Subject: [PATCH] Remove process association if it is known to be dead Otherwise because ActivityRecord#launchFailed is set to true on first failure and other places still try to resume/start it by the existing process, which causes 2nd failure and then removes the activity record. The case can happen when the binder buffer of the app is full or the process becomes zombie state. Because the argument knownToBeDead will request to kill the existing process and start a new one. With removing the record of window process controller, it won't resume the died app again. While the old process is died and new process is attached, the activity record on top can still become alive again. Bug: 220859166 Test: Add below test code at the beginning of ClientLifecycleManager#scheduleTransaction ActivityRecord a = ActivityRecord.forTokenLocked( transaction.getActivityToken()); if (a != null && a.app != null && a.app.getPid() == SystemProperties.getInt("p", -1)) { throw new RemoteException("test"); } Use "adb shell setprop p $pid" for a background activity. After starting it again to resume it, the old process will be killed and the activity can be launched successfully with new process. Change-Id: I30cbd8386ea3a4c4c3c76426b5d0966ea6d67575 --- .../java/com/android/server/wm/ActivityTaskSupervisor.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java index 3d7dead7d4c03..d4e3b3177ac03 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java +++ b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java @@ -954,7 +954,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks { // This is the first time we failed -- restart process and // retry. r.launchFailed = true; - proc.removeActivity(r, true /* keepAssociation */); + r.detachFromProcess(); throw e; } } finally { @@ -1046,6 +1046,9 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks { // If a dead object exception was thrown -- fall through to // restart the application. knownToBeDead = true; + // Remove the process record so it won't be considered as alive. + mService.mProcessNames.remove(wpc.mName, wpc.mUid); + mService.mProcessMap.remove(wpc.getPid()); } r.notifyUnknownVisibilityLaunchedForKeyguardTransition();