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

Commit ade199be authored by Garfield Tan's avatar Garfield Tan Committed by Android (Google) Code Review
Browse files

Merge changes from topic "launch_params_modifier_cleanup"

* changes:
  Some cleanup around LaunchParamsModifier.
  Remove warning about cases where root is null
parents 460e9b6b 8e64f2b0
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -1883,7 +1883,7 @@ class ActivityStarter {
        }
        }


        mSupervisor.getLaunchParamsController().calculate(targetTask, r.info.windowLayout, r,
        mSupervisor.getLaunchParamsController().calculate(targetTask, r.info.windowLayout, r,
                sourceRecord, mOptions, PHASE_BOUNDS, mLaunchParams, mRequest);
                sourceRecord, mOptions, mRequest, PHASE_BOUNDS, mLaunchParams);
        mPreferredTaskDisplayArea = mLaunchParams.hasPreferredTaskDisplayArea()
        mPreferredTaskDisplayArea = mLaunchParams.hasPreferredTaskDisplayArea()
                ? mLaunchParams.mPreferredTaskDisplayArea
                ? mLaunchParams.mPreferredTaskDisplayArea
                : mRootWindowContainer.getDefaultTaskDisplayArea();
                : mRootWindowContainer.getDefaultTaskDisplayArea();
@@ -2274,7 +2274,7 @@ class ActivityStarter {
        // Preferred display id is the only state we need for now and it could be updated again
        // Preferred display id is the only state we need for now and it could be updated again
        // after we located a reusable task (which might be resided in another display).
        // after we located a reusable task (which might be resided in another display).
        mSupervisor.getLaunchParamsController().calculate(inTask, r.info.windowLayout, r,
        mSupervisor.getLaunchParamsController().calculate(inTask, r.info.windowLayout, r,
                sourceRecord, options, PHASE_DISPLAY, mLaunchParams, mRequest);
                sourceRecord, options, mRequest, PHASE_DISPLAY, mLaunchParams);
        mPreferredTaskDisplayArea = mLaunchParams.hasPreferredTaskDisplayArea()
        mPreferredTaskDisplayArea = mLaunchParams.hasPreferredTaskDisplayArea()
                ? mLaunchParams.mPreferredTaskDisplayArea
                ? mLaunchParams.mPreferredTaskDisplayArea
                : mRootWindowContainer.getDefaultTaskDisplayArea();
                : mRootWindowContainer.getDefaultTaskDisplayArea();
+12 −11
Original line number Original line Diff line number Diff line
@@ -73,11 +73,12 @@ class LaunchParamsController {
     * @param activity  The {@link ActivityRecord} currently being positioned.
     * @param activity  The {@link ActivityRecord} currently being positioned.
     * @param source    The {@link ActivityRecord} from which activity was started from.
     * @param source    The {@link ActivityRecord} from which activity was started from.
     * @param options   The {@link ActivityOptions} specified for the activity.
     * @param options   The {@link ActivityOptions} specified for the activity.
     * @param result    The resulting params.
     * @param request   The optional request from the activity starter.
     * @param request   The optional request from the activity starter.
     * @param phase     The {@link LaunchParamsModifier.Phase} that the resolution should finish.
     * @param result    The resulting params.
     */
     */
    void calculate(Task task, WindowLayout layout, ActivityRecord activity, ActivityRecord source,
    void calculate(Task task, WindowLayout layout, ActivityRecord activity, ActivityRecord source,
            ActivityOptions options, int phase, LaunchParams result, @Nullable Request request) {
            ActivityOptions options, @Nullable Request request, int phase, LaunchParams result) {
        result.reset();
        result.reset();


        if (task != null || activity != null) {
        if (task != null || activity != null) {
@@ -92,8 +93,8 @@ class LaunchParamsController {
            mTmpResult.reset();
            mTmpResult.reset();
            final LaunchParamsModifier modifier = mModifiers.get(i);
            final LaunchParamsModifier modifier = mModifiers.get(i);


            switch(modifier.onCalculate(task, layout, activity, source, options, phase, mTmpCurrent,
            switch(modifier.onCalculate(task, layout, activity, source, options, request, phase,
                    mTmpResult, request)) {
                    mTmpCurrent, mTmpResult)) {
                case RESULT_SKIP:
                case RESULT_SKIP:
                    // Do not apply any results when we are told to skip
                    // Do not apply any results when we are told to skip
                    continue;
                    continue;
@@ -130,8 +131,8 @@ class LaunchParamsController {


    boolean layoutTask(Task task, WindowLayout layout, ActivityRecord activity,
    boolean layoutTask(Task task, WindowLayout layout, ActivityRecord activity,
            ActivityRecord source, ActivityOptions options) {
            ActivityRecord source, ActivityOptions options) {
        calculate(task, layout, activity, source, options, PHASE_BOUNDS, mTmpParams,
        calculate(task, layout, activity, source, options, null /* request */, PHASE_BOUNDS,
                null /* request */);
                mTmpParams);


        // No changes, return.
        // No changes, return.
        if (mTmpParams.isEmpty()) {
        if (mTmpParams.isEmpty()) {
@@ -308,17 +309,17 @@ class LaunchParamsController {
         *                      launched should have this be non-null.
         *                      launched should have this be non-null.
         * @param source        the Activity that launched a new task. Could be {@code null}.
         * @param source        the Activity that launched a new task. Could be {@code null}.
         * @param options       {@link ActivityOptions} used to start the activity with.
         * @param options       {@link ActivityOptions} used to start the activity with.
         * @param request       Optional data to give more context on the launch
         * @param phase         the calculation phase, see {@link Phase}
         * @param phase         the calculation phase, see {@link Phase}
         * @param currentParams launching params after the process of last {@link
         * @param currentParams launching params after the process of last {@link
         *                      LaunchParamsModifier}.
         *                      LaunchParamsModifier}.
         * @param outParams     the result params to be set.
         * @param outParams     the result params to be set.
         * @param request       Optional data to give more context on the launch
         * @return see {@link LaunchParamsModifier.Result}
         * @return see {@link LaunchParamsModifier.Result}
         */
         */
        @Result
        @Result
        int onCalculate(@Nullable Task task, WindowLayout layout, ActivityRecord activity,
        int onCalculate(@Nullable Task task, @Nullable WindowLayout layout,
                ActivityRecord source, ActivityOptions options, @Phase int phase,
                @Nullable ActivityRecord activity, @Nullable ActivityRecord source,
                LaunchParams currentParams, LaunchParams outParams,
                @Nullable ActivityOptions options, @Nullable Request request,
                @Nullable Request request);
                @Phase int phase, LaunchParams currentParams, LaunchParams outParams);
    }
    }
}
}
+10 −22
Original line number Original line Diff line number Diff line
@@ -95,30 +95,22 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
        mSupervisor = supervisor;
        mSupervisor = supervisor;
    }
    }


    @VisibleForTesting
    int onCalculate(Task task, ActivityInfo.WindowLayout layout, ActivityRecord activity,
            ActivityRecord source, ActivityOptions options, LaunchParams currentParams,
            LaunchParams outParams) {
        return onCalculate(task, layout, activity, source, options, PHASE_BOUNDS, currentParams,
                outParams, null);
    }

    @Override
    @Override
    public int onCalculate(@Nullable Task task, @NonNull ActivityInfo.WindowLayout layout,
    public int onCalculate(@Nullable Task task, @Nullable ActivityInfo.WindowLayout layout,
            @NonNull ActivityRecord activity, @Nullable ActivityRecord source,
            @Nullable ActivityRecord activity, @Nullable ActivityRecord source,
            ActivityOptions options, int phase, LaunchParams currentParams, LaunchParams outParams,
            @Nullable ActivityOptions options, @Nullable Request request, int phase,
            @Nullable Request request) {
            LaunchParams currentParams, LaunchParams outParams) {
        initLogBuilder(task, activity);
        initLogBuilder(task, activity);
        final int result = calculate(task, layout, activity, source, options, phase, currentParams,
        final int result = calculate(task, layout, activity, source, options, request, phase,
                outParams, request);
                currentParams, outParams);
        outputLog();
        outputLog();
        return result;
        return result;
    }
    }


    private int calculate(@Nullable Task task, @NonNull ActivityInfo.WindowLayout layout,
    private int calculate(@Nullable Task task, @Nullable ActivityInfo.WindowLayout layout,
            @NonNull ActivityRecord activity, @Nullable ActivityRecord source,
            @Nullable ActivityRecord activity, @Nullable ActivityRecord source,
            ActivityOptions options, int phase, LaunchParams currentParams, LaunchParams outParams,
            @Nullable ActivityOptions options, @Nullable Request request, int phase,
            @Nullable Request request) {
            LaunchParams currentParams, LaunchParams outParams) {
        final ActivityRecord root;
        final ActivityRecord root;
        if (task != null) {
        if (task != null) {
            root = task.getRootActivity() == null ? activity : task.getRootActivity();
            root = task.getRootActivity() == null ? activity : task.getRootActivity();
@@ -126,10 +118,6 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
            root = activity;
            root = activity;
        }
        }


        // TODO: Investigate whether we can safely ignore all cases where we don't have root
        // activity available. Note we can't know if the bounds are valid if we're not sure of the
        // requested orientation of the root activity. Therefore if we found such a case we may need
        // to pass the activity into this modifier in that case.
        if (root == null) {
        if (root == null) {
            // There is a case that can lead us here. The caller is moving the top activity that is
            // There is a case that can lead us here. The caller is moving the top activity that is
            // in a task that has multiple activities to PIP mode. For that the caller is creating a
            // in a task that has multiple activities to PIP mode. For that the caller is creating a
+1 −1
Original line number Original line Diff line number Diff line
@@ -422,7 +422,7 @@ public class ActivityStarterTests extends WindowTestsBase {
        // verify that values are passed to the modifier. Values are passed thrice -- two for
        // verify that values are passed to the modifier. Values are passed thrice -- two for
        // setting initial state, another when task is created.
        // setting initial state, another when task is created.
        verify(modifier, times(3)).onCalculate(any(), eq(windowLayout), any(), any(), eq(options),
        verify(modifier, times(3)).onCalculate(any(), eq(windowLayout), any(), any(), eq(options),
                anyInt(), any(), any(), any());
                any(), anyInt(), any(), any());
    }
    }


    /**
    /**
+32 −33
Original line number Original line Diff line number Diff line
@@ -95,10 +95,10 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
        final ActivityOptions options = mock(ActivityOptions.class);
        final ActivityOptions options = mock(ActivityOptions.class);
        final Request request = new Request();
        final Request request = new Request();


        mController.calculate(record.getTask(), layout, record, source, options, PHASE_BOUNDS,
        mController.calculate(record.getTask(), layout, record, source, options, request,
                new LaunchParams(), request);
                PHASE_BOUNDS, new LaunchParams());
        verify(positioner, times(1)).onCalculate(eq(record.getTask()), eq(layout), eq(record),
        verify(positioner, times(1)).onCalculate(eq(record.getTask()), eq(layout), eq(record),
                eq(source), eq(options), anyInt(), any(), any(), eq(request));
                eq(source), eq(options), eq(request), anyInt(), any(), any());
    }
    }


    /**
    /**
@@ -121,9 +121,9 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
        mPersister.putLaunchParams(userId, name, expected);
        mPersister.putLaunchParams(userId, name, expected);


        mController.calculate(activity.getTask(), null /*layout*/, activity, null /*source*/,
        mController.calculate(activity.getTask(), null /*layout*/, activity, null /*source*/,
                null /*options*/, PHASE_BOUNDS, new LaunchParams(), null /* request */);
                null /*options*/, null /*request*/, PHASE_BOUNDS, new LaunchParams());
        verify(positioner, times(1)).onCalculate(any(), any(), any(), any(), any(), anyInt(),
        verify(positioner, times(1)).onCalculate(any(), any(), any(), any(), any(), any(),
                eq(expected), any(), any());
                anyInt(), eq(expected), any());
    }
    }


    /**
    /**
@@ -141,10 +141,10 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
        mController.registerModifier(earlyExitPositioner);
        mController.registerModifier(earlyExitPositioner);


        mController.calculate(null /*task*/, null /*layout*/, null /*activity*/,
        mController.calculate(null /*task*/, null /*layout*/, null /*activity*/,
                null /*source*/, null /*options*/, PHASE_BOUNDS, new LaunchParams(),
                null /*source*/, null /*options*/, null /*request*/,
                null /* request */);
                PHASE_BOUNDS, new LaunchParams());
        verify(ignoredPositioner, never()).onCalculate(any(), any(), any(), any(), any(), anyInt(),
        verify(ignoredPositioner, never()).onCalculate(any(), any(), any(), any(), any(), any(),
                any(), any(), any());
                anyInt(), any(), any());
    }
    }


    /**
    /**
@@ -160,22 +160,22 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
        mController.registerModifier(firstPositioner);
        mController.registerModifier(firstPositioner);


        mController.calculate(null /*task*/, null /*layout*/, null /*activity*/,
        mController.calculate(null /*task*/, null /*layout*/, null /*activity*/,
                null /*source*/, null /*options*/, PHASE_BOUNDS, new LaunchParams(),
                null /*source*/, null /*options*/, null /*request*/, PHASE_BOUNDS,
                null /* request */);
                new LaunchParams());
        verify(firstPositioner, times(1)).onCalculate(any(), any(), any(), any(), any(), anyInt(),
        verify(firstPositioner, times(1)).onCalculate(any(), any(), any(), any(), any(), any(),
                any(), any(), any());
                anyInt(), any(), any());


        final LaunchParamsModifier secondPositioner = spy(earlyExitPositioner);
        final LaunchParamsModifier secondPositioner = spy(earlyExitPositioner);


        mController.registerModifier(secondPositioner);
        mController.registerModifier(secondPositioner);


        mController.calculate(null /*task*/, null /*layout*/, null /*activity*/,
        mController.calculate(null /*task*/, null /*layout*/, null /*activity*/,
                null /*source*/, null /*options*/, PHASE_BOUNDS, new LaunchParams(),
                null /*source*/, null /*options*/, null /*request*/, PHASE_BOUNDS,
                null /* request */);
                new LaunchParams());
        verify(firstPositioner, times(1)).onCalculate(any(), any(), any(), any(), any(), anyInt(),
        verify(firstPositioner, times(1)).onCalculate(any(), any(), any(), any(), any(), any(),
                any(), any(), any());
                anyInt(), any(), any());
        verify(secondPositioner, times(1)).onCalculate(any(), any(), any(), any(), any(), anyInt(),
        verify(secondPositioner, times(1)).onCalculate(any(), any(), any(), any(), any(), any(),
                any(), any(), any());
                anyInt(), any(), any());
    }
    }


    /**
    /**
@@ -197,10 +197,10 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
        mController.registerModifier(positioner2);
        mController.registerModifier(positioner2);


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


        verify(positioner1, times(1)).onCalculate(any(), any(), any(), any(), any(), anyInt(),
        verify(positioner1, times(1)).onCalculate(any(), any(), any(), any(), any(), any(),
                eq(positioner2.getLaunchParams()), any(), any());
                anyInt(), eq(positioner2.getLaunchParams()), any());
    }
    }


    /**
    /**
@@ -223,7 +223,7 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
        final LaunchParams result = new LaunchParams();
        final LaunchParams result = new LaunchParams();


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


        assertEquals(result, positioner2.getLaunchParams());
        assertEquals(result, positioner2.getLaunchParams());
    }
    }
@@ -242,17 +242,17 @@ public class LaunchParamsControllerTests extends WindowTestsBase {


        // VR activities should always land on default display.
        // VR activities should always land on default display.
        mController.calculate(null /*task*/, null /*layout*/, vrActivity /*activity*/,
        mController.calculate(null /*task*/, null /*layout*/, vrActivity /*activity*/,
                null /*source*/, null /*options*/, PHASE_BOUNDS, result, null /* request */);
                null /*source*/, null /*options*/, null/*request*/, PHASE_BOUNDS, result);
        assertEquals(mRootWindowContainer.getDefaultTaskDisplayArea(),
        assertEquals(mRootWindowContainer.getDefaultTaskDisplayArea(),
                result.mPreferredTaskDisplayArea);
                result.mPreferredTaskDisplayArea);


        // Otherwise, always lands on VR 2D display.
        // Otherwise, always lands on VR 2D display.
        final ActivityRecord vr2dActivity = new ActivityBuilder(mAtm).build();
        final ActivityRecord vr2dActivity = new ActivityBuilder(mAtm).build();
        mController.calculate(null /*task*/, null /*layout*/, vr2dActivity /*activity*/,
        mController.calculate(null /*task*/, null /*layout*/, vr2dActivity /*activity*/,
                null /*source*/, null /*options*/, PHASE_BOUNDS, result, null /* request */);
                null /*source*/, null /*options*/, null /*request*/, PHASE_BOUNDS, result);
        assertEquals(vrDisplay.getDefaultTaskDisplayArea(), result.mPreferredTaskDisplayArea);
        assertEquals(vrDisplay.getDefaultTaskDisplayArea(), result.mPreferredTaskDisplayArea);
        mController.calculate(null /*task*/, null /*layout*/, null /*activity*/, null /*source*/,
        mController.calculate(null /*task*/, null /*layout*/, null /*activity*/, null /*source*/,
                null /*options*/, PHASE_BOUNDS, result, null /* request */);
                null /*options*/, null /*request*/, PHASE_BOUNDS, result);
        assertEquals(vrDisplay.getDefaultTaskDisplayArea(), result.mPreferredTaskDisplayArea);
        assertEquals(vrDisplay.getDefaultTaskDisplayArea(), result.mPreferredTaskDisplayArea);


        mAtm.mVr2dDisplayId = INVALID_DISPLAY;
        mAtm.mVr2dDisplayId = INVALID_DISPLAY;
@@ -273,10 +273,10 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
        final WindowLayout layout = new WindowLayout(0, 0, 0, 0, 0, 0, 0);
        final WindowLayout layout = new WindowLayout(0, 0, 0, 0, 0, 0, 0);
        final ActivityOptions options = mock(ActivityOptions.class);
        final ActivityOptions options = mock(ActivityOptions.class);


        mController.calculate(record.getTask(), layout, record, source, options, PHASE_BOUNDS,
        mController.calculate(record.getTask(), layout, record, source, options, null/*request*/,
                new LaunchParams(), null /* request */);
                PHASE_BOUNDS, new LaunchParams());
        verify(positioner, times(1)).onCalculate(eq(record.getTask()), eq(layout), eq(record),
        verify(positioner, times(1)).onCalculate(eq(record.getTask()), eq(layout), eq(record),
                eq(source), eq(options), eq(PHASE_BOUNDS), any(), any(), any());
                eq(source), eq(options), any(), eq(PHASE_BOUNDS), any(), any());
    }
    }


    /**
    /**
@@ -408,9 +408,8 @@ public class LaunchParamsControllerTests extends WindowTestsBase {


        @Override
        @Override
        public int onCalculate(Task task, WindowLayout layout, ActivityRecord activity,
        public int onCalculate(Task task, WindowLayout layout, ActivityRecord activity,
                ActivityRecord source, ActivityOptions options, int phase,
                ActivityRecord source, ActivityOptions options, Request request, int phase,
                LaunchParams currentParams, LaunchParams outParams,
                LaunchParams currentParams, LaunchParams outParams) {
                Request request) {
            outParams.set(mParams);
            outParams.set(mParams);
            return mReturnVal;
            return mReturnVal;
        }
        }
Loading