From d6f0286fe028a29c5b2ace04682b50d38377b0bc Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 17 Feb 2023 19:19:42 +0800 Subject: [PATCH] Resume stopped preserved window when relaunching visible activity The ViewRoot will be stopped with activity onStop. And unstop when resuming activity, but it is only called when resuming an existing activity (from performRestart). So if a ViewRoot is preserved during relaunching while the activity was stopped, the ViewRoot is also stopped. And because the activity is a new instance, performRestart won't be called, then the RootView keeps the stopped state. The case happens more frequently since wm shell is introduced, which by default use "preserveWindow=true" for ActivityRecord#ensureActivityConfiguration via WindowOrganizer#applyTransaction. Bug: 269179932 Test: WMShellFlickerTests:CopyContentInSplit Test: Simple simulation: Modify code to force "preserveWindow" to always be enabled. Launch an activity without handling config change in landscape. Return to home and launch the activity again in portrait. The activity should be able to response for input event. Change-Id: Iee780c12535217a5a9726f9f4d6b21952ce56d70 --- core/java/android/view/ViewRootImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 472daf9889246..e9b3e2808a6d6 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -1135,6 +1135,10 @@ public final class ViewRootImpl implements ViewParent, updateLastConfigurationFromResources(getConfiguration()); // Make sure to report the completion of draw for relaunch with preserved window. reportNextDraw("rebuilt"); + // Make sure to resume this root view when relaunching its host activity which was stopped. + if (mStopped && getHostVisibility() != View.GONE) { + setWindowStopped(false); + } } private Configuration getConfiguration() {