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

Commit 2fc48886 authored by Sean Stout's avatar Sean Stout Committed by Android (Google) Code Review
Browse files

Merge "Revert^2 "Use same display for activities in same process.""

parents 9e393c0f c32262be
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -7584,6 +7584,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET;
    }

    String getProcessName() {
        return info.applicationInfo.processName;
    }

    int getUid() {
        return info.applicationInfo.uid;
    }
@@ -7596,6 +7600,14 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return app != null ? app.getPid() : 0;
    }

    int getLaunchedFromPid() {
        return launchedFromPid;
    }

    int getLaunchedFromUid() {
        return launchedFromUid;
    }

    /**
     * Determines whether this ActivityRecord can turn the screen on. It checks whether the flag
     * {@link ActivityRecord#getTurnScreenOnFlag} is set and checks whether the ActivityRecord
+5 −5
Original line number Diff line number Diff line
@@ -57,9 +57,6 @@ import static android.view.WindowManager.TRANSIT_OPEN;

import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_CONFIGURATION;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_TASKS;
import static com.android.server.wm.ActivityTaskSupervisor.DEFER_RESUME;
import static com.android.server.wm.ActivityTaskSupervisor.ON_TOP;
import static com.android.server.wm.ActivityTaskSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ACTIVITY_STARTS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_PERMISSIONS_REVIEW;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RESULTS;
@@ -71,6 +68,9 @@ import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_USER_
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.ActivityTaskManagerService.ANIMATE;
import static com.android.server.wm.ActivityTaskSupervisor.DEFER_RESUME;
import static com.android.server.wm.ActivityTaskSupervisor.ON_TOP;
import static com.android.server.wm.ActivityTaskSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_BOUNDS;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_DISPLAY;
import static com.android.server.wm.Task.ActivityState.RESUMED;
@@ -1870,7 +1870,7 @@ class ActivityStarter {
        }

        mSupervisor.getLaunchParamsController().calculate(targetTask, r.info.windowLayout, r,
                sourceRecord, mOptions, PHASE_BOUNDS, mLaunchParams);
                sourceRecord, mOptions, PHASE_BOUNDS, mLaunchParams, mRequest);
        mPreferredTaskDisplayArea = mLaunchParams.hasPreferredTaskDisplayArea()
                ? mLaunchParams.mPreferredTaskDisplayArea
                : mRootWindowContainer.getDefaultTaskDisplayArea();
@@ -2254,7 +2254,7 @@ class ActivityStarter {
        // 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).
        mSupervisor.getLaunchParamsController().calculate(inTask, r.info.windowLayout, r,
                sourceRecord, options, PHASE_DISPLAY, mLaunchParams);
                sourceRecord, options, PHASE_DISPLAY, mLaunchParams, mRequest);
        mPreferredTaskDisplayArea = mLaunchParams.hasPreferredTaskDisplayArea()
                ? mLaunchParams.mPreferredTaskDisplayArea
                : mRootWindowContainer.getDefaultTaskDisplayArea();
+12 −7
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.wm;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.view.Display.INVALID_DISPLAY;

import static com.android.server.wm.ActivityStarter.Request;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_BOUNDS;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.RESULT_CONTINUE;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.RESULT_DONE;
@@ -73,9 +74,10 @@ class LaunchParamsController {
     * @param source    The {@link ActivityRecord} from which activity was started from.
     * @param options   The {@link ActivityOptions} specified for the activity.
     * @param result    The resulting params.
     * @param request   The optional request from the activity starter.
     */
    void calculate(Task task, WindowLayout layout, ActivityRecord activity,
                   ActivityRecord source, ActivityOptions options, int phase, LaunchParams result) {
    void calculate(Task task, WindowLayout layout, ActivityRecord activity, ActivityRecord source,
            ActivityOptions options, int phase, LaunchParams result, @Nullable Request request) {
        result.reset();

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

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

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

        // No changes, return.
        if (mTmpParams.isEmpty()) {
@@ -305,15 +308,17 @@ class LaunchParamsController {
         *                      launched should have this be non-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 phase         the calculation phase, see {@link LaunchParamsModifier.Phase}
         * @param phase         the calculation phase, see {@link Phase}
         * @param currentParams launching params after the process of last {@link
         *                      LaunchParamsModifier}.
         * @param outParams     the result params to be set.
         * @param request       Optional data to give more context on the launch
         * @return see {@link LaunchParamsModifier.Result}
         */
        @Result
        int onCalculate(Task task, WindowLayout layout, ActivityRecord activity,
        int onCalculate(@Nullable Task task, WindowLayout layout, ActivityRecord activity,
                ActivityRecord source, ActivityOptions options, @Phase int phase,
                LaunchParams currentParams, LaunchParams outParams);
                LaunchParams currentParams, LaunchParams outParams,
                @Nullable Request request);
    }
}
+62 −12
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import static android.util.DisplayMetrics.DENSITY_DEFAULT;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;

import static com.android.server.wm.ActivityStarter.Request;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;

@@ -99,23 +100,25 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
            ActivityRecord source, ActivityOptions options, LaunchParams currentParams,
            LaunchParams outParams) {
        return onCalculate(task, layout, activity, source, options, PHASE_BOUNDS, currentParams,
                outParams);
                outParams, null);
    }

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

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

        // STEP 1: Determine the display area to launch the activity/task.
        final TaskDisplayArea taskDisplayArea = getPreferredLaunchTaskDisplayArea(task,
                options, source, currentParams);
                options, source, currentParams, activity, request);
        outParams.mPreferredTaskDisplayArea = taskDisplayArea;
        // TODO(b/152116619): Update the usages of display to use taskDisplayArea below.
        final DisplayContent display = taskDisplayArea.mDisplayContent;
