diff --git a/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowContext.kt b/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowContext.kt index 047658c419..cd4813631d 100644 --- a/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowContext.kt +++ b/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowContext.kt @@ -61,9 +61,13 @@ open class RecentsWindowContext(windowContext: Context, wallpaperColorHints: Int return dragLayer } + fun initDeviceProfile() { + deviceProfile = InvariantDeviceProfile.INSTANCE[this].getDeviceProfile(this) + } + override fun getDeviceProfile(): DeviceProfile { if (deviceProfile == null) { - deviceProfile = InvariantDeviceProfile.INSTANCE[this].getDeviceProfile(this).copy(this) + initDeviceProfile() } return deviceProfile!! } @@ -79,7 +83,10 @@ open class RecentsWindowContext(windowContext: Context, wallpaperColorHints: Int * @param type The window type to pass to the created WindowManager.LayoutParams. * @param title The window title to pass to the created WindowManager.LayoutParams. */ - fun createDefaultWindowLayoutParams(type: Int, title: String): WindowManager.LayoutParams { + private fun createDefaultWindowLayoutParams( + type: Int, + title: String, + ): WindowManager.LayoutParams { var windowFlags = (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS or diff --git a/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowManager.kt b/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowManager.kt index 9e8d69b868..02bdedd50b 100644 --- a/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowManager.kt +++ b/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowManager.kt @@ -21,6 +21,7 @@ import android.app.ActivityOptions import android.content.ComponentName import android.content.Context import android.content.LocusId +import android.content.res.Configuration import android.os.Bundle import android.view.KeyEvent import android.view.LayoutInflater @@ -32,6 +33,7 @@ import android.view.View import android.view.WindowManager import android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY import android.window.RemoteTransition +import com.android.launcher3.AbstractFloatingView import com.android.launcher3.BaseActivity import com.android.launcher3.LauncherAnimationRunner import com.android.launcher3.LauncherAnimationRunner.RemoteAnimationFactory @@ -135,73 +137,6 @@ class RecentsWindowManager(context: Context, wallpaperColorHints: Int) : listOf(RunnableList(), RunnableList(), RunnableList(), RunnableList()) private var onInitListener: Predicate? = null - private val taskStackChangeListener = - object : TaskStackChangeListener { - override fun onTaskMovedToFront(taskId: Int) { - if ((isShowing() && isInState(DEFAULT))) { - // handling state where we end recents animation by swiping livetile away - // TODO: animate this switch. - cleanupRecentsWindow() - } - } - } - - private val recentsAnimationListener = - object : RecentsAnimationListener { - override fun onRecentsAnimationCanceled(thumbnailDatas: HashMap) { - recentAnimationStopped() - } - - override fun onRecentsAnimationFinished(controller: RecentsAnimationController) { - recentAnimationStopped() - } - } - - init { - TaskStackChangeListeners.getInstance().registerTaskStackListener(taskStackChangeListener) - } - - override fun destroy() { - super.destroy() - cleanupRecentsWindow() - TaskStackChangeListeners.getInstance().unregisterTaskStackListener(taskStackChangeListener) - callbacks?.removeListener(recentsAnimationListener) - recentsWindowTracker.onContextDestroyed(this) - recentsView?.destroy() - } - - override fun startHome() { - startHome(/* finishRecentsAnimation= */ true) - } - - fun startHome(finishRecentsAnimation: Boolean) { - val recentsView: RecentsView<*, *> = getOverviewPanel() - - if (!finishRecentsAnimation) { - recentsView.switchToScreenshot /* onFinishRunnable= */ {} - startHomeInternal() - return - } - recentsView.switchToScreenshot { - recentsView.finishRecentsAnimation(/* toRecents= */ true) { startHomeInternal() } - } - } - - private fun startHomeInternal() { - val runner = LauncherAnimationRunner(mainThreadHandler, animationToHomeFactory, true) - val options = - ActivityOptions.makeRemoteAnimation( - RemoteAnimationAdapter(runner, HOME_APPEAR_DURATION, 0), - RemoteTransition( - runner.toRemoteTransition(), - iApplicationThread, - "StartHomeFromRecents", - ), - ) - OverviewComponentObserver.startHomeIntentSafely(this, options.toBundle(), TAG) - stateManager.moveToRestState() - } - private val animationToHomeFactory = RemoteAnimationFactory { _: Int, @@ -242,17 +177,49 @@ class RecentsWindowManager(context: Context, wallpaperColorHints: Int) : TestLogging.recordEvent(SEQUENCE_MAIN, "onBackInvoked") } - private fun cleanupRecentsWindow() { - RecentsWindowProtoLogProxy.logCleanup(isShowing()) - if (isShowing()) { - windowManager.removeViewImmediate(windowView) + private val taskStackChangeListener = + object : TaskStackChangeListener { + override fun onTaskMovedToFront(taskId: Int) { + if ((isShowing() && isInState(DEFAULT))) { + // handling state where we end recents animation by swiping livetile away + // TODO: animate this switch. + cleanupRecentsWindow() + } + } } - stateManager.moveToRestState() - callbacks?.removeListener(recentsAnimationListener) + + private val recentsAnimationListener = + object : RecentsAnimationListener { + override fun onRecentsAnimationCanceled(thumbnailDatas: HashMap) { + recentAnimationStopped() + } + + override fun onRecentsAnimationFinished(controller: RecentsAnimationController) { + recentAnimationStopped() + } + } + + init { + TaskStackChangeListeners.getInstance().registerTaskStackListener(taskStackChangeListener) } - private fun isShowing(): Boolean { - return windowView?.parent != null + override fun handleConfigurationChanged(configuration: Configuration?) { + initDeviceProfile() + AbstractFloatingView.closeOpenViews( + this, + true, + AbstractFloatingView.TYPE_ALL and AbstractFloatingView.TYPE_REBIND_SAFE.inv(), + ) + dispatchDeviceProfileChanged() + } + + override fun destroy() { + super.destroy() + cleanupRecentsWindow() + TaskStackChangeListeners.getInstance().unregisterTaskStackListener(taskStackChangeListener) + callbacks?.removeListener(recentsAnimationListener) + recentsWindowTracker.onContextDestroyed(this) + recentsView?.destroy() } fun startRecentsWindow(callbacks: RecentsAnimationCallbacks? = null) { @@ -301,6 +268,51 @@ class RecentsWindowManager(context: Context, wallpaperColorHints: Int) : callbacks?.addListener(recentsAnimationListener) } + override fun startHome() { + startHome(/* finishRecentsAnimation= */ true) + } + + fun startHome(finishRecentsAnimation: Boolean) { + val recentsView: RecentsView<*, *> = getOverviewPanel() + + if (!finishRecentsAnimation) { + recentsView.switchToScreenshot /* onFinishRunnable= */ {} + startHomeInternal() + return + } + recentsView.switchToScreenshot { + recentsView.finishRecentsAnimation(/* toRecents= */ true) { startHomeInternal() } + } + } + + private fun startHomeInternal() { + val runner = LauncherAnimationRunner(mainThreadHandler, animationToHomeFactory, true) + val options = + ActivityOptions.makeRemoteAnimation( + RemoteAnimationAdapter(runner, HOME_APPEAR_DURATION, 0), + RemoteTransition( + runner.toRemoteTransition(), + iApplicationThread, + "StartHomeFromRecents", + ), + ) + OverviewComponentObserver.startHomeIntentSafely(this, options.toBundle(), TAG) + stateManager.moveToRestState() + } + + private fun cleanupRecentsWindow() { + RecentsWindowProtoLogProxy.logCleanup(isShowing()) + if (isShowing()) { + windowManager.removeViewImmediate(windowView) + } + stateManager.moveToRestState() + callbacks?.removeListener(recentsAnimationListener) + } + + private fun isShowing(): Boolean { + return windowView?.parent != null + } + private fun recentAnimationStopped() { if (isInState(BACKGROUND_APP)) { cleanupRecentsWindow() @@ -352,7 +364,6 @@ class RecentsWindowManager(context: Context, wallpaperColorHints: Int) : override fun onStateSetEnd(state: RecentsState) { super.onStateSetEnd(state) RecentsWindowProtoLogProxy.logOnStateSetEnd(getStateName(state)) - if (state == HOME || state == BG_LAUNCHER) { cleanupRecentsWindow() }