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

Commit c047fa42 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Add running apps icons to taskbar for desktop environment." into tm-qpr-dev

parents 5cfe9c01 a729c5a2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -452,6 +452,7 @@ public class ShellTaskOrganizer extends TaskOrganizer implements
        }
        notifyLocusVisibilityIfNeeded(info.getTaskInfo());
        notifyCompatUI(info.getTaskInfo(), listener);
        mRecentTasks.ifPresent(recentTasks -> recentTasks.onTaskAdded(info.getTaskInfo()));
    }

    /**
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.wm.shell.recents;

import android.app.ActivityManager;

import com.android.wm.shell.recents.IRecentTasksListener;
import com.android.wm.shell.util.GroupedRecentTaskInfo;

@@ -38,4 +40,9 @@ interface IRecentTasks {
     * Gets the set of recent tasks.
     */
    GroupedRecentTaskInfo[] getRecentTasks(int maxNum, int flags, int userId) = 3;

    /**
     * Gets the set of running tasks.
     */
    ActivityManager.RunningTaskInfo[] getRunningTasks(int maxNum) = 4;
}
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.wm.shell.recents;

import android.app.ActivityManager;

/**
 * Listener interface that Launcher attaches to SystemUI to get split-screen callbacks.
 */
@@ -25,4 +27,14 @@ oneway interface IRecentTasksListener {
     * Called when the set of recent tasks change.
     */
    void onRecentTasksChanged();

    /**
     * Called when a running task appears.
     */
    void onRunningTaskAppeared(in ActivityManager.RunningTaskInfo taskInfo);

    /**
     * Called when a running task vanishes.
     */
    void onRunningTaskVanished(in ActivityManager.RunningTaskInfo taskInfo);
}
 No newline at end of file
+76 −17
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.wm.shell.recents;

import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.content.pm.PackageManager.FEATURE_PC;

import static com.android.wm.shell.common.ExecutorUtils.executeRemoteCallWithTaskPermission;

@@ -63,8 +64,9 @@ public class RecentTasksController implements TaskStackListenerCallback,
    private final ShellExecutor mMainExecutor;
    private final TaskStackListenerImpl mTaskStackListener;
    private final RecentTasks mImpl = new RecentTasksImpl();
    private IRecentTasksListener mListener;
    private final boolean mIsDesktopMode;

    private final ArrayList<Runnable> mCallbacks = new ArrayList<>();
    // Mapping of split task ids, mappings are symmetrical (ie. if t1 is the taskid of a task in a
    // pair, then mSplitTasks[t1] = t2, and mSplitTasks[t2] = t1)
    private final SparseIntArray mSplitTasks = new SparseIntArray();
@@ -95,6 +97,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
    RecentTasksController(Context context, TaskStackListenerImpl taskStackListener,
            ShellExecutor mainExecutor) {
        mContext = context;
        mIsDesktopMode = mContext.getPackageManager().hasSystemFeature(FEATURE_PC);
        mTaskStackListener = taskStackListener;
        mMainExecutor = mainExecutor;
    }
