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

Commit 6b5eae11 authored by Winson Chung's avatar Winson Chung
Browse files

Removing legacy transitions calls in window organizer

- Pre-shell transit Split was the last user of legacy transitions, and
  that was cleaned up recently so we can remove the legacy call as well

Bug: 365884835
Bug: 378565144
Flag: EXEMPT removing unused code
Test: Build fw/sysui
Change-Id: I5987d865555063f129c5ade2799e9800c43cef39
parent 4d2a2953
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -65,17 +65,6 @@ interface IWindowOrganizerController {
     */
    void startTransition(IBinder transitionToken, in @nullable WindowContainerTransaction t);

    /**
     * Starts a legacy transition.
     * @param type The transition type.
     * @param adapter The animation to use.
     * @param syncCallback A sync callback for the contents of `t`
     * @param t Operations that are part of the transition.
     * @return sync-id or -1 if this no-op'd because a transition is already running.
     */
    int startLegacyTransition(int type, in RemoteAnimationAdapter adapter,
            in IWindowContainerTransactionCallback syncCallback, in WindowContainerTransaction t);

    /**
     * Finishes a transition. This must be called for all created transitions.
     * @param transitionToken Which transition to finish
+0 −21
Original line number Diff line number Diff line
@@ -129,27 +129,6 @@ public class WindowOrganizer {
        }
    }

    /**
     * Start a legacy transition.
     * @param type The type of the transition. This is ignored if a transitionToken is provided.
     * @param adapter An existing transition to start. If null, a new transition is created.
     * @param t The set of window operations that are part of this transition.
     * @return true on success, false if a transition was already running.
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
    @NonNull
    public int startLegacyTransition(int type, @NonNull RemoteAnimationAdapter adapter,
            @NonNull WindowContainerTransactionCallback syncCallback,
            @NonNull WindowContainerTransaction t) {
        try {
            return getWindowOrganizerController().startLegacyTransition(
                    type, adapter, syncCallback.mInterface, t);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Register an ITransitionPlayer to handle transition animations.
     * @hide
+5 −48
Original line number Diff line number Diff line
@@ -20,17 +20,14 @@ import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL;

import android.annotation.BinderThread;
import android.annotation.NonNull;
import android.os.RemoteException;
import android.util.Slog;
import android.view.SurfaceControl;
import android.view.WindowManager;
import android.window.WindowContainerTransaction;
import android.window.WindowContainerTransactionCallback;
import android.window.WindowOrganizer;

import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.shared.TransactionPool;
import com.android.wm.shell.transition.LegacyTransitions;

import java.util.ArrayList;

@@ -86,25 +83,6 @@ public final class SyncTransactionQueue {
        }
    }

    /**
     * Queues a legacy transition to be sent serially to WM
     */
    public void queue(LegacyTransitions.ILegacyTransition transition,
            @WindowManager.TransitionType int type, WindowContainerTransaction wct) {
        if (wct.isEmpty()) {
            if (DEBUG) Slog.d(TAG, "Skip queue due to transaction change is empty");
            return;
        }
        SyncCallback cb = new SyncCallback(transition, type, wct);
        synchronized (mQueue) {
            if (DEBUG) Slog.d(TAG, "Queueing up legacy transition " + wct);
            mQueue.add(cb);
            if (mQueue.size() == 1) {
                cb.send();
            }
        }
    }

    /**
     * Queues a sync transaction only if there are already sync transaction(s) queued or in flight.
     * Otherwise just returns without queueing.
@@ -168,17 +146,9 @@ public final class SyncTransactionQueue {
    private class SyncCallback extends WindowContainerTransactionCallback {
        int mId = -1;
        final WindowContainerTransaction mWCT;
        final LegacyTransitions.LegacyTransition mLegacyTransition;

        SyncCallback(WindowContainerTransaction wct) {
            mWCT = wct;
            mLegacyTransition = null;
        }

        SyncCallback(LegacyTransitions.ILegacyTransition legacyTransition,
                @WindowManager.TransitionType int type, WindowContainerTransaction wct) {
            mWCT = wct;
            mLegacyTransition = new LegacyTransitions.LegacyTransition(type, legacyTransition);
        }

        // Must be sychronized on mQueue
@@ -194,12 +164,7 @@ public final class SyncTransactionQueue {
            }
            if (DEBUG) Slog.d(TAG, "Sending sync transaction: " + mWCT);
            try {
                if (mLegacyTransition != null) {
                    mId = new WindowOrganizer().startLegacyTransition(mLegacyTransition.getType(),
                            mLegacyTransition.getAdapter(), this, mWCT);
                } else {
                mId = new WindowOrganizer().applySyncTransaction(mWCT, this);
                }
            } catch (RuntimeException e) {
                Slog.e(TAG, "Send failed", e);
                // Finish current sync callback immediately.
@@ -228,18 +193,10 @@ public final class SyncTransactionQueue {
                    if (DEBUG) Slog.d(TAG, "onTransactionReady id=" + mId);
                    mQueue.remove(this);
                    onTransactionReceived(t);
                    if (mLegacyTransition != null) {
                        try {
                            mLegacyTransition.getSyncCallback().onTransactionReady(mId, t);
                        } catch (RemoteException e) {
                            Slog.e(TAG, "Error sending callback to legacy transition: " + mId, e);
                        }
                    } else {
                    ProtoLog.v(WM_SHELL,
                            "SyncTransactionQueue.onTransactionReady(): syncId=%d apply", id);
                    t.apply();
                    t.close();
                    }
                    if (!mQueue.isEmpty()) {
                        mQueue.get(0).send();
                    }
+0 −139
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.transition;

import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_TRANSITIONS;

import android.annotation.NonNull;
import android.os.RemoteException;
import android.view.IRemoteAnimationFinishedCallback;
import android.view.IRemoteAnimationRunner;
import android.view.RemoteAnimationAdapter;
import android.view.RemoteAnimationTarget;
import android.view.SurfaceControl;
import android.view.WindowManager;
import android.window.IWindowContainerTransactionCallback;

import com.android.internal.protolog.ProtoLog;

/**
 * Utilities and interfaces for transition-like usage on top of the legacy app-transition and
 * synctransaction tools.
 */
public class LegacyTransitions {

    /**
     * Interface for a "legacy" transition. Effectively wraps a sync callback + remoteAnimation
     * into one callback.
     */
    public interface ILegacyTransition {
        /**
         * Called when both the associated sync transaction finishes and the remote animation is
         * ready.
         */
        void onAnimationStart(int transit, RemoteAnimationTarget[] apps,
                RemoteAnimationTarget[] wallpapers, RemoteAnimationTarget[] nonApps,
                IRemoteAnimationFinishedCallback finishedCallback, SurfaceControl.Transaction t);
    }

    /**
     * Makes sure that a remote animation and corresponding sync callback are called together
     * such that the sync callback is called first. This assumes that both the callback receiver
     * and the remoteanimation are in the same process so that order is preserved on both ends.
     */
    public static class LegacyTransition {
        private final ILegacyTransition mLegacyTransition;
        private int mSyncId = -1;
        private SurfaceControl.Transaction mTransaction;
        private int mTransit;
        private RemoteAnimationTarget[] mApps;
        private RemoteAnimationTarget[] mWallpapers;
        private RemoteAnimationTarget[] mNonApps;
        private IRemoteAnimationFinishedCallback mFinishCallback = null;
        private boolean mCancelled = false;
        private final SyncCallback mSyncCallback = new SyncCallback();
        private final RemoteAnimationAdapter mAdapter =
                new RemoteAnimationAdapter(new RemoteAnimationWrapper(), 0, 0);

        public LegacyTransition(@WindowManager.TransitionType int type,
                @NonNull ILegacyTransition legacyTransition) {
            mLegacyTransition = legacyTransition;
            mTransit = type;
        }

        public @WindowManager.TransitionType int getType() {
            return mTransit;
        }

        public IWindowContainerTransactionCallback getSyncCallback() {
            return mSyncCallback;
        }

        public RemoteAnimationAdapter getAdapter() {
            return mAdapter;
        }

        private class SyncCallback extends IWindowContainerTransactionCallback.Stub {
            @Override
            public void onTransactionReady(int id, SurfaceControl.Transaction t)
                    throws RemoteException {
                ProtoLog.v(WM_SHELL_TRANSITIONS,
                        "LegacyTransitions.onTransactionReady(): syncId=%d", id);
                mSyncId = id;
                mTransaction = t;
                checkApply(true /* log */);
            }
        }

        private class RemoteAnimationWrapper extends IRemoteAnimationRunner.Stub {
            @Override
            public void onAnimationStart(int transit, RemoteAnimationTarget[] apps,
                    RemoteAnimationTarget[] wallpapers, RemoteAnimationTarget[] nonApps,
                    IRemoteAnimationFinishedCallback finishedCallback) throws RemoteException {
                mTransit = transit;
                mApps = apps;
                mWallpapers = wallpapers;
                mNonApps = nonApps;
                mFinishCallback = finishedCallback;
                checkApply(false /* log */);
            }

            @Override
            public void onAnimationCancelled() throws RemoteException {
                mCancelled = true;
                mApps = mWallpapers = mNonApps = null;
                checkApply(false /* log */);
            }
        }


        private void checkApply(boolean log) throws RemoteException {
            if (mSyncId < 0 || (mFinishCallback == null && !mCancelled)) {
                if (log) {
                    ProtoLog.v(WM_SHELL_TRANSITIONS, "\tSkipping hasFinishedCb=%b canceled=%b",
                            mFinishCallback != null, mCancelled);
                }
                return;
            }
            if (log) {
                ProtoLog.v(WM_SHELL_TRANSITIONS, "\tapply");
            }
            mLegacyTransition.onAnimationStart(mTransit, mApps, mWallpapers,
                    mNonApps, mFinishCallback, mTransaction);
        }
    }
}
+0 −29
Original line number Diff line number Diff line
@@ -472,35 +472,6 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
        transition.setAllReady();
    }

    // TODO(b/365884835): remove this method and callers.
    @Override
    public int startLegacyTransition(int type, @NonNull RemoteAnimationAdapter adapter,
            @NonNull IWindowContainerTransactionCallback callback,
            @NonNull WindowContainerTransaction t) {
        enforceTaskPermission("startLegacyTransition()");
        final CallerInfo caller = new CallerInfo();
        final long ident = Binder.clearCallingIdentity();
        int syncId;
        try {
            synchronized (mGlobalLock) {
                if (type < 0) {
                    throw new IllegalArgumentException("Can't create transition with no type");
                }
                if (mTransitionController.getTransitionPlayer() != null) {
                    throw new IllegalArgumentException("Can't use legacy transitions in"
                            + " when shell transitions are enabled.");
                }
                syncId = startSyncWithOrganizer(callback);
                applyTransaction(t, syncId, mService.mChainTracker.startLegacy("legacyTransit"),
                        caller);
                setSyncReady(syncId);
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
        return syncId;
    }

    @Override
    public void finishTransition(@NonNull IBinder transitionToken,
            @Nullable WindowContainerTransaction t) {