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

Commit 8b94a4bb authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing RemoteAnimationTargetCompat and using RemoteAnimationTarget directly

Bug: 221961069
Test: Presubmit
Change-Id: I4497b44677a5c32bbf5dc0745559b3bc2f2efcc8
parent 61a511a3
Loading
Loading
Loading
Loading
+3 −12
Original line number Diff line number Diff line
@@ -194,12 +194,8 @@ public class ActivityManagerWrapper {
                            Rect homeContentInsets, Rect minimizedHomeBounds) {
                        final RecentsAnimationControllerCompat controllerCompat =
                                new RecentsAnimationControllerCompat(controller);
                        final RemoteAnimationTargetCompat[] appsCompat =
                                RemoteAnimationTargetCompat.wrap(apps);
                        final RemoteAnimationTargetCompat[] wallpapersCompat =
                                RemoteAnimationTargetCompat.wrap(wallpapers);
                        animationHandler.onAnimationStart(controllerCompat, appsCompat,
                                wallpapersCompat, homeContentInsets, minimizedHomeBounds);
                        animationHandler.onAnimationStart(controllerCompat, apps,
                                wallpapers, homeContentInsets, minimizedHomeBounds);
                    }

                    @Override
@@ -210,12 +206,7 @@ public class ActivityManagerWrapper {

                    @Override
                    public void onTasksAppeared(RemoteAnimationTarget[] apps) {
                        final RemoteAnimationTargetCompat[] compats =
                                new RemoteAnimationTargetCompat[apps.length];
                        for (int i = 0; i < apps.length; ++i) {
                            compats[i] = new RemoteAnimationTargetCompat(apps[i]);
                        }
                        animationHandler.onTasksAppeared(compats);
                        animationHandler.onTasksAppeared(apps);
                    }
                };
            }
+3 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.shared.system;

import android.graphics.Rect;
import android.view.RemoteAnimationTarget;

import com.android.systemui.shared.recents.model.ThumbnailData;

@@ -27,7 +28,7 @@ public interface RecentsAnimationListener {
     * Called when the animation into Recents can start. This call is made on the binder thread.
     */
    void onAnimationStart(RecentsAnimationControllerCompat controller,
            RemoteAnimationTargetCompat[] apps, RemoteAnimationTargetCompat[] wallpapers,
            RemoteAnimationTarget[] apps, RemoteAnimationTarget[] wallpapers,
            Rect homeContentInsets, Rect minimizedHomeBounds);

    /**
@@ -39,7 +40,7 @@ public interface RecentsAnimationListener {
     * Called when the task of an activity that has been started while the recents animation
     * was running becomes ready for control.
     */
    void onTasksAppeared(RemoteAnimationTargetCompat[] app);
    void onTasksAppeared(RemoteAnimationTarget[] app);

    /**
     * Called to request that the current task tile be switched out for a screenshot (if not
+9 −15
Original line number Diff line number Diff line
@@ -83,12 +83,6 @@ public class RemoteAnimationAdapterCompat {
                    RemoteAnimationTarget[] wallpapers,
                    RemoteAnimationTarget[] nonApps,
                    final IRemoteAnimationFinishedCallback finishedCallback) {
                final RemoteAnimationTargetCompat[] appsCompat =
                        RemoteAnimationTargetCompat.wrap(apps);
                final RemoteAnimationTargetCompat[] wallpapersCompat =
                        RemoteAnimationTargetCompat.wrap(wallpapers);
                final RemoteAnimationTargetCompat[] nonAppsCompat =
                        RemoteAnimationTargetCompat.wrap(nonApps);
                final Runnable animationFinishedCallback = new Runnable() {
                    @Override
                    public void run() {
@@ -100,8 +94,8 @@ public class RemoteAnimationAdapterCompat {
                        }
                    }
                };
                remoteAnimationAdapter.onAnimationStart(transit, appsCompat, wallpapersCompat,
                        nonAppsCompat, animationFinishedCallback);
                remoteAnimationAdapter.onAnimationStart(transit, apps, wallpapers,
                        nonApps, animationFinishedCallback);
            }

            @Override
@@ -121,12 +115,12 @@ public class RemoteAnimationAdapterCompat {
                    SurfaceControl.Transaction t,
                    IRemoteTransitionFinishedCallback finishCallback) {
                final ArrayMap<SurfaceControl, SurfaceControl> leashMap = new ArrayMap<>();
                final RemoteAnimationTargetCompat[] appsCompat =
                final RemoteAnimationTarget[] apps =
                        RemoteAnimationTargetCompat.wrapApps(info, t, leashMap);
                final RemoteAnimationTargetCompat[] wallpapersCompat =
                final RemoteAnimationTarget[] wallpapers =
                        RemoteAnimationTargetCompat.wrapNonApps(
                                info, true /* wallpapers */, t, leashMap);
                final RemoteAnimationTargetCompat[] nonAppsCompat =
                final RemoteAnimationTarget[] nonApps =
                        RemoteAnimationTargetCompat.wrapNonApps(
                                info, false /* wallpapers */, t, leashMap);

