From 2289c28f7fb83f2b89e8ca0036edba5280b08528 Mon Sep 17 00:00:00 2001 From: Ahmed Fakhry Date: Tue, 11 Feb 2025 00:05:21 +0000 Subject: [PATCH] Notify with `onIsInDesktopModeChanged()` This CL renamed `onDesktopVisibilityChanged()` to `onIsInDesktopModeChanged()` and adds a parameter for the display ID on which the change is taking place. When the multiple desktops flags are disabled, the behavior should remain exactly as it is today; `onIsInDesktopModeChanged()` is triggered only for the `DEFAULT_DISPLAY`, and when the same old conditions occur. Bug: 394685645 Test: m Flag: com.android.window.flags.enable_multiple_desktops_frontend Flag: com.android.window.flags.enable_multiple_desktops_backend Change-Id: I31658b1b7932c787ebd430cee7e5c99bdd01e8c9 --- .../DesktopVisibilityController.kt | 49 ++++++++++++++----- .../launcher3/util/DisplayController.java | 6 ++- .../util/window/WindowManagerProxy.java | 8 +-- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt b/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt index 62543e48f3..3773d027ed 100644 --- a/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt +++ b/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt @@ -19,7 +19,9 @@ import android.content.Context import android.os.Debug import android.util.Log import android.util.SparseArray +import android.view.Display.DEFAULT_DISPLAY import android.window.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY +import androidx.core.util.forEach import com.android.launcher3.LauncherState import com.android.launcher3.dagger.ApplicationContext import com.android.launcher3.dagger.LauncherAppComponent @@ -105,7 +107,7 @@ constructor( field = visibleTasksCount val areDesktopTasksVisibleNow = areDesktopTasksVisibleAndNotInOverview() if (wereDesktopTasksVisibleBefore != areDesktopTasksVisibleNow) { - notifyDesktopVisibilityListeners(areDesktopTasksVisibleNow) + notifyIsInDesktopModeChanged(DEFAULT_DISPLAY, areDesktopTasksVisibleNow) } if ( @@ -250,8 +252,23 @@ constructor( val wereDesktopTasksVisibleBefore = areDesktopTasksVisibleAndNotInOverview() inOverviewState = overviewStateEnabled val areDesktopTasksVisibleNow = areDesktopTasksVisibleAndNotInOverview() - if (wereDesktopTasksVisibleBefore != areDesktopTasksVisibleNow) { - notifyDesktopVisibilityListeners(areDesktopTasksVisibleNow) + + if (!DesktopModeStatus.enableMultipleDesktops(context)) { + if (wereDesktopTasksVisibleBefore != areDesktopTasksVisibleNow) { + notifyIsInDesktopModeChanged(DEFAULT_DISPLAY, areDesktopTasksVisibleNow) + } + } else { + // When overview state changes, it changes together on all displays. + displaysDesksConfigsMap.forEach { displayId, deskConfig -> + // Overview affects the state of desks only if desktop mode is active on this + // display. + if (isInDesktopMode(displayId)) { + notifyIsInDesktopModeChanged( + displayId, + isInDesktopModeAndNotInOverview(displayId), + ) + } + } } if (ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY.isTrue) { @@ -279,19 +296,19 @@ constructor( desktopVisibilityListeners.remove(listener) } - private fun notifyDesktopVisibilityListeners(areDesktopTasksVisible: Boolean) { - if (DesktopModeStatus.enableMultipleDesktops(context)) { - // This is triggered using the legacy way of determining the visibility of the desktop - // mode and should not be used when the multi-desks feature is enabled. - // (See b/394685645 for details). - return + private fun notifyIsInDesktopModeChanged( + displayId: Int, + isInDesktopModeAndNotInOverview: Boolean, + ) { + if (DEBUG) { + Log.d( + TAG, + "notifyIsInDesktopModeChanged: displayId=$displayId, isInDesktopModeAndNotInOverview=$isInDesktopModeAndNotInOverview", + ) } - if (DEBUG) { - Log.d(TAG, "notifyDesktopVisibilityListeners: visible=$areDesktopTasksVisible") - } for (listener in desktopVisibilityListeners) { - listener.onDesktopVisibilityChanged(areDesktopTasksVisible) + listener.onIsInDesktopModeChanged(displayId, isInDesktopModeAndNotInOverview) } } @@ -438,6 +455,8 @@ constructor( return } + val wasInDesktopMode = isInDesktopModeAndNotInOverview(displayId) + getDisplayDeskConfig(displayId).also { check(oldActiveDesk == it.activeDeskId) { "Mismatch between the Shell's oldActiveDesk: $oldActiveDesk, and Launcher's: ${it.activeDeskId}" @@ -447,6 +466,10 @@ constructor( } it.activeDeskId = newActiveDesk } + + if (wasInDesktopMode != isInDesktopModeAndNotInOverview(displayId)) { + notifyIsInDesktopModeChanged(displayId, !wasInDesktopMode) + } } /** TODO: b/333533253 - Remove after flag rollout */ diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java index 80086870a1..638bd608f8 100644 --- a/src/com/android/launcher3/util/DisplayController.java +++ b/src/com/android/launcher3/util/DisplayController.java @@ -229,8 +229,10 @@ public class DisplayController implements ComponentCallbacks, } @Override - public void onDesktopVisibilityChanged(boolean visible) { - notifyConfigChange(); + public void onIsInDesktopModeChanged(int displayId, boolean isInDesktopModeAndNotInOverview) { + if (DEFAULT_DISPLAY == displayId) { + notifyConfigChange(); + } } /** diff --git a/src/com/android/launcher3/util/window/WindowManagerProxy.java b/src/com/android/launcher3/util/window/WindowManagerProxy.java index bbb9e28a4a..647d170340 100644 --- a/src/com/android/launcher3/util/window/WindowManagerProxy.java +++ b/src/com/android/launcher3/util/window/WindowManagerProxy.java @@ -503,11 +503,13 @@ public class WindowManagerProxy { /** A listener for when the user enters/exits Desktop Mode. */ public interface DesktopVisibilityListener { /** - * Callback for when the user enters or exits Desktop Mode + * Called when the desktop mode state on the display whose ID is `displayId` changes. * - * @param visible whether Desktop Mode is now visible + * @param displayId The ID of the display for which this notification is triggering. + * @param isInDesktopModeAndNotInOverview True if a desktop is currently active on the given + * display, and Overview is currently inactive. */ - void onDesktopVisibilityChanged(boolean visible); + void onIsInDesktopModeChanged(int displayId, boolean isInDesktopModeAndNotInOverview); } }