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

Commit 4cfeabc6 authored by Orhan Uysal's avatar Orhan Uysal
Browse files

Create onTaskMovedToFront callback.

Create a new onTaskMovedToFront callback that launcher can use to register with
shell. This new callback is based on shell transitions and uses
TaskStackTransitionObserver to update launcher.

Ignore-AOSP-First: new file so it shouldn't conflict
Flag: com.android.window.flags.enable_task_stack_observer_in_shell
Test: atest TaskStackTransitionObserverTest
Test: atest RecentTasksControllerTest
Bug: 341932484
Bug: 344684650
Change-Id: I0d50637cfd06ecf8a41966dbc410266eaa21954a
parent a3c08e42
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ import com.android.wm.shell.performance.PerfHintController;
import com.android.wm.shell.recents.RecentTasks;
import com.android.wm.shell.recents.RecentTasksController;
import com.android.wm.shell.recents.RecentsTransitionHandler;
import com.android.wm.shell.recents.TaskStackTransitionObserver;
import com.android.wm.shell.shared.DesktopModeStatus;
import com.android.wm.shell.shared.ShellTransitions;
import com.android.wm.shell.shared.annotations.ShellAnimationThread;
@@ -619,12 +620,13 @@ public abstract class WMShellBaseModule {
            TaskStackListenerImpl taskStackListener,
            ActivityTaskManager activityTaskManager,
            Optional<DesktopModeTaskRepository> desktopModeTaskRepository,
            TaskStackTransitionObserver taskStackTransitionObserver,
            @ShellMainThread ShellExecutor mainExecutor
    ) {
        return Optional.ofNullable(
                RecentTasksController.create(context, shellInit, shellController,
                        shellCommandHandler, taskStackListener, activityTaskManager,
                        desktopModeTaskRepository, mainExecutor));
                        desktopModeTaskRepository, taskStackTransitionObserver, mainExecutor));
    }

    @BindsOptionalOf
@@ -923,6 +925,19 @@ public abstract class WMShellBaseModule {
        });
    }

    //
    // Task Stack
    //

    @WMSingleton
    @Provides
    static TaskStackTransitionObserver provideTaskStackTransitionObserver(
            Lazy<Transitions> transitions,
            ShellInit shellInit
    ) {
        return new TaskStackTransitionObserver(transitions, shellInit);
    }

    //
    // Misc
    //