@@ -176,10 +179,15 @@ public class RecentTasksController implements TaskStackListenerCallback,
        notifyRecentTasksChanged();
    }

    public void onTaskRemoved(TaskInfo taskInfo) {
    public void onTaskAdded(ActivityManager.RunningTaskInfo taskInfo) {
        notifyRunningTaskAppeared(taskInfo);
    }

    public void onTaskRemoved(ActivityManager.RunningTaskInfo taskInfo) {
        // Remove any split pairs associated with this task
        removeSplitPair(taskInfo.taskId);
        notifyRecentTasksChanged();
        notifyRunningTaskVanished(taskInfo);
    }

    public void onTaskWindowingModeChanged(TaskInfo taskInfo) {
@@ -189,19 +197,50 @@ public class RecentTasksController implements TaskStackListenerCallback,
    @VisibleForTesting
    void notifyRecentTasksChanged() {
        ProtoLog.v(ShellProtoLogGroup.WM_SHELL_RECENT_TASKS, "Notify recent tasks changed");
        for (int i = 0; i < mCallbacks.size(); i++) {
            mCallbacks.get(i).run();
        if (mListener == null) {
            return;
        }
        try {
            mListener.onRecentTasksChanged();
        } catch (RemoteException e) {
            Slog.w(TAG, "Failed call notifyRecentTasksChanged", e);
        }
    }

    private void registerRecentTasksListener(Runnable listener) {
        if (!mCallbacks.contains(listener)) {
            mCallbacks.add(listener);
    /**
     * Notify the running task listener that a task appeared on desktop environment.
     */
    private void notifyRunningTaskAppeared(ActivityManager.RunningTaskInfo taskInfo) {
        if (mListener == null || !mIsDesktopMode || taskInfo.realActivity == null) {
            return;
        }
        try {
            mListener.onRunningTaskAppeared(taskInfo);
        } catch (RemoteException e) {
            Slog.w(TAG, "Failed call onRunningTaskAppeared", e);
        }
    }

    private void unregisterRecentTasksListener(Runnable listener) {
        mCallbacks.remove(listener);
    /**
     * Notify the running task listener that a task was removed on desktop environment.
     */
    private void notifyRunningTaskVanished(ActivityManager.RunningTaskInfo taskInfo) {
        if (mListener == null || !mIsDesktopMode || taskInfo.realActivity == null) {
            return;
        }
        try {
            mListener.onRunningTaskVanished(taskInfo);
        } catch (RemoteException e) {
            Slog.w(TAG, "Failed call onRunningTaskVanished", e);
        }
    }

    private void registerRecentTasksListener(IRecentTasksListener listener) {
        mListener = listener;
    }

    private void unregisterRecentTasksListener() {
        mListener = null;
    }

    @VisibleForTesting
@@ -280,19 +319,28 @@ public class RecentTasksController implements TaskStackListenerCallback,
        private RecentTasksController mController;
        private final SingleInstanceRemoteListener<RecentTasksController,
                IRecentTasksListener> mListener;
        private final Runnable mRecentTasksListener =
                new Runnable() {
        private final IRecentTasksListener mRecentTasksListener = new IRecentTasksListener.Stub() {
            @Override
                    public void run() {
            public void onRecentTasksChanged() throws RemoteException {
                mListener.call(l -> l.onRecentTasksChanged());
            }

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

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

        public IRecentTasksImpl(RecentTasksController controller) {
            mController = controller;
            mListener = new SingleInstanceRemoteListener<>(controller,
                    c -> c.registerRecentTasksListener(mRecentTasksListener),
                    c -> c.unregisterRecentTasksListener(mRecentTasksListener));
                    c -> c.unregisterRecentTasksListener());
        }

        /**
@@ -331,5 +379,16 @@ public class RecentTasksController implements TaskStackListenerCallback,
                    true /* blocking */);
            return out[0];
        }

        @Override
        public ActivityManager.RunningTaskInfo[] getRunningTasks(int maxNum) {
            final ActivityManager.RunningTaskInfo[][] tasks =
                    new ActivityManager.RunningTaskInfo[][] {null};
            executeRemoteCallWithTaskPermission(mController, "getRunningTasks",
                    (controller) -> tasks[0] = ActivityTaskManager.getInstance().getTasks(maxNum)
                            .toArray(new ActivityManager.RunningTaskInfo[0]),
                    true /* blocking */);
            return tasks[0];
        }
    }
}
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -30,11 +30,13 @@ import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import static java.lang.Integer.MAX_VALUE;

import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.view.SurfaceControl;

@@ -77,6 +79,7 @@ public class RecentTasksControllerTest extends ShellTestCase {
    @Before
    public void setUp() {
        mMainExecutor = new TestShellExecutor();
        when(mContext.getPackageManager()).thenReturn(mock(PackageManager.class));
        mRecentTasksController = spy(new RecentTasksController(mContext, mTaskStackListener,
                mMainExecutor));
        mShellTaskOrganizer = new ShellTaskOrganizer(mMainExecutor, mContext,