Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3ad8e00f authored by Riddle Hsu's avatar Riddle Hsu
Browse files

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
parent 1be9ef4f
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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();
+13 −0
Original line number Diff line number Diff line
@@ -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);