Merge changes I4df9945c,I5706cb38 into sc-dev

* changes:
  Update device info on Display.getDeviceProductInfo()
  Display API: Do not expose internal locks
This commit is contained in:
TreeHugger Robot
2021-03-11 21:22:40 +00:00
committed by Android (Google) Code Review

View File

@@ -84,6 +84,7 @@ public final class Display {
private static final String TAG = "Display"; private static final String TAG = "Display";
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private final Object mLock = new Object();
private final DisplayManagerGlobal mGlobal; private final DisplayManagerGlobal mGlobal;
private final int mDisplayId; private final int mDisplayId;
private final int mFlags; private final int mFlags;
@@ -569,7 +570,7 @@ public final class Display {
* @return True if the display is still valid. * @return True if the display is still valid.
*/ */
public boolean isValid() { public boolean isValid() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mIsValid; return mIsValid;
} }
@@ -584,7 +585,7 @@ public final class Display {
*/ */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public boolean getDisplayInfo(DisplayInfo outDisplayInfo) { public boolean getDisplayInfo(DisplayInfo outDisplayInfo) {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
outDisplayInfo.copyFrom(mDisplayInfo); outDisplayInfo.copyFrom(mDisplayInfo);
return mIsValid; return mIsValid;
@@ -601,7 +602,7 @@ public final class Display {
* @hide * @hide
*/ */
public int getLayerStack() { public int getLayerStack() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.layerStack; return mDisplayInfo.layerStack;
} }
@@ -648,7 +649,7 @@ public final class Display {
* @hide * @hide
*/ */
public DisplayAddress getAddress() { public DisplayAddress getAddress() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.address; return mDisplayInfo.address;
} }
@@ -708,7 +709,7 @@ public final class Display {
* @return The display's name. * @return The display's name.
*/ */
public String getName() { public String getName() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.name; return mDisplayInfo.name;
} }
@@ -721,7 +722,7 @@ public final class Display {
* @hide * @hide
*/ */
public float getBrightnessDefault() { public float getBrightnessDefault() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.brightnessDefault; return mDisplayInfo.brightnessDefault;
} }
@@ -760,7 +761,7 @@ public final class Display {
*/ */
@Deprecated @Deprecated
public void getSize(Point outSize) { public void getSize(Point outSize) {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments()); mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
outSize.x = mTempMetrics.widthPixels; outSize.x = mTempMetrics.widthPixels;
@@ -777,7 +778,7 @@ public final class Display {
*/ */
@Deprecated @Deprecated
public void getRectSize(Rect outSize) { public void getRectSize(Rect outSize) {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments()); mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels); outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels);
@@ -815,7 +816,7 @@ public final class Display {
* for example, screen decorations like the status bar are being hidden. * for example, screen decorations like the status bar are being hidden.
*/ */
public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) { public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth; outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth;
outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight; outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight;
@@ -831,7 +832,7 @@ public final class Display {
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public int getMaximumSizeDimension() { public int getMaximumSizeDimension() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight); return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
} }
@@ -842,7 +843,7 @@ public final class Display {
*/ */
@Deprecated @Deprecated
public int getWidth() { public int getWidth() {
synchronized (this) { synchronized (mLock) {
updateCachedAppSizeIfNeededLocked(); updateCachedAppSizeIfNeededLocked();
return mCachedAppWidthCompat; return mCachedAppWidthCompat;
} }
@@ -853,7 +854,7 @@ public final class Display {
*/ */
@Deprecated @Deprecated
public int getHeight() { public int getHeight() {
synchronized (this) { synchronized (mLock) {
updateCachedAppSizeIfNeededLocked(); updateCachedAppSizeIfNeededLocked();
return mCachedAppHeightCompat; return mCachedAppHeightCompat;
} }
@@ -878,7 +879,7 @@ public final class Display {
*/ */
@Surface.Rotation @Surface.Rotation
public int getRotation() { public int getRotation() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mMayAdjustByFixedRotation return mMayAdjustByFixedRotation
? getDisplayAdjustments().getRotation(mDisplayInfo.rotation) ? getDisplayAdjustments().getRotation(mDisplayInfo.rotation)
@@ -904,7 +905,7 @@ public final class Display {
*/ */
@Nullable @Nullable
public DisplayCutout getCutout() { public DisplayCutout getCutout() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mMayAdjustByFixedRotation return mMayAdjustByFixedRotation
? getDisplayAdjustments().getDisplayCutout(mDisplayInfo.displayCutout) ? getDisplayAdjustments().getDisplayCutout(mDisplayInfo.displayCutout)
@@ -922,7 +923,7 @@ public final class Display {
@SuppressLint("VisiblySynchronized") @SuppressLint("VisiblySynchronized")
@Nullable @Nullable
public RoundedCorner getRoundedCorner(@RoundedCorner.Position int position) { public RoundedCorner getRoundedCorner(@RoundedCorner.Position int position) {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
RoundedCorners roundedCorners; RoundedCorners roundedCorners;
if (mMayAdjustByFixedRotation) { if (mMayAdjustByFixedRotation) {
@@ -954,7 +955,7 @@ public final class Display {
* Gets the refresh rate of this display in frames per second. * Gets the refresh rate of this display in frames per second.
*/ */
public float getRefreshRate() { public float getRefreshRate() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.getRefreshRate(); return mDisplayInfo.getRefreshRate();
} }
@@ -970,7 +971,7 @@ public final class Display {
*/ */
@Deprecated @Deprecated
public float[] getSupportedRefreshRates() { public float[] getSupportedRefreshRates() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.getDefaultRefreshRates(); return mDisplayInfo.getDefaultRefreshRates();
} }
@@ -980,7 +981,7 @@ public final class Display {
* Returns the active mode of the display. * Returns the active mode of the display.
*/ */
public Mode getMode() { public Mode getMode() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.getMode(); return mDisplayInfo.getMode();
} }
@@ -990,7 +991,7 @@ public final class Display {
* Gets the supported modes of this display. * Gets the supported modes of this display.
*/ */
public Mode[] getSupportedModes() { public Mode[] getSupportedModes() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
final Display.Mode[] modes = mDisplayInfo.supportedModes; final Display.Mode[] modes = mDisplayInfo.supportedModes;
return Arrays.copyOf(modes, modes.length); return Arrays.copyOf(modes, modes.length);
@@ -1016,7 +1017,7 @@ public final class Display {
*/ */
@SuppressLint("VisiblySynchronized") @SuppressLint("VisiblySynchronized")
public boolean isMinimalPostProcessingSupported() { public boolean isMinimalPostProcessingSupported() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.minimalPostProcessingSupported; return mDisplayInfo.minimalPostProcessingSupported;
} }
@@ -1036,7 +1037,7 @@ public final class Display {
* @hide * @hide
*/ */
public int getColorMode() { public int getColorMode() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.colorMode; return mDisplayInfo.colorMode;
} }
@@ -1063,7 +1064,7 @@ public final class Display {
* @see #isHdr() * @see #isHdr()
*/ */
public HdrCapabilities getHdrCapabilities() { public HdrCapabilities getHdrCapabilities() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.hdrCapabilities; return mDisplayInfo.hdrCapabilities;
} }
@@ -1076,7 +1077,7 @@ public final class Display {
* @see HdrCapabilities#getSupportedHdrTypes() * @see HdrCapabilities#getSupportedHdrTypes()
*/ */
public boolean isHdr() { public boolean isHdr() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.isHdr(); return mDisplayInfo.isHdr();
} }
@@ -1089,7 +1090,7 @@ public final class Display {
* {@link Configuration#isScreenWideColorGamut()}. * {@link Configuration#isScreenWideColorGamut()}.
*/ */
public boolean isWideColorGamut() { public boolean isWideColorGamut() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.isWideColorGamut(); return mDisplayInfo.isWideColorGamut();
} }
@@ -1104,7 +1105,7 @@ public final class Display {
*/ */
@Nullable @Nullable
public ColorSpace getPreferredWideGamutColorSpace() { public ColorSpace getPreferredWideGamutColorSpace() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
if (mDisplayInfo.isWideColorGamut()) { if (mDisplayInfo.isWideColorGamut()) {
return mGlobal.getPreferredWideGamutColorSpace(); return mGlobal.getPreferredWideGamutColorSpace();
@@ -1118,7 +1119,7 @@ public final class Display {
* @hide * @hide
*/ */
public int[] getSupportedColorModes() { public int[] getSupportedColorModes() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
int[] colorModes = mDisplayInfo.supportedColorModes; int[] colorModes = mDisplayInfo.supportedColorModes;
return Arrays.copyOf(colorModes, colorModes.length); return Arrays.copyOf(colorModes, colorModes.length);
@@ -1135,7 +1136,7 @@ public final class Display {
@NonNull @NonNull
@TestApi @TestApi
public @ColorMode ColorSpace[] getSupportedWideColorGamut() { public @ColorMode ColorSpace[] getSupportedWideColorGamut() {
synchronized (this) { synchronized (mLock) {
final ColorSpace[] defaultColorSpaces = new ColorSpace[0]; final ColorSpace[] defaultColorSpaces = new ColorSpace[0];
updateDisplayInfoLocked(); updateDisplayInfoLocked();
if (!isWideColorGamut()) { if (!isWideColorGamut()) {
@@ -1169,7 +1170,7 @@ public final class Display {
* A/V synchronization. * A/V synchronization.
*/ */
public long getAppVsyncOffsetNanos() { public long getAppVsyncOffsetNanos() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.appVsyncOffsetNanos; return mDisplayInfo.appVsyncOffsetNanos;
} }
@@ -1187,7 +1188,7 @@ public final class Display {
* ({@link System#nanoTime}). * ({@link System#nanoTime}).
*/ */
public long getPresentationDeadlineNanos() { public long getPresentationDeadlineNanos() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mDisplayInfo.presentationDeadlineNanos; return mDisplayInfo.presentationDeadlineNanos;
} }
@@ -1202,7 +1203,10 @@ public final class Display {
*/ */
@Nullable @Nullable
public DeviceProductInfo getDeviceProductInfo() { public DeviceProductInfo getDeviceProductInfo() {
return mDisplayInfo.deviceProductInfo; synchronized (mLock) {
updateDisplayInfoLocked();
return mDisplayInfo.deviceProductInfo;
}
} }
/** /**
@@ -1235,7 +1239,7 @@ public final class Display {
*/ */
@Deprecated @Deprecated
public void getMetrics(DisplayMetrics outMetrics) { public void getMetrics(DisplayMetrics outMetrics) {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
mDisplayInfo.getAppMetrics(outMetrics, getDisplayAdjustments()); mDisplayInfo.getAppMetrics(outMetrics, getDisplayAdjustments());
} }
@@ -1288,7 +1292,7 @@ public final class Display {
*/ */
@Deprecated @Deprecated
public void getRealSize(Point outSize) { public void getRealSize(Point outSize) {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
if (shouldReportMaxBounds()) { if (shouldReportMaxBounds()) {
final Rect bounds = mResources.getConfiguration() final Rect bounds = mResources.getConfiguration()
@@ -1358,7 +1362,7 @@ public final class Display {
*/ */
@Deprecated @Deprecated
public void getRealMetrics(DisplayMetrics outMetrics) { public void getRealMetrics(DisplayMetrics outMetrics) {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
if (shouldReportMaxBounds()) { if (shouldReportMaxBounds()) {
mDisplayInfo.getMaxBoundsMetrics(outMetrics, mDisplayInfo.getMaxBoundsMetrics(outMetrics,
@@ -1434,7 +1438,7 @@ public final class Display {
* {@link #STATE_UNKNOWN}. * {@link #STATE_UNKNOWN}.
*/ */
public int getState() { public int getState() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
return mIsValid ? mDisplayInfo.state : STATE_UNKNOWN; return mIsValid ? mDisplayInfo.state : STATE_UNKNOWN;
} }
@@ -1518,7 +1522,7 @@ public final class Display {
// For debugging purposes // For debugging purposes
@Override @Override
public String toString() { public String toString() {
synchronized (this) { synchronized (mLock) {
updateDisplayInfoLocked(); updateDisplayInfoLocked();
final DisplayAdjustments adjustments = getDisplayAdjustments(); final DisplayAdjustments adjustments = getDisplayAdjustments();
mDisplayInfo.getAppMetrics(mTempMetrics, adjustments); mDisplayInfo.getAppMetrics(mTempMetrics, adjustments);