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

Commit 687b4273 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Introducing windowing mode in WindowConfiguration.

Currently Stacks (specifically their ids) are used to determine
windowing mode for activities. This isn't flexible when it comes
to changing/mixing various windowing modes at different levels
of the window hierarchy. E.g. how do you have the non-default
display support freeform or split-screen or how do you
interleave freeform windows with fullscreen windows.
To help with this problem we are introducing windowing mode
in WindowConfiguration that can be used to set the windowing
mode for any WindowContainer in the hierarchy.

Currently all displays are set to fullscreen windowing mode and
stacks windowing modes are set based on their id.

Test: bit FrameworksServicesTests:com.android.server.wm.WindowConfigurationTests
Test: adb shell am instrument -w -e package com.android.server.wm com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Test: go/wm-smoke
Change-Id: Iccdc3212cda651998d6ad76ce5261d089bff897a
parent 249a4536
Loading
Loading
Loading
Loading
+69 −4
Original line number Diff line number Diff line
@@ -44,16 +44,43 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
     */
    private Rect mAppBounds;

    /** The current windowing mode of the configuration. */
    private @WindowingMode int mWindowingMode;

    /** Windowing mode is currently not defined. */
    public static final int WINDOWING_MODE_UNDEFINED = 0;
    /** Occupies the full area of the screen or the parent container. */
    public static final int WINDOWING_MODE_FULLSCREEN = 1;
    /** Always on-top (always visible). of other siblings in its parent container. */
    public static final int WINDOWING_MODE_PINNED = 2;
    /** Occupies a dedicated region of the screen or its parent container. */
    public static final int WINDOWING_MODE_DOCKED = 3;
    /** Can be freely resized within its parent container. */
    public static final int WINDOWING_MODE_FREEFORM = 4;

    @IntDef(value = {
            WINDOWING_MODE_UNDEFINED,
            WINDOWING_MODE_FULLSCREEN,
            WINDOWING_MODE_PINNED,
            WINDOWING_MODE_DOCKED,
            WINDOWING_MODE_FREEFORM,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface WindowingMode {}

    /** Bit that indicates that the {@link #mAppBounds} changed. */
    public static final int WINDOW_CONFIG_APP_BOUNDS = 1 << 0;
    /** Bit that indicates that the {@link #mWindowingMode} changed. */
    public static final int WINDOW_CONFIG_WINDOWING_MODE = 1 << 1;

    @IntDef(flag = true,
            value = {
                    WINDOW_CONFIG_APP_BOUNDS,
                    WINDOW_CONFIG_WINDOWING_MODE,
            })
    @Retention(RetentionPolicy.SOURCE)
    public @interface WindowConfig {}

    /** Bit that indicates that the {@link #mAppBounds} changed. */
    public static final int WINDOW_CONFIG_APP_BOUNDS = 1 << 0;

    public WindowConfiguration() {
        unset();
    }
@@ -69,10 +96,12 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(mAppBounds, flags);
        dest.writeInt(mWindowingMode);
    }

    private void readFromParcel(Parcel source) {
        mAppBounds = source.readParcelable(Rect.class.getClassLoader());
        mWindowingMode = source.readInt();
    }

    @Override
@@ -125,8 +154,18 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
        return mAppBounds;
    }

    public void setWindowingMode(@WindowingMode int windowingMode) {
        mWindowingMode = windowingMode;
    }

    @WindowingMode
    public int getWindowingMode() {
        return mWindowingMode;
    }

    public void setTo(WindowConfiguration other) {
        setAppBounds(other.mAppBounds);
        setWindowingMode(other.mWindowingMode);
    }

    /** Set this object to completely undefined. */
