Add return-to logic for onTopLauncher.

- When an on-top launcher is moved to back, this commit makes sure
  that it's moved to the bottom of the home stack, and the home
  stack is moved to back.
- This commit also sets the proper return-to type for tasks launched
  from an on-top launcher.

Bug: 29393795
Change-Id: If0cfb35d95a5bdab008a6a3809319d3909a56f19
diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java
index 7a6b13b..9f875a1 100644
--- a/services/core/java/com/android/server/am/ActivityStarter.java
+++ b/services/core/java/com/android/server/am/ActivityStarter.java
@@ -1559,7 +1559,15 @@
 
     private void updateTaskReturnToType(
             TaskRecord task, int launchFlags, ActivityStack focusedStack) {
-        if ((launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME))
+        if (focusedStack != null && focusedStack.isHomeStack() &&
+                focusedStack.topTask().isOnTopLauncher()) {
+            // Since an on-top launcher will is moved to back when tasks are launched from it,
+            // those tasks should first try to return to a non-home activity.
+            // This also makes sure that non-home activities are visible under a transparent
+            // non-home activity.
+            task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE);
+            return;
+        } else if ((launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME))
                 == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
             // Caller wants to appear on home activity.
             task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);