From 3ad8e00f86e777f8c498d61e261554e4b54e9cae Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Mon, 7 Mar 2022 19:00:16 +0800 Subject: [PATCH] Transfer launch cookie when finishing activity For example: launcher starts a task T which contains activity A with launch cookie. And after A was launched or used a while, it launches B and finishes itself. When closing task T, it still expects that launcher can receive the same launch cookie of the task, then launcher can animate such as returning to the bounds of widget. So this change allows B to transfer its launch cookie to A when B is going to finish. Fixes: 220290671 Test: atest ActivityRecordTests#testTransferLaunchCookieWhenFinishing Change-Id: I520dc696de64c4e750be607cc03c843499508269 --- .../java/com/android/server/wm/ActivityRecord.java | 14 ++++++++++++++ .../com/android/server/wm/ActivityRecordTests.java | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index e66f309d2cccf..c5e938f38d2fd 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -3642,6 +3642,20 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return; } finishing = true; + + // Transfer the launch cookie to the next running activity above this in the same task. + if (mLaunchCookie != null && mState != RESUMED && task != null && !task.mInRemoveTask + && !task.isClearingToReuseTask()) { + final ActivityRecord nextCookieTarget = task.getActivity( + // Intend to only associate the same app by checking uid. + r -> r.mLaunchCookie == null && !r.finishing && r.isUid(getUid()), + this, false /* includeBoundary */, false /* traverseTopToBottom */); + if (nextCookieTarget != null) { + nextCookieTarget.mLaunchCookie = mLaunchCookie; + mLaunchCookie = null; + } + } + final TaskFragment taskFragment = getTaskFragment(); if (taskFragment != null) { final Task task = taskFragment.getTask(); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index a89c5a1fbf1f7..40ab8eb70c049 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -2217,6 +2217,19 @@ public class ActivityRecordTests extends WindowTestsBase { assertTrue(activity.pictureInPictureArgs.isLaunchIntoPip()); } + @Test + public void testTransferLaunchCookieWhenFinishing() { + final ActivityRecord activity1 = createActivityWithTask(); + final Binder launchCookie = new Binder(); + activity1.mLaunchCookie = launchCookie; + final ActivityRecord activity2 = createActivityRecord(activity1.getTask()); + activity1.setState(PAUSED, "test"); + activity1.makeFinishingLocked(); + + assertEquals(launchCookie, activity2.mLaunchCookie); + assertNull(activity1.mLaunchCookie); + } + private void verifyProcessInfoUpdate(ActivityRecord activity, State state, boolean shouldUpdate, boolean activityChange) { reset(activity.app);