summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/content/res/Configuration.java54
-rw-r--r--core/java/android/view/Display.java11
-rw-r--r--core/java/android/view/Surface.java8
-rw-r--r--services/core/java/com/android/server/wm/DisplayContent.java2
4 files changed, 74 insertions, 1 deletions
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index 6834ba816910..be31d1b0b5e5 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -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;
@@ -1763,6 +1788,24 @@ public final class Configuration implements Parcelable, Comparable<Configuration
/**
* @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
+ *
* Clears the locale without changing layout direction.
*/
public void clearLocales() {
@@ -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.
}
}
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java
index cdb9b8229314..7346a215ed8e 100644
--- a/core/java/android/view/Display.java
+++ b/core/java/android/view/Display.java
@@ -726,6 +726,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.
*/
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index 4f9dbd5ad7a0..1b702326cc28 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -131,11 +131,17 @@ 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)
*/
public static final int ROTATION_0 = 0;
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index c98d60dcad93..9fe73815b380 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -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);