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/ b/services/core/java/com/android/server/wm/
index 65db23c..5ba4479 100644
--- a/services/core/java/com/android/server/wm/
+++ b/services/core/java/com/android/server/wm/
@@ -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/ b/services/tests/wmtests/src/com/android/server/wm/
index 730e9be..cfc50b5 100644
--- a/services/tests/wmtests/src/com/android/server/wm/
+++ b/services/tests/wmtests/src/com/android/server/wm/
@@ -437,6 +437,7 @@
         final WindowState homeWindow = createWindow(null, TYPE_BASE_APPLICATION, homeActivity,
+        makeWindowVisible(homeWindow);
         homeWindow.getAttrs().flags |= FLAG_SHOW_WALLPAPER;