Do not create starting window if there is no task.

Do not add starting window on the activity if no task exists in
the activity.
Also add an error log for the activity without task.

Bug: 233153876
Bug: 240032099
Test: atest SplashscreenTests ActivityRecordTests
Change-Id: Iea264cd8b605443c695165c1136d56b86ffd4eb1
Merged-In: Iea264cd8b605443c695165c1136d56b86ffd4eb1
(cherry picked from commit 24697fe3fdf92cac03b553892a3e1d17ae30c8a1)
(cherry picked from commit f5909156007fb7976c34ec187a68792d92a6edc2)
Merged-In: Iea264cd8b605443c695165c1136d56b86ffd4eb1
diff --git a/services/core/java/com/android/server/wm/StartingSurfaceController.java b/services/core/java/com/android/server/wm/StartingSurfaceController.java
index f83173b..0bb773a 100644
--- a/services/core/java/com/android/server/wm/StartingSurfaceController.java
+++ b/services/core/java/com/android/server/wm/StartingSurfaceController.java
@@ -220,6 +220,11 @@
         // Attempt to add starting window from the top-most activity.
         for (int i = mDeferringAddStartActivities.size() - 1; i >= 0; --i) {
             final DeferringStartingWindowRecord next = mDeferringAddStartActivities.get(i);
+            if (next.mDeferring.getTask() == null) {
+                Slog.e(TAG, "No task exists: " + next.mDeferring.shortComponentName
+                        + " parent: " + next.mDeferring.getParent());
+                continue;
+            }
             next.mDeferring.showStartingWindow(next.mPrev, mInitNewTask, mInitTaskSwitch,
                     mInitProcessRunning, true /* startActivity */, next.mSource, topOptions);
             // If one succeeds, it is done.