+5 −4
Original line number Diff line number Diff line
@@ -664,7 +664,8 @@ public abstract class WMShellModule {
    @Provides
    static Object provideIndependentShellComponentsToCreate(
            DragAndDropController dragAndDropController,
            Optional<DesktopTasksTransitionObserver> desktopTasksTransitionObserverOptional) {
            Optional<DesktopTasksTransitionObserver> desktopTasksTransitionObserverOptional
    ) {
        return new Object();
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -42,4 +42,7 @@ oneway interface IRecentTasksListener {
     * Called when a running task changes.
     */
    void onRunningTaskChanged(in RunningTaskInfo taskInfo);

    /** A task has moved to front. */
    oneway void onTaskMovedToFront(in RunningTaskInfo taskInfo);
}
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
# WM shell sub-module task stack owners
uysalorhan@google.com
samcackett@google.com
alexchau@google.com
silvajordan@google.com
uwaisashraf@google.com
 No newline at end of file
+39 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.content.pm.PackageManager.FEATURE_PC;

import static com.android.window.flags.Flags.enableDesktopWindowingTaskbarRunningApps;
import static com.android.window.flags.Flags.enableTaskStackObserverInShell;
import static com.android.wm.shell.sysui.ShellSharedConstants.KEY_EXTRA_SHELL_RECENT_TASKS;

import android.app.ActivityManager;
@@ -57,6 +58,7 @@ import com.android.wm.shell.shared.annotations.ShellMainThread;
import com.android.wm.shell.sysui.ShellCommandHandler;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.util.GroupedRecentTaskInfo;
import com.android.wm.shell.util.SplitBounds;

@@ -73,7 +75,8 @@ import java.util.function.Consumer;
 * Manages the recent task list from the system, caching it as necessary.
 */
public class RecentTasksController implements TaskStackListenerCallback,
        RemoteCallable<RecentTasksController>, DesktopModeTaskRepository.ActiveTasksListener {
        RemoteCallable<RecentTasksController>, DesktopModeTaskRepository.ActiveTasksListener,
        TaskStackTransitionObserver.TaskStackTransitionObserverListener {
    private static final String TAG = RecentTasksController.class.getSimpleName();

    private final Context mContext;
@@ -84,6 +87,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
    private final TaskStackListenerImpl mTaskStackListener;
    private final RecentTasksImpl mImpl = new RecentTasksImpl();
    private final ActivityTaskManager mActivityTaskManager;
    private final TaskStackTransitionObserver mTaskStackTransitionObserver;
    private RecentsTransitionHandler mTransitionHandler = null;
    private IRecentTasksListener mListener;
    private final boolean mPcFeatureEnabled;
@@ -112,13 +116,15 @@ public class RecentTasksController implements TaskStackListenerCallback,
            TaskStackListenerImpl taskStackListener,
            ActivityTaskManager activityTaskManager,
            Optional<DesktopModeTaskRepository> desktopModeTaskRepository,
            TaskStackTransitionObserver taskStackTransitionObserver,
            @ShellMainThread ShellExecutor mainExecutor
    ) {
        if (!context.getResources().getBoolean(com.android.internal.R.bool.config_hasRecents)) {
            return null;
        }
        return new RecentTasksController(context, shellInit, shellController, shellCommandHandler,
                taskStackListener, activityTaskManager, desktopModeTaskRepository, mainExecutor);
                taskStackListener, activityTaskManager, desktopModeTaskRepository,
                taskStackTransitionObserver, mainExecutor);
    }

    RecentTasksController(Context context,
@@ -128,6 +134,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
            TaskStackListenerImpl taskStackListener,
            ActivityTaskManager activityTaskManager,
            Optional<DesktopModeTaskRepository> desktopModeTaskRepository,
            TaskStackTransitionObserver taskStackTransitionObserver,
            ShellExecutor mainExecutor) {
        mContext = context;
        mShellController = shellController;
@@ -136,6 +143,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
        mPcFeatureEnabled = mContext.getPackageManager().hasSystemFeature(FEATURE_PC);
        mTaskStackListener = taskStackListener;
        mDesktopModeTaskRepository = desktopModeTaskRepository;
        mTaskStackTransitionObserver = taskStackTransitionObserver;
        mMainExecutor = mainExecutor;
        shellInit.addInitCallback(this::onInit, this);
    }
@@ -154,6 +162,10 @@ public class RecentTasksController implements TaskStackListenerCallback,
        mShellCommandHandler.addDumpCallback(this::dump, this);
        mTaskStackListener.addListener(this);
        mDesktopModeTaskRepository.ifPresent(it -> it.addActiveTaskListener(this));
        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            mTaskStackTransitionObserver.addTaskStackTransitionObserverListener(this,
                    mMainExecutor);
        }
    }

    void setTransitionHandler(RecentsTransitionHandler handler) {
@@ -267,6 +279,12 @@ public class RecentTasksController implements TaskStackListenerCallback,
        notifyRecentTasksChanged();
    }

    @Override
    public void onTaskMovedToFrontThroughTransition(
            ActivityManager.RunningTaskInfo runningTaskInfo) {
        notifyTaskMovedToFront(runningTaskInfo);
    }

    @VisibleForTesting
    void notifyRecentTasksChanged() {
        ProtoLog.v(ShellProtoLogGroup.WM_SHELL_RECENT_TASKS, "Notify recent tasks changed");
@@ -328,6 +346,19 @@ public class RecentTasksController implements TaskStackListenerCallback,
        }
    }

    private void notifyTaskMovedToFront(ActivityManager.RunningTaskInfo taskInfo) {
        if (mListener == null
                || !enableTaskStackObserverInShell()
                || taskInfo.realActivity == null) {
            return;
        }
        try {
            mListener.onTaskMovedToFront(taskInfo);
        } catch (RemoteException e) {
            Slog.w(TAG, "Failed call onTaskMovedToFront", e);
        }
    }

    private boolean shouldEnableRunningTasksForDesktopMode() {
        return mPcFeatureEnabled
                || (DesktopModeStatus.canEnterDesktopMode(mContext)
@@ -464,6 +495,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
        }
        return null;
    }

    public void dump(@NonNull PrintWriter pw, String prefix) {
        final String innerPrefix = prefix + "  ";
        pw.println(prefix + TAG);
@@ -547,6 +579,11 @@ public class RecentTasksController implements TaskStackListenerCallback,
            public void onRunningTaskChanged(ActivityManager.RunningTaskInfo taskInfo) {
                mListener.call(l -> l.onRunningTaskChanged(taskInfo));
            }

            @Override
            public void onTaskMovedToFront(ActivityManager.RunningTaskInfo taskInfo) {
                mListener.call(l -> l.onTaskMovedToFront(taskInfo));
            }
        };

        public IRecentTasksImpl(RecentTasksController controller) {
Loading