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

Commit 6e857e6d authored by Evan Rosky's avatar Evan Rosky Committed by Android (Google) Code Review
Browse files

Merge "Unify TaskOrg and Transition binders" into main

parents 41145db2 43a864dc
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.app.ActivityManager;
import android.graphics.Rect;
import android.window.StartingWindowInfo;
import android.window.StartingWindowRemovalInfo;
import android.window.TransitionInfo;
import android.window.TransitionRequestInfo;
import android.window.WindowContainerToken;

/**
@@ -90,4 +92,28 @@ oneway interface ITaskOrganizer {
     * Called when the IME has drawn on the organized task.
     */
    void onImeDrawnOnTask(int taskId);

    /**
     * Called when all participants of a transition are ready to animate. This is in response to
     * {@link IWindowOrganizerController#startTransition}.
     *
     * @param transitionToken An identifying token for the transition that is now ready to animate.
     * @param info A collection of all the changes encapsulated by this transition.
     * @param t A surface transaction containing the surface state prior to animating.
     * @param finishT A surface transaction that will reset parenting/layering and generally put
     *                surfaces into their final (post-transition) state. Apply this after playing
     *                the animation but before calling finish.
     */
    void onTransitionReady(in IBinder transitionToken, in TransitionInfo info,
            in SurfaceControl.Transaction t, in SurfaceControl.Transaction finishT);

    /**
     * Called when something in WMCore requires a transition to play -- for example when an Activity
     * is started in a new Task.
     *
     * @param transitionToken An identifying token for the transition that needs to be started.
     *                        Pass this to {@link IWindowOrganizerController#startTransition}.
     * @param request Information about this particular request.
     */
    void requestStartTransition(in IBinder transitionToken, in TransitionRequestInfo request);
}
+22 −0
Original line number Diff line number Diff line
@@ -185,6 +185,16 @@ public class TaskOrganizer extends WindowOrganizer {
    @BinderThread
    public void onImeDrawnOnTask(int taskId) {}

    /** @hide */
    @BinderThread
    public void onTransitionReady(@NonNull IBinder iBinder, @NonNull TransitionInfo transitionInfo,
            @NonNull SurfaceControl.Transaction t, @NonNull SurfaceControl.Transaction finishT) {}

    /** @hide */
    @BinderThread
    public void requestStartTransition(@NonNull IBinder iBinder,
            @NonNull TransitionRequestInfo request) {}

    /**
     * @deprecated Use {@link #createRootTask(CreateRootTaskRequest)}
     * @hide
@@ -364,6 +374,18 @@ public class TaskOrganizer extends WindowOrganizer {
        public void onImeDrawnOnTask(int taskId) {
            mExecutor.execute(() -> TaskOrganizer.this.onImeDrawnOnTask(taskId));
        }

        @Override
        public void onTransitionReady(IBinder iBinder, TransitionInfo transitionInfo,
                SurfaceControl.Transaction t, SurfaceControl.Transaction finishT) {
            mExecutor.execute(() -> TaskOrganizer.this.onTransitionReady(
                    iBinder, transitionInfo, t, finishT));
        }

        @Override
        public void requestStartTransition(IBinder iBinder, TransitionRequestInfo request) {
            mExecutor.execute(() -> TaskOrganizer.this.requestStartTransition(iBinder, request));
        }
    };

    @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
+39 −1
Original line number Diff line number Diff line
@@ -25,10 +25,12 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.view.Display.DEFAULT_DISPLAY;

import static com.android.window.flags.Flags.unifyShellBinders;
import static com.android.wm.shell.compatui.impl.CompatUIEventsKt.SIZE_COMPAT_RESTART_BUTTON_APPEARED;
import static com.android.wm.shell.compatui.impl.CompatUIEventsKt.SIZE_COMPAT_RESTART_BUTTON_CLICKED;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_TASK_ORG;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_TASK_ORG_NOISY;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_TRANSITIONS;

import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -51,6 +53,8 @@ import android.window.StartingWindowInfo;
import android.window.StartingWindowRemovalInfo;
import android.window.TaskAppearedInfo;
import android.window.TaskOrganizer;
import android.window.TransitionInfo;
import android.window.TransitionRequestInfo;
import android.window.WindowContainerTransaction;
import android.window.WindowContainerTransactionCallback;

@@ -68,6 +72,7 @@ import com.android.wm.shell.recents.RecentTasksController;
import com.android.wm.shell.startingsurface.StartingWindowController;
import com.android.wm.shell.sysui.ShellCommandHandler;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.unfold.UnfoldAnimationController;

import java.io.PrintWriter;
@@ -281,6 +286,8 @@ public class ShellTaskOrganizer extends TaskOrganizer {
    @Nullable
    private RunningTaskInfo mLastFocusedTaskInfo;

    private Transitions mTransitions;

    public ShellTaskOrganizer(ShellExecutor mainExecutor) {
        this(null /* shellInit */, null /* shellCommandHandler */,
                null /* taskOrganizerController */, null /* compatUI */,
@@ -337,8 +344,11 @@ public class ShellTaskOrganizer extends TaskOrganizer {
                }
            });
        }
        if (!unifyShellBinders()) {
            // wait to register until Transitions is initialized
            registerOrganizer();
        }
    }

    @Override
    public List<TaskAppearedInfo> registerOrganizer() {
@@ -363,6 +373,14 @@ public class ShellTaskOrganizer extends TaskOrganizer {
        }
    }

    /**
     * Initialize this organizer with required components.
     */
    public void initializeDependencies(Transitions transitions) {
        mTransitions = transitions;
        registerOrganizer();
    }

    @Override
    public void applyTransaction(@NonNull WindowContainerTransaction t) {
        if (!t.isEmpty()) {
@@ -1233,6 +1251,26 @@ public class ShellTaskOrganizer extends TaskOrganizer {
                || (Flags.enableOverviewOnConnectedDisplays() && displayId != DEFAULT_DISPLAY));
    }

    @Override
    public void onTransitionReady(IBinder iBinder, TransitionInfo transitionInfo,
            SurfaceControl.Transaction t, SurfaceControl.Transaction finishT) {
        if (!unifyShellBinders()) return;
        if (mTransitions == null) {
            throw new IllegalStateException("No transition player registered!");
        }
        ProtoLog.v(WM_SHELL_TRANSITIONS, "onTransitionReady(transaction=%d)", t.getId());
        mTransitions.onTransitionReady(iBinder, transitionInfo, t, finishT);
    }

    @Override
    public void requestStartTransition(IBinder iBinder, TransitionRequestInfo request) {
        if (!unifyShellBinders()) return;
        if (mTransitions == null) {
            throw new IllegalStateException("No transition player registered!");
        }
        mTransitions.requestStartTransition(iBinder, request);
    }

    public void dump(@NonNull PrintWriter pw, String prefix) {
        synchronized (mLock) {
            final String innerPrefix = prefix + "  ";
+13 −7
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import static android.window.TransitionInfo.FLAG_IS_WALLPAPER;
import static android.window.TransitionInfo.FLAG_NO_ANIMATION;
import static android.window.TransitionInfo.FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT;

import static com.android.window.flags.Flags.unifyShellBinders;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_TRANSITIONS;
import static com.android.wm.shell.shared.TransitionUtil.FLAG_IS_DESKTOP_WALLPAPER_ACTIVITY;
import static com.android.wm.shell.shared.TransitionUtil.isClosingType;
@@ -383,11 +384,15 @@ public class Transitions implements RemoteCallable<Transitions>,
                new SettingsObserver());

        // Register this transition handler with Core
        if (unifyShellBinders()) {
            mOrganizer.initializeDependencies(this);
        } else {
            try {
                mOrganizer.registerTransitionPlayer(mPlayerImpl);
            } catch (RuntimeException e) {
                throw e;
            }
        }
        // Pre-load the instance.
        TransitionMetrics.getInstance();

@@ -691,8 +696,8 @@ public class Transitions implements RemoteCallable<Transitions>,
        return mTracks.get(trackId);
    }

    @VisibleForTesting
    void onTransitionReady(@NonNull IBinder transitionToken, @NonNull TransitionInfo info,
    /** @see ITransitionPlayer#onTransitionReady */
    public void onTransitionReady(@NonNull IBinder transitionToken, @NonNull TransitionInfo info,
            @NonNull SurfaceControl.Transaction t, @NonNull SurfaceControl.Transaction finishT) {
        info.setUnreleasedWarningCallSiteForAllSurfaces("Transitions.onTransitionReady");
        ProtoLog.v(WM_SHELL_TRANSITIONS, "onTransitionReady (#%d) %s: %s",
@@ -1220,7 +1225,8 @@ public class Transitions implements RemoteCallable<Transitions>,
        processReadyQueue(track);
    }

    void requestStartTransition(@NonNull IBinder transitionToken,
    /** @see ITransitionPlayer#requestStartTransition  */
    public void requestStartTransition(@NonNull IBinder transitionToken,
            @Nullable TransitionRequestInfo request) {
        ProtoLog.v(WM_SHELL_TRANSITIONS, "Transition requested (#%d): %s %s",
                request.getDebugId(), transitionToken, request);
+44 −0
Original line number Diff line number Diff line
@@ -46,17 +46,21 @@ import android.view.Display;
import android.view.SurfaceControl;
import android.window.ITaskOrganizer;
import android.window.ITaskOrganizerController;
import android.window.ITransitionPlayer;
import android.window.IWindowlessStartingSurfaceCallback;
import android.window.SplashScreenView;
import android.window.StartingWindowInfo;
import android.window.StartingWindowRemovalInfo;
import android.window.TaskAppearedInfo;
import android.window.TaskSnapshot;
import android.window.TransitionInfo;
import android.window.TransitionRequestInfo;
import android.window.WindowContainerToken;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.ProtoLog;
import com.android.internal.util.ArrayUtils;
import com.android.window.flags.Flags;

import java.io.PrintWriter;
import java.util.ArrayDeque;
@@ -484,6 +488,8 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
    // Set of organized tasks (by taskId) that dispatch back pressed to their organizers
    private final HashSet<Integer> mInterceptBackPressedOnRootTasks = new HashSet<>();

    public final ITransitionPlayer mAsTransitionPlayer = new AsTransitionPlayer();

    TaskOrganizerController(ActivityTaskManagerService atm) {
        mService = atm;
        mGlobalLock = atm.mGlobalLock;
@@ -505,6 +511,8 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
    @Override
    public ParceledListSlice<TaskAppearedInfo> registerTaskOrganizer(ITaskOrganizer organizer) {
        enforceTaskPermission("registerTaskOrganizer()");
        final int callerPid = Binder.getCallingPid();
        final int callerUid = Binder.getCallingUid();
        final int uid = Binder.getCallingUid();
        final long origId = Binder.clearCallingIdentity();
        try {
@@ -530,6 +538,12 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
                        taskInfos.add(new TaskAppearedInfo(task.getTaskInfo(), taskLeash));
                    }
                });
                if (Flags.unifyShellBinders()) {
                    final WindowProcessController wpc =
                            mService.getProcessController(callerPid, callerUid);
                    mService.getTransitionController().registerTransitionPlayer(
                            mAsTransitionPlayer, wpc);
                }
            };
            if (mService.getTransitionController().isShellTransitionsEnabled()) {
                mService.getTransitionController().mRunningLock.runWhenIdle(1000, withGlobalLock);
@@ -551,6 +565,10 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
        final long origId = Binder.clearCallingIdentity();
        try {
            final Runnable withGlobalLock = () -> {
                if (Flags.unifyShellBinders()) {
                    mService.getTransitionController().unregisterTransitionPlayer(
                            mAsTransitionPlayer);
                }
                final TaskOrganizerState state = mTaskOrganizerStates.get(organizer.asBinder());
                if (state == null) {
                    return;
@@ -1230,4 +1248,30 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
    TaskOrganizerPendingEventsQueue getTaskOrganizerPendingEvents(IBinder taskOrganizer) {
        return mTaskOrganizerStates.get(taskOrganizer).mPendingEventsQueue;
    }

    class AsTransitionPlayer implements ITransitionPlayer {
        @Override
        public void onTransitionReady(IBinder transitionToken, TransitionInfo info,
                SurfaceControl.Transaction t, SurfaceControl.Transaction finishT)
                throws RemoteException {
            mTaskOrganizers.getLast().onTransitionReady(transitionToken, info, t, finishT);
        }

        @Override
        public void requestStartTransition(IBinder transitionToken, TransitionRequestInfo request)
                throws RemoteException {
            mTaskOrganizers.getLast().requestStartTransition(transitionToken, request);
        }

        @Override
        public void removeStartingWindow(StartingWindowRemovalInfo removalInfo)
                throws RemoteException {
            mTaskOrganizers.getLast().removeStartingWindow(removalInfo);
        }

        @Override
        public IBinder asBinder() {
            return mTaskOrganizers.getLast().asBinder();
        }
    }
}
Loading