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

Commit f97aeb8a authored by Josh Yang's avatar Josh Yang
Browse files

[Origin transition] Explicitly ensure the correct thread is being used.

The previous impl assumes the transition plays in main thread. But in
reality, it can run in any handler thread. This change fixes the
assumesption and ensure it always run in the correct thread.

Flag: EXEMPTED trivial fix
Bug: 347060315
Test: atest PlatformAnimationLibCoreTests
      manual test with test app
Change-Id: Ica8bb4f943e7b459a436765caee30bb43abca29c
parent 5bc0fe80
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import java.util.List;
/**
 * An implementation of {@link IRemoteTransition} that accepts a {@link UIComponent} as the origin
 * and automatically attaches it to the transition leash before the transition starts.
 *
 * @hide
 */
public class OriginRemoteTransition extends IRemoteTransition.Stub {
@@ -258,8 +259,7 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub {
            // The transition didn't start. Ensure we apply the start transaction and report
            // finish afterwards.
            mStartTransaction
                    .addTransactionCommittedListener(
                            mContext.getMainExecutor(), this::finishInternal)
                    .addTransactionCommittedListener(mHandler::post, this::finishInternal)
                    .apply();
            return;
        }
@@ -268,8 +268,7 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub {
        mPlayer.onEnd(finished);
        // Detach the origin from the transition leash and report finish after it's done.
        mOriginTransaction
                .detachFromTransitionLeash(
                        mOrigin, mContext.getMainExecutor(), this::finishInternal)
                .detachFromTransitionLeash(mOrigin, mHandler::post, this::finishInternal)
                .commit();
    }

@@ -329,7 +328,9 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub {
                /* baseBounds= */ maxBounds);
    }

    /** An interface that represents an origin transitions.
    /**
     * An interface that represents an origin transitions.
     *
     * @hide
     */
    public interface TransitionPlayer {
+10 −12
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import java.util.concurrent.Executor;
 * be changed to INVISIBLE in its view tree. This allows the {@link View} to transform in the
 * full-screen size leash without being constrained by the view tree's boundary or inheriting its
 * parent's alpha and transformation.
 *
 * @hide
 */
public class ViewUIComponent implements UIComponent {
@@ -98,9 +99,7 @@ public class ViewUIComponent implements UIComponent {
        mView.getViewTreeObserver().addOnDrawListener(mOnDrawListener);

        // Make the view invisible AFTER the surface is shown.
        t.addTransactionCommittedListener(
                        mView.getContext().getMainExecutor(),
                        () -> mView.setVisibility(View.INVISIBLE))
        t.addTransactionCommittedListener(mView::post, () -> mView.setVisibility(View.INVISIBLE))
                .apply();
    }

@@ -118,7 +117,7 @@ public class ViewUIComponent implements UIComponent {
        SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        t.reparent(sc, null)
                .addTransactionCommittedListener(
                        mView.getContext().getMainExecutor(),
                        mView::post,
                        () -> {
                            s.release();
                            sc.release();
@@ -235,41 +234,40 @@ public class ViewUIComponent implements UIComponent {
        mView.post(this::draw);
    }

    /**
     * @hide
     */
    /** @hide */
    public static class Transaction implements UIComponent.Transaction<ViewUIComponent> {
        private final List<Runnable> mChanges = new ArrayList<>();

        @Override
        public Transaction setAlpha(ViewUIComponent ui, float alpha) {
            mChanges.add(() -> ui.setAlpha(alpha));
            mChanges.add(() -> ui.mView.post(() -> ui.setAlpha(alpha)));
            return this;
        }

        @Override
        public Transaction setVisible(ViewUIComponent ui, boolean visible) {
            mChanges.add(() -> ui.setVisible(visible));
            mChanges.add(() -> ui.mView.post(() -> ui.setVisible(visible)));
            return this;
        }

        @Override
        public Transaction setBounds(ViewUIComponent ui, Rect bounds) {
            mChanges.add(() -> ui.setBounds(bounds));
            mChanges.add(() -> ui.mView.post(() -> ui.setBounds(bounds)));
            return this;
        }

        @Override
        public Transaction attachToTransitionLeash(
                ViewUIComponent ui, SurfaceControl transitionLeash, int w, int h) {
            mChanges.add(() -> ui.attachToTransitionLeash(transitionLeash, w, h));
            mChanges.add(
                    () -> ui.mView.post(() -> ui.attachToTransitionLeash(transitionLeash, w, h)));
            return this;
        }

        @Override
        public Transaction detachFromTransitionLeash(
                ViewUIComponent ui, Executor executor, Runnable onDone) {
            mChanges.add(() -> ui.detachFromTransitionLeash(executor, onDone));
            mChanges.add(() -> ui.mView.post(() -> ui.detachFromTransitionLeash(executor, onDone)));
            return this;
        }