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

Commit af699641 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Set launch cookie when starting activity from recents" into tm-qpr-dev

parents fccadc85 74e8233d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2593,6 +2593,9 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                        // activity lifecycle transaction to make sure the override pending app
                        // transition will be applied immediately.
                        targetActivity.applyOptionsAnimation();
                        if (activityOptions != null && activityOptions.getLaunchCookie() != null) {
                            targetActivity.mLaunchCookie = activityOptions.getLaunchCookie();
                        }
                    } finally {
                        mActivityMetricsLogger.notifyActivityLaunched(launchingState,
                                START_TASK_TO_FRONT, false /* newActivityCreated */,
+40 −0
Original line number Diff line number Diff line
@@ -40,14 +40,18 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;

import android.app.ActivityOptions;
import android.app.WaitResult;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Binder;
import android.os.ConditionVariable;
import android.os.IBinder;
import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;
import android.view.Display;
@@ -308,4 +312,40 @@ public class ActivityTaskSupervisorTests extends WindowTestsBase {
        waitHandlerIdle(mAtm.mH);
        verify(mRootWindowContainer, timeout(TIMEOUT_MS)).startHomeOnEmptyDisplays("userUnlocked");
    }

    /** Verifies that launch from recents sets the launch cookie on the activity. */
    @Test
    public void testStartActivityFromRecents_withLaunchCookie() {
        final ActivityRecord activity = new ActivityBuilder(mAtm).setCreateTask(true).build();

        IBinder launchCookie = new Binder("test_launch_cookie");
        ActivityOptions options = ActivityOptions.makeBasic();
        options.setLaunchCookie(launchCookie);
        SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options.toBundle());

        doNothing().when(mSupervisor.mService).moveTaskToFrontLocked(eq(null), eq(null), anyInt(),
                anyInt(), any());

        mSupervisor.startActivityFromRecents(-1, -1, activity.getRootTaskId(), safeOptions);

        assertThat(activity.mLaunchCookie).isEqualTo(launchCookie);
        verify(mAtm).moveTaskToFrontLocked(any(), eq(null), anyInt(), anyInt(), eq(safeOptions));
    }

    /** Verifies that launch from recents doesn't set the launch cookie on the activity. */
    @Test
    public void testStartActivityFromRecents_withoutLaunchCookie() {
        final ActivityRecord activity = new ActivityBuilder(mAtm).setCreateTask(true).build();

        SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(
                ActivityOptions.makeBasic().toBundle());

        doNothing().when(mSupervisor.mService).moveTaskToFrontLocked(eq(null), eq(null), anyInt(),
                anyInt(), any());

        mSupervisor.startActivityFromRecents(-1, -1, activity.getRootTaskId(), safeOptions);

        assertThat(activity.mLaunchCookie).isNull();
        verify(mAtm).moveTaskToFrontLocked(any(), eq(null), anyInt(), anyInt(), eq(safeOptions));
    }
}