Merge "Stash desktop apps on home gesture or taskbar home button press" into udc-qpr-dev

This commit is contained in:
Ats Jenk
2023-05-17 00:16:04 +00:00
committed by Android (Google) Code Review
5 changed files with 105 additions and 0 deletions
@@ -15,14 +15,22 @@
*/ */
package com.android.launcher3.statehandlers; package com.android.launcher3.statehandlers;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import android.os.RemoteException;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.android.launcher3.Launcher; import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState; import com.android.launcher3.LauncherState;
import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.uioverrides.QuickstepLauncher; 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 * 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 mInOverviewState;
private boolean mGestureInProgress; private boolean mGestureInProgress;
@Nullable
private IDesktopTaskListener mDesktopTaskListener;
public DesktopVisibilityController(Launcher launcher) { public DesktopVisibilityController(Launcher launcher) {
mLauncher = 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. * 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) { private void setLauncherViewsVisibility(int visibility) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "setLauncherViewsVisibility: visibility=" + visibility); Log.d(TAG, "setLauncherViewsVisibility: visibility=" + visibility);
@@ -43,12 +43,15 @@ import androidx.annotation.StringRes;
import com.android.launcher3.R; import com.android.launcher3.R;
import com.android.launcher3.logging.StatsLogManager; import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.statehandlers.DesktopVisibilityController;
import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol; import com.android.launcher3.testing.shared.TestProtocol;
import com.android.quickstep.LauncherActivityInterface;
import com.android.quickstep.OverviewCommandHelper; import com.android.quickstep.OverviewCommandHelper;
import com.android.quickstep.SystemUiProxy; import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.TaskUtils; import com.android.quickstep.TaskUtils;
import com.android.quickstep.TouchInteractionService; import com.android.quickstep.TouchInteractionService;
import com.android.quickstep.views.DesktopTaskView;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@@ -267,6 +270,15 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
private void navigateHome() { private void navigateHome() {
TaskUtils.closeSystemWindowsAsync(CLOSE_SYSTEM_WINDOWS_REASON_HOME_KEY); 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); mService.getOverviewCommandHelper().addCommand(OverviewCommandHelper.TYPE_HOME);
} }
@@ -259,6 +259,9 @@ public class QuickstepLauncher extends Launcher {
mTISBindHelper = new TISBindHelper(this, this::onTISConnected); mTISBindHelper = new TISBindHelper(this, this::onTISConnected);
mDepthController = new DepthController(this); mDepthController = new DepthController(this);
mDesktopVisibilityController = new DesktopVisibilityController(this); mDesktopVisibilityController = new DesktopVisibilityController(this);
if (DesktopTaskView.DESKTOP_MODE_SUPPORTED) {
mDesktopVisibilityController.registerSystemUiListener();
}
mHotseatPredictionController = new HotseatPredictionController(this); mHotseatPredictionController = new HotseatPredictionController(this);
mEnableWidgetDepth = SystemProperties.getBoolean("ro.launcher.depth.widget", true); mEnableWidgetDepth = SystemProperties.getBoolean("ro.launcher.depth.widget", true);
@@ -483,6 +486,10 @@ public class QuickstepLauncher extends Launcher {
mLauncherUnfoldAnimationController.onDestroy(); mLauncherUnfoldAnimationController.onDestroy();
} }
if (mDesktopVisibilityController != null) {
mDesktopVisibilityController.unregisterSystemUiListener();
}
super.onDestroy(); super.onDestroy();
mHotseatPredictionController.destroy(); mHotseatPredictionController.destroy();
mSplitWithKeyboardShortcutController.onDestroy(); mSplitWithKeyboardShortcutController.onDestroy();
@@ -101,6 +101,7 @@ import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.dragndrop.DragView; import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.logging.StatsLogManager; import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.logging.StatsLogManager.StatsLogger; import com.android.launcher3.logging.StatsLogManager.StatsLogger;
import com.android.launcher3.statehandlers.DesktopVisibilityController;
import com.android.launcher3.statemanager.BaseState; import com.android.launcher3.statemanager.BaseState;
import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.taskbar.TaskbarUIController; import com.android.launcher3.taskbar.TaskbarUIController;
@@ -1133,6 +1134,14 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
mStateCallback.setState(STATE_SCALED_CONTROLLER_HOME | STATE_CAPTURE_SCREENSHOT); mStateCallback.setState(STATE_SCALED_CONTROLLER_HOME | STATE_CAPTURE_SCREENSHOT);
// Notify the SysUI to use fade-in animation when entering PiP // Notify the SysUI to use fade-in animation when entering PiP
SystemUiProxy.INSTANCE.get(mContext).setPipAnimationTypeToAlpha(); 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; break;
case RECENTS: case RECENTS:
mStateCallback.setState(STATE_SCALED_CONTROLLER_RECENTS | STATE_CAPTURE_SCREENSHOT mStateCallback.setState(STATE_SCALED_CONTROLLER_RECENTS | STATE_CAPTURE_SCREENSHOT
@@ -74,6 +74,7 @@ import com.android.wm.shell.back.IBackAnimation;
import com.android.wm.shell.bubbles.IBubbles; import com.android.wm.shell.bubbles.IBubbles;
import com.android.wm.shell.bubbles.IBubblesListener; import com.android.wm.shell.bubbles.IBubblesListener;
import com.android.wm.shell.desktopmode.IDesktopMode; 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.draganddrop.IDragAndDrop;
import com.android.wm.shell.onehanded.IOneHanded; import com.android.wm.shell.onehanded.IOneHanded;
import com.android.wm.shell.pip.IPip; import com.android.wm.shell.pip.IPip;
@@ -130,6 +131,7 @@ public class SystemUiProxy implements ISystemUiProxy {
private ILauncherUnlockAnimationController mLauncherUnlockAnimationController; private ILauncherUnlockAnimationController mLauncherUnlockAnimationController;
private IRecentTasksListener mRecentTasksListener; private IRecentTasksListener mRecentTasksListener;
private IUnfoldTransitionListener mUnfoldAnimationListener; private IUnfoldTransitionListener mUnfoldAnimationListener;
private IDesktopTaskListener mDesktopTaskListener;
private final LinkedHashMap<RemoteTransition, TransitionFilter> mRemoteTransitions = private final LinkedHashMap<RemoteTransition, TransitionFilter> mRemoteTransitions =
new LinkedHashMap<>(); new LinkedHashMap<>();
private IBinder mOriginalTransactionToken = null; private IBinder mOriginalTransactionToken = null;
@@ -243,6 +245,7 @@ public class SystemUiProxy implements ISystemUiProxy {
registerRecentTasksListener(mRecentTasksListener); registerRecentTasksListener(mRecentTasksListener);
setBackToLauncherCallback(mBackToLauncherCallback, mBackToLauncherRunner); setBackToLauncherCallback(mBackToLauncherCallback, mBackToLauncherRunner);
setUnfoldAnimationListener(mUnfoldAnimationListener); 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 */ /** Call shell to get number of visible freeform tasks */
public int getVisibleDesktopTaskCount(int displayId) { public int getVisibleDesktopTaskCount(int displayId) {
if (mDesktopMode != null) { if (mDesktopMode != null) {
@@ -1159,6 +1173,18 @@ public class SystemUiProxy implements ISystemUiProxy {
return 0; 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 // Unfold transition
// //