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

Commit 7c093e97 authored by Riddle Hsu's avatar Riddle Hsu Committed by Automerger Merge Worker
Browse files

Merge "Transfer launch cookie for consecutive launch" into sc-dev am: bee1f181

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13927658

Change-Id: Ia190ecea1058574329aede2f19ff409c93e1deeb
parents e283ebd1 bee1f181
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);