chore: Cleanup, and hidden feature logged

Signed-off-by: Pun Butrach <pun.butrach@gmail.com>
This commit is contained in:
Pun Butrach
2026-01-10 20:48:25 +07:00
parent 5180c3d4c4
commit 11f7abcb66
1818 changed files with 104955 additions and 147858 deletions
@@ -16,31 +16,25 @@
package com.android.wm.shell.unfold;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.KEYGUARD_VISIBILITY_TRANSIT_FLAGS;
import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_FLAG_PHYSICAL_DISPLAY_SWITCH;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_TRANSITIONS;
import static com.android.wm.shell.transition.Transitions.TRANSIT_BUBBLE_CONVERT_FLOATING_TO_BAR;
import android.animation.ValueAnimator;
import android.app.ActivityManager;
import android.os.Handler;
import android.os.IBinder;
import android.util.Slog;
import android.view.SurfaceControl;
import android.window.TransitionInfo;
import android.window.TransitionRequestInfo;
import android.window.WindowContainerTransaction;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.bubbles.BubbleTaskUnfoldTransitionMerger;
import com.android.wm.shell.shared.TransactionPool;
import com.android.internal.protolog.common.ProtoLog;
import com.android.wm.shell.common.TransactionPool;
import com.android.wm.shell.shared.TransitionUtil;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;
@@ -51,11 +45,8 @@ import com.android.wm.shell.unfold.animation.FullscreenUnfoldTaskAnimator;
import com.android.wm.shell.unfold.animation.SplitTaskUnfoldAnimator;
import com.android.wm.shell.unfold.animation.UnfoldTaskAnimator;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Executor;
/**
@@ -65,67 +56,37 @@ import java.util.concurrent.Executor;
*/
public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListener {
private static final String TAG = "UnfoldTransitionHandler";
@VisibleForTesting
static final int FINISH_ANIMATION_TIMEOUT_MILLIS = 5_000;
@Retention(RetentionPolicy.SOURCE)
@IntDef({
DefaultDisplayChange.DEFAULT_DISPLAY_NO_CHANGE,
DefaultDisplayChange.DEFAULT_DISPLAY_UNFOLD,
DefaultDisplayChange.DEFAULT_DISPLAY_FOLD,
})
private @interface DefaultDisplayChange {
int DEFAULT_DISPLAY_NO_CHANGE = 0;
int DEFAULT_DISPLAY_UNFOLD = 1;
int DEFAULT_DISPLAY_FOLD = 2;
}
private final ShellUnfoldProgressProvider mUnfoldProgressProvider;
private final Transitions mTransitions;
private final Optional<BubbleTaskUnfoldTransitionMerger> mBubbleTaskUnfoldTransitionMerger;
private final Executor mExecutor;
private final TransactionPool mTransactionPool;
private final Handler mHandler;
@Nullable
private TransitionFinishCallback mFinishCallback;
@Nullable
private IBinder mTransition;
// TODO: b/318803244 - remove when we could guarantee finishing the animation
// after startAnimation callback
private boolean mAnimationFinished = false;
private float mLastAnimationProgress = 0.0f;
private final List<UnfoldTaskAnimator> mAnimators = new ArrayList<>();
private final Runnable mAnimationPlayingTimeoutRunnable = () -> {
Slog.wtf(TAG, "Timeout occurred when playing the unfold animation, "
+ "force finishing the transition");
finishTransitionIfNeeded();
};
public UnfoldTransitionHandler(ShellInit shellInit,
ShellUnfoldProgressProvider unfoldProgressProvider,
FullscreenUnfoldTaskAnimator fullscreenUnfoldAnimator,
SplitTaskUnfoldAnimator splitUnfoldTaskAnimator,
TransactionPool transactionPool,
Executor executor,
Handler handler,
Transitions transitions,
Optional<BubbleTaskUnfoldTransitionMerger> bubbleTaskUnfoldTransitionMerger) {
Transitions transitions) {
mUnfoldProgressProvider = unfoldProgressProvider;
mTransitions = transitions;
mTransactionPool = transactionPool;
mExecutor = executor;
mHandler = handler;
mBubbleTaskUnfoldTransitionMerger = bubbleTaskUnfoldTransitionMerger;
mAnimators.add(splitUnfoldTaskAnimator);
mAnimators.add(fullscreenUnfoldAnimator);
// TODO(b/238217847): Temporarily add this check here until we can remove the dynamic
// override for this controller from the base module
if (unfoldProgressProvider != ShellUnfoldProgressProvider.NO_PROVIDER) {
if (unfoldProgressProvider != ShellUnfoldProgressProvider.NO_PROVIDER
&& Transitions.ENABLE_SHELL_TRANSITIONS) {
shellInit.addInitCallback(this::onInit, this);
}
}
@@ -146,6 +107,16 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
@NonNull SurfaceControl.Transaction startTransaction,
@NonNull SurfaceControl.Transaction finishTransaction,
@NonNull TransitionFinishCallback finishCallback) {
if (shouldPlayUnfoldAnimation(info) && transition != mTransition) {
// Take over transition that has unfold, we might receive it if no other handler
// accepted request in handleRequest, e.g. for rotation + unfold or
// TRANSIT_NONE + unfold transitions
mTransition = transition;
ProtoLog.v(WM_SHELL_TRANSITIONS, "UnfoldTransitionHandler: "
+ "take over startAnimation");
}
if (transition != mTransition) return false;
for (int i = 0; i < mAnimators.size(); i++) {
@@ -180,11 +151,6 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
// finish shell transition immediately
if (mAnimationFinished) {
finishTransitionIfNeeded();
} else {
// TODO: b/318803244 - remove timeout handling when we could guarantee that
// the animation will be always finished after receiving startAnimation
mHandler.removeCallbacks(mAnimationPlayingTimeoutRunnable);
mHandler.postDelayed(mAnimationPlayingTimeoutRunnable, FINISH_ANIMATION_TIMEOUT_MILLIS);
}
return true;
@@ -192,8 +158,6 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
@Override
public void onStateChangeProgress(float progress) {
mLastAnimationProgress = progress;
if (mTransition == null) return;
SurfaceControl.Transaction transaction = null;
@@ -218,24 +182,15 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
@Override
public void onStateChangeFinished() {
mAnimationFinished = true;
finishTransitionIfNeeded();
// mLastAnimationProgress is guaranteed to be 0f when folding finishes, see
// {@link PhysicsBasedUnfoldTransitionProgressProvider#cancelTransition}.
// We can use it as an indication that the next animation progress events will be related
// to unfolding, so let's reset mAnimationFinished to 'false' in this case.
final boolean isFoldingFinished = mLastAnimationProgress == 0f;
mAnimationFinished = !isFoldingFinished;
}
@Override
public void mergeAnimation(@NonNull IBinder transition, @NonNull TransitionInfo info,
@NonNull SurfaceControl.Transaction startT,
@NonNull SurfaceControl.Transaction finishT,
@NonNull IBinder mergeTarget,
@NonNull SurfaceControl.Transaction t, @NonNull IBinder mergeTarget,
@NonNull TransitionFinishCallback finishCallback) {
if (info.getType() != TRANSIT_CHANGE
&& info.getType() != TRANSIT_BUBBLE_CONVERT_FLOATING_TO_BAR) {
if (info.getType() != TRANSIT_CHANGE) {
return;
}
if ((info.getFlags() & KEYGUARD_VISIBILITY_TRANSIT_FLAGS) != 0) {
@@ -243,37 +198,19 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
}
// TODO (b/286928742) unfold transition handler should be part of mixed handler to
// handle merges better.
for (int i = 0; i < info.getChanges().size(); ++i) {
final TransitionInfo.Change change = info.getChanges().get(i);
final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
if (taskInfo != null
&& taskInfo.configuration.windowConfiguration.isAlwaysOnTop()) {
// Tasks that are always on top, excluding bubbles, will handle their own transition
// as they are on top of everything else. If this is a transition for a bubble task,
// attempt to merge it. Otherwise skip merging transitions.
if (mBubbleTaskUnfoldTransitionMerger.isPresent()) {
boolean merged =
mBubbleTaskUnfoldTransitionMerger
.get()
.mergeTaskWithUnfold(taskInfo, info, change, startT, finishT);
if (!merged) {
return;
}
} else {
return;
}
// Tasks that are always on top (e.g. bubbles), will handle their own transition
// as they are on top of everything else. So skip merging transitions here.
return;
}
}
// Apply changes happening during the unfold animation immediately
startT.apply();
t.apply();
finishCallback.onTransitionFinished(null);
if (getDefaultDisplayChange(info) == DefaultDisplayChange.DEFAULT_DISPLAY_FOLD) {
// Force-finish current unfold animation as we are processing folding now which doesn't
// have any animations on the Shell side
finishTransitionIfNeeded();
}
}
/** Whether `request` contains an unfold action. */
@@ -282,25 +219,18 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
if (!ValueAnimator.areAnimatorsEnabled()) return false;
return (request.getType() == TRANSIT_CHANGE
&& getDefaultDisplayChange(request.getDisplayChange())
== DefaultDisplayChange.DEFAULT_DISPLAY_UNFOLD);
&& request.getDisplayChange() != null
&& isUnfoldDisplayChange(request.getDisplayChange()));
}
@DefaultDisplayChange
private int getDefaultDisplayChange(
@Nullable TransitionRequestInfo.DisplayChange displayChange) {
if (displayChange == null) return DefaultDisplayChange.DEFAULT_DISPLAY_NO_CHANGE;
if (displayChange.getDisplayId() != DEFAULT_DISPLAY) {
return DefaultDisplayChange.DEFAULT_DISPLAY_NO_CHANGE;
}
private boolean isUnfoldDisplayChange(
@NonNull TransitionRequestInfo.DisplayChange displayChange) {
if (!displayChange.isPhysicalDisplayChanged()) {
return DefaultDisplayChange.DEFAULT_DISPLAY_NO_CHANGE;
return false;
}
if (displayChange.getStartAbsBounds() == null || displayChange.getEndAbsBounds() == null) {
return DefaultDisplayChange.DEFAULT_DISPLAY_NO_CHANGE;
return false;
}
// Handle only unfolding, currently we don't have an animation when folding
@@ -309,11 +239,17 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
final int startArea = displayChange.getStartAbsBounds().width()
* displayChange.getStartAbsBounds().height();
return endArea > startArea ? DefaultDisplayChange.DEFAULT_DISPLAY_UNFOLD
: DefaultDisplayChange.DEFAULT_DISPLAY_FOLD;
return endArea > startArea;
}
private int getDefaultDisplayChange(@NonNull TransitionInfo transitionInfo) {
/** Whether `transitionInfo` contains an unfold action. */
public boolean shouldPlayUnfoldAnimation(@NonNull TransitionInfo transitionInfo) {
// Unfold animation won't play when animations are disabled
if (!ValueAnimator.areAnimatorsEnabled()) return false;
// Only handle transitions that are marked as physical display switch
// See PhysicalDisplaySwitchTransitionLauncher for the conditions
if ((transitionInfo.getFlags() & TRANSIT_FLAG_PHYSICAL_DISPLAY_SWITCH) == 0) return false;
for (int i = 0; i < transitionInfo.getChanges().size(); i++) {
final TransitionInfo.Change change = transitionInfo.getChanges().get(i);
// We are interested only in display container changes
@@ -332,13 +268,11 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
* change.getStartAbsBounds().height();
if (afterArea > beforeArea) {
return DefaultDisplayChange.DEFAULT_DISPLAY_UNFOLD;
} else {
return DefaultDisplayChange.DEFAULT_DISPLAY_FOLD;
return true;
}
}
return DefaultDisplayChange.DEFAULT_DISPLAY_NO_CHANGE;
return false;
}
@Nullable
@@ -359,6 +293,10 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
@Override
public void onFoldStateChanged(boolean isFolded) {
if (isFolded) {
// Reset unfold animation finished flag on folding, so it could be used next time
// when we unfold the device as an indication that animation hasn't finished yet
mAnimationFinished = false;
// If we are currently animating unfold animation we should finish it because
// the animation might not start and finish as the device was folded
finishTransitionIfNeeded();
@@ -374,7 +312,6 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
animator.stop();
}
mHandler.removeCallbacks(mAnimationPlayingTimeoutRunnable);
mFinishCallback.onTransitionFinished(null);
mFinishCallback = null;
mTransition = null;