Check isOnScreen for wallpaper target of recents animation

If an unresponsive activity is launched by recents activity.
WindowState#mDestroying of recents activity will be set until
the exit animation is done. But because the next app is slow,
before the transition is done, when starting the recents activity
again, if it is set as wallpaper target, WallpaperController#
updateWallpaperVisibility/isWallpaperVisible will make wallpaper
window visible. But the later layout procedure calls WidowState#
prepareSurfaceLocked that checks WindowState#isOnScreen to
decide whether to hide the wallpaper. And since mDestroying is
still true, isOnScreen will return false that leads to hide
wallpaper. Then the visibility change of wallpaper becomes a loop
that causes layout repeats.

This change makes the condition of wallpaper target for recents
animation consistent with normal case. That means the recents
activity will be wallpaper target until its relayout with visible
state that clears mDestroying.

Bug: 174417869
Test: Assume home is the recents activity, launch an activity
      which sleep 10s in onCreate from home, and then swipe
      up by gesture navigation. There should not appear log
      message "Performed 6 layouts in a row. Skipping".
Change-Id: I8982657bbe04a01406b50a6a2f32d34d33f560d4
diff --git a/services/core/java/com/android/server/wm/RecentsAnimationController.java b/services/core/java/com/android/server/wm/RecentsAnimationController.java
index 65db23c..5ba4479 100644
--- a/services/core/java/com/android/server/wm/RecentsAnimationController.java
+++ b/services/core/java/com/android/server/wm/RecentsAnimationController.java
@@ -799,7 +799,7 @@
         return w != null && w.mAttrs.type == TYPE_BASE_APPLICATION &&
                 ((w.mActivityRecord != null && mTargetActivityRecord == w.mActivityRecord)
                         || isAnimatingTask(w.getTask()))
-                && isTargetOverWallpaper();
+                && isTargetOverWallpaper() && w.isOnScreen();
     }
 
     /**
diff --git a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java
index 730e9be..cfc50b5 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java
@@ -437,6 +437,7 @@
 
         final WindowState homeWindow = createWindow(null, TYPE_BASE_APPLICATION, homeActivity,
                 "homeWindow");
+        makeWindowVisible(homeWindow);
         homeActivity.addWindow(homeWindow);
         homeWindow.getAttrs().flags |= FLAG_SHOW_WALLPAPER;