@@ -298,7 +301,8 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
    }

    private TaskDisplayArea getPreferredLaunchTaskDisplayArea(@Nullable Task task,
            @Nullable ActivityOptions options, ActivityRecord source, LaunchParams currentParams) {
            @Nullable ActivityOptions options, ActivityRecord source, LaunchParams currentParams,
            @NonNull ActivityRecord activityRecord, @Nullable Request request) {
        TaskDisplayArea taskDisplayArea = null;

        final WindowContainerToken optionLaunchTaskDisplayAreaToken = options != null
@@ -369,7 +373,7 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
            taskDisplayArea = currentParams.mPreferredTaskDisplayArea;
        }

        // Fallback to default display if the device didn't declare support for multi-display
        // Re-route to default display if the device didn't declare support for multi-display
        if (taskDisplayArea != null && !mSupervisor.mService.mSupportsMultiDisplay
                && taskDisplayArea.getDisplayId() != DEFAULT_DISPLAY) {
            taskDisplayArea = mSupervisor.mRootWindowContainer.getDefaultTaskDisplayArea();
@@ -377,7 +381,53 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {

        return (taskDisplayArea != null)
                ? taskDisplayArea
                : mSupervisor.mRootWindowContainer.getDefaultTaskDisplayArea();
                : getFallbackDisplayAreaForActivity(activityRecord, request);
    }

    /**
     * Calculates the default {@link TaskDisplayArea} for a task. We attempt to put the activity
     * within the same display area if possible. The strategy is to find the display in the
     * following order:
     *
     * <ol>
     *     <li>The display area of the top activity from the launching process will be used</li>
     *     <li>The display area of the top activity from the real launching process will be used
     *     </li>
     *     <li>Default display area from the associated root window container.</li>
     * </ol>
     * @param activityRecord the activity being started
     * @param request optional {@link Request} made to start the activity record
     * @return {@link TaskDisplayArea} to house the task
     */
    private TaskDisplayArea getFallbackDisplayAreaForActivity(
            @NonNull ActivityRecord activityRecord, @Nullable Request request) {

        WindowProcessController controllerFromLaunchingRecord = mSupervisor.mService
                .getProcessController(activityRecord.launchedFromPid,
                        activityRecord.launchedFromUid);
        final TaskDisplayArea displayAreaForLaunchingRecord = controllerFromLaunchingRecord == null
                ? null : controllerFromLaunchingRecord.getTopActivityDisplayArea();
        if (displayAreaForLaunchingRecord != null) {
            return displayAreaForLaunchingRecord;
        }

        WindowProcessController controllerFromProcess = mSupervisor.mService.getProcessController(
                activityRecord.getProcessName(), activityRecord.getUid());
        final TaskDisplayArea displayAreaForRecord = controllerFromProcess == null ? null
                : controllerFromProcess.getTopActivityDisplayArea();
        if (displayAreaForRecord != null) {
            return displayAreaForRecord;
        }

        WindowProcessController controllerFromRequest = request == null ? null : mSupervisor
                .mService.getProcessController(request.realCallingPid, request.realCallingUid);
        final TaskDisplayArea displayAreaFromSourceProcess = controllerFromRequest == null ? null
                : controllerFromRequest.getTopActivityDisplayArea();
        if (displayAreaFromSourceProcess != null) {
            return displayAreaFromSourceProcess;
        }

        return mSupervisor.mRootWindowContainer.getDefaultTaskDisplayArea();
    }

    private boolean canInheritWindowingModeFromSource(@NonNull DisplayContent display,
+22 −0
Original line number Diff line number Diff line
@@ -730,6 +730,28 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
        return mHasActivities || mHasRecentTasks;
    }

    @Nullable
    TaskDisplayArea getTopActivityDisplayArea() {
        if (mActivities.isEmpty()) {
            return null;
        }

        final int lastIndex = mActivities.size() - 1;
        ActivityRecord topRecord = mActivities.get(lastIndex);
        TaskDisplayArea displayArea = topRecord.getDisplayArea();

        for (int index = lastIndex - 1; index >= 0; --index) {
            ActivityRecord nextRecord = mActivities.get(index);
            TaskDisplayArea nextDisplayArea = nextRecord.getDisplayArea();
            if (nextRecord.compareTo(topRecord) > 0 && nextDisplayArea != null) {
                topRecord = nextRecord;
                displayArea = nextDisplayArea;
            }
        }

        return displayArea;
    }

    private boolean hasActivityInVisibleTask() {
        for (int i = mActivities.size() - 1; i >= 0; --i) {
            Task task = mActivities.get(i).getTask();
Loading