Handle window removed event properly

If the removed window contains the focused view and it is an
application window, don't restore the focus in the previous window.

Fixes: 174088541
Test: manual test in Dialer and RoatryPlayground

Change-Id: I5e2d85ab4df987de8997289820f1a37c7e6a3c61
diff --git a/src/com/android/car/rotary/RotaryService.java b/src/com/android/car/rotary/RotaryService.java
index cd3c7e6..6a89305 100644
--- a/src/com/android/car/rotary/RotaryService.java
+++ b/src/com/android/car/rotary/RotaryService.java
@@ -889,7 +889,7 @@
     /**
      * Handles a {@link AccessibilityEvent#TYPE_WINDOWS_CHANGED} event indicating that a window was
      * removed. Attempts to restore the most recent focus when the window containing
-     * {@link #mFocusedNode} is removed.
+     * {@link #mFocusedNode} is not an application window and it's removed.
      */
     private void handleWindowRemovedEvent(@NonNull AccessibilityEvent event) {
         int windowId = event.getWindowId();
@@ -901,6 +901,12 @@
             if (type.intValue() == TYPE_INPUT_METHOD) {
                 setEditNode(null);
             }
+            // No need to restore the focus if it's an application window. When an application
+            // window is removed, another window will gain focus shortly and the FocusParkingView
+            // in that window will restore the focus.
+            if (type.intValue() == TYPE_APPLICATION) {
+                return;
+            }
         } else {
             L.w("No window type found in cache for window ID: " + windowId);
         }