@@ -189,9 +183,9 @@ public class RemoteAnimationAdapterCompat {
                        }
                    }
                    // Make wallpaper visible immediately since launcher apparently won't do this.
                    for (int i = wallpapersCompat.length - 1; i >= 0; --i) {
                        t.show(wallpapersCompat[i].leash);
                        t.setAlpha(wallpapersCompat[i].leash, 1.f);
                    for (int i = wallpapers.length - 1; i >= 0; --i) {
                        t.show(wallpapers[i].leash);
                        t.setAlpha(wallpapers[i].leash, 1.f);
                    }
                } else {
                    if (launcherTask != null) {
@@ -237,7 +231,7 @@ public class RemoteAnimationAdapterCompat {
                }
                // TODO(bc-unlcok): Pass correct transit type.
                remoteAnimationAdapter.onAnimationStart(TRANSIT_OLD_NONE,
                        appsCompat, wallpapersCompat, nonAppsCompat, () -> {
                        apps, wallpapers, nonApps, () -> {
                            synchronized (mFinishRunnables) {
                                if (mFinishRunnables.remove(token) == null) return;
                            }
+3 −2
Original line number Diff line number Diff line
@@ -16,11 +16,12 @@

package com.android.systemui.shared.system;

import android.view.RemoteAnimationTarget;
import android.view.WindowManager;

public interface RemoteAnimationRunnerCompat {
    void onAnimationStart(@WindowManager.TransitionOldType int transit,
            RemoteAnimationTargetCompat[] apps, RemoteAnimationTargetCompat[] wallpapers,
            RemoteAnimationTargetCompat[] nonApps, Runnable finishedCallback);
            RemoteAnimationTarget[] apps, RemoteAnimationTarget[] wallpapers,
            RemoteAnimationTarget[] nonApps, Runnable finishedCallback);
    void onAnimationCancelled();
}
 No newline at end of file
+74 −166
Original line number Diff line number Diff line
@@ -11,12 +11,15 @@
 * 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
 * limitations under the License.
 */

package com.android.systemui.shared.system;

import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.view.RemoteAnimationTarget.MODE_CHANGING;
import static android.view.RemoteAnimationTarget.MODE_CLOSING;
import static android.view.RemoteAnimationTarget.MODE_OPENING;
import static android.view.WindowManager.LayoutParams.INVALID_WINDOW_TYPE;
import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
import static android.view.WindowManager.TRANSIT_CLOSE;
@@ -29,88 +32,28 @@ import static android.window.TransitionInfo.FLAG_STARTING_WINDOW_TRANSFER_RECIPI
import static com.android.wm.shell.common.split.SplitScreenConstants.FLAG_IS_DIVIDER_BAR;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.TaskInfo;
import android.app.WindowConfiguration;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.ArrayMap;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.view.RemoteAnimationTarget;
import android.view.SurfaceControl;
import android.view.WindowManager;
import android.window.TransitionInfo;
import android.window.TransitionInfo.Change;

import java.util.ArrayList;
import java.util.function.BiPredicate;

/**
 * @see RemoteAnimationTarget
 * Some utility methods for creating {@link RemoteAnimationTarget} instances.
 */
public class RemoteAnimationTargetCompat {

    public static final int MODE_OPENING = RemoteAnimationTarget.MODE_OPENING;
    public static final int MODE_CLOSING = RemoteAnimationTarget.MODE_CLOSING;
    public static final int MODE_CHANGING = RemoteAnimationTarget.MODE_CHANGING;
    public final int mode;

    public static final int ACTIVITY_TYPE_UNDEFINED = WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
    public static final int ACTIVITY_TYPE_STANDARD = WindowConfiguration.ACTIVITY_TYPE_STANDARD;
    public static final int ACTIVITY_TYPE_HOME = WindowConfiguration.ACTIVITY_TYPE_HOME;
    public static final int ACTIVITY_TYPE_RECENTS = WindowConfiguration.ACTIVITY_TYPE_RECENTS;
    public static final int ACTIVITY_TYPE_ASSISTANT = WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
    public final int activityType;

    public final int taskId;
    public final SurfaceControl leash;
    public final boolean isTranslucent;
    public final Rect clipRect;
    public final int prefixOrderIndex;
    public final Point position;
    public final Rect localBounds;
    public final Rect sourceContainerBounds;
    public final Rect screenSpaceBounds;
    public final Rect startScreenSpaceBounds;
    public final boolean isNotInRecents;
    public final Rect contentInsets;
    public final ActivityManager.RunningTaskInfo taskInfo;
    public final boolean allowEnterPip;
    public final int rotationChange;
    public final int windowType;
    public final WindowConfiguration windowConfiguration;

    private final SurfaceControl mStartLeash;

    // Fields used only to unwrap into RemoteAnimationTarget
    private final Rect startBounds;

    public final boolean willShowImeOnTarget;

    public RemoteAnimationTargetCompat(RemoteAnimationTarget app) {
        taskId = app.taskId;
        mode = app.mode;
        leash = app.leash;
        isTranslucent = app.isTranslucent;
        clipRect = app.clipRect;
        position = app.position;
        localBounds = app.localBounds;
        sourceContainerBounds = app.sourceContainerBounds;
        screenSpaceBounds = app.screenSpaceBounds;
        startScreenSpaceBounds = screenSpaceBounds;
        prefixOrderIndex = app.prefixOrderIndex;
        isNotInRecents = app.isNotInRecents;
        contentInsets = app.contentInsets;
        activityType = app.windowConfiguration.getActivityType();
        taskInfo = app.taskInfo;
        allowEnterPip = app.allowEnterPip;
        rotationChange = app.rotationChange;

        mStartLeash = app.startLeash;
        windowType = app.windowType;
        windowConfiguration = app.windowConfiguration;
        startBounds = app.startBounds;
        willShowImeOnTarget = app.willShowImeOnTarget;
    }

    private static int newModeToLegacyMode(int newMode) {
        switch (newMode) {
            case WindowManager.TRANSIT_OPEN:
@@ -120,21 +63,10 @@ public class RemoteAnimationTargetCompat {
            case WindowManager.TRANSIT_TO_BACK:
                return MODE_CLOSING;
            default:
                return 2; // MODE_CHANGING
                return MODE_CHANGING;
        }
    }

    public RemoteAnimationTarget unwrap() {
        final RemoteAnimationTarget target = new RemoteAnimationTarget(
                taskId, mode, leash, isTranslucent, clipRect, contentInsets,
                prefixOrderIndex, position, localBounds, screenSpaceBounds, windowConfiguration,
                isNotInRecents, mStartLeash, startBounds, taskInfo, allowEnterPip, windowType
        );
        target.setWillShowImeOnTarget(willShowImeOnTarget);
        target.setRotationChange(rotationChange);
        return target;
    }

    /**
     * Almost a copy of Transitions#setupStartState.
     * TODO: remove when there is proper cross-process transaction sync.
@@ -206,54 +138,61 @@ public class RemoteAnimationTargetCompat {
        return leashSurface;
    }

    public RemoteAnimationTargetCompat(TransitionInfo.Change change, int order,
            TransitionInfo info, SurfaceControl.Transaction t) {
        mode = newModeToLegacyMode(change.getMode());
    /**
     * Creates a new RemoteAnimationTarget from the provided change info
     */
    public static RemoteAnimationTarget newTarget(TransitionInfo.Change change, int order,
            TransitionInfo info, SurfaceControl.Transaction t,
            @Nullable ArrayMap<SurfaceControl, SurfaceControl> leashMap) {
        int taskId;
        boolean isNotInRecents;
        ActivityManager.RunningTaskInfo taskInfo;
        WindowConfiguration windowConfiguration;

        taskInfo = change.getTaskInfo();
        if (taskInfo != null) {
            taskId = taskInfo.taskId;
            isNotInRecents = !taskInfo.isRunning;
            activityType = taskInfo.getActivityType();
            windowConfiguration = taskInfo.configuration.windowConfiguration;
        } else {
            taskId = INVALID_TASK_ID;
            isNotInRecents = true;
            activityType = ACTIVITY_TYPE_UNDEFINED;
            windowConfiguration = new WindowConfiguration();
        }

        // TODO: once we can properly sync transactions across process, then get rid of this leash.
        leash = createLeash(info, change, order, t);

        isTranslucent = (change.getFlags() & TransitionInfo.FLAG_TRANSLUCENT) != 0;
        clipRect = null;
        position = null;
        localBounds = new Rect(change.getEndAbsBounds());
        Rect localBounds = new Rect(change.getEndAbsBounds());
        localBounds.offsetTo(change.getEndRelOffset().x, change.getEndRelOffset().y);
        sourceContainerBounds = null;
        screenSpaceBounds = new Rect(change.getEndAbsBounds());
        startScreenSpaceBounds = new Rect(change.getStartAbsBounds());

        prefixOrderIndex = order;
        // TODO(shell-transitions): I guess we need to send content insets? evaluate how its used.
        contentInsets = new Rect(0, 0, 0, 0);
        allowEnterPip = change.getAllowEnterPip();
        mStartLeash = null;
        rotationChange = change.getEndRotation() - change.getStartRotation();
        windowType = (change.getFlags() & FLAG_IS_DIVIDER_BAR) != 0
                ? TYPE_DOCK_DIVIDER : INVALID_WINDOW_TYPE;

        startBounds = change.getStartAbsBounds();
        willShowImeOnTarget = (change.getFlags() & TransitionInfo.FLAG_WILL_IME_SHOWN) != 0;
    }

    public static RemoteAnimationTargetCompat[] wrap(RemoteAnimationTarget[] apps) {
        final int length = apps != null ? apps.length : 0;
        final RemoteAnimationTargetCompat[] appsCompat = new RemoteAnimationTargetCompat[length];
        for (int i = 0; i < length; i++) {
            appsCompat[i] = new RemoteAnimationTargetCompat(apps[i]);
        RemoteAnimationTarget target = new RemoteAnimationTarget(
                taskId,
                newModeToLegacyMode(change.getMode()),
                // TODO: once we can properly sync transactions across process,
                // then get rid of this leash.
                createLeash(info, change, order, t),
                (change.getFlags() & TransitionInfo.FLAG_TRANSLUCENT) != 0,
                null,
                // TODO(shell-transitions): we need to send content insets? evaluate how its used.
                new Rect(0, 0, 0, 0),
                order,
                null,
                localBounds,
                new Rect(change.getEndAbsBounds()),
                windowConfiguration,
                isNotInRecents,
                null,
                new Rect(change.getStartAbsBounds()),
                taskInfo,
                change.getAllowEnterPip(),
                (change.getFlags() & FLAG_IS_DIVIDER_BAR) != 0
                        ? TYPE_DOCK_DIVIDER : INVALID_WINDOW_TYPE
        );
        target.setWillShowImeOnTarget(
                (change.getFlags() & TransitionInfo.FLAG_WILL_IME_SHOWN) != 0);
        target.setRotationChange(change.getEndRotation() - change.getStartRotation());
        if (leashMap != null) {
            leashMap.put(change.getLeash(), target.leash);
        }
        return appsCompat;
        return target;
    }

    /**
@@ -262,35 +201,20 @@ public class RemoteAnimationTargetCompat {
     * @param leashMap Temporary map of change leash -> launcher leash. Is an output, so should be
     *                 populated by this function. If null, it is ignored.
     */
    public static RemoteAnimationTargetCompat[] wrapApps(TransitionInfo info,
    public static RemoteAnimationTarget[] wrapApps(TransitionInfo info,
            SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap) {
        final ArrayList<RemoteAnimationTargetCompat> out = new ArrayList<>();
        final SparseArray<TransitionInfo.Change> childTaskTargets = new SparseArray<>();
        for (int i = 0; i < info.getChanges().size(); i++) {
            final TransitionInfo.Change change = info.getChanges().get(i);
            if (change.getTaskInfo() == null) continue;

            final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
        SparseBooleanArray childTaskTargets = new SparseBooleanArray();
        return wrap(info, t, leashMap, (change, taskInfo) -> {
            // Children always come before parent since changes are in top-to-bottom z-order.
            if (taskInfo != null) {
                if (childTaskTargets.contains(taskInfo.taskId)) {
            if ((taskInfo == null) || childTaskTargets.get(taskInfo.taskId)) {
                // has children, so not a leaf. Skip.
                    continue;
                return false;
            }
            if (taskInfo.hasParentTask()) {
                    childTaskTargets.put(taskInfo.parentTaskId, change);
                }
                childTaskTargets.put(taskInfo.parentTaskId, true);
            }

            final RemoteAnimationTargetCompat targetCompat =
                    new RemoteAnimationTargetCompat(change, info.getChanges().size() - i, info, t);
            if (leashMap != null) {
                leashMap.put(change.getLeash(), targetCompat.leash);
            }
            out.add(targetCompat);
        }

        return out.toArray(new RemoteAnimationTargetCompat[out.size()]);
            return true;
        });
    }

    /**
@@ -301,38 +225,22 @@ public class RemoteAnimationTargetCompat {
     * @param leashMap Temporary map of change leash -> launcher leash. Is an output, so should be
     *                 populated by this function. If null, it is ignored.
     */
    public static RemoteAnimationTargetCompat[] wrapNonApps(TransitionInfo info, boolean wallpapers,
    public static RemoteAnimationTarget[] wrapNonApps(TransitionInfo info, boolean wallpapers,
            SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap) {
        final ArrayList<RemoteAnimationTargetCompat> out = new ArrayList<>();

        for (int i = 0; i < info.getChanges().size(); i++) {
            final TransitionInfo.Change change = info.getChanges().get(i);
            if (change.getTaskInfo() != null) continue;

            final boolean changeIsWallpaper =
                    (change.getFlags() & TransitionInfo.FLAG_IS_WALLPAPER) != 0;
            if (wallpapers != changeIsWallpaper) continue;

            final RemoteAnimationTargetCompat targetCompat =
                    new RemoteAnimationTargetCompat(change, info.getChanges().size() - i, info, t);
            if (leashMap != null) {
                leashMap.put(change.getLeash(), targetCompat.leash);
            }
            out.add(targetCompat);
        return wrap(info, t, leashMap, (change, taskInfo) -> (taskInfo == null)
                && wallpapers == ((change.getFlags() & TransitionInfo.FLAG_IS_WALLPAPER) != 0));
    }

        return out.toArray(new RemoteAnimationTargetCompat[out.size()]);
    }

    /**
     * @see SurfaceControl#release()
     */
    public void release() {
        if (leash != null) {
            leash.release();
    private static RemoteAnimationTarget[] wrap(TransitionInfo info,
            SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap,
            BiPredicate<Change, TaskInfo> filter) {
        final ArrayList<RemoteAnimationTarget> out = new ArrayList<>();
        for (int i = 0; i < info.getChanges().size(); i++) {
            TransitionInfo.Change change = info.getChanges().get(i);
            if (filter.test(change, change.getTaskInfo())) {
                out.add(newTarget(change, info.getChanges().size() - i, info, t, leashMap));
            }
        if (mStartLeash != null) {
            mStartLeash.release();
        }
        return out.toArray(new RemoteAnimationTarget[out.size()]);
    }
}
Loading