AppWindowToken: Guard against null SurfaceControl in prepareSurfaces

It seems this code was written with the assumption that if prepareSurfaces
is called, then we must be attached to the hiearchy and we must have
a valid surface. As always though, the story runs deeper. We can actually
call AppWindowToken#prepareSurfaces within the scope of AppWindowToken#removeImmediately.
This transpires via these steps:
     1. AppWindowToken removes children.
     2. Child windowstate calls WMS#postWindowRemoveCleanupLocked
     3. WMS immediately performs surface placement.
     4. Surface placement leads to AppWindowToken#prepareSurfaces.

This means that prepareSurfaces can be called after we have set mSurfaceControl
to null but before the parent has removed us from its list, and that the assumption
that the control must be non-null in prepareSurfaces was false.

Bug: 123606376
Test: Makes one of them crash less
Change-Id: Ic2985cb6f2a31613de5942926b036fd24a91e68a
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index a52f1af..3237fe0 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -2852,10 +2852,13 @@
         // to check super here.
         final boolean reallyAnimating = super.isSelfAnimating();
         final boolean show = !isHidden() || reallyAnimating;
-        if (show && !mLastSurfaceShowing) {
-            mPendingTransaction.show(mSurfaceControl);
-        } else if (!show && mLastSurfaceShowing) {
-            mPendingTransaction.hide(mSurfaceControl);
+
+        if (mSurfaceControl != null) {
+            if (show && !mLastSurfaceShowing) {
+                mPendingTransaction.show(mSurfaceControl);
+            } else if (!show && mLastSurfaceShowing) {
+                mPendingTransaction.hide(mSurfaceControl);
+            }
         }
         if (mThumbnail != null) {
             mThumbnail.setShowing(mPendingTransaction, show);