From 990c149544e2fa5d7c38e83e3eb4fed23854adae Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Tue, 27 Sep 2022 15:29:39 -0700 Subject: [PATCH] Bring other Desktop apps to front when opening a new one. This enables the launcher to bring all desktop apps to the front when launching a new app. This is only enabled when Desktop Mode feature flag is enabled and Shell transition is enabled. Bug: None Test: Manual, launch new apps from launcher Change-Id: I5ae3941c7d27db3180ea6725a37868416b6649fb --- .../desktopmode/DesktopModeController.java | 48 +++++++++++++++++-- .../wm/shell/transition/Transitions.java | 16 +++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeController.java index 99739c457aa67..dc7ed15dbe3a1 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeController.java @@ -19,6 +19,7 @@ package com.android.wm.shell.desktopmode; import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.view.WindowManager.TRANSIT_CHANGE; +import static android.view.WindowManager.TRANSIT_OPEN; import static com.android.wm.shell.common.ExecutorUtils.executeRemoteCallWithTaskPermission; import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE; @@ -29,13 +30,18 @@ import android.content.Context; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; +import android.os.IBinder; import android.os.UserHandle; import android.provider.Settings; import android.util.ArraySet; +import android.view.SurfaceControl; import android.window.DisplayAreaInfo; +import android.window.TransitionInfo; +import android.window.TransitionRequestInfo; import android.window.WindowContainerTransaction; import androidx.annotation.BinderThread; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.internal.annotations.VisibleForTesting; @@ -55,7 +61,8 @@ import java.util.Comparator; /** * Handles windowing changes when desktop mode system setting changes */ -public class DesktopModeController implements RemoteCallable { +public class DesktopModeController implements RemoteCallable, + Transitions.TransitionHandler { private final Context mContext; private final ShellTaskOrganizer mShellTaskOrganizer; @@ -89,6 +96,7 @@ public class DesktopModeController implements RemoteCallable activeTasks = mDesktopModeTaskRepository.getActiveTasks(); ProtoLog.d(WM_SHELL_DESKTOP_MODE, "bringDesktopAppsToFront: tasks=%s", activeTasks.size()); ArrayList taskInfos = new ArrayList<>(); @@ -173,7 +181,12 @@ public class DesktopModeController implements RemoteCallable { "This shouldn't happen, maybe the default handler is broken."); } + /** + * Gives every handler (in order) a chance to handle request until one consumes the transition. + * @return the WindowContainerTransaction given by the handler which consumed the transition. + */ + public WindowContainerTransaction dispatchRequest(@NonNull IBinder transition, + @NonNull TransitionRequestInfo request, @Nullable TransitionHandler skip) { + for (int i = mHandlers.size() - 1; i >= 0; --i) { + if (mHandlers.get(i) == skip) continue; + WindowContainerTransaction wct = mHandlers.get(i).handleRequest(transition, request); + if (wct != null) { + return wct; + } + } + return null; + } + /** Special version of finish just for dealing with no-op/invalid transitions. */ private void onAbort(IBinder transition) { onFinish(transition, null /* wct */, null /* wctCB */, true /* abort */);