feat: WM-Shell QPR1 (src and shared)
This commit is contained in:
@@ -16,25 +16,31 @@
|
||||
|
||||
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.common.ProtoLog;
|
||||
import com.android.wm.shell.common.TransactionPool;
|
||||
import com.android.internal.protolog.ProtoLog;
|
||||
import com.android.wm.shell.bubbles.BubbleTaskUnfoldTransitionMerger;
|
||||
import com.android.wm.shell.shared.TransactionPool;
|
||||
import com.android.wm.shell.shared.TransitionUtil;
|
||||
import com.android.wm.shell.sysui.ShellInit;
|
||||
import com.android.wm.shell.transition.Transitions;
|
||||
@@ -45,8 +51,11 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -56,37 +65,67 @@ 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,
|
||||
Transitions transitions) {
|
||||
Handler handler,
|
||||
Transitions transitions,
|
||||
Optional<BubbleTaskUnfoldTransitionMerger> bubbleTaskUnfoldTransitionMerger) {
|
||||
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
|
||||
&& Transitions.ENABLE_SHELL_TRANSITIONS) {
|
||||
if (unfoldProgressProvider != ShellUnfoldProgressProvider.NO_PROVIDER) {
|
||||
shellInit.addInitCallback(this::onInit, this);
|
||||
}
|
||||
}
|
||||
@@ -107,16 +146,6 @@ 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++) {
|
||||
@@ -151,6 +180,11 @@ 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;
|
||||
@@ -158,6 +192,8 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
|
||||
|
||||
@Override
|
||||
public void onStateChangeProgress(float progress) {
|
||||
mLastAnimationProgress = progress;
|
||||
|
||||
if (mTransition == null) return;
|
||||
|
||||
SurfaceControl.Transaction transaction = null;
|
||||
@@ -182,15 +218,24 @@ 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 t, @NonNull IBinder mergeTarget,
|
||||
@NonNull SurfaceControl.Transaction startT,
|
||||
@NonNull SurfaceControl.Transaction finishT,
|
||||
@NonNull IBinder mergeTarget,
|
||||
@NonNull TransitionFinishCallback finishCallback) {
|
||||
if (info.getType() != TRANSIT_CHANGE) {
|
||||
if (info.getType() != TRANSIT_CHANGE
|
||||
&& info.getType() != TRANSIT_BUBBLE_CONVERT_FLOATING_TO_BAR) {
|
||||
return;
|
||||
}
|
||||
if ((info.getFlags() & KEYGUARD_VISIBILITY_TRANSIT_FLAGS) != 0) {
|
||||
@@ -198,19 +243,37 @@ 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 (e.g. bubbles), will handle their own transition
|
||||
// as they are on top of everything else. So skip merging transitions here.
|
||||
return;
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Apply changes happening during the unfold animation immediately
|
||||
t.apply();
|
||||
startT.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. */
|
||||
@@ -219,18 +282,25 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
|
||||
if (!ValueAnimator.areAnimatorsEnabled()) return false;
|
||||
|
||||
return (request.getType() == TRANSIT_CHANGE
|
||||
&& request.getDisplayChange() != null
|
||||
&& isUnfoldDisplayChange(request.getDisplayChange()));
|
||||
&& getDefaultDisplayChange(request.getDisplayChange())
|
||||
== DefaultDisplayChange.DEFAULT_DISPLAY_UNFOLD);
|
||||
}
|
||||
|
||||
private boolean isUnfoldDisplayChange(
|
||||
@NonNull TransitionRequestInfo.DisplayChange displayChange) {
|
||||
@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;
|
||||
}
|
||||
|
||||
if (!displayChange.isPhysicalDisplayChanged()) {
|
||||
return false;
|
||||
return DefaultDisplayChange.DEFAULT_DISPLAY_NO_CHANGE;
|
||||
}
|
||||
|
||||
if (displayChange.getStartAbsBounds() == null || displayChange.getEndAbsBounds() == null) {
|
||||
return false;
|
||||
return DefaultDisplayChange.DEFAULT_DISPLAY_NO_CHANGE;
|
||||
}
|
||||
|
||||
// Handle only unfolding, currently we don't have an animation when folding
|
||||
@@ -239,17 +309,11 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
|
||||
final int startArea = displayChange.getStartAbsBounds().width()
|
||||
* displayChange.getStartAbsBounds().height();
|
||||
|
||||
return endArea > startArea;
|
||||
return endArea > startArea ? DefaultDisplayChange.DEFAULT_DISPLAY_UNFOLD
|
||||
: DefaultDisplayChange.DEFAULT_DISPLAY_FOLD;
|
||||
}
|
||||
|
||||
/** 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;
|
||||
|
||||
private int getDefaultDisplayChange(@NonNull TransitionInfo transitionInfo) {
|
||||
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
|
||||
@@ -268,11 +332,13 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
|
||||
* change.getStartAbsBounds().height();
|
||||
|
||||
if (afterArea > beforeArea) {
|
||||
return true;
|
||||
return DefaultDisplayChange.DEFAULT_DISPLAY_UNFOLD;
|
||||
} else {
|
||||
return DefaultDisplayChange.DEFAULT_DISPLAY_FOLD;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return DefaultDisplayChange.DEFAULT_DISPLAY_NO_CHANGE;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -293,10 +359,6 @@ 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();
|
||||
@@ -312,6 +374,7 @@ public class UnfoldTransitionHandler implements TransitionHandler, UnfoldListene
|
||||
animator.stop();
|
||||
}
|
||||
|
||||
mHandler.removeCallbacks(mAnimationPlayingTimeoutRunnable);
|
||||
mFinishCallback.onTransitionFinished(null);
|
||||
mFinishCallback = null;
|
||||
mTransition = null;
|
||||
|
||||
Reference in New Issue
Block a user