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

Commit 67b7cd18 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Notify recents animation state for CommandQueue

This restores the callback that was missed for shell transition.

In legacy transition it was called from
 core: wm.RecentsAnimationController -> StatusBarManagerService
       -> binder call to sysui's CommandQueue.

Now with shell transition, RecentsTransitionHandler and CommandQueue
are in the same process by default, so just set the callback directly.

Then it can reach RotationButtonController#setRecentsAnimationRunning
to affect shouldOverrideUserLockPrefs that decides whether the locked
rotation should be reset when receiving natural rotation.

Fix: 300216165
Test: atest WMShellTest#initRecentTasks_registersListener
Test: Disable auto-rotation. Launch calculator in portrait.
      Rotate device to landscape and press rotation button.
      Use gesture navigation to switch to a portrait-only app.
      (RotationButtonController should reset locked rotation to 0)
      Switch to calculator, it should keep in portrait.
Change-Id: Id841d70bce0f1c8a41a17b2d7ba9163be77aad59
parent 7b4ab317
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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) {
    }
}
+15 −0
Original line number Diff line number Diff line
@@ -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));
                    }
                });
            });
        }
    }


+12 −0
Original line number Diff line number Diff line
@@ -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) {
@@ -381,6 +387,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,
@@ -519,6 +528,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");
+25 −0
Original line number Diff line number Diff line
/*
 * 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) {
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -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
Loading