@@ -136,6 +175,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu

    public void setToDefaults() {
        setAppBounds(null);
        setWindowingMode(WINDOWING_MODE_UNDEFINED);
    }

    /**
@@ -151,6 +191,11 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
            changed |= WINDOW_CONFIG_APP_BOUNDS;
            setAppBounds(delta.mAppBounds);
        }
        if (delta.mWindowingMode != WINDOWING_MODE_UNDEFINED
                && mWindowingMode != delta.mWindowingMode) {
            changed |= WINDOW_CONFIG_WINDOWING_MODE;
            setWindowingMode(delta.mWindowingMode);
        }
        return changed;
    }

@@ -174,6 +219,11 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
            changes |= WINDOW_CONFIG_APP_BOUNDS;
        }

        if ((compareUndefined || other.mWindowingMode != WINDOWING_MODE_UNDEFINED)
                && mWindowingMode != other.mWindowingMode) {
            changes |= WINDOW_CONFIG_WINDOWING_MODE;
        }

        return changes;
    }

@@ -194,6 +244,8 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
            n = mAppBounds.bottom - that.mAppBounds.bottom;
            if (n != 0) return n;
        }
        n = mWindowingMode - that.mWindowingMode;
        if (n != 0) return n;

        // if (n != 0) return n;
        return n;
@@ -215,11 +267,24 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
        if (mAppBounds != null) {
            result = 31 * result + mAppBounds.hashCode();
        }
        result = 31 * result + mWindowingMode;
        return result;
    }

    @Override
    public String toString() {
        return "{mAppBounds=" + mAppBounds + "}";
        return "{mAppBounds=" + mAppBounds
                + " mWindowingMode=" + windowingModeToString(mWindowingMode) + "}";
    }

    private static String windowingModeToString(@WindowingMode int windowingMode) {
        switch (windowingMode) {
            case WINDOWING_MODE_UNDEFINED: return "undefined";
            case WINDOWING_MODE_FULLSCREEN: return "fullscreen";
            case WINDOWING_MODE_PINNED: return "pinned";
            case WINDOWING_MODE_DOCKED: return "docked";
            case WINDOWING_MODE_FREEFORM: return "freeform";
        }
        return String.valueOf(windowingMode);
    }
}
+7 −3
Original line number Diff line number Diff line
@@ -460,14 +460,18 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID
                ? new LaunchingTaskPositioner() : null;
        mTmpRect2.setEmpty();
        final Configuration overrideConfig = getOverrideConfiguration();
        mWindowContainerController = createStackWindowController(display.mDisplayId, onTop,
                mTmpRect2);
                mTmpRect2, overrideConfig);
        onOverrideConfigurationChanged(overrideConfig);
        mStackSupervisor.mStacks.put(mStackId, this);
        postAddToDisplay(display, mTmpRect2.isEmpty() ? null : mTmpRect2, onTop);
    }

    T createStackWindowController(int displayId, boolean onTop, Rect outBounds) {
        return (T) new StackWindowController(mStackId, this, displayId, onTop, outBounds);
    T createStackWindowController(int displayId, boolean onTop, Rect outBounds,
            Configuration outOverrideConfig) {
        return (T) new StackWindowController(mStackId, this, displayId, onTop, outBounds,
                outOverrideConfig);
    }

    T getWindowContainerController() {
+3 −2
Original line number Diff line number Diff line
@@ -39,8 +39,9 @@ class PinnedActivityStack extends ActivityStack<PinnedStackWindowController>

    @Override
    PinnedStackWindowController createStackWindowController(int displayId, boolean onTop,
            Rect outBounds) {
        return new PinnedStackWindowController(mStackId, this, displayId, onTop, outBounds);
            Rect outBounds, Configuration outOverrideConfig) {
        return new PinnedStackWindowController(mStackId, this, displayId, onTop, outBounds,
                outOverrideConfig);
    }

    Rect getDefaultPictureInPictureBounds(float aspectRatio) {
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.wm;

import android.app.WindowConfiguration;
import android.content.res.Configuration;

/**
@@ -109,6 +110,12 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
        }
    }

    /** Sets the windowing mode for the configuration container. */
    void setWindowingMode(@WindowConfiguration.WindowingMode int windowingMode) {
        mOverrideConfiguration.windowConfiguration.setWindowingMode(windowingMode);
        onOverrideConfigurationChanged(mOverrideConfiguration);
    }

    /**
     * Must be called when new parent for the container was set.
     */
+8 −2
Original line number Diff line number Diff line
@@ -20,9 +20,12 @@ import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.HOME_STACK_ID;
import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.FLAG_PRIVATE;
import static android.view.Surface.ROTATION_0;
@@ -109,6 +112,7 @@ import static com.android.server.wm.proto.DisplayProto.STACKS;

import android.annotation.NonNull;
import android.app.ActivityManager.StackId;
import android.app.WindowConfiguration;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
@@ -1191,8 +1195,10 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

        final int dw = displayInfo.logicalWidth;
        final int dh = displayInfo.logicalHeight;
        config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT :
                Configuration.ORIENTATION_LANDSCAPE;
        config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
        // TODO: Probably best to set this based on some setting in the display content object,
        // so the display can be configured for things like fullscreen.
        config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);

        config.screenWidthDp =
                (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Loading