diff options
| author | 2023-09-19 16:54:46 +0000 | |
|---|---|---|
| committer | 2023-09-19 16:54:46 +0000 | |
| commit | 2de0d19cd89e5085867748282e78d6d39e4fadfa (patch) | |
| tree | 92c71a471b58a9f2f7cb36869f7791a5fa629610 | |
| parent | 5d73030460fca23cc067ab88447c756c626db299 (diff) | |
| parent | 67b7cd184172e6b0d887be387d38917919425a2a (diff) | |
Merge "Notify recents animation state for CommandQueue" into main
6 files changed, 78 insertions, 0 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasks.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasks.java index 069066e4bd49..2616b8b08bf1 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasks.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasks.java @@ -34,4 +34,10 @@ public interface RecentTasks { default void getRecentTasks(int maxNum, int flags, int userId, Executor callbackExecutor, Consumer<List<GroupedRecentTaskInfo>> callback) { } + + /** + * Adds the listener to be notified of whether the recent task animation is running. + */ + default void addAnimationStateListener(Executor listenerExecutor, Consumer<Boolean> listener) { + } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java index 94e1b33dbf58..ccc34389557c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java @@ -428,6 +428,21 @@ public class RecentTasksController implements TaskStackListenerCallback, executor.execute(() -> callback.accept(tasks)); }); } + + @Override + public void addAnimationStateListener(Executor executor, Consumer<Boolean> listener) { + mMainExecutor.execute(() -> { + if (mTransitionHandler == null) { + return; + } + mTransitionHandler.addTransitionStateListener(new RecentsTransitionStateListener() { + @Override + public void onAnimationStateChanged(boolean running) { + executor.execute(() -> listener.accept(running)); + } + }); + }); + } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java index 6cd33bc342c8..7ae06662873f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java @@ -76,6 +76,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler { private final RecentTasksController mRecentTasksController; private IApplicationThread mAnimApp = null; private final ArrayList<RecentsController> mControllers = new ArrayList<>(); + private final ArrayList<RecentsTransitionStateListener> mStateListeners = new ArrayList<>(); /** * List of other handlers which might need to mix recents with other things. These are checked @@ -106,6 +107,11 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler { mMixers.remove(mixer); } + /** Adds the callback for receiving the state change of transition. */ + public void addTransitionStateListener(RecentsTransitionStateListener listener) { + mStateListeners.add(listener); + } + @VisibleForTesting public IBinder startRecentsTransition(PendingIntent intent, Intent fillIn, Bundle options, IApplicationThread appThread, IRecentsAnimationRunner listener) { @@ -389,6 +395,9 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler { mTransition = null; mPendingPauseSnapshotsForCancel = null; mControllers.remove(this); + for (int i = 0; i < mStateListeners.size(); i++) { + mStateListeners.get(i).onAnimationStateChanged(false); + } } boolean start(TransitionInfo info, SurfaceControl.Transaction t, @@ -528,6 +537,9 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler { apps.toArray(new RemoteAnimationTarget[apps.size()]), wallpapers.toArray(new RemoteAnimationTarget[wallpapers.size()]), new Rect(0, 0, 0, 0), new Rect(), b); + for (int i = 0; i < mStateListeners.size(); i++) { + mStateListeners.get(i).onAnimationStateChanged(true); + } } catch (RemoteException e) { Slog.e(TAG, "Error starting recents animation", e); cancel("onAnimationStart() failed"); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionStateListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionStateListener.java new file mode 100644 index 000000000000..804dcc8a10e6 --- /dev/null +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionStateListener.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.wm.shell.recents; + +/** The listener for the events from {@link RecentsTransitionHandler}. */ +public interface RecentsTransitionStateListener { + + /** Notifies whether the recents animation is running. */ + default void onAnimationStateChanged(boolean running) { + } +} diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java index 6fafcd51bd50..897c4da0fae2 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java @@ -61,6 +61,7 @@ import com.android.wm.shell.onehanded.OneHandedEventCallback; import com.android.wm.shell.onehanded.OneHandedTransitionCallback; import com.android.wm.shell.onehanded.OneHandedUiEventLogger; import com.android.wm.shell.pip.Pip; +import com.android.wm.shell.recents.RecentTasks; import com.android.wm.shell.splitscreen.SplitScreen; import com.android.wm.shell.sysui.ShellInterface; @@ -109,6 +110,7 @@ public final class WMShell implements private final Optional<SplitScreen> mSplitScreenOptional; private final Optional<OneHanded> mOneHandedOptional; private final Optional<DesktopMode> mDesktopModeOptional; + private final Optional<RecentTasks> mRecentTasksOptional; private final CommandQueue mCommandQueue; private final ConfigurationController mConfigurationController; @@ -172,6 +174,7 @@ public final class WMShell implements Optional<SplitScreen> splitScreenOptional, Optional<OneHanded> oneHandedOptional, Optional<DesktopMode> desktopMode, + Optional<RecentTasks> recentTasks, CommandQueue commandQueue, ConfigurationController configurationController, KeyguardStateController keyguardStateController, @@ -195,6 +198,7 @@ public final class WMShell implements mSplitScreenOptional = splitScreenOptional; mOneHandedOptional = oneHandedOptional; mDesktopModeOptional = desktopMode; + mRecentTasksOptional = recentTasks; mWakefulnessLifecycle = wakefulnessLifecycle; mUserTracker = userTracker; mDisplayTracker = displayTracker; @@ -220,6 +224,7 @@ public final class WMShell implements mSplitScreenOptional.ifPresent(this::initSplitScreen); mOneHandedOptional.ifPresent(this::initOneHanded); mDesktopModeOptional.ifPresent(this::initDesktopMode); + mRecentTasksOptional.ifPresent(this::initRecentTasks); mNoteTaskInitializer.initialize(); } @@ -351,6 +356,12 @@ public final class WMShell implements }, mSysUiMainExecutor); } + @VisibleForTesting + void initRecentTasks(RecentTasks recentTasks) { + recentTasks.addAnimationStateListener(mSysUiMainExecutor, + mCommandQueue::onRecentsAnimationStateChanged); + } + @Override public boolean isDumpCritical() { // Dump can't be critical because the shell has to dump on the main thread for diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java index ef0adbb91a63..d2c8aea5988f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java @@ -41,6 +41,7 @@ import com.android.wm.shell.onehanded.OneHanded; import com.android.wm.shell.onehanded.OneHandedEventCallback; import com.android.wm.shell.onehanded.OneHandedTransitionCallback; import com.android.wm.shell.pip.Pip; +import com.android.wm.shell.recents.RecentTasks; import com.android.wm.shell.splitscreen.SplitScreen; import com.android.wm.shell.sysui.ShellInterface; @@ -79,6 +80,7 @@ public class WMShellTest extends SysuiTestCase { @Mock ShellExecutor mSysUiMainExecutor; @Mock NoteTaskInitializer mNoteTaskInitializer; @Mock DesktopMode mDesktopMode; + @Mock RecentTasks mRecentTasks; @Before public void setUp() { @@ -91,6 +93,7 @@ public class WMShellTest extends SysuiTestCase { Optional.of(mSplitScreen), Optional.of(mOneHanded), Optional.of(mDesktopMode), + Optional.of(mRecentTasks), mCommandQueue, mConfigurationController, mKeyguardStateController, @@ -129,4 +132,10 @@ public class WMShellTest extends SysuiTestCase { any(DesktopModeTaskRepository.VisibleTasksListener.class), any(Executor.class)); } + + @Test + public void initRecentTasks_registersListener() { + mWMShell.initRecentTasks(mRecentTasks); + verify(mRecentTasks).addAnimationStateListener(any(Executor.class), any()); + } } |