diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index b6a1784839dee..50a09a307de61 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -2436,6 +2436,18 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A private int getStartingWindowType(boolean newTask, boolean taskSwitch, boolean processRunning, boolean allowTaskSnapshot, boolean activityCreated, boolean activityAllDrawn, TaskSnapshot snapshot) { + // A special case that a new activity is launching to an existing task which is moving to + // front. If the launching activity is the one that started the task, it could be a + // trampoline that will be always created and finished immediately. Then give a chance to + // see if the snapshot is usable for the current running activity so the transition will + // look smoother, instead of showing a splash screen on the second launch. + if (!newTask && taskSwitch && processRunning && !activityCreated && task.intent != null + && mActivityComponent.equals(task.intent.getComponent())) { + final ActivityRecord topAttached = task.getActivity(ActivityRecord::attachedToProcess); + if (topAttached != null && topAttached.isSnapshotCompatible(snapshot)) { + return STARTING_WINDOW_TYPE_SNAPSHOT; + } + } final boolean isActivityHome = isActivityTypeHome(); if ((newTask || !processRunning || (taskSwitch && !activityCreated)) && !isActivityHome) { diff --git a/services/core/java/com/android/server/wm/StartingSurfaceController.java b/services/core/java/com/android/server/wm/StartingSurfaceController.java index 813e06fecf486..ccd018faf075d 100644 --- a/services/core/java/com/android/server/wm/StartingSurfaceController.java +++ b/services/core/java/com/android/server/wm/StartingSurfaceController.java @@ -26,6 +26,7 @@ import static android.window.StartingWindowInfo.TYPE_PARAMETER_PROCESS_RUNNING; import static android.window.StartingWindowInfo.TYPE_PARAMETER_TASK_SWITCH; import static android.window.StartingWindowInfo.TYPE_PARAMETER_USE_SOLID_COLOR_SPLASH_SCREEN; +import static com.android.server.wm.ActivityRecord.STARTING_WINDOW_TYPE_SNAPSHOT; import static com.android.server.wm.ActivityRecord.STARTING_WINDOW_TYPE_SPLASH_SCREEN; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; @@ -114,7 +115,7 @@ public class StartingSurfaceController { if (allowTaskSnapshot) { parameter |= TYPE_PARAMETER_ALLOW_TASK_SNAPSHOT; } - if (activityCreated) { + if (activityCreated || startingWindowType == STARTING_WINDOW_TYPE_SNAPSHOT) { parameter |= TYPE_PARAMETER_ACTIVITY_CREATED; } if (isSolidColor) { @@ -138,7 +139,6 @@ public class StartingSurfaceController { final WindowState topFullscreenOpaqueWindow; final Task task; synchronized (mService.mGlobalLock) { - final WindowState mainWindow = activity.findMainWindow(); task = activity.getTask(); if (task == null) { Slog.w(TAG, "TaskSnapshotSurface.create: Failed to find task for activity=" @@ -153,9 +153,9 @@ public class StartingSurfaceController { return null; } topFullscreenOpaqueWindow = topFullscreenActivity.getTopFullscreenOpaqueWindow(); - if (mainWindow == null || topFullscreenOpaqueWindow == null) { - Slog.w(TAG, "TaskSnapshotSurface.create: Failed to find main window for activity=" - + activity); + if (topFullscreenOpaqueWindow == null) { + Slog.w(TAG, "TaskSnapshotSurface.create: no opaque window in " + + topFullscreenActivity); return null; } if (topFullscreenActivity.getWindowConfiguration().getRotation() diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index f97f768872fdd..0a3ce7497e23a 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -56,6 +56,7 @@ import static android.view.SurfaceControl.METADATA_TASK_ID; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; +import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; import static android.view.WindowManager.TRANSIT_CHANGE; import static android.view.WindowManager.TRANSIT_CLOSE; import static android.view.WindowManager.TRANSIT_FLAG_APP_CRASHED; @@ -3525,10 +3526,13 @@ class Task extends TaskFragment { mAtmService.mKeyguardController.isDisplayOccluded(DEFAULT_DISPLAY); info.startingWindowTypeParameter = activity.mStartingData.mTypeParams; - final WindowState mainWindow = activity.findMainWindow(); - if (mainWindow != null) { - info.mainWindowLayoutParams = mainWindow.getAttrs(); - info.requestedVisibilities.set(mainWindow.getRequestedVisibilities()); + if ((info.startingWindowTypeParameter + & StartingWindowInfo.TYPE_PARAMETER_ACTIVITY_CREATED) != 0) { + final WindowState topMainWin = getWindow(w -> w.mAttrs.type == TYPE_BASE_APPLICATION); + if (topMainWin != null) { + info.mainWindowLayoutParams = topMainWin.getAttrs(); + info.requestedVisibilities.set(topMainWin.getRequestedVisibilities()); + } } // If the developer has persist a different configuration, we need to override it to the // starting window because persisted configuration does not effect to Task.