summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Josh Yang <yzj@google.com> 2024-11-19 11:04:00 -0800
committer Josh Yang <yzj@google.com> 2024-11-19 11:04:00 -0800
commitf97aeb8a0eaa43057bba932c1033f9c12ac2b870 (patch)
tree9cc3c37681d0822cd341285b79d67820dd240047
parent5bc0fe80786c2f1560d5a69613f3583686652400 (diff)
[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
-rw-r--r--packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginRemoteTransition.java11
-rw-r--r--packages/SystemUI/animation/lib/src/com/android/systemui/animation/ViewUIComponent.java22
2 files changed, 16 insertions, 17 deletions
diff --git a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginRemoteTransition.java b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginRemoteTransition.java
index 2b5ff7c4b598..0f5e3679cc5f 100644
--- a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginRemoteTransition.java
+++ b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/OriginRemoteTransition.java
@@ -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 {
diff --git a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/ViewUIComponent.java b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/ViewUIComponent.java
index 4c047d589a66..9cef43c3deba 100644
--- a/packages/SystemUI/animation/lib/src/com/android/systemui/animation/ViewUIComponent.java
+++ b/packages/SystemUI/animation/lib/src/com/android/systemui/animation/ViewUIComponent.java
@@ -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;
}