Respond to configuration changes in RecentsWindowManager

Summary: Will respond appropriately to config changes, there are
	additional issues within recentsview itself with some
	issues with the viewmodel binding.

Test: Local testing currently, will add more to bug

Flag: com.android.launcher3.enable_fallback_overview_in_window
      com.android.launcher3.enable_launcher_overview_in_window

Change-Id: I854de2204b11d36941849703076def0c039060bf
This commit is contained in:
Randy Pfohl
2025-02-14 03:42:20 +00:00
parent 5b15f38553
commit d08484669c
2 changed files with 96 additions and 78 deletions
@@ -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
@@ -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<Boolean>? = 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<Int, ThumbnailData>) {
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<Int, ThumbnailData>) {
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()
}