From 3c2f615fb79094457abd5615800e1e3e95018c98 Mon Sep 17 00:00:00 2001 From: Luca Zuccarini Date: Mon, 18 Nov 2024 15:06:46 +0000 Subject: Animation takeovers in Predictive Back. Bug: 323863002 Flag: com.android.systemui.shared.return_animation_framework_library Flag: com.android.systemui.shared.return_animation_framework_long_lived Test: atest BackAnimationControllerTest Change-Id: Ide64132bc2856c88893e50d148fa4850b5575114 --- .../window/IBackAnimationHandoffHandler.aidl | 40 +++++++++ .../android/window/IOnBackInvokedCallback.aidl | 6 ++ .../android/window/ImeOnBackInvokedDispatcher.java | 5 ++ .../window/WindowOnBackInvokedDispatcher.java | 5 ++ .../wm/shell/back/BackAnimationController.java | 99 ++++++++++++++++++++-- .../wm/shell/back/BackAnimationControllerTest.java | 53 ++++++++++++ .../server/wm/BackNavigationControllerTests.java | 5 ++ 7 files changed, 208 insertions(+), 5 deletions(-) create mode 100644 core/java/android/window/IBackAnimationHandoffHandler.aidl diff --git a/core/java/android/window/IBackAnimationHandoffHandler.aidl b/core/java/android/window/IBackAnimationHandoffHandler.aidl new file mode 100644 index 000000000000..577948dd0abc --- /dev/null +++ b/core/java/android/window/IBackAnimationHandoffHandler.aidl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2024 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 android.window; + +import android.os.Bundle; +import android.view.RemoteAnimationTarget; +import android.window.BackMotionEvent; +import android.window.WindowAnimationState; + + +/** + * Interface that allows an {@link OnBackInvokedCallback} object to hand off an animation to another + * handler. + * + * @hide + */ +oneway interface IBackAnimationHandoffHandler { + /** + * Triggers a handoff of the animation of the given targets and their associated states. + * Important: since this is a one-way method, the caller must first make sure that the animation + * can indeed be taken over. + */ + oneway void handOffAnimation(in RemoteAnimationTarget[] targets, + in WindowAnimationState[] states); +} diff --git a/core/java/android/window/IOnBackInvokedCallback.aidl b/core/java/android/window/IOnBackInvokedCallback.aidl index e07d4a9fc61b..81ad4b7bd19e 100644 --- a/core/java/android/window/IOnBackInvokedCallback.aidl +++ b/core/java/android/window/IOnBackInvokedCallback.aidl @@ -18,6 +18,7 @@ package android.window; import android.window.BackMotionEvent; +import android.window.IBackAnimationHandoffHandler; /** * Interface that wraps a {@link OnBackInvokedCallback} object, to be stored in window manager @@ -61,4 +62,9 @@ oneway interface IOnBackInvokedCallback { * Sets whether the back gesture is past the trigger threshold. */ void setTriggerBack(in boolean triggerBack); + + /** + * Sets a {@link IBackAnimationHandoffHandler} that can be used to hand off the back animation. + */ + void setHandoffHandler(in IBackAnimationHandoffHandler handoffHandler); } diff --git a/core/java/android/window/ImeOnBackInvokedDispatcher.java b/core/java/android/window/ImeOnBackInvokedDispatcher.java index c67b9cac250b..d478108d928a 100644 --- a/core/java/android/window/ImeOnBackInvokedDispatcher.java +++ b/core/java/android/window/ImeOnBackInvokedDispatcher.java @@ -392,6 +392,11 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc // no-op } + @Override + public void setHandoffHandler(IBackAnimationHandoffHandler handoffHandler) { + // no-op + } + private void maybeRunOnAnimationCallback(Consumer block) { if (mCallback instanceof OnBackAnimationCallback) { mHandler.post(() -> block.accept((OnBackAnimationCallback) mCallback)); diff --git a/core/java/android/window/WindowOnBackInvokedDispatcher.java b/core/java/android/window/WindowOnBackInvokedDispatcher.java index 0ea4bb41d3a4..20e3f6b93bd0 100644 --- a/core/java/android/window/WindowOnBackInvokedDispatcher.java +++ b/core/java/android/window/WindowOnBackInvokedDispatcher.java @@ -545,6 +545,11 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { }); } + @Override + public void setHandoffHandler(IBackAnimationHandoffHandler handoffHandler) { + // no-op + } + @Override public void onBackProgressed(BackMotionEvent backEvent) { // This is only called in some special cases such as when activity embedding is active diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java index ce7a97703f44..e9cfd9bc2209 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java @@ -37,6 +37,7 @@ import static com.android.wm.shell.shared.ShellSharedConstants.KEY_EXTRA_SHELL_B import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SuppressLint; +import android.app.ActivityManager; import android.app.ActivityTaskManager; import android.app.IActivityTaskManager; import android.app.TaskInfo; @@ -73,10 +74,12 @@ import android.window.BackMotionEvent; import android.window.BackNavigationInfo; import android.window.BackTouchTracker; import android.window.IBackAnimationFinishedCallback; +import android.window.IBackAnimationHandoffHandler; import android.window.IBackAnimationRunner; import android.window.IOnBackInvokedCallback; import android.window.TransitionInfo; import android.window.TransitionRequestInfo; +import android.window.WindowAnimationState; import android.window.WindowContainerToken; import android.window.WindowContainerTransaction; @@ -84,6 +87,8 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.protolog.ProtoLog; import com.android.internal.util.LatencyTracker; import com.android.internal.view.AppearanceRegion; +import com.android.systemui.animation.TransitionAnimator; +import com.android.window.flags.Flags; import com.android.wm.shell.R; import com.android.wm.shell.common.ExternalInterfaceBinder; import com.android.wm.shell.common.RemoteCallable; @@ -227,6 +232,15 @@ public class BackAnimationController implements RemoteCallable