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

Commit 03995ce6 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Transfer launch cookie for consecutive launch

Otherwise if the trampoline activity may finish, the cookie is lost.

Bug: 129067201
Test: ActivityMetricsLaunchObserverTests#testConsecutiveLaunchNewTask
Change-Id: I8dcb8706c1ce9878d57ad6a29d6e245119ba957a
parent f1c8817e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1606,7 +1606,8 @@ public class ActivityOptions {

    /**
     * Sets a launch cookie that can be used to track the activity and task that are launch as a
     * result of this option.
     * result of this option. If the launched activity is a trampoline that starts another activity
     * immediately, the cookie will be transferred to the next activity.
     *
     * @hide
     */
+5 −0
Original line number Diff line number Diff line
@@ -287,6 +287,11 @@ class ActivityMetricsLogger {
            if (mLastLaunchedActivity == r) {
                return;
            }
            if (mLastLaunchedActivity != null) {
                // Transfer the launch cookie because it is a consecutive launch event.
                r.mLaunchCookie = mLastLaunchedActivity.mLaunchCookie;
                mLastLaunchedActivity.mLaunchCookie = null;
            }
            mLastLaunchedActivity = r;
            if (!r.noDisplay && !r.isReportedDrawn()) {
                if (DEBUG_METRICS) Slog.i(TAG, "Add pending draw " + r);
+21 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.app.ActivityOptions;
import android.app.ActivityOptions.SourceInfo;
import android.app.WaitResult;
import android.content.Intent;
import android.os.IBinder;
import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.util.ArrayMap;
@@ -401,6 +402,26 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase {
        transitToDrawnAndVerifyOnLaunchFinished(mTopActivity);
    }

    @Test
    public void testConsecutiveLaunchNewTask() {
        final IBinder launchCookie = mock(IBinder.class);
        mTrampolineActivity.noDisplay = true;
        mTrampolineActivity.mLaunchCookie = launchCookie;
        onActivityLaunched(mTrampolineActivity);
        final ActivityRecord activityOnNewTask = new ActivityBuilder(mAtm)
                .setCreateTask(true)
                .build();
        mActivityMetricsLogger.notifyActivityLaunching(activityOnNewTask.intent,
                mTrampolineActivity /* caller */);
        notifyActivityLaunched(START_SUCCESS, activityOnNewTask);

        transitToDrawnAndVerifyOnLaunchFinished(activityOnNewTask);
        assertWithMessage("Trampoline's cookie must be transferred").that(
                mTrampolineActivity.mLaunchCookie).isNull();
        assertWithMessage("The last launch task has the transferred cookie").that(
                activityOnNewTask.mLaunchCookie).isEqualTo(launchCookie);
    }

    @Test
    public void testConsecutiveLaunchOnDifferentDisplay() {
        onActivityLaunched(mTopActivity);