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

Commit 6196ac06 authored by Winson Chung's avatar Winson Chung
Browse files

Update launch cookie when moving a task to front

- We're using the launch cookies to track app launches, and in the
  case that a task is brought forward the starting activity is not
  used (currently the launch cookie is only set there).  In this
  case we should update the top activity of the task with the new
  launch cookie.

Bug: 129067201
Test: atest ActivityStarterTests
Change-Id: I563e8aa107d6423672b7dfc2313fa0f3dc33a517
parent 1027fb5c
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -972,6 +972,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                if (lastLaunchTime == 0) pw.print("0");
                else TimeUtils.formatDuration(lastLaunchTime, now, pw);
                pw.println();
        if (mLaunchCookie != null) {
            pw.print(prefix);
            pw.print("launchCookie=");
            pw.println(mLaunchCookie);
        }
        pw.print(prefix); pw.print("mHaveState="); pw.print(mHaveState);
                pw.print(" mIcicle="); pw.println(mIcicle);
        pw.print(prefix); pw.print("state="); pw.print(mState);
+5 −0
Original line number Diff line number Diff line
@@ -2639,6 +2639,11 @@ class ActivityStarter {
            intentTask.setWindowingMode(mPreferredWindowingMode);
        }

        // Update the target's launch cookie to those specified in the options if set
        if (mStartActivity.mLaunchCookie != null) {
            intentActivity.mLaunchCookie = mStartActivity.mLaunchCookie;
        }

        // Need to update mTargetRootTask because if task was moved out of it, the original root
        // task may be destroyed.
        mTargetRootTask = intentActivity.getRootTask();
+34 −0
Original line number Diff line number Diff line
@@ -1142,4 +1142,38 @@ public class ActivityStarterTests extends WindowTestsBase {
        verify(targetRecord).makeVisibleIfNeeded(null, true);
        assertTrue(targetRecord.mVisibleRequested);
    }

    @Test
    public void testLaunchCookie_newAndExistingTask() {
        final ActivityStarter starter = prepareStarter(0, false);

        // Put an activity on default display as the top focused activity.
        ActivityRecord r = new ActivityBuilder(mAtm).setCreateTask(true).build();

        // Start an activity with a launch cookie
        final Binder cookie = new Binder();
        final ActivityOptions options = ActivityOptions.makeBasic();
        options.setLaunchCookie(cookie);
        final Intent intent = new Intent();
        intent.setComponent(ActivityBuilder.getDefaultComponent());
        starter.setReason("testLaunchCookie_newTask")
                .setIntent(intent)
                .setActivityOptions(options.toBundle())
                .execute();

        // Verify the cookie is set
        assertTrue(mRootWindowContainer.topRunningActivity().mLaunchCookie == cookie);

        // Relaunch the activity to bring the task forward
        final Binder newCookie = new Binder();
        final ActivityOptions newOptions = ActivityOptions.makeBasic();
        newOptions.setLaunchCookie(newCookie);
        starter.setReason("testLaunchCookie_existingTask")
                .setIntent(intent)
                .setActivityOptions(newOptions.toBundle())
                .execute();

        // Verify the cookie is updated
        assertTrue(mRootWindowContainer.topRunningActivity().mLaunchCookie == newCookie);
    }
}