Loading libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java +1 −0 Original line number Diff line number Diff line Loading @@ -452,6 +452,7 @@ public class ShellTaskOrganizer extends TaskOrganizer implements } notifyLocusVisibilityIfNeeded(info.getTaskInfo()); notifyCompatUI(info.getTaskInfo(), listener); mRecentTasks.ifPresent(recentTasks -> recentTasks.onTaskAdded(info.getTaskInfo())); } /** Loading libs/WindowManager/Shell/src/com/android/wm/shell/recents/IRecentTasks.aidl +7 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; } libs/WindowManager/Shell/src/com/android/wm/shell/recents/IRecentTasksListener.aidl +12 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading @@ -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 libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java +76 −17 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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; } Loading Loading @@ -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) { Loading @@ -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 Loading Loading @@ -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()); } /** Loading Loading @@ -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 libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/recents/RecentTasksControllerTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/ShellTaskOrganizer.java +1 −0 Original line number Diff line number Diff line Loading @@ -452,6 +452,7 @@ public class ShellTaskOrganizer extends TaskOrganizer implements } notifyLocusVisibilityIfNeeded(info.getTaskInfo()); notifyCompatUI(info.getTaskInfo(), listener); mRecentTasks.ifPresent(recentTasks -> recentTasks.onTaskAdded(info.getTaskInfo())); } /** Loading
libs/WindowManager/Shell/src/com/android/wm/shell/recents/IRecentTasks.aidl +7 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; }
libs/WindowManager/Shell/src/com/android/wm/shell/recents/IRecentTasksListener.aidl +12 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading @@ -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
libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java +76 −17 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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; } Loading Loading @@ -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) { Loading @@ -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 Loading Loading @@ -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()); } /** Loading Loading @@ -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
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/recents/RecentTasksControllerTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading