Remove task activities from LRU list when task is reparented.

- When a task is reparented, the activities are not removed from the
  previous stack's LRU list.  Afterwards, when the activity is destroyed,
  the previous stack's LRU list will contain an activity that has no
  task.  Instead, we should remove all of the task's activities from the
  LRU list when it is removed, and update the LRU list of the new stack
  when the top activity is next resumed.
- Also fixing issue with stack header in dumpsys not printing if there are
  no activities (but other states were still being printed for that stack)

Bug: 36253246
Test: adb shell dumpsys activity activities
Change-Id: Ia14f170dceff9eadc48d1ac4aac2f16c714adde2
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 5c49dfd..fc62297 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -3569,8 +3569,16 @@
                 stackHeader.append("  mFullscreen=" + stack.mFullscreen);
                 stackHeader.append("\n");
                 stackHeader.append("  mBounds=" + stack.mBounds);
-                printed |= stack.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage,
-                        needSep, stackHeader.toString());
+
+                final boolean printedStackHeader = stack.dumpActivitiesLocked(fd, pw, dumpAll,
+                        dumpClient, dumpPackage, needSep, stackHeader.toString());
+                printed |= printedStackHeader;
+                if (!printedStackHeader) {
+                    // Ensure we always dump the stack header even if there are no activities
+                    pw.println();
+                    pw.println(stackHeader);
+                }
+
                 printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, "    ", "Run", false,
                         !dumpAll, false, dumpPackage, true,
                         "    Running activities (most recent first):", null);