From d6073dc838d9b75852b5b8e0b763bc41a65bfbb4 Mon Sep 17 00:00:00 2001 From: Luca Zuccarini Date: Mon, 22 Jan 2024 17:06:41 +0000 Subject: Extract shared utils so they can be used without depending on core Shell. This is in preparation of making the Animation library a dependency of Shell. The Animation lib itself needs to depend on these utilities to handle transitions, so pulling it out into its own target solves dependency cycles. Fix: 321724947 Flag: NA Test: both soong and gradle builds work Change-Id: I1c461d976a5d3a72e3cd86fc8b904224c403382f --- libs/WindowManager/Shell/Android.bp | 8 + .../android/wm/shell/shared/CounterRotator.java | 83 +++++ .../android/wm/shell/shared/TransitionUtil.java | 365 +++++++++++++++++++++ .../ActivityEmbeddingAnimationAdapter.java | 2 +- .../ActivityEmbeddingAnimationRunner.java | 2 +- .../ActivityEmbeddingAnimationSpec.java | 2 +- .../ActivityEmbeddingController.java | 2 +- .../shell/bubbles/BubblesTransitionObserver.java | 2 +- .../shell/common/split/SplitScreenConstants.java | 5 +- .../desktopmode/DragToDesktopTransitionHandler.kt | 2 +- .../shell/keyguard/KeyguardTransitionHandler.java | 2 +- .../com/android/wm/shell/pip/PipTransition.java | 2 +- .../android/wm/shell/pip/tv/TvPipTransition.java | 2 +- .../wm/shell/recents/RecentsTransitionHandler.java | 2 +- .../shell/splitscreen/SplitScreenTransitions.java | 2 +- .../wm/shell/splitscreen/StageCoordinator.java | 6 +- .../wm/shell/taskview/TaskViewTransitions.java | 2 +- .../wm/shell/transition/CounterRotatorHelper.java | 4 +- .../wm/shell/transition/DefaultMixedHandler.java | 4 +- .../shell/transition/DefaultTransitionHandler.java | 2 +- .../shell/transition/HomeTransitionObserver.java | 2 +- .../shell/transition/RemoteTransitionHandler.java | 2 +- .../transition/TransitionAnimationHelper.java | 2 +- .../android/wm/shell/transition/Transitions.java | 6 +- .../wm/shell/unfold/UnfoldTransitionHandler.java | 2 +- .../com/android/wm/shell/util/CounterRotator.java | 83 ----- .../com/android/wm/shell/util/TransitionUtil.java | 364 -------------------- packages/SystemUI/shared/Android.bp | 1 + .../shared/system/RemoteAnimationRunnerCompat.java | 2 +- .../shared/system/RemoteAnimationTargetCompat.java | 2 +- .../android/systemui/keyguard/KeyguardService.java | 4 +- .../shared/system/RemoteTransitionTest.java | 2 +- 32 files changed, 492 insertions(+), 481 deletions(-) create mode 100644 libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/CounterRotator.java create mode 100644 libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/TransitionUtil.java delete mode 100644 libs/WindowManager/Shell/src/com/android/wm/shell/util/CounterRotator.java delete mode 100644 libs/WindowManager/Shell/src/com/android/wm/shell/util/TransitionUtil.java diff --git a/libs/WindowManager/Shell/Android.bp b/libs/WindowManager/Shell/Android.bp index 4cdc06a999a7..a12fa5fe26ff 100644 --- a/libs/WindowManager/Shell/Android.bp +++ b/libs/WindowManager/Shell/Android.bp @@ -39,6 +39,7 @@ filegroup { } // Sources that have no dependencies that can be used directly downstream of this library +// TODO(b/322791067): move these sources to WindowManager-Shell-shared filegroup { name: "wm_shell_util-sources", srcs: [ @@ -137,6 +138,12 @@ java_library { }, } +java_library { + name: "WindowManager-Shell-shared", + + srcs: ["shared/**/*.java"], +} + android_library { name: "WindowManager-Shell", srcs: [ @@ -162,6 +169,7 @@ android_library { "com_android_wm_shell_flags_lib", "com.android.window.flags.window-aconfig-java", "WindowManager-Shell-proto", + "WindowManager-Shell-shared", "perfetto_trace_java_protos", "dagger2", "jsr330", diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/CounterRotator.java b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/CounterRotator.java new file mode 100644 index 000000000000..fd3a749af284 --- /dev/null +++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/CounterRotator.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * 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. + */ + +package com.android.wm.shell.shared; + +import android.graphics.Point; +import android.util.RotationUtils; +import android.view.SurfaceControl; + +/** + * Utility class that takes care of rotating unchanging child-surfaces to match the parent rotation + * during a transition animation. This gives the illusion that the child surfaces haven't rotated + * relative to the screen. + */ +public class CounterRotator { + private SurfaceControl mSurface = null; + + /** Gets the surface with the counter-rotation. */ + public SurfaceControl getSurface() { + return mSurface; + } + + /** + * Sets up this rotator. + * + * @param rotateDelta is the forward rotation change (the rotation the display is making). + * @param parentW (and H) Is the size of the rotating parent after the rotation. + */ + public void setup(SurfaceControl.Transaction t, SurfaceControl parent, int rotateDelta, + float parentW, float parentH) { + if (rotateDelta == 0) return; + mSurface = new SurfaceControl.Builder() + .setName("Transition Unrotate") + .setContainerLayer() + .setParent(parent) + .build(); + // Rotate forward to match the new rotation (rotateDelta is the forward rotation the parent + // already took). Child surfaces will be in the old rotation relative to the new parent + // rotation, so we need to forward-rotate the child surfaces to match. + RotationUtils.rotateSurface(t, mSurface, rotateDelta); + final Point tmpPt = new Point(0, 0); + // parentW/H are the size in the END rotation, the rotation utilities expect the starting + // size. So swap them if necessary + if ((rotateDelta % 2) != 0) { + final float w = parentW; + parentW = parentH; + parentH = w; + } + RotationUtils.rotatePoint(tmpPt, rotateDelta, (int) parentW, (int) parentH); + t.setPosition(mSurface, tmpPt.x, tmpPt.y); + t.show(mSurface); + } + + /** + * Adds a surface that needs to be counter-rotate. + */ + public void addChild(SurfaceControl.Transaction t, SurfaceControl child) { + if (mSurface == null) return; + t.reparent(child, mSurface); + } + + /** + * Clean-up. Since finishTransaction should reset all change leashes, we only need to remove the + * counter rotation surface. + */ + public void cleanUp(SurfaceControl.Transaction finishTransaction) { + if (mSurface == null) return; + finishTransaction.remove(mSurface); + } +} diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/TransitionUtil.java b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/TransitionUtil.java new file mode 100644 index 000000000000..dcd4062cb819 --- /dev/null +++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/TransitionUtil.java @@ -0,0 +1,365 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * 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. + */ + +package com.android.wm.shell.shared; + +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_CHANGE; +import static android.view.WindowManager.TRANSIT_CLOSE; +import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY; +import static android.view.WindowManager.TRANSIT_OPEN; +import static android.view.WindowManager.TRANSIT_TO_BACK; +import static android.view.WindowManager.TRANSIT_TO_FRONT; +import static android.window.TransitionInfo.FLAG_FIRST_CUSTOM; +import static android.window.TransitionInfo.FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY; +import static android.window.TransitionInfo.FLAG_IS_DISPLAY; +import static android.window.TransitionInfo.FLAG_IS_WALLPAPER; +import static android.window.TransitionInfo.FLAG_MOVED_TO_TOP; +import static android.window.TransitionInfo.FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SuppressLint; +import android.app.ActivityManager; +import android.app.WindowConfiguration; +import android.graphics.Rect; +import android.util.ArrayMap; +import android.util.SparseBooleanArray; +import android.view.RemoteAnimationTarget; +import android.view.SurfaceControl; +import android.view.WindowManager; +import android.window.TransitionInfo; + +import java.util.function.Predicate; + +/** Various utility functions for transitions. */ +public class TransitionUtil { + /** Flag applied to a transition change to identify it as a divider bar for animation. */ + public static final int FLAG_IS_DIVIDER_BAR = FLAG_FIRST_CUSTOM; + + /** @return true if the transition was triggered by opening something vs closing something */ + public static boolean isOpeningType(@WindowManager.TransitionType int type) { + return type == TRANSIT_OPEN + || type == TRANSIT_TO_FRONT + || type == TRANSIT_KEYGUARD_GOING_AWAY; + } + + /** @return true if the transition was triggered by closing something vs opening something */ + public static boolean isClosingType(@WindowManager.TransitionType int type) { + return type == TRANSIT_CLOSE || type == TRANSIT_TO_BACK; + } + + /** Returns {@code true} if the transition is opening or closing mode. */ + public static boolean isOpenOrCloseMode(@TransitionInfo.TransitionMode int mode) { + return mode == TRANSIT_OPEN || mode == TRANSIT_CLOSE + || mode == TRANSIT_TO_FRONT || mode == TRANSIT_TO_BACK; + } + + /** Returns {@code true} if the transition has a display change. */ + public static boolean hasDisplayChange(@NonNull TransitionInfo info) { + for (int i = info.getChanges().size() - 1; i >= 0; --i) { + final TransitionInfo.Change change = info.getChanges().get(i); + if (change.getMode() == TRANSIT_CHANGE && change.hasFlags(FLAG_IS_DISPLAY)) { + return true; + } + } + return false; + } + + /** Returns `true` if `change` is a wallpaper. */ + public static boolean isWallpaper(TransitionInfo.Change change) { + return (change.getTaskInfo() == null) + && change.hasFlags(FLAG_IS_WALLPAPER) + && !change.hasFlags(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY); + } + + /** Returns `true` if `change` is not an app window or wallpaper. */ + public static boolean isNonApp(TransitionInfo.Change change) { + return (change.getTaskInfo() == null) + && !change.hasFlags(FLAG_IS_WALLPAPER) + && !change.hasFlags(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY); + } + + /** Returns `true` if `change` is the divider. */ + public static boolean isDividerBar(TransitionInfo.Change change) { + return isNonApp(change) && change.hasFlags(FLAG_IS_DIVIDER_BAR); + } + + /** Returns `true` if `change` is only re-ordering. */ + public static boolean isOrderOnly(TransitionInfo.Change change) { + return change.getMode() == TRANSIT_CHANGE + && (change.getFlags() & FLAG_MOVED_TO_TOP) != 0 + && change.getStartAbsBounds().equals(change.getEndAbsBounds()) + && (change.getLastParent() == null + || change.getLastParent().equals(change.getParent())); + } + + /** + * Filter that selects leaf-tasks only. THIS IS ORDER-DEPENDENT! For it to work properly, you + * MUST call `test` in the same order that the changes appear in the TransitionInfo. + */ + public static class LeafTaskFilter implements Predicate { + private final SparseBooleanArray mChildTaskTargets = new SparseBooleanArray(); + + @Override + public boolean test(TransitionInfo.Change change) { + final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo(); + if (taskInfo == null) return false; + // Children always come before parent since changes are in top-to-bottom z-order. + boolean hasChildren = mChildTaskTargets.get(taskInfo.taskId); + if (taskInfo.hasParentTask()) { + mChildTaskTargets.put(taskInfo.parentTaskId, true); + } + // If it has children, it's not a leaf. + return !hasChildren; + } + } + + + private static int newModeToLegacyMode(int newMode) { + switch (newMode) { + case WindowManager.TRANSIT_OPEN: + case WindowManager.TRANSIT_TO_FRONT: + return MODE_OPENING; + case WindowManager.TRANSIT_CLOSE: + case WindowManager.TRANSIT_TO_BACK: + return MODE_CLOSING; + default: + return MODE_CHANGING; + } + } + + /** + * Very similar to Transitions#setupAnimHierarchy but specialized for leashes. + */ + @SuppressLint("NewApi") + private static void setupLeash(@NonNull SurfaceControl leash, + @NonNull TransitionInfo.Change change, int layer, + @NonNull TransitionInfo info, @NonNull SurfaceControl.Transaction t) { + final boolean isOpening = TransitionUtil.isOpeningType(info.getType()); + // Put animating stuff above this line and put static stuff below it. + int zSplitLine = info.getChanges().size(); + // changes should be ordered top-to-bottom in z + final int mode = change.getMode(); + + final int rootIdx = TransitionUtil.rootIndexFor(change, info); + t.reparent(leash, info.getRoot(rootIdx).getLeash()); + final Rect absBounds = + (mode == TRANSIT_OPEN) ? change.getEndAbsBounds() : change.getStartAbsBounds(); + t.setPosition(leash, absBounds.left - info.getRoot(rootIdx).getOffset().x, + absBounds.top - info.getRoot(rootIdx).getOffset().y); + + if (isDividerBar(change)) { + if (isOpeningType(mode)) { + t.setAlpha(leash, 0.f); + } + // Set the transition leash position to 0 in case the divider leash position being + // taking down. + t.setPosition(leash, 0, 0); + t.setLayer(leash, Integer.MAX_VALUE); + return; + } + + // Put all the OPEN/SHOW on top + if ((change.getFlags() & FLAG_IS_WALLPAPER) != 0) { + // Wallpaper is always at the bottom, opening wallpaper on top of closing one. + if (mode == WindowManager.TRANSIT_OPEN || mode == WindowManager.TRANSIT_TO_FRONT) { + t.setLayer(leash, -zSplitLine + info.getChanges().size() - layer); + } else { + t.setLayer(leash, -zSplitLine - layer); + } + } else if (TransitionUtil.isOpeningType(mode)) { + if (isOpening) { + t.setLayer(leash, zSplitLine + info.getChanges().size() - layer); + if ((change.getFlags() & FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT) == 0) { + // if transferred, it should be left visible. + t.setAlpha(leash, 0.f); + } + } else { + // put on bottom and leave it visible + t.setLayer(leash, zSplitLine - layer); + } + } else if (TransitionUtil.isClosingType(mode)) { + if (isOpening) { + // put on bottom and leave visible + t.setLayer(leash, zSplitLine - layer); + } else { + // put on top + t.setLayer(leash, zSplitLine + info.getChanges().size() - layer); + } + } else { // CHANGE + t.setLayer(leash, zSplitLine + info.getChanges().size() - layer); + } + } + + @SuppressLint("NewApi") + private static SurfaceControl createLeash(TransitionInfo info, TransitionInfo.Change change, + int order, SurfaceControl.Transaction t) { + // TODO: once we can properly sync transactions across process, then get rid of this leash. + if (change.getParent() != null && (change.getFlags() & FLAG_IS_WALLPAPER) != 0) { + // Special case for wallpaper atm. Normally these are left alone; but, a quirk of + // making leashes means we have to handle them specially. + return change.getLeash(); + } + final int rootIdx = TransitionUtil.rootIndexFor(change, info); + SurfaceControl leashSurface = new SurfaceControl.Builder() + .setName(change.getLeash().toString() + "_transition-leash") + .setContainerLayer() + // Initial the surface visible to respect the visibility of the original surface. + .setHidden(false) + .setParent(info.getRoot(rootIdx).getLeash()) + .build(); + // Copied Transitions setup code (which expects bottom-to-top order, so we swap here) + setupLeash(leashSurface, change, info.getChanges().size() - order, info, t); + t.reparent(change.getLeash(), leashSurface); + t.setAlpha(change.getLeash(), 1.0f); + t.show(change.getLeash()); + if (!isDividerBar(change)) { + // For divider, don't modify its inner leash position when creating the outer leash + // for the transition. In case the position being wrong after the transition finished. + t.setPosition(change.getLeash(), 0, 0); + } + t.setLayer(change.getLeash(), 0); + return leashSurface; + } + + /** + * 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 leashMap) { + return newTarget(change, order, false /* forceTranslucent */, info, t, leashMap); + } + + /** + * Creates a new RemoteAnimationTarget from the provided change info + */ + public static RemoteAnimationTarget newTarget(TransitionInfo.Change change, int order, + boolean forceTranslucent, TransitionInfo info, SurfaceControl.Transaction t, + @Nullable ArrayMap leashMap) { + final SurfaceControl leash = createLeash(info, change, order, t); + if (leashMap != null) { + leashMap.put(change.getLeash(), leash); + } + return newTarget(change, order, leash, forceTranslucent); + } + + /** + * Creates a new RemoteAnimationTarget from the provided change and leash + */ + public static RemoteAnimationTarget newTarget(TransitionInfo.Change change, int order, + SurfaceControl leash) { + return newTarget(change, order, leash, false /* forceTranslucent */); + } + + /** + * Creates a new RemoteAnimationTarget from the provided change and leash + */ + public static RemoteAnimationTarget newTarget(TransitionInfo.Change change, int order, + SurfaceControl leash, boolean forceTranslucent) { + if (isDividerBar(change)) { + return getDividerTarget(change, leash); + } + + int taskId; + boolean isNotInRecents; + ActivityManager.RunningTaskInfo taskInfo; + WindowConfiguration windowConfiguration; + + taskInfo = change.getTaskInfo(); + if (taskInfo != null) { + taskId = taskInfo.taskId; + isNotInRecents = !taskInfo.isRunning; + windowConfiguration = taskInfo.configuration.windowConfiguration; + } else { + taskId = INVALID_TASK_ID; + isNotInRecents = true; + windowConfiguration = new WindowConfiguration(); + } + + Rect localBounds = new Rect(change.getEndAbsBounds()); + localBounds.offsetTo(change.getEndRelOffset().x, change.getEndRelOffset().y); + + RemoteAnimationTarget target = new RemoteAnimationTarget( + taskId, + newModeToLegacyMode(change.getMode()), + // TODO: once we can properly sync transactions across process, + // then get rid of this leash. + leash, + forceTranslucent || (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(), + INVALID_WINDOW_TYPE + ); + target.setWillShowImeOnTarget( + (change.getFlags() & TransitionInfo.FLAG_WILL_IME_SHOWN) != 0); + target.setRotationChange(change.getEndRotation() - change.getStartRotation()); + target.backgroundColor = change.getBackgroundColor(); + return target; + } + + private static RemoteAnimationTarget getDividerTarget(TransitionInfo.Change change, + SurfaceControl leash) { + return new RemoteAnimationTarget(-1 /* taskId */, newModeToLegacyMode(change.getMode()), + leash, false /* isTranslucent */, null /* clipRect */, + null /* contentInsets */, Integer.MAX_VALUE /* prefixOrderIndex */, + new android.graphics.Point(0, 0) /* position */, change.getStartAbsBounds(), + change.getStartAbsBounds(), new WindowConfiguration(), true, null /* startLeash */, + null /* startBounds */, null /* taskInfo */, false /* allowEnterPip */, + TYPE_DOCK_DIVIDER); + } + + /** + * Finds the "correct" root idx for a change. The change's end display is prioritized, then + * the start display. If there is no display, it will fallback on the 0th root in the + * transition. There MUST be at-least 1 root in the transition (ie. it's not a no-op). + */ + public static int rootIndexFor(@NonNull TransitionInfo.Change change, + @NonNull TransitionInfo info) { + int rootIdx = info.findRootIndex(change.getEndDisplayId()); + if (rootIdx >= 0) return rootIdx; + rootIdx = info.findRootIndex(change.getStartDisplayId()); + if (rootIdx >= 0) return rootIdx; + return 0; + } + + /** + * Gets the {@link TransitionInfo.Root} for the given {@link TransitionInfo.Change}. + * @see #rootIndexFor(TransitionInfo.Change, TransitionInfo) + */ + @NonNull + public static TransitionInfo.Root getRootFor(@NonNull TransitionInfo.Change change, + @NonNull TransitionInfo info) { + return info.getRoot(rootIndexFor(change, info)); + } +} diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationAdapter.java b/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationAdapter.java index 8241e1a481ee..8d30db64a3e5 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationAdapter.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationAdapter.java @@ -29,7 +29,7 @@ import android.window.TransitionInfo; import androidx.annotation.NonNull; -import com.android.wm.shell.util.TransitionUtil; +import com.android.wm.shell.shared.TransitionUtil; /** * Wrapper to handle the ActivityEmbedding animation update in one diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationRunner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationRunner.java index 44ee5615ac74..539832e3cf3c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationRunner.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationRunner.java @@ -46,7 +46,7 @@ import androidx.annotation.Nullable; import com.android.internal.annotations.VisibleForTesting; import com.android.wm.shell.activityembedding.ActivityEmbeddingAnimationAdapter.SnapshotAdapter; import com.android.wm.shell.common.ScreenshotUtils; -import com.android.wm.shell.util.TransitionUtil; +import com.android.wm.shell.shared.TransitionUtil; import java.util.ArrayList; import java.util.List; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationSpec.java b/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationSpec.java index efa5a1a64ade..0272f1cda6ef 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationSpec.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationSpec.java @@ -38,7 +38,7 @@ import android.view.animation.TranslateAnimation; import android.window.TransitionInfo; import com.android.internal.policy.TransitionAnimation; -import com.android.wm.shell.util.TransitionUtil; +import com.android.wm.shell.shared.TransitionUtil; /** Animation spec for ActivityEmbedding transition. */ // TODO(b/206557124): provide an easier way to customize animation diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingController.java index b4e852cfaa48..1f9358e2aa91 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingController.java @@ -38,9 +38,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.internal.annotations.VisibleForTesting; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.sysui.ShellInit; import com.android.wm.shell.transition.Transitions; -import com.android.wm.shell.util.TransitionUtil; import java.util.List; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblesTransitionObserver.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblesTransitionObserver.java index 9e8a385262e4..c1f704ab455d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblesTransitionObserver.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblesTransitionObserver.java @@ -24,8 +24,8 @@ import android.window.TransitionInfo; import androidx.annotation.NonNull; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.transition.Transitions; -import com.android.wm.shell.util.TransitionUtil; /** * Observer used to identify tasks that are opening or moving to front. If a bubble activity is diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitScreenConstants.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitScreenConstants.java index 49db8d9c54a6..e8c809e5db4a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitScreenConstants.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitScreenConstants.java @@ -20,10 +20,11 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; -import static android.window.TransitionInfo.FLAG_FIRST_CUSTOM; import android.annotation.IntDef; +import com.android.wm.shell.shared.TransitionUtil; + /** Helper utility class of methods and constants that are available to be imported in Launcher. */ public class SplitScreenConstants { /** Duration used for every split fade-in or fade-out. */ @@ -126,7 +127,7 @@ public class SplitScreenConstants { WINDOWING_MODE_FREEFORM}; /** Flag applied to a transition change to identify it as a divider bar for animation. */ - public static final int FLAG_IS_DIVIDER_BAR = FLAG_FIRST_CUSTOM; + public static final int FLAG_IS_DIVIDER_BAR = TransitionUtil.FLAG_IS_DIVIDER_BAR; public static final String splitPositionToString(@SplitPosition int pos) { switch (pos) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandler.kt index c3a82ce258df..1f3e0e524a1c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandler.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandler.kt @@ -26,6 +26,7 @@ import android.window.WindowContainerToken import android.window.WindowContainerTransaction import com.android.wm.shell.RootTaskDisplayAreaOrganizer import com.android.wm.shell.protolog.ShellProtoLogGroup +import com.android.wm.shell.shared.TransitionUtil import com.android.wm.shell.splitscreen.SplitScreenController import com.android.wm.shell.transition.Transitions import com.android.wm.shell.transition.Transitions.TRANSIT_DESKTOP_MODE_CANCEL_DRAG_TO_DESKTOP @@ -33,7 +34,6 @@ import com.android.wm.shell.transition.Transitions.TRANSIT_DESKTOP_MODE_END_DRAG import com.android.wm.shell.transition.Transitions.TRANSIT_DESKTOP_MODE_START_DRAG_TO_DESKTOP import com.android.wm.shell.transition.Transitions.TransitionHandler import com.android.wm.shell.util.KtProtoLog -import com.android.wm.shell.util.TransitionUtil import com.android.wm.shell.windowdecor.DesktopModeWindowDecoration import com.android.wm.shell.windowdecor.MoveToDesktopAnimator import com.android.wm.shell.windowdecor.MoveToDesktopAnimator.Companion.DRAG_FREEFORM_SCALE diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/keyguard/KeyguardTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/keyguard/KeyguardTransitionHandler.java index e63bbc07bc41..73de231fb63a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/keyguard/KeyguardTransitionHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/keyguard/KeyguardTransitionHandler.java @@ -27,7 +27,7 @@ import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_OCCLUDING; import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_UNOCCLUDING; import static android.view.WindowManager.TRANSIT_SLEEP; -import static com.android.wm.shell.util.TransitionUtil.isOpeningType; +import static com.android.wm.shell.shared.TransitionUtil.isOpeningType; import android.annotation.NonNull; import android.annotation.Nullable; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java index 8e375a9ef5ee..a055fb1abcb9 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java @@ -70,11 +70,11 @@ import com.android.wm.shell.common.pip.PipBoundsState; import com.android.wm.shell.common.pip.PipDisplayLayoutState; import com.android.wm.shell.common.pip.PipUtils; import com.android.wm.shell.protolog.ShellProtoLogGroup; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.splitscreen.SplitScreenController; import com.android.wm.shell.sysui.ShellInit; import com.android.wm.shell.transition.CounterRotatorHelper; import com.android.wm.shell.transition.Transitions; -import com.android.wm.shell.util.TransitionUtil; import java.io.PrintWriter; import java.lang.annotation.Retention; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTransition.java index 571c839adf11..462211084f52 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTransition.java @@ -71,9 +71,9 @@ import com.android.wm.shell.pip.PipSurfaceTransactionHelper; import com.android.wm.shell.pip.PipTransitionController; import com.android.wm.shell.pip.PipTransitionState; import com.android.wm.shell.protolog.ShellProtoLogGroup; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.sysui.ShellInit; import com.android.wm.shell.transition.Transitions; -import com.android.wm.shell.util.TransitionUtil; import java.util.ArrayList; import java.util.List; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java index 1232baacdac7..97d3457aaa38 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java @@ -58,10 +58,10 @@ import com.android.internal.os.IResultReceiver; import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.protolog.ShellProtoLogGroup; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.sysui.ShellInit; import com.android.wm.shell.transition.HomeTransitionObserver; import com.android.wm.shell.transition.Transitions; -import com.android.wm.shell.util.TransitionUtil; import java.util.ArrayList; import java.util.function.Consumer; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenTransitions.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenTransitions.java index 5de8a9be9576..e8894a836663 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenTransitions.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenTransitions.java @@ -48,9 +48,9 @@ import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.common.TransactionPool; import com.android.wm.shell.common.split.SplitDecorManager; import com.android.wm.shell.protolog.ShellProtoLogGroup; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.transition.OneShotRemoteHandler; import com.android.wm.shell.transition.Transitions; -import com.android.wm.shell.util.TransitionUtil; import java.util.ArrayList; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java index af05aa2c5ec6..e5045aea189b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java @@ -44,6 +44,8 @@ import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSIT import static com.android.wm.shell.common.split.SplitScreenConstants.splitPositionToString; import static com.android.wm.shell.common.split.SplitScreenUtils.reverseSplitPosition; import static com.android.wm.shell.common.split.SplitScreenUtils.splitFailureMessage; +import static com.android.wm.shell.shared.TransitionUtil.isClosingType; +import static com.android.wm.shell.shared.TransitionUtil.isOpeningType; import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_MAIN; import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_SIDE; import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_UNDEFINED; @@ -64,8 +66,6 @@ import static com.android.wm.shell.splitscreen.SplitScreenController.exitReasonT import static com.android.wm.shell.transition.Transitions.ENABLE_SHELL_TRANSITIONS; import static com.android.wm.shell.transition.Transitions.TRANSIT_SPLIT_SCREEN_OPEN_TO_SIDE; import static com.android.wm.shell.transition.Transitions.TRANSIT_SPLIT_SCREEN_PAIR_OPEN; -import static com.android.wm.shell.util.TransitionUtil.isClosingType; -import static com.android.wm.shell.util.TransitionUtil.isOpeningType; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -135,13 +135,13 @@ import com.android.wm.shell.common.split.SplitScreenUtils; import com.android.wm.shell.common.split.SplitWindowManager; import com.android.wm.shell.protolog.ShellProtoLogGroup; import com.android.wm.shell.recents.RecentTasksController; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.splitscreen.SplitScreen.StageType; import com.android.wm.shell.splitscreen.SplitScreenController.ExitReason; import com.android.wm.shell.transition.DefaultMixedHandler; import com.android.wm.shell.transition.LegacyTransitions; import com.android.wm.shell.transition.Transitions; import com.android.wm.shell.util.SplitBounds; -import com.android.wm.shell.util.TransitionUtil; import com.android.wm.shell.windowdecor.WindowDecorViewModel; import dalvik.annotation.optimization.NeverCompile; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTransitions.java b/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTransitions.java index 84f21f693eb8..198ec82b5f21 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTransitions.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTransitions.java @@ -37,8 +37,8 @@ import android.window.WindowContainerTransaction; import androidx.annotation.VisibleForTesting; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.transition.Transitions; -import com.android.wm.shell.util.TransitionUtil; import java.util.ArrayList; import java.util.Objects; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/CounterRotatorHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/CounterRotatorHelper.java index 628ce27fe514..b03daaafd70c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/CounterRotatorHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/CounterRotatorHelper.java @@ -27,8 +27,8 @@ import android.window.WindowContainerToken; import androidx.annotation.NonNull; -import com.android.wm.shell.util.CounterRotator; -import com.android.wm.shell.util.TransitionUtil; +import com.android.wm.shell.shared.CounterRotator; +import com.android.wm.shell.shared.TransitionUtil; import java.util.List; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java index 8c2203ef7a49..8746b8c8d55c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java @@ -24,7 +24,7 @@ import static android.view.WindowManager.TRANSIT_CHANGE; import static android.view.WindowManager.TRANSIT_PIP; import static android.window.TransitionInfo.FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY; -import static com.android.wm.shell.util.TransitionUtil.isOpeningType; +import static com.android.wm.shell.shared.TransitionUtil.isOpeningType; import android.annotation.NonNull; import android.annotation.Nullable; @@ -48,11 +48,11 @@ import com.android.wm.shell.keyguard.KeyguardTransitionHandler; import com.android.wm.shell.pip.PipTransitionController; import com.android.wm.shell.protolog.ShellProtoLogGroup; import com.android.wm.shell.recents.RecentsTransitionHandler; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.splitscreen.SplitScreenController; import com.android.wm.shell.splitscreen.StageCoordinator; import com.android.wm.shell.sysui.ShellInit; import com.android.wm.shell.unfold.UnfoldTransitionHandler; -import com.android.wm.shell.util.TransitionUtil; import java.util.ArrayList; import java.util.Map; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java index 193a4fb5b503..c70a8219489e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java @@ -109,8 +109,8 @@ import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.TransactionPool; import com.android.wm.shell.protolog.ShellProtoLogGroup; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.sysui.ShellInit; -import com.android.wm.shell.util.TransitionUtil; import java.util.ArrayList; import java.util.List; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/HomeTransitionObserver.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/HomeTransitionObserver.java index af31f5f27fe9..cb2944c120e0 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/HomeTransitionObserver.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/HomeTransitionObserver.java @@ -32,7 +32,7 @@ import android.window.TransitionInfo; import com.android.wm.shell.common.RemoteCallable; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SingleInstanceRemoteListener; -import com.android.wm.shell.util.TransitionUtil; +import com.android.wm.shell.shared.TransitionUtil; /** * The {@link TransitionObserver} that observes for transitions involving the home diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/RemoteTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/RemoteTransitionHandler.java index 293b66084d28..4c4c5806ea55 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/RemoteTransitionHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/RemoteTransitionHandler.java @@ -39,7 +39,7 @@ import androidx.annotation.BinderThread; import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.protolog.ShellProtoLogGroup; -import com.android.wm.shell.util.TransitionUtil; +import com.android.wm.shell.shared.TransitionUtil; import java.util.ArrayList; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/TransitionAnimationHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/TransitionAnimationHelper.java index b012d359931a..1be85d05c16e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/TransitionAnimationHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/TransitionAnimationHelper.java @@ -56,7 +56,7 @@ import com.android.internal.R; import com.android.internal.policy.TransitionAnimation; import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.protolog.ShellProtoLogGroup; -import com.android.wm.shell.util.TransitionUtil; +import com.android.wm.shell.shared.TransitionUtil; /** The helper class that provides methods for adding styles to transition animations. */ public class TransitionAnimationHelper { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java index 67fc7e2b4ea6..5e79681e060b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java @@ -37,9 +37,9 @@ import static android.window.TransitionInfo.FLAG_NO_ANIMATION; import static android.window.TransitionInfo.FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT; import static com.android.wm.shell.common.ExecutorUtils.executeRemoteCallWithTaskPermission; +import static com.android.wm.shell.shared.TransitionUtil.isClosingType; +import static com.android.wm.shell.shared.TransitionUtil.isOpeningType; import static com.android.wm.shell.sysui.ShellSharedConstants.KEY_EXTRA_SHELL_SHELL_TRANSITIONS; -import static com.android.wm.shell.util.TransitionUtil.isClosingType; -import static com.android.wm.shell.util.TransitionUtil.isOpeningType; import android.annotation.NonNull; import android.annotation.Nullable; @@ -80,13 +80,13 @@ import com.android.wm.shell.common.TransactionPool; import com.android.wm.shell.common.annotations.ExternalThread; import com.android.wm.shell.keyguard.KeyguardTransitionHandler; import com.android.wm.shell.protolog.ShellProtoLogGroup; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.sysui.ShellCommandHandler; import com.android.wm.shell.sysui.ShellController; import com.android.wm.shell.sysui.ShellInit; import com.android.wm.shell.transition.tracing.LegacyTransitionTracer; import com.android.wm.shell.transition.tracing.PerfettoTransitionTracer; import com.android.wm.shell.transition.tracing.TransitionTracer; -import com.android.wm.shell.util.TransitionUtil; import java.io.PrintWriter; import java.util.ArrayList; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/unfold/UnfoldTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/unfold/UnfoldTransitionHandler.java index 98d343b66760..c26604a84a61 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/unfold/UnfoldTransitionHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/unfold/UnfoldTransitionHandler.java @@ -35,6 +35,7 @@ import androidx.annotation.Nullable; 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; import com.android.wm.shell.transition.Transitions.TransitionFinishCallback; @@ -43,7 +44,6 @@ import com.android.wm.shell.unfold.ShellUnfoldProgressProvider.UnfoldListener; 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 com.android.wm.shell.util.TransitionUtil; import java.util.ArrayList; import java.util.List; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/util/CounterRotator.java b/libs/WindowManager/Shell/src/com/android/wm/shell/util/CounterRotator.java deleted file mode 100644 index 7e95814c06c2..000000000000 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/util/CounterRotator.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * 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. - */ - -package com.android.wm.shell.util; - -import android.graphics.Point; -import android.util.RotationUtils; -import android.view.SurfaceControl; - -/** - * Utility class that takes care of rotating unchanging child-surfaces to match the parent rotation - * during a transition animation. This gives the illusion that the child surfaces haven't rotated - * relative to the screen. - */ -public class CounterRotator { - private SurfaceControl mSurface = null; - - /** Gets the surface with the counter-rotation. */ - public SurfaceControl getSurface() { - return mSurface; - } - - /** - * Sets up this rotator. - * - * @param rotateDelta is the forward rotation change (the rotation the display is making). - * @param parentW (and H) Is the size of the rotating parent after the rotation. - */ - public void setup(SurfaceControl.Transaction t, SurfaceControl parent, int rotateDelta, - float parentW, float parentH) { - if (rotateDelta == 0) return; - mSurface = new SurfaceControl.Builder() - .setName("Transition Unrotate") - .setContainerLayer() - .setParent(parent) - .build(); - // Rotate forward to match the new rotation (rotateDelta is the forward rotation the parent - // already took). Child surfaces will be in the old rotation relative to the new parent - // rotation, so we need to forward-rotate the child surfaces to match. - RotationUtils.rotateSurface(t, mSurface, rotateDelta); - final Point tmpPt = new Point(0, 0); - // parentW/H are the size in the END rotation, the rotation utilities expect the starting - // size. So swap them if necessary - if ((rotateDelta % 2) != 0) { - final float w = parentW; - parentW = parentH; - parentH = w; - } - RotationUtils.rotatePoint(tmpPt, rotateDelta, (int) parentW, (int) parentH); - t.setPosition(mSurface, tmpPt.x, tmpPt.y); - t.show(mSurface); - } - - /** - * Adds a surface that needs to be counter-rotate. - */ - public void addChild(SurfaceControl.Transaction t, SurfaceControl child) { - if (mSurface == null) return; - t.reparent(child, mSurface); - } - - /** - * Clean-up. Since finishTransaction should reset all change leashes, we only need to remove the - * counter rotation surface. - */ - public void cleanUp(SurfaceControl.Transaction finishTransaction) { - if (mSurface == null) return; - finishTransaction.remove(mSurface); - } -} diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/util/TransitionUtil.java b/libs/WindowManager/Shell/src/com/android/wm/shell/util/TransitionUtil.java deleted file mode 100644 index 936faa3ee6bf..000000000000 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/util/TransitionUtil.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * 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. - */ - -package com.android.wm.shell.util; - -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_CHANGE; -import static android.view.WindowManager.TRANSIT_CLOSE; -import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY; -import static android.view.WindowManager.TRANSIT_OPEN; -import static android.view.WindowManager.TRANSIT_TO_BACK; -import static android.view.WindowManager.TRANSIT_TO_FRONT; -import static android.window.TransitionInfo.FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY; -import static android.window.TransitionInfo.FLAG_IS_DISPLAY; -import static android.window.TransitionInfo.FLAG_IS_WALLPAPER; -import static android.window.TransitionInfo.FLAG_MOVED_TO_TOP; -import static android.window.TransitionInfo.FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT; - -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.WindowConfiguration; -import android.graphics.Rect; -import android.util.ArrayMap; -import android.util.SparseBooleanArray; -import android.view.RemoteAnimationTarget; -import android.view.SurfaceControl; -import android.view.WindowManager; -import android.window.TransitionInfo; - -import java.util.function.Predicate; - -/** Various utility functions for transitions. */ -public class TransitionUtil { - - /** @return true if the transition was triggered by opening something vs closing something */ - public static boolean isOpeningType(@WindowManager.TransitionType int type) { - return type == TRANSIT_OPEN - || type == TRANSIT_TO_FRONT - || type == TRANSIT_KEYGUARD_GOING_AWAY; - } - - /** @return true if the transition was triggered by closing something vs opening something */ - public static boolean isClosingType(@WindowManager.TransitionType int type) { - return type == TRANSIT_CLOSE || type == TRANSIT_TO_BACK; - } - - /** Returns {@code true} if the transition is opening or closing mode. */ - public static boolean isOpenOrCloseMode(@TransitionInfo.TransitionMode int mode) { - return mode == TRANSIT_OPEN || mode == TRANSIT_CLOSE - || mode == TRANSIT_TO_FRONT || mode == TRANSIT_TO_BACK; - } - - /** Returns {@code true} if the transition has a display change. */ - public static boolean hasDisplayChange(@NonNull TransitionInfo info) { - for (int i = info.getChanges().size() - 1; i >= 0; --i) { - final TransitionInfo.Change change = info.getChanges().get(i); - if (change.getMode() == TRANSIT_CHANGE && change.hasFlags(FLAG_IS_DISPLAY)) { - return true; - } - } - return false; - } - - /** Returns `true` if `change` is a wallpaper. */ - public static boolean isWallpaper(TransitionInfo.Change change) { - return (change.getTaskInfo() == null) - && change.hasFlags(FLAG_IS_WALLPAPER) - && !change.hasFlags(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY); - } - - /** Returns `true` if `change` is not an app window or wallpaper. */ - public static boolean isNonApp(TransitionInfo.Change change) { - return (change.getTaskInfo() == null) - && !change.hasFlags(FLAG_IS_WALLPAPER) - && !change.hasFlags(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY); - } - - /** Returns `true` if `change` is the divider. */ - public static boolean isDividerBar(TransitionInfo.Change change) { - return isNonApp(change) && change.hasFlags(FLAG_IS_DIVIDER_BAR); - } - - /** Returns `true` if `change` is only re-ordering. */ - public static boolean isOrderOnly(TransitionInfo.Change change) { - return change.getMode() == TRANSIT_CHANGE - && (change.getFlags() & FLAG_MOVED_TO_TOP) != 0 - && change.getStartAbsBounds().equals(change.getEndAbsBounds()) - && (change.getLastParent() == null - || change.getLastParent().equals(change.getParent())); - } - - /** - * Filter that selects leaf-tasks only. THIS IS ORDER-DEPENDENT! For it to work properly, you - * MUST call `test` in the same order that the changes appear in the TransitionInfo. - */ - public static class LeafTaskFilter implements Predicate { - private final SparseBooleanArray mChildTaskTargets = new SparseBooleanArray(); - - @Override - public boolean test(TransitionInfo.Change change) { - final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo(); - if (taskInfo == null) return false; - // Children always come before parent since changes are in top-to-bottom z-order. - boolean hasChildren = mChildTaskTargets.get(taskInfo.taskId); - if (taskInfo.hasParentTask()) { - mChildTaskTargets.put(taskInfo.parentTaskId, true); - } - // If it has children, it's not a leaf. - return !hasChildren; - } - } - - - private static int newModeToLegacyMode(int newMode) { - switch (newMode) { - case WindowManager.TRANSIT_OPEN: - case WindowManager.TRANSIT_TO_FRONT: - return MODE_OPENING; - case WindowManager.TRANSIT_CLOSE: - case WindowManager.TRANSIT_TO_BACK: - return MODE_CLOSING; - default: - return MODE_CHANGING; - } - } - - /** - * Very similar to Transitions#setupAnimHierarchy but specialized for leashes. - */ - @SuppressLint("NewApi") - private static void setupLeash(@NonNull SurfaceControl leash, - @NonNull TransitionInfo.Change change, int layer, - @NonNull TransitionInfo info, @NonNull SurfaceControl.Transaction t) { - final boolean isOpening = TransitionUtil.isOpeningType(info.getType()); - // Put animating stuff above this line and put static stuff below it. - int zSplitLine = info.getChanges().size(); - // changes should be ordered top-to-bottom in z - final int mode = change.getMode(); - - final int rootIdx = TransitionUtil.rootIndexFor(change, info); - t.reparent(leash, info.getRoot(rootIdx).getLeash()); - final Rect absBounds = - (mode == TRANSIT_OPEN) ? change.getEndAbsBounds() : change.getStartAbsBounds(); - t.setPosition(leash, absBounds.left - info.getRoot(rootIdx).getOffset().x, - absBounds.top - info.getRoot(rootIdx).getOffset().y); - - if (isDividerBar(change)) { - if (isOpeningType(mode)) { - t.setAlpha(leash, 0.f); - } - // Set the transition leash position to 0 in case the divider leash position being - // taking down. - t.setPosition(leash, 0, 0); - t.setLayer(leash, Integer.MAX_VALUE); - return; - } - - // Put all the OPEN/SHOW on top - if ((change.getFlags() & FLAG_IS_WALLPAPER) != 0) { - // Wallpaper is always at the bottom, opening wallpaper on top of closing one. - if (mode == WindowManager.TRANSIT_OPEN || mode == WindowManager.TRANSIT_TO_FRONT) { - t.setLayer(leash, -zSplitLine + info.getChanges().size() - layer); - } else { - t.setLayer(leash, -zSplitLine - layer); - } - } else if (TransitionUtil.isOpeningType(mode)) { - if (isOpening) { - t.setLayer(leash, zSplitLine + info.getChanges().size() - layer); - if ((change.getFlags() & FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT) == 0) { - // if transferred, it should be left visible. - t.setAlpha(leash, 0.f); - } - } else { - // put on bottom and leave it visible - t.setLayer(leash, zSplitLine - layer); - } - } else if (TransitionUtil.isClosingType(mode)) { - if (isOpening) { - // put on bottom and leave visible - t.setLayer(leash, zSplitLine - layer); - } else { - // put on top - t.setLayer(leash, zSplitLine + info.getChanges().size() - layer); - } - } else { // CHANGE - t.setLayer(leash, zSplitLine + info.getChanges().size() - layer); - } - } - - @SuppressLint("NewApi") - private static SurfaceControl createLeash(TransitionInfo info, TransitionInfo.Change change, - int order, SurfaceControl.Transaction t) { - // TODO: once we can properly sync transactions across process, then get rid of this leash. - if (change.getParent() != null && (change.getFlags() & FLAG_IS_WALLPAPER) != 0) { - // Special case for wallpaper atm. Normally these are left alone; but, a quirk of - // making leashes means we have to handle them specially. - return change.getLeash(); - } - final int rootIdx = TransitionUtil.rootIndexFor(change, info); - SurfaceControl leashSurface = new SurfaceControl.Builder() - .setName(change.getLeash().toString() + "_transition-leash") - .setContainerLayer() - // Initial the surface visible to respect the visibility of the original surface. - .setHidden(false) - .setParent(info.getRoot(rootIdx).getLeash()) - .build(); - // Copied Transitions setup code (which expects bottom-to-top order, so we swap here) - setupLeash(leashSurface, change, info.getChanges().size() - order, info, t); - t.reparent(change.getLeash(), leashSurface); - t.setAlpha(change.getLeash(), 1.0f); - t.show(change.getLeash()); - if (!isDividerBar(change)) { - // For divider, don't modify its inner leash position when creating the outer leash - // for the transition. In case the position being wrong after the transition finished. - t.setPosition(change.getLeash(), 0, 0); - } - t.setLayer(change.getLeash(), 0); - return leashSurface; - } - - /** - * 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 leashMap) { - return newTarget(change, order, false /* forceTranslucent */, info, t, leashMap); - } - - /** - * Creates a new RemoteAnimationTarget from the provided change info - */ - public static RemoteAnimationTarget newTarget(TransitionInfo.Change change, int order, - boolean forceTranslucent, TransitionInfo info, SurfaceControl.Transaction t, - @Nullable ArrayMap leashMap) { - final SurfaceControl leash = createLeash(info, change, order, t); - if (leashMap != null) { - leashMap.put(change.getLeash(), leash); - } - return newTarget(change, order, leash, forceTranslucent); - } - - /** - * Creates a new RemoteAnimationTarget from the provided change and leash - */ - public static RemoteAnimationTarget newTarget(TransitionInfo.Change change, int order, - SurfaceControl leash) { - return newTarget(change, order, leash, false /* forceTranslucent */); - } - - /** - * Creates a new RemoteAnimationTarget from the provided change and leash - */ - public static RemoteAnimationTarget newTarget(TransitionInfo.Change change, int order, - SurfaceControl leash, boolean forceTranslucent) { - if (isDividerBar(change)) { - return getDividerTarget(change, leash); - } - - int taskId; - boolean isNotInRecents; - ActivityManager.RunningTaskInfo taskInfo; - WindowConfiguration windowConfiguration; - - taskInfo = change.getTaskInfo(); - if (taskInfo != null) { - taskId = taskInfo.taskId; - isNotInRecents = !taskInfo.isRunning; - windowConfiguration = taskInfo.configuration.windowConfiguration; - } else { - taskId = INVALID_TASK_ID; - isNotInRecents = true; - windowConfiguration = new WindowConfiguration(); - } - - Rect localBounds = new Rect(change.getEndAbsBounds()); - localBounds.offsetTo(change.getEndRelOffset().x, change.getEndRelOffset().y); - - RemoteAnimationTarget target = new RemoteAnimationTarget( - taskId, - newModeToLegacyMode(change.getMode()), - // TODO: once we can properly sync transactions across process, - // then get rid of this leash. - leash, - forceTranslucent || (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(), - INVALID_WINDOW_TYPE - ); - target.setWillShowImeOnTarget( - (change.getFlags() & TransitionInfo.FLAG_WILL_IME_SHOWN) != 0); - target.setRotationChange(change.getEndRotation() - change.getStartRotation()); - target.backgroundColor = change.getBackgroundColor(); - return target; - } - - private static RemoteAnimationTarget getDividerTarget(TransitionInfo.Change change, - SurfaceControl leash) { - return new RemoteAnimationTarget(-1 /* taskId */, newModeToLegacyMode(change.getMode()), - leash, false /* isTranslucent */, null /* clipRect */, - null /* contentInsets */, Integer.MAX_VALUE /* prefixOrderIndex */, - new android.graphics.Point(0, 0) /* position */, change.getStartAbsBounds(), - change.getStartAbsBounds(), new WindowConfiguration(), true, null /* startLeash */, - null /* startBounds */, null /* taskInfo */, false /* allowEnterPip */, - TYPE_DOCK_DIVIDER); - } - - /** - * Finds the "correct" root idx for a change. The change's end display is prioritized, then - * the start display. If there is no display, it will fallback on the 0th root in the - * transition. There MUST be at-least 1 root in the transition (ie. it's not a no-op). - */ - public static int rootIndexFor(@NonNull TransitionInfo.Change change, - @NonNull TransitionInfo info) { - int rootIdx = info.findRootIndex(change.getEndDisplayId()); - if (rootIdx >= 0) return rootIdx; - rootIdx = info.findRootIndex(change.getStartDisplayId()); - if (rootIdx >= 0) return rootIdx; - return 0; - } - - /** - * Gets the {@link TransitionInfo.Root} for the given {@link TransitionInfo.Change}. - * @see #rootIndexFor(TransitionInfo.Change, TransitionInfo) - */ - @NonNull - public static TransitionInfo.Root getRootFor(@NonNull TransitionInfo.Change change, - @NonNull TransitionInfo info) { - return info.getRoot(rootIndexFor(change, info)); - } -} diff --git a/packages/SystemUI/shared/Android.bp b/packages/SystemUI/shared/Android.bp index 326c7ef52fce..4e04af6d00bd 100644 --- a/packages/SystemUI/shared/Android.bp +++ b/packages/SystemUI/shared/Android.bp @@ -53,6 +53,7 @@ android_library { "SystemUIPluginLib", "SystemUIUnfoldLib", "SystemUISharedLib-Keyguard", + "WindowManager-Shell-shared", "tracinglib", "androidx.dynamicanimation_dynamicanimation", "androidx.concurrent_concurrent-futures", diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationRunnerCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationRunnerCompat.java index 88b9c020e9a5..a78080fdabf2 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationRunnerCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationRunnerCompat.java @@ -38,7 +38,7 @@ import android.window.IRemoteTransition; import android.window.IRemoteTransitionFinishedCallback; import android.window.TransitionInfo; -import com.android.wm.shell.util.CounterRotator; +import com.android.wm.shell.shared.CounterRotator; public abstract class RemoteAnimationRunnerCompat extends IRemoteAnimationRunner.Stub { private static final String TAG = "RemoteAnimRunnerCompat"; diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationTargetCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationTargetCompat.java index f094102ad88f..b5a8c0c23063 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationTargetCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationTargetCompat.java @@ -22,7 +22,7 @@ import android.view.SurfaceControl; import android.window.TransitionInfo; import android.window.TransitionInfo.Change; -import com.android.wm.shell.util.TransitionUtil; +import com.android.wm.shell.shared.TransitionUtil; import java.util.ArrayList; import java.util.function.Predicate; diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java index f10b87ee1cc5..b5f9c69a71b0 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java @@ -85,10 +85,10 @@ import com.android.systemui.keyguard.ui.viewmodel.WindowManagerLockscreenVisibil import com.android.systemui.power.domain.interactor.PowerInteractor; import com.android.systemui.power.shared.model.ScreenPowerState; import com.android.systemui.settings.DisplayTracker; +import com.android.wm.shell.shared.CounterRotator; +import com.android.wm.shell.shared.TransitionUtil; import com.android.wm.shell.transition.ShellTransitions; import com.android.wm.shell.transition.Transitions; -import com.android.wm.shell.util.CounterRotator; -import com.android.wm.shell.util.TransitionUtil; import java.util.ArrayList; import java.util.Map; diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/system/RemoteTransitionTest.java b/packages/SystemUI/tests/src/com/android/systemui/shared/system/RemoteTransitionTest.java index 190ee81cc55a..460892af1154 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shared/system/RemoteTransitionTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shared/system/RemoteTransitionTest.java @@ -49,7 +49,7 @@ import android.window.TransitionInfo; import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; -import com.android.wm.shell.util.TransitionUtil; +import com.android.wm.shell.shared.TransitionUtil; import org.junit.Before; import org.junit.Test; -- cgit v1.2.3-59-g8ed1b