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

Commit 3df11a88 authored by Gaurav Bhola's avatar Gaurav Bhola
Browse files

Add support for preferred root task that can be set via launch params.

- This helps form factors to override the task launches and place them
  in a task stack container as desired by OEM/form-factor specific
  policy.

Flag: EXEMPT BUGFIX (doesn't affect existing code paths and used on any
      form-factor other than automotive)
Bug: 433539393
Test: atest LaunchParamsControllerTests

DISABLE_TOPIC_PROTECTOR

Change-Id: Iab675a09b7c23283ab49fd9ceffa4b8720527a8b
parent e16e1b3f
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -199,6 +199,10 @@ class LaunchParamsController {
        @Nullable
        TaskDisplayArea mPreferredTaskDisplayArea;

        /** The root task the {@link Task} would prefer to be on. */
        @Nullable
        Task mPreferredRootTask;

        /** The windowing mode to be in. */
        @WindowingMode
        int mWindowingMode;
@@ -213,6 +217,7 @@ class LaunchParamsController {
            mBoundsSet = false;
            mAppBounds.setEmpty();
            mPreferredTaskDisplayArea = null;
            mPreferredRootTask = null;
            mWindowingMode = WINDOWING_MODE_UNDEFINED;
            mNeedsSafeRegionBounds = null;
        }
@@ -223,6 +228,7 @@ class LaunchParamsController {
            mBoundsSet = params.mBoundsSet;
            mAppBounds.set(params.mAppBounds);
            mPreferredTaskDisplayArea = params.mPreferredTaskDisplayArea;
            mPreferredRootTask = params.mPreferredRootTask;
            mWindowingMode = params.mWindowingMode;
            mNeedsSafeRegionBounds = params.mNeedsSafeRegionBounds;
        }
@@ -233,6 +239,7 @@ class LaunchParamsController {
            mBoundsSet = params.mBoundsSet;
            mAppBounds.set(params.mAppBounds);
            mPreferredTaskDisplayArea = params.mPreferredTaskDisplayArea;
            mPreferredRootTask = params.mPreferredRootTask;
            mWindowingMode = params.mWindowingMode;
            // Only update mNeedsSafeRegionBounds if a modifier updates it by setting a non null
            // value. Otherwise, carry over from previous modifiers
@@ -245,6 +252,7 @@ class LaunchParamsController {
        boolean isEmpty() {
            return (mBounds.isEmpty() && !mBoundsSet) && mAppBounds.isEmpty()
                    && mPreferredTaskDisplayArea == null
                    && mPreferredRootTask == null
                    && mWindowingMode == WINDOWING_MODE_UNDEFINED && mNeedsSafeRegionBounds == null;
        }

@@ -264,6 +272,7 @@ class LaunchParamsController {
            LaunchParams that = (LaunchParams) o;

            if (mPreferredTaskDisplayArea != that.mPreferredTaskDisplayArea) return false;
            if (mPreferredRootTask != that.mPreferredRootTask) return false;
            if (mWindowingMode != that.mWindowingMode) return false;
            if (!mAppBounds.equals(that.mAppBounds)) return false;
            if (!Objects.equals(mNeedsSafeRegionBounds, that.mNeedsSafeRegionBounds)) return false;
@@ -278,6 +287,8 @@ class LaunchParamsController {
            result = 31 * result + mAppBounds.hashCode();
            result = 31 * result + (mPreferredTaskDisplayArea != null
                    ? mPreferredTaskDisplayArea.hashCode() : 0);
            result = 31 * result + (mPreferredRootTask != null
                    ? mPreferredRootTask.hashCode() : 0);
            result = 31 * result + mWindowingMode;
            result = 31 * result + (mNeedsSafeRegionBounds != null
                    ? Boolean.hashCode(mNeedsSafeRegionBounds) : 0);
+5 −0
Original line number Diff line number Diff line
@@ -3144,6 +3144,11 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            }
        }

        final Task candidateRoot = launchParams != null ? launchParams.mPreferredRootTask : null;
        if (candidateRoot != null && canLaunchOnDisplay(r, candidateRoot)) {
            return candidateRoot;
        }

        // Next preference goes to the task id set in the activity options.
        if (options != null) {
            final int candidateTaskId = options.getLaunchTaskId();
+20 −0
Original line number Diff line number Diff line
@@ -581,6 +581,26 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
                task.getRequestedOverrideConfiguration().windowConfiguration.getAppBounds());
    }

    /*
     * Tests that the preferred root task is propagated through the controller.
     */
    @Test
    public void testPreferredRootTaskPropagation() {
        final Task preferredRootTask = new TaskBuilder(mAtm.mTaskSupervisor).build();
        final LaunchParams params = new LaunchParams();
        params.mPreferredRootTask = preferredRootTask;
        final InstrumentedPositioner positioner = new InstrumentedPositioner(RESULT_DONE, params);

        mController.registerModifier(positioner);

        final LaunchParams result = new LaunchParams();

        mController.calculate(null /*task*/, null /*layout*/, null /*activity*/, null /*source*/,
                null /*options*/, null /*request*/, PHASE_BOUNDS, result);

        assertEquals(preferredRootTask, result.mPreferredRootTask);
    }

    public static class InstrumentedPositioner implements LaunchParamsModifier {

        private final int mReturnVal;
+24 −0
Original line number Diff line number Diff line
@@ -1289,6 +1289,30 @@ public class RootWindowContainerTests extends WindowTestsBase {
        assertEquals(task, rootTask);
    }

    @Test
    public void testGetOrCreateRootTask_withPreferredRootTask_returnsPreferredRootTask() {
        // Arrange: Create a preferred root task and set it in the launch parameters.
        final Task preferredRootTask = new TaskBuilder(mSupervisor).build();
        final ActivityRecord activity = new ActivityBuilder(mAtm).build();

        final LaunchParamsController.LaunchParams launchParams =
                new LaunchParamsController.LaunchParams();
        launchParams.mPreferredRootTask = preferredRootTask;

        // Act: Call the method under test.
        final Task resultTask = mRootWindowContainer.getOrCreateRootTask(
                activity,
                null /* options */,
                null /* candidateTask */,
                null /* sourceTask */,
                true /* onTop */,
                launchParams,
                0 /* launchFlags */);

        // Assert: Verify that the returned task is the preferred one.
        assertEquals(preferredRootTask, resultTask);
    }

    @Test
    public void testSwitchUser_missingHomeRootTask() {
        final Task fullscreenTask = mRootWindowContainer.getDefaultTaskDisplayArea().createRootTask(