Clean-up WindowState if exit animation is done before app finishes

In ag/862571 we prevent window states from been removed before the
app is stopped since it can still be rendering to the surface.
The CL also left WindowState.mExiting as true after the exit
transition animation runs. This is okay if the app finishes before
the exit animation is done, but if the exit animation finishes before
the app finishes, then we will always think we need to run an exit
animation and not remove the windows when the app and later activity
manager tries to remove the windows.
mExiting is used to mean exiting animation is running, if it is set to
true then all the code assumes an exit animation is still running and
doesn't remove the window state.
- Always set mExiting when animation is done.
- Renamed mExiting to mAnimatingExit so it is more clear what it is used
for
- Allow window state to be removed is the current surface isn't shown.
This should be save since there won't be any visual effect to the user.
- Rename WindowState.mClientRemoveRequested to WindowState.mWindowRemovalAllowed
and move setting it to true into WMS.removeWindow() so it catches all cases.
- Cleaned-up the code some to be a little clearer.

Bug: 27112965
Change-Id: I6f03d3c75b5b7728e42ceadc8703df40a3b4ae63
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 2a091ba..12c62bd 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -254,7 +254,7 @@
                 // In cases where there are multiple windows, we prefer the non-exiting window. This
                 // happens for example when replacing windows during an activity relaunch. When
                 // constructing the animation, we want the new window, not the exiting one.
-                if (win.mExiting) {
+                if (win.mAnimatingExit) {
                     candidate = win;
                 } else {
                     return win;
@@ -307,11 +307,11 @@
             // If the app already requested to remove its window, we don't modify
             // its exiting state. Otherwise the stale window won't get removed on
             // exit and could cause focus to be given to the wrong window.
-            if (!(win.mRemoveOnExit && win.mExiting)) {
-                win.mExiting = exiting;
+            if (!(win.mRemoveOnExit && win.mAnimatingExit)) {
+                win.mAnimatingExit = exiting;
             }
             // If we're no longer exiting, remove the window from destroying list
-            if (!win.mExiting && win.mDestroying) {
+            if (!win.mAnimatingExit && win.mDestroying) {
                 win.mDestroying = false;
                 service.mDestroySurface.remove(win);
             }
@@ -330,13 +330,13 @@
                 continue;
             }
 
-            if (!mAppStopped && !win.mClientRemoveRequested) {
+            if (!(mAppStopped || win.mWindowRemovalAllowed)) {
                 continue;
             }
 
             win.destroyOrSaveSurface();
             if (win.mRemoveOnExit) {
-                win.mExiting = false;
+                win.mAnimatingExit = false;
                 service.removeWindowInnerLocked(win);
             }
             final DisplayContent displayContent = win.getDisplayContent();