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

Commit c1f2f2a9 authored by Bryce Lee's avatar Bryce Lee
Browse files

Add rotation to configuration.

Certain activities are dependent on the rotation of the device to
determine layout. In these cases, orientation does not provide enough
details.

This CL adds the field (hidden) to the configuration.

Change-Id: Idb3ba10cb4de8838737c25e92264e6cee224e264
Fixes: 32839232
Test: go/wm-smoke
parent 09e1fae7
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Locale;

import static android.view.Surface.ROTATION_0;
import static android.view.Surface.ROTATION_UNDEFINED;

/**
 * This class describes all device configuration information that can
 * impact the resources the application retrieves.  This includes both
@@ -597,6 +600,13 @@ public final class Configuration implements Parcelable, Comparable<Configuration
     */
    public int orientation;

    /**
     * The mRotation used at the time orientation was determined.
     * TODO(b/36812336): Move mRotation out of {@link Configuration}.
     * {@hide}
     */
    private int mRotation;

    /** Constant for {@link #uiMode}: bits that encode the mode type. */
    public static final int UI_MODE_TYPE_MASK = 0x0f;
    /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
@@ -884,6 +894,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        navigation = o.navigation;
        navigationHidden = o.navigationHidden;
        orientation = o.orientation;
        mRotation = o.mRotation;
        screenLayout = o.screenLayout;
        colorMode = o.colorMode;
        uiMode = o.uiMode;
@@ -1074,6 +1085,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        navigation = NAVIGATION_UNDEFINED;
        navigationHidden = NAVIGATIONHIDDEN_UNDEFINED;
        orientation = ORIENTATION_UNDEFINED;
        mRotation = ROTATION_UNDEFINED;
        screenLayout = SCREENLAYOUT_UNDEFINED;
        colorMode = COLOR_MODE_UNDEFINED;
        uiMode = UI_MODE_TYPE_UNDEFINED;
@@ -1182,6 +1194,11 @@ public final class Configuration implements Parcelable, Comparable<Configuration
            changed |= ActivityInfo.CONFIG_ORIENTATION;
            orientation = delta.orientation;
        }
        if (delta.mRotation != ROTATION_UNDEFINED
                && mRotation != delta.mRotation) {
            changed |= ActivityInfo.CONFIG_ORIENTATION;
            mRotation = delta.mRotation;
        }

        if (((delta.screenLayout & SCREENLAYOUT_SIZE_MASK) != SCREENLAYOUT_SIZE_UNDEFINED)
                && (delta.screenLayout & SCREENLAYOUT_SIZE_MASK)
@@ -1376,6 +1393,10 @@ public final class Configuration implements Parcelable, Comparable<Configuration
                && orientation != delta.orientation) {
            changed |= ActivityInfo.CONFIG_ORIENTATION;
        }
        if ((compareUndefined || delta.mRotation != ROTATION_UNDEFINED)
                && mRotation != delta.mRotation) {
            changed |= ActivityInfo.CONFIG_ORIENTATION;
        }
        if ((compareUndefined || getScreenLayoutNoDirection(delta.screenLayout) !=
                (SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED))
                && getScreenLayoutNoDirection(screenLayout) !=
@@ -1512,6 +1533,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        dest.writeInt(navigation);
        dest.writeInt(navigationHidden);
        dest.writeInt(orientation);
        dest.writeInt(mRotation);
        dest.writeInt(screenLayout);
        dest.writeInt(colorMode);
        dest.writeInt(uiMode);
@@ -1548,6 +1570,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        navigation = source.readInt();
        navigationHidden = source.readInt();
        orientation = source.readInt();
        mRotation = source.readInt();
        screenLayout = source.readInt();
        colorMode = source.readInt();
        uiMode = source.readInt();
@@ -1632,6 +1655,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        if (n != 0) return n;
        n = this.orientation - that.orientation;
        if (n != 0) return n;
        n = this.mRotation - that.mRotation;
        if (n != 0) return n;
        n = this.colorMode - that.colorMode;
        if (n != 0) return n;
        n = this.screenLayout - that.screenLayout;
@@ -1760,6 +1785,24 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        appBounds.set(left, top, right, bottom);
    }

    /**
     * @hide
     *
     * Setter for orientation converts from {@link Surface} values to internal representation.
     */
    public void setRotation(int rotation) {
        this.mRotation = rotation;
    }

    /**
     * @hide
     *
     * Getter for orientation. Converts from internal representation to  {@link Surface} values.
     */
    public int getRotation() {
        return mRotation != ROTATION_UNDEFINED ? mRotation : ROTATION_0;
    }

    /**
     * @hide
     *
@@ -2193,6 +2236,10 @@ public final class Configuration implements Parcelable, Comparable<Configuration
            delta.orientation = change.orientation;
        }

        if (base.mRotation != change.mRotation) {
            base.mRotation = change.mRotation;
        }

        if ((base.screenLayout & SCREENLAYOUT_SIZE_MASK) !=
                (change.screenLayout & SCREENLAYOUT_SIZE_MASK)) {
            delta.screenLayout |= change.screenLayout & SCREENLAYOUT_SIZE_MASK;
@@ -2264,6 +2311,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
    private static final String XML_ATTR_NAVIGATION = "nav";
    private static final String XML_ATTR_NAVIGATION_HIDDEN = "navHid";
    private static final String XML_ATTR_ORIENTATION = "ori";
    private static final String XML_ATTR_ROTATION = "rot";
    private static final String XML_ATTR_SCREEN_LAYOUT = "scrLay";
    private static final String XML_ATTR_COLOR_MODE = "clrMod";
    private static final String XML_ATTR_UI_MODE = "ui";
@@ -2323,6 +2371,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
                DENSITY_DPI_UNDEFINED);
        configOut.appBounds =
            Rect.unflattenFromString(XmlUtils.readStringAttribute(parser, XML_ATTR_APP_BOUNDS));
        configOut.mRotation = XmlUtils.readIntAttribute(parser, XML_ATTR_ROTATION,
                ROTATION_UNDEFINED);

        // For persistence, we don't care about assetsSeq, so do not read it out.
    }
@@ -2399,6 +2449,10 @@ public final class Configuration implements Parcelable, Comparable<Configuration
                config.appBounds.flattenToString());
        }

        if (config.mRotation != ROTATION_UNDEFINED) {
            XmlUtils.writeIntAttribute(xml, XML_ATTR_ROTATION, config.mRotation);
        }

        // For persistence, we do not care about assetsSeq, so do not write it out.
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -725,6 +725,17 @@ public final class Display {
        }
    }

    /**
     * Returns the rotation associated with this display as used during layout. This is currently
     * derived from the {@link Configuration}.
     *
     * @hide
     */
    @Surface.Rotation
    public int getLayoutRotation() {
        return mResources.getConfiguration().getRotation();
    }

    /**
     * @deprecated use {@link #getRotation}
     * @return orientation of this display.
+7 −1
Original line number Diff line number Diff line
@@ -131,10 +131,16 @@ public class Surface implements Parcelable {
    public static final int SCALING_MODE_NO_SCALE_CROP = 3;

    /** @hide */
    @IntDef({ROTATION_0, ROTATION_90, ROTATION_180, ROTATION_270})
    @IntDef({ROTATION_UNDEFINED, ROTATION_0, ROTATION_90, ROTATION_180, ROTATION_270})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Rotation {}

    /**
     * Rotation constant: undefined
     * @hide
     */
    public static final int ROTATION_UNDEFINED = -1;

    /**
     * Rotation constant: 0 degree rotation (natural orientation)
     */
+2 −0
Original line number Diff line number Diff line
@@ -1183,6 +1183,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        final int dh = displayInfo.logicalHeight;
        config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT :
                Configuration.ORIENTATION_LANDSCAPE;
        config.setRotation(displayInfo.rotation);

        config.screenWidthDp =
                (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
                        config.uiMode, mDisplayId) / mDisplayMetrics.density);