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

Commit bee1f181 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Transfer launch cookie for consecutive launch" into sc-dev

parents ce87fc2b 03995ce6
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line 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
     * 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
     * @hide
     */
     */
+5 −0
Original line number Original line Diff line number Diff line
@@ -287,6 +287,11 @@ class ActivityMetricsLogger {
            if (mLastLaunchedActivity == r) {
            if (mLastLaunchedActivity == r) {
                return;
                return;
            }
            }
            if (mLastLaunchedActivity != null) {
                // Transfer the launch cookie because it is a consecutive launch event.
                r.mLaunchCookie = mLastLaunchedActivity.mLaunchCookie;
                mLastLaunchedActivity.mLaunchCookie = null;
            }
            mLastLaunchedActivity = r;
            mLastLaunchedActivity = r;
            if (!r.noDisplay && !r.isReportedDrawn()) {
            if (!r.noDisplay && !r.isReportedDrawn()) {
                if (DEBUG_METRICS) Slog.i(TAG, "Add pending draw " + r);
                if (DEBUG_METRICS) Slog.i(TAG, "Add pending draw " + r);
+21 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ import android.app.ActivityOptions;
import android.app.ActivityOptions.SourceInfo;
import android.app.ActivityOptions.SourceInfo;
import android.app.WaitResult;
import android.app.WaitResult;
import android.content.Intent;
import android.content.Intent;
import android.os.IBinder;
import android.os.SystemClock;
import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
import android.util.ArrayMap;
import android.util.ArrayMap;
@@ -401,6 +402,26 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase {
        transitToDrawnAndVerifyOnLaunchFinished(mTopActivity);
        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
    @Test
    public void testConsecutiveLaunchOnDifferentDisplay() {
    public void testConsecutiveLaunchOnDifferentDisplay() {
        onActivityLaunched(mTopActivity);
        onActivityLaunched(mTopActivity);