summaryrefslogtreecommitdiff
path: root/core/java/android/view/Display.java
diff options
context:
space:
mode:
authorRiddle Hsu <riddlehsu@google.com>2020-03-06 21:01:13 +0800
committerRiddle Hsu <riddlehsu@google.com>2020-05-11 13:30:14 +0800
commitca70b013021a4486dbed015dd7f362d00878efbe (patch)
tree7078a1f14b180fd1d57c6c309ea1abebd8041de1 /core/java/android/view/Display.java
parent53ed707827f48bdb183add5f08d285dc06e9c705 (diff)
Add fixed rotation display adjustments
If an activity is launched with fixed rotation transform, its window layout and configuration will be rotated. But if it gets real information from the display, the values (getRotation, getRealSize, getRealMetric, getCutout) are inconsistent with the actual appearance. This change provides the basic information to adjust the returned values. Bug: 147213487 Test: atest DisplayAdjustmentsTests#testFixedRotationAdjustments Change-Id: I864d5759f41209d5f93c4a9011b720675c25e765
Diffstat (limited to 'core/java/android/view/Display.java')
-rw-r--r--core/java/android/view/Display.java34
1 files changed, 30 insertions, 4 deletions
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java
index 4469fdbb12ec..8e2efe3f2b38 100644
--- a/core/java/android/view/Display.java
+++ b/core/java/android/view/Display.java
@@ -104,6 +104,14 @@ public final class Display {
private int mCachedAppHeightCompat;
/**
+ * Indicates that the application is started in a different rotation than the real display, so
+ * the display information may be adjusted. That ensures the methods {@link #getRotation},
+ * {@link #getRealSize}, {@link #getRealMetrics}, and {@link #getCutout} are consistent with how
+ * the application window is laid out.
+ */
+ private boolean mMayAdjustByFixedRotation;
+
+ /**
* The default Display id, which is the id of the primary display assuming there is one.
*/
public static final int DEFAULT_DISPLAY = 0;
@@ -804,7 +812,9 @@ public final class Display {
public int getRotation() {
synchronized (this) {
updateDisplayInfoLocked();
- return mDisplayInfo.rotation;
+ return mMayAdjustByFixedRotation
+ ? getDisplayAdjustments().getRotation(mDisplayInfo.rotation)
+ : mDisplayInfo.rotation;
}
}
@@ -828,7 +838,9 @@ public final class Display {
public DisplayCutout getCutout() {
synchronized (this) {
updateDisplayInfoLocked();
- return mDisplayInfo.displayCutout;
+ return mMayAdjustByFixedRotation
+ ? getDisplayAdjustments().getDisplayCutout(mDisplayInfo.displayCutout)
+ : mDisplayInfo.displayCutout;
}
}
@@ -1140,6 +1152,9 @@ public final class Display {
updateDisplayInfoLocked();
outSize.x = mDisplayInfo.logicalWidth;
outSize.y = mDisplayInfo.logicalHeight;
+ if (mMayAdjustByFixedRotation) {
+ getDisplayAdjustments().adjustSize(outSize, mDisplayInfo.rotation);
+ }
}
}
@@ -1159,6 +1174,9 @@ public final class Display {
updateDisplayInfoLocked();
mDisplayInfo.getLogicalMetrics(outMetrics,
CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
+ if (mMayAdjustByFixedRotation) {
+ getDisplayAdjustments().adjustMetrics(outMetrics, mDisplayInfo.rotation);
+ }
}
}
@@ -1225,6 +1243,11 @@ public final class Display {
}
}
}
+
+ // TODO(b/147213487): Replace the condition with per-resources state.
+ mMayAdjustByFixedRotation = mIsValid && mResources != null
+ && mResources.getConfiguration().windowConfiguration.getRotation()
+ != mDisplayInfo.rotation;
}
private void updateCachedAppSizeIfNeededLocked() {
@@ -1243,9 +1266,12 @@ public final class Display {
public String toString() {
synchronized (this) {
updateDisplayInfoLocked();
- mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
+ final DisplayAdjustments adjustments = getDisplayAdjustments();
+ mDisplayInfo.getAppMetrics(mTempMetrics, adjustments);
return "Display id " + mDisplayId + ": " + mDisplayInfo
- + ", " + mTempMetrics + ", isValid=" + mIsValid;
+ + (mMayAdjustByFixedRotation
+ ? (", " + adjustments.getFixedRotationAdjustments() + ", ") : ", ")
+ + mTempMetrics + ", isValid=" + mIsValid;
}
}