From 7cd5a681f7b77bad48b77eebf967575e35add2a8 Mon Sep 17 00:00:00 2001 From: Ats Jenk Date: Thu, 11 May 2023 15:21:18 -0700 Subject: [PATCH] Stash desktop apps on home gesture or taskbar home button press When we detect the home gesture or tap on home button in taskbar, check if desktop apps are visible. If they are, signal WMShell to stash the desktop apps. Flag: persist.wm.debug.desktop_mode_2 Bug: 261234402 Test: have gesture nav enabled, put an app on desktop and swipe up to home, verify toast is shown, and next app launches to desktop Test: have 3-button nav enabled, put an app on desktop and press home, verify toast is shown, and next app launches to desktop Change-Id: I824e640bfafa20cb3451cbd8f035fe9dca18094f --- .../DesktopVisibilityController.java | 51 +++++++++++++++++++ .../taskbar/TaskbarNavButtonController.java | 12 +++++ .../uioverrides/QuickstepLauncher.java | 7 +++ .../android/quickstep/AbsSwipeUpHandler.java | 9 ++++ .../com/android/quickstep/SystemUiProxy.java | 26 ++++++++++ 5 files changed, 105 insertions(+) diff --git a/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.java b/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.java index d087d39955..479dc82e40 100644 --- a/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.java +++ b/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.java @@ -15,14 +15,22 @@ */ package com.android.launcher3.statehandlers; +import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; + +import android.os.RemoteException; import android.os.SystemProperties; import android.util.Log; import android.view.View; +import android.widget.Toast; + +import androidx.annotation.Nullable; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.uioverrides.QuickstepLauncher; +import com.android.quickstep.SystemUiProxy; +import com.android.wm.shell.desktopmode.IDesktopTaskListener; /** * Controls the visibility of the workspace and the resumed / paused state when desktop mode @@ -39,10 +47,44 @@ public class DesktopVisibilityController { private boolean mInOverviewState; private boolean mGestureInProgress; + @Nullable + private IDesktopTaskListener mDesktopTaskListener; + public DesktopVisibilityController(Launcher launcher) { mLauncher = launcher; } + /** + * Register a listener with System UI to receive updates about desktop tasks state + */ + public void registerSystemUiListener() { + mDesktopTaskListener = new IDesktopTaskListener.Stub() { + @Override + public void onVisibilityChanged(int displayId, boolean visible) throws RemoteException { + // TODO(b/261234402): move visibility from sysui state to listener + } + + @Override + public void onStashedChanged(int displayId, boolean stashed) throws RemoteException { + // TODO(b/261234402): show a persistent toast + MAIN_EXECUTOR.execute(() -> { + if (stashed && displayId == mLauncher.getDisplayId()) { + Toast.makeText(mLauncher, "Adding app to Desktop", + Toast.LENGTH_SHORT).show(); + } + }); + } + }; + SystemUiProxy.INSTANCE.get(mLauncher).setDesktopTaskListener(mDesktopTaskListener); + } + + /** + * Clear listener from System UI that was set with {@link #registerSystemUiListener()} + */ + public void unregisterSystemUiListener() { + SystemUiProxy.INSTANCE.get(mLauncher).setDesktopTaskListener(null); + } + /** * Whether desktop mode is supported. */ @@ -130,6 +172,15 @@ public class DesktopVisibilityController { } } + /** + * Handle launcher moving to home due to home gesture or home button press. + */ + public void onHomeActionTriggered() { + if (areFreeformTasksVisible()) { + SystemUiProxy.INSTANCE.get(mLauncher).stashDesktopApps(mLauncher.getDisplayId()); + } + } + private void setLauncherViewsVisibility(int visibility) { if (DEBUG) { Log.d(TAG, "setLauncherViewsVisibility: visibility=" + visibility); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarNavButtonController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarNavButtonController.java index 610efebfcb..0f8de34461 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarNavButtonController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarNavButtonController.java @@ -43,12 +43,15 @@ import androidx.annotation.StringRes; import com.android.launcher3.R; import com.android.launcher3.logging.StatsLogManager; +import com.android.launcher3.statehandlers.DesktopVisibilityController; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.shared.TestProtocol; +import com.android.quickstep.LauncherActivityInterface; import com.android.quickstep.OverviewCommandHelper; import com.android.quickstep.SystemUiProxy; import com.android.quickstep.TaskUtils; import com.android.quickstep.TouchInteractionService; +import com.android.quickstep.views.DesktopTaskView; import java.io.PrintWriter; import java.lang.annotation.Retention; @@ -267,6 +270,15 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa private void navigateHome() { TaskUtils.closeSystemWindowsAsync(CLOSE_SYSTEM_WINDOWS_REASON_HOME_KEY); + + if (DesktopTaskView.DESKTOP_IS_PROTO2_ENABLED) { + DesktopVisibilityController desktopVisibilityController = + LauncherActivityInterface.INSTANCE.getDesktopVisibilityController(); + if (desktopVisibilityController != null) { + desktopVisibilityController.onHomeActionTriggered(); + } + } + mService.getOverviewCommandHelper().addCommand(OverviewCommandHelper.TYPE_HOME); } diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 65f449caba..f9ebe8b314 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -257,6 +257,9 @@ public class QuickstepLauncher extends Launcher { mTISBindHelper = new TISBindHelper(this, this::onTISConnected); mDepthController = new DepthController(this); mDesktopVisibilityController = new DesktopVisibilityController(this); + if (DesktopTaskView.DESKTOP_MODE_SUPPORTED) { + mDesktopVisibilityController.registerSystemUiListener(); + } mHotseatPredictionController = new HotseatPredictionController(this); mEnableWidgetDepth = SystemProperties.getBoolean("ro.launcher.depth.widget", true); @@ -484,6 +487,10 @@ public class QuickstepLauncher extends Launcher { mLauncherUnfoldAnimationController.onDestroy(); } + if (mDesktopVisibilityController != null) { + mDesktopVisibilityController.unregisterSystemUiListener(); + } + super.onDestroy(); mHotseatPredictionController.destroy(); mSplitWithKeyboardShortcutController.onDestroy(); diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index b49eb24971..92536f118d 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -101,6 +101,7 @@ import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.dragndrop.DragView; import com.android.launcher3.logging.StatsLogManager; import com.android.launcher3.logging.StatsLogManager.StatsLogger; +import com.android.launcher3.statehandlers.DesktopVisibilityController; import com.android.launcher3.statemanager.BaseState; import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.taskbar.TaskbarUIController; @@ -1133,6 +1134,14 @@ public abstract class AbsSwipeUpHandler, mStateCallback.setState(STATE_SCALED_CONTROLLER_HOME | STATE_CAPTURE_SCREENSHOT); // Notify the SysUI to use fade-in animation when entering PiP SystemUiProxy.INSTANCE.get(mContext).setPipAnimationTypeToAlpha(); + if (DesktopTaskView.DESKTOP_IS_PROTO2_ENABLED) { + // Notify the SysUI to stash desktop apps if they are visible + DesktopVisibilityController desktopVisibilityController = + mActivityInterface.getDesktopVisibilityController(); + if (desktopVisibilityController != null) { + desktopVisibilityController.onHomeActionTriggered(); + } + } break; case RECENTS: mStateCallback.setState(STATE_SCALED_CONTROLLER_RECENTS | STATE_CAPTURE_SCREENSHOT diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.java b/quickstep/src/com/android/quickstep/SystemUiProxy.java index 29aed2532b..0be97413cd 100644 --- a/quickstep/src/com/android/quickstep/SystemUiProxy.java +++ b/quickstep/src/com/android/quickstep/SystemUiProxy.java @@ -74,6 +74,7 @@ import com.android.wm.shell.back.IBackAnimation; import com.android.wm.shell.bubbles.IBubbles; import com.android.wm.shell.bubbles.IBubblesListener; import com.android.wm.shell.desktopmode.IDesktopMode; +import com.android.wm.shell.desktopmode.IDesktopTaskListener; import com.android.wm.shell.draganddrop.IDragAndDrop; import com.android.wm.shell.onehanded.IOneHanded; import com.android.wm.shell.pip.IPip; @@ -130,6 +131,7 @@ public class SystemUiProxy implements ISystemUiProxy { private ILauncherUnlockAnimationController mLauncherUnlockAnimationController; private IRecentTasksListener mRecentTasksListener; private IUnfoldTransitionListener mUnfoldAnimationListener; + private IDesktopTaskListener mDesktopTaskListener; private final LinkedHashMap mRemoteTransitions = new LinkedHashMap<>(); private IBinder mOriginalTransactionToken = null; @@ -243,6 +245,7 @@ public class SystemUiProxy implements ISystemUiProxy { registerRecentTasksListener(mRecentTasksListener); setBackToLauncherCallback(mBackToLauncherCallback, mBackToLauncherRunner); setUnfoldAnimationListener(mUnfoldAnimationListener); + setDesktopTaskListener(mDesktopTaskListener); } /** @@ -1147,6 +1150,17 @@ public class SystemUiProxy implements ISystemUiProxy { } } + /** Call shell to stash desktop apps */ + public void stashDesktopApps(int displayId) { + if (mDesktopMode != null) { + try { + mDesktopMode.stashDesktopApps(displayId); + } catch (RemoteException e) { + Log.w(TAG, "Failed call stashDesktopApps", e); + } + } + } + /** Call shell to get number of visible freeform tasks */ public int getVisibleDesktopTaskCount(int displayId) { if (mDesktopMode != null) { @@ -1159,6 +1173,18 @@ public class SystemUiProxy implements ISystemUiProxy { return 0; } + /** Set a listener on shell to get updates about desktop task state */ + public void setDesktopTaskListener(@Nullable IDesktopTaskListener listener) { + mDesktopTaskListener = listener; + if (mDesktopMode != null) { + try { + mDesktopMode.setTaskListener(listener); + } catch (RemoteException e) { + Log.w(TAG, "Failed call setDesktopTaskListener", e); + } + } + } + // // Unfold transition //