From 5b5c6e6f25546c2c10ae8518451ee04e476983fb Mon Sep 17 00:00:00 2001 From: Jerry Chang Date: Mon, 24 Oct 2022 07:00:15 +0000 Subject: [PATCH] Apply new remote animation when reusing existing activities When reusing existing activity to a start activity flow. The new remote animation wrapped in the start options might be ignored. Update to make sure reusing existing activity will apply new remote animation. Also makes sure to clear the next app transition after executed event it throws. Bug: 241191055 Test: atest ActivityStarterTests Test: manual verified the new remote animation will be applied when reusing existing activity. Change-Id: I0e3fc0ac0c349b0988222cc536e2bd88543871c8 --- .../com/android/server/wm/ActivityRecord.java | 2 +- .../android/server/wm/ActivityStarter.java | 6 ++++- .../server/wm/AppTransitionController.java | 2 +- .../server/wm/ActivityStarterTests.java | 27 +++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 2eb2cf643c420..7a9f2ceee3927 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -496,7 +496,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A /** The most recently given options. */ private ActivityOptions mPendingOptions; /** Non-null if {@link #mPendingOptions} specifies the remote animation. */ - private RemoteAnimationAdapter mPendingRemoteAnimation; + RemoteAnimationAdapter mPendingRemoteAnimation; private RemoteTransition mPendingRemoteTransition; ActivityOptions returningOptions; // options that are coming back via convertToTranslucent AppTimeTracker appTimeTracker; // set if we are tracking the time in this app/task/activity diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index 027d485d15a0b..ed50c1e979add 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -2947,10 +2947,14 @@ class ActivityStarter { } } - // Update the target's launch cookie to those specified in the options if set + // Update the target's launch cookie and pending remote animation to those specified in the + // options if set. if (mStartActivity.mLaunchCookie != null) { intentActivity.mLaunchCookie = mStartActivity.mLaunchCookie; } + if (mStartActivity.mPendingRemoteAnimation != null) { + intentActivity.mPendingRemoteAnimation = mStartActivity.mPendingRemoteAnimation; + } // Need to update mTargetRootTask because if task was moved out of it, the original root // task may be destroyed. diff --git a/services/core/java/com/android/server/wm/AppTransitionController.java b/services/core/java/com/android/server/wm/AppTransitionController.java index 9c95e31cc5f55..722d0e9a242c5 100644 --- a/services/core/java/com/android/server/wm/AppTransitionController.java +++ b/services/core/java/com/android/server/wm/AppTransitionController.java @@ -300,8 +300,8 @@ public class AppTransitionController { layoutRedo = appTransition.goodToGo(transit, topOpeningApp); handleNonAppWindowsInTransition(transit, flags); appTransition.postAnimationCallback(); - appTransition.clear(); } finally { + appTransition.clear(); mService.mSurfaceAnimationRunner.continueStartingAnimations(); } diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java index 00be7ed5bc6c2..496f6817bb08d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java @@ -98,6 +98,7 @@ import android.service.voice.IVoiceInteractionSession; import android.util.Pair; import android.util.Size; import android.view.Gravity; +import android.view.RemoteAnimationAdapter; import android.window.TaskFragmentOrganizerToken; import androidx.test.filters.SmallTest; @@ -1314,6 +1315,32 @@ public class ActivityStarterTests extends WindowTestsBase { assertTrue(mRootWindowContainer.topRunningActivity().mLaunchCookie == newCookie); } + @Test + public void testRemoteAnimation_appliesToExistingTask() { + final ActivityStarter starter = prepareStarter(0, false); + + // Put an activity on default display as the top focused activity. + ActivityRecord r = new ActivityBuilder(mAtm).setCreateTask(true).build(); + final Intent intent = new Intent(); + intent.setComponent(ActivityBuilder.getDefaultComponent()); + starter.setReason("testRemoteAnimation_newTask") + .setIntent(intent) + .execute(); + + assertNull(mRootWindowContainer.topRunningActivity().mPendingRemoteAnimation); + + // Relaunch the activity with remote animation indicated in options. + final RemoteAnimationAdapter adaptor = mock(RemoteAnimationAdapter.class); + final ActivityOptions options = ActivityOptions.makeRemoteAnimation(adaptor); + starter.setReason("testRemoteAnimation_existingTask") + .setIntent(intent) + .setActivityOptions(options.toBundle()) + .execute(); + + // Verify the remote animation is updated. + assertEquals(adaptor, mRootWindowContainer.topRunningActivity().mPendingRemoteAnimation); + } + @Test public void testStartLaunchIntoPipActivity() { final ActivityStarter starter = prepareStarter(0, false);