Don't remove all app token windows when window client dies

AppWindowToken can contain windows from multiple clients (Processes)
If one of the client dies we shouldn't remove all windows in the app
token. We should only remove dea windows.

Bug: 28467642
Change-Id: I8be6a98e0acc79719158567114f4902066069c1b
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index b4ead44..805c986 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -109,7 +109,6 @@
     // Set to true when the token has been removed from the window mgr.
     boolean removed;
 
-    boolean appDied;
     // Information about an application starting window if displayed.
     StartingData startingData;
     WindowState startingWindow;
@@ -458,12 +457,12 @@
 
     void removeAllDeadWindows() {
         for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
-                // removeWindowLocked at bottom of loop may remove multiple entries from
-                // allAppWindows if the window to be removed has child windows. It also may
-                // not remove any windows from allAppWindows at all if win is exiting and
-                // currently animating away. This ensures that winNdx is monotonically decreasing
-                // and never beyond allAppWindows bounds.
-                winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
+            // removeWindowLocked at bottom of loop may remove multiple entries from
+            // allAppWindows if the window to be removed has child windows. It also may
+            // not remove any windows from allAppWindows at all if win is exiting and
+            // currently animating away. This ensures that winNdx is monotonically decreasing
+            // and never beyond allAppWindows bounds.
+            winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) {
             WindowState win = allAppWindows.get(winNdx);
             if (win.mAppDied) {
                 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
@@ -476,6 +475,15 @@
         }
     }
 
+    boolean hasWindowsAlive() {
+        for (int i = allAppWindows.size() - 1; i >= 0; i--) {
+            if (!allAppWindows.get(i).mAppDied) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     void setReplacingWindows(boolean animate) {
         if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken
                 + " with replacing windows.");