Save window when an app died while it's visible

- If an app died visible, keep the dead window and leave it on screen.

- Apply 50% dim over the dead window to indicate it's no longer active.

- Monitor touch inputs on the dead window and restart the app on tap.

bug: 24913379
Change-Id: I911da4e6135f2bffaf3b1bbe6f911ff689a278ff
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 0afc715..b025ce2 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -2872,25 +2872,25 @@
             return;
         }
 
-        int stackId = task.stack.mStackId;
         if (task.mResizeable && options != null) {
             ActivityOptions opts = new ActivityOptions(options);
             if (opts.hasBounds()) {
                 Rect bounds = opts.getBounds();
                 task.updateOverrideConfiguration(bounds);
+                final int stackId = task.getLaunchStackId();
+                if (stackId != task.stack.mStackId) {
+                    moveTaskToStackUncheckedLocked(task, stackId, ON_TOP, !FORCE_FOCUS, reason);
+                    // moveTaskToStackUncheckedLocked() should already placed the task on top,
+                    // still need moveTaskToFrontLocked() below for any transition settings.
+                }
+                // WM resizeTask must be done after the task is moved to the correct stack,
+                // because Task's setBounds() also updates dim layer's bounds, but that has
+                // dependency on the stack.
                 mWindowManager.resizeTask(task.taskId, bounds, task.mOverrideConfig,
                         false /*relayout*/, false /*forced*/);
-                stackId = task.getLaunchStackId();
             }
         }
 
-        if (stackId != task.stack.mStackId) {
-            moveTaskToStackUncheckedLocked(task, stackId, ON_TOP, !FORCE_FOCUS, reason);
-
-            // moveTaskToStackUncheckedLocked() should already placed the task on top,
-            // still need moveTaskToFrontLocked() below for any transition settings.
-        }
-
         final ActivityRecord r = task.getTopActivity();
         task.stack.moveTaskToFrontLocked(task, false /* noAnimation */, options,
                 r == null ? null : r.appTimeTracker, reason);