Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e1befb3 authored by Tony Wickham's avatar Tony Wickham
Browse files

Handle running task launch properly in desktop mode

- Move logic from KeyboardQuickSwitchViewController to handle
  bringing desktop tasks to front, and still support recent
  tasks for non-desktop mode.

Flag: com.android.launcher3.enable_recents_in_taskbar
Test: manually launch tasks from the Recents section in both
Desktop mode and full screen mode (running vs recent)
Bug: 315354060

Change-Id: I0520351b4d0095a3538c6165acd82a7b4c45a5e2
parent ff83f1c4
Loading
Loading
Loading
Loading
+2 −30
Original line number Diff line number Diff line
@@ -15,12 +15,7 @@
 */
package com.android.launcher3.taskbar;

import static android.window.SplashScreen.SPLASH_SCREEN_STYLE_UNDEFINED;

import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;

import android.animation.Animator;
import android.app.ActivityOptions;
import android.view.KeyEvent;
import android.view.animation.AnimationUtils;
import android.window.RemoteTransition;
@@ -31,13 +26,10 @@ import androidx.annotation.Nullable;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorListeners;
import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.util.DesktopTask;
import com.android.quickstep.util.GroupTask;
import com.android.quickstep.util.SlideInRemoteTransition;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.QuickStepContract;

import java.io.PrintWriter;
@@ -158,28 +150,8 @@ public class KeyboardQuickSwitchViewController {
                AnimationUtils.loadInterpolator(
                        context, android.R.interpolator.fast_out_extra_slow_in)),
                "SlideInTransition");
        if (task instanceof DesktopTask) {
            UI_HELPER_EXECUTOR.execute(() ->
                    SystemUiProxy.INSTANCE.get(mKeyboardQuickSwitchView.getContext())
                            .showDesktopApps(
                                    mKeyboardQuickSwitchView.getDisplay().getDisplayId(),
                                    remoteTransition));
        } else if (mOnDesktop) {
            UI_HELPER_EXECUTOR.execute(() ->
                    SystemUiProxy.INSTANCE.get(mKeyboardQuickSwitchView.getContext())
                            .showDesktopApp(task.task1.key.id));
        } else if (task.task2 == null) {
            UI_HELPER_EXECUTOR.execute(() -> {
                ActivityOptions activityOptions = mControllers.taskbarActivityContext
                        .makeDefaultActivityOptions(SPLASH_SCREEN_STYLE_UNDEFINED).options;
                activityOptions.setRemoteTransition(remoteTransition);

                ActivityManagerWrapper.getInstance().startActivityFromRecents(
                        task.task1.key, activityOptions);
            });
        } else {
            mControllers.uiController.launchSplitTasks(task, remoteTransition);
        }
        mControllers.taskbarActivityContext.handleGroupTaskLaunch(
                task, remoteTransition, mOnDesktop);
        return -1;
    }

+38 −5
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import android.view.View;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.Toast;
import android.window.RemoteTransition;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -131,6 +132,9 @@ import com.android.launcher3.views.ActivityContext;
import com.android.quickstep.LauncherActivityInterface;
import com.android.quickstep.NavHandle;
import com.android.quickstep.RecentsModel;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.util.DesktopTask;
import com.android.quickstep.util.GroupTask;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;
import com.android.systemui.shared.recents.model.Task;
@@ -298,7 +302,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
                TaskbarEduTooltipController.newInstance(this),
                new KeyboardQuickSwitchController(),
                new TaskbarPinningController(this, () ->
                        DisplayController.INSTANCE.get(this).getInfo().isInDesktopMode()),
                        DisplayController.isInDesktopMode(this)),
                bubbleControllersOptional);

        mLauncherPrefs = LauncherPrefs.get(this);
@@ -1081,10 +1085,9 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
        RecentsView recents = taskbarUIController.getRecentsView();
        boolean shouldCloseAllOpenViews = true;
        Object tag = view.getTag();
        if (tag instanceof Task) {
            Task task = (Task) tag;
            ActivityManagerWrapper.getInstance().startActivityFromRecents(task.key,
                    ActivityOptions.makeBasic());
        if (tag instanceof GroupTask groupTask) {
            handleGroupTaskLaunch(groupTask, /* remoteTransition = */ null,
                    DisplayController.isInDesktopMode(this));
            mControllers.taskbarStashController.updateAndAnimateTransientTaskbar(true);
        } else if (tag instanceof FolderInfo) {
            // Tapping an expandable folder icon on Taskbar
@@ -1184,6 +1187,36 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
        }
    }

    /**
     * Launches the given GroupTask with the following behavior:
     * - If the GroupTask is a DesktopTask, launch the tasks in that Desktop.
     * - If {@code onDesktop}, bring the given GroupTask to the front.
     * - If the GroupTask is a single task, launch it via startActivityFromRecents.
     * - Otherwise, we assume the GroupTask is a Split pair and launch them together.
     */
    public void handleGroupTaskLaunch(GroupTask task, @Nullable RemoteTransition remoteTransition,
            boolean onDesktop) {
        if (task instanceof DesktopTask) {
            UI_HELPER_EXECUTOR.execute(() ->
                    SystemUiProxy.INSTANCE.get(this).showDesktopApps(getDisplay().getDisplayId(),
                            remoteTransition));
        } else if (onDesktop) {
            UI_HELPER_EXECUTOR.execute(() ->
                    SystemUiProxy.INSTANCE.get(this).showDesktopApp(task.task1.key.id));
        } else if (task.task2 == null) {
            UI_HELPER_EXECUTOR.execute(() -> {
                ActivityOptions activityOptions =
                        makeDefaultActivityOptions(SPLASH_SCREEN_STYLE_UNDEFINED).options;
                activityOptions.setRemoteTransition(remoteTransition);

                ActivityManagerWrapper.getInstance().startActivityFromRecents(
                        task.task1.key, activityOptions);
            });
        } else {
            mControllers.uiController.launchSplitTasks(task, remoteTransition);
        }
    }

    /**
     * Runs when the user taps a Taskbar icon in TaskbarActivityContext (Overview or inside an app),
     * and calls the appropriate method to animate and launch.
+5 −0
Original line number Diff line number Diff line
@@ -182,6 +182,11 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable {
        return INSTANCE.get(context).getInfo().isTransientTaskbar();
    }

    /** Returns whether we are currently in Desktop mode. */
    public static boolean isInDesktopMode(Context context) {
        return INSTANCE.get(context).getInfo().isInDesktopMode();
    }

    /**
     * Handles info change for desktop mode.
     */