From 917173f5709b1042d74e21280635e3807c559af1 Mon Sep 17 00:00:00 2001
From: Chilun <chilunhuang@google.com>
Date: Fri, 4 Jan 2019 16:47:42 +0800
Subject: [PATCH] Restart the application only for the bad process

The case is a test using the same package name as default home.
Starting the instrumentation of the test will kill the home process.
When AM try to restart the default home, there is a wrong logic that
cause the instrumentation process to be killled.

The problem of original logic is always set knownToBeDead as true even
the existing process is ok.

Test: atest CtsAppTestCases#ServiceTest
Bug: 120107272
Change-Id: Ic2c3f6236c3631b0e386d24750bf5952d8227ea9
---
 .../java/com/android/server/wm/ActivityStackSupervisor.java   | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
index d5286b9ae87c7..a50ae8431cb03 100644
--- a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
@@ -947,6 +947,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
         final WindowProcessController wpc =
                 mService.getProcessController(r.processName, r.info.applicationInfo.uid);
 
+        boolean knownToBeDead = false;
         if (wpc != null && wpc.hasThread()) {
             try {
                 if ((r.info.flags & ActivityInfo.FLAG_MULTIPROCESS) == 0
@@ -965,6 +966,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
 
             // If a dead object exception was thrown -- fall through to
             // restart the application.
+            knownToBeDead = true;
         }
 
         // Suppress transition until the new activity becomes ready, otherwise the keyguard can
@@ -978,7 +980,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
         // ATMS lock held.
         final Message msg = PooledLambda.obtainMessage(
                 ActivityManagerInternal::startProcess, mService.mAmInternal, r.processName,
-                r.info.applicationInfo, true, "activity", r.intent.getComponent());
+                r.info.applicationInfo, knownToBeDead, "activity", r.intent.getComponent());
         mService.mH.sendMessage(msg);
     }
 
-- 
GitLab