From 253696fea3e6224c0950ace721942d8fae5d7470 Mon Sep 17 00:00:00 2001 From: Naomi Musgrave Date: Fri, 30 Jul 2021 08:39:40 +0100 Subject: [PATCH] Temporary flag for Launcher to debug their usage of sandboxed display APIs The flag does not impact any other application calling the sandboxed display APIs. The flag will be removed after Launcher finishes identifying the breakages attributed to the display API changes. For Launcher to receive the un-sandboxed values: adb shell cmd display constrain-display-apis false Test: manual Bug: 193421404 Change-Id: I5d8612fd7dcb49769ae005130c9786b2d8416bfc --- core/java/android/view/Display.java | 6 +++--- core/java/android/view/DisplayInfo.java | 15 +++++++++++++- .../server/display/DisplayManagerService.java | 20 +++++++++++++++++-- .../display/DisplayManagerShellCommand.java | 16 +++++++++++++++ .../server/display/LogicalDisplay.java | 2 ++ 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java index 9cb0d1ff2c3f4..e7ff978266a2a 100644 --- a/core/java/android/view/Display.java +++ b/core/java/android/view/Display.java @@ -1463,10 +1463,10 @@ public final class Display { return false; } final Configuration config = mResources.getConfiguration(); - // TODO(b/179308296) Temporarily exclude Launcher from being given max bounds, by checking - // if the caller is the recents component. + // TODO(b/179308296) Temporarily - never report max bounds to only Launcher if the feature + // is disabled. return config != null && !config.windowConfiguration.getMaxBounds().isEmpty() - && !isRecentsComponent(); + && (mDisplayInfo.shouldConstrainMetricsForLauncher || !isRecentsComponent()); } /** diff --git a/core/java/android/view/DisplayInfo.java b/core/java/android/view/DisplayInfo.java index 8e5f905e9c749..6572510465513 100644 --- a/core/java/android/view/DisplayInfo.java +++ b/core/java/android/view/DisplayInfo.java @@ -305,6 +305,13 @@ public final class DisplayInfo implements Parcelable { */ public float brightnessDefault; + /** + * @hide + * True if Display#getRealSize and getRealMetrics should be constrained for Launcher, false + * otherwise. + */ + public boolean shouldConstrainMetricsForLauncher = false; + /** * The {@link RoundedCorners} if present, otherwise {@code null}. */ @@ -381,7 +388,8 @@ public final class DisplayInfo implements Parcelable { && brightnessMinimum == other.brightnessMinimum && brightnessMaximum == other.brightnessMaximum && brightnessDefault == other.brightnessDefault - && Objects.equals(roundedCorners, other.roundedCorners); + && Objects.equals(roundedCorners, other.roundedCorners) + && shouldConstrainMetricsForLauncher == other.shouldConstrainMetricsForLauncher; } @Override @@ -432,6 +440,7 @@ public final class DisplayInfo implements Parcelable { brightnessMaximum = other.brightnessMaximum; brightnessDefault = other.brightnessDefault; roundedCorners = other.roundedCorners; + shouldConstrainMetricsForLauncher = other.shouldConstrainMetricsForLauncher; } public void readFromParcel(Parcel source) { @@ -488,6 +497,7 @@ public final class DisplayInfo implements Parcelable { for (int i = 0; i < numUserDisabledFormats; i++) { userDisabledHdrTypes[i] = source.readInt(); } + shouldConstrainMetricsForLauncher = source.readBoolean(); } @Override @@ -542,6 +552,7 @@ public final class DisplayInfo implements Parcelable { for (int i = 0; i < userDisabledHdrTypes.length; i++) { dest.writeInt(userDisabledHdrTypes[i]); } + dest.writeBoolean(shouldConstrainMetricsForLauncher); } @Override @@ -796,6 +807,8 @@ public final class DisplayInfo implements Parcelable { sb.append(brightnessMaximum); sb.append(", brightnessDefault "); sb.append(brightnessDefault); + sb.append(", shouldConstrainMetricsForLauncher "); + sb.append(shouldConstrainMetricsForLauncher); sb.append("}"); return sb.toString(); } diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java index afd18894f5312..a0944c021b926 100644 --- a/services/core/java/com/android/server/display/DisplayManagerService.java +++ b/services/core/java/com/android/server/display/DisplayManagerService.java @@ -63,8 +63,6 @@ import android.hardware.display.DisplayManagerGlobal; import android.hardware.display.DisplayManagerInternal; import android.hardware.display.DisplayManagerInternal.DisplayGroupListener; import android.hardware.display.DisplayManagerInternal.DisplayTransactionListener; -import android.hardware.display.DisplayManagerInternal.RefreshRateLimitation; -import android.hardware.display.DisplayManagerInternal.RefreshRateRange; import android.hardware.display.DisplayViewport; import android.hardware.display.DisplayedContentSample; import android.hardware.display.DisplayedContentSamplingAttributes; @@ -636,6 +634,9 @@ public final class DisplayManagerService extends SystemService { synchronized (mSyncRoot) { final LogicalDisplay display = mLogicalDisplayMapper.getDisplayLocked(displayId); if (display != null) { + // Do not let constrain be overwritten by override from WindowManager. + info.shouldConstrainMetricsForLauncher = + display.getDisplayInfoLocked().shouldConstrainMetricsForLauncher; if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) { handleLogicalDisplayChangedLocked(display); scheduleTraversalLocked(false); @@ -1723,6 +1724,21 @@ public final class DisplayManagerService extends SystemService { } } + void setShouldConstrainMetricsForLauncher(boolean constrain) { + // Apply constrain for every display. + synchronized (mSyncRoot) { + int[] displayIds = mLogicalDisplayMapper.getDisplayIdsLocked(Process.myUid()); + for (int i : displayIds) { + final LogicalDisplay display = mLogicalDisplayMapper.getDisplayLocked(i); + if (display == null) { + return; + } + display.getDisplayInfoLocked().shouldConstrainMetricsForLauncher = constrain; + setDisplayInfoOverrideFromWindowManagerInternal(i, display.getDisplayInfoLocked()); + } + } + } + private void clearViewportsLocked() { mViewports.clear(); } diff --git a/services/core/java/com/android/server/display/DisplayManagerShellCommand.java b/services/core/java/com/android/server/display/DisplayManagerShellCommand.java index 48edb73ac81df..94e64f070ef89 100644 --- a/services/core/java/com/android/server/display/DisplayManagerShellCommand.java +++ b/services/core/java/com/android/server/display/DisplayManagerShellCommand.java @@ -58,6 +58,8 @@ class DisplayManagerShellCommand extends ShellCommand { return setDisplayModeDirectorLoggingEnabled(false); case "dwb-set-cct": return setAmbientColorTemperatureOverride(); + case "constrain-launcher-metrics": + return setConstrainLauncherMetrics(); default: return handleDefaultCommands(cmd); } @@ -88,6 +90,9 @@ class DisplayManagerShellCommand extends ShellCommand { pw.println(" Disable display mode director logging."); pw.println(" dwb-set-cct CCT"); pw.println(" Sets the ambient color temperature override to CCT (use -1 to disable)."); + pw.println(" constrain-launcher-metrics [true|false]"); + pw.println(" Sets if Display#getRealSize and getRealMetrics should be constrained for "); + pw.println(" Launcher."); pw.println(); Intent.printIntentArgsHelp(pw , ""); } @@ -150,4 +155,15 @@ class DisplayManagerShellCommand extends ShellCommand { mService.setAmbientColorTemperatureOverride(cct); return 0; } + + private int setConstrainLauncherMetrics() { + String constrainText = getNextArg(); + if (constrainText == null) { + getErrPrintWriter().println("Error: no value specified"); + return 1; + } + boolean constrain = Boolean.parseBoolean(constrainText); + mService.setShouldConstrainMetricsForLauncher(constrain); + return 0; + } } diff --git a/services/core/java/com/android/server/display/LogicalDisplay.java b/services/core/java/com/android/server/display/LogicalDisplay.java index 5186744d5c27a..86c9ca9374820 100644 --- a/services/core/java/com/android/server/display/LogicalDisplay.java +++ b/services/core/java/com/android/server/display/LogicalDisplay.java @@ -233,6 +233,8 @@ final class LogicalDisplay { info.physicalXDpi = mOverrideDisplayInfo.physicalXDpi; info.physicalYDpi = mOverrideDisplayInfo.physicalYDpi; info.roundedCorners = mOverrideDisplayInfo.roundedCorners; + info.shouldConstrainMetricsForLauncher = + mOverrideDisplayInfo.shouldConstrainMetricsForLauncher; } mInfo.set(info); }