From 24be34dcc9611458cd26d90bdf943938e159c0bc Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Mon, 28 May 2018 18:55:38 +0200 Subject: [PATCH] WM: Make maxAspectRatio work with display cutouts Fixes an issue where the max aspect ratio was not correctly calculated if there was a display cutout. The issue was that the max aspect ratio logic assumed that nothing ever applies a top inset (n.b. the status bar is ignored for this inset). This is no longer true with display cutouts, which cut into the app bounds from the top. To make things work, we now need to grow the bounds for the app window by that inset. Later on, the top part will be trimmed again for the bounds reported to the app. Note that we cannot outright discard the top part, or colored bars would cease to work. Change-Id: I53925196a6a41736fc4748b12bbc3b8a9b0d174b Fixes: 80248462 Test: atest AspectRatioTests --- .../com/android/server/am/ActivityRecord.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index 16f4585c6095e..d456f6255426b 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -2413,11 +2413,16 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo } // Compute configuration based on max supported width and height. - outBounds.set(0, 0, maxActivityWidth, maxActivityHeight); - // Position the activity frame on the opposite side of the nav bar. - final int navBarPosition = service.mWindowManager.getNavBarPosition(); - final int left = navBarPosition == NAV_BAR_LEFT ? appBounds.right - outBounds.width() : 0; - outBounds.offsetTo(left, 0 /* top */); + // Also account for the left / top insets (e.g. from display cutouts), which will be clipped + // away later in StackWindowController.adjustConfigurationForBounds(). Otherwise, the app + // bounds would end up too small. + outBounds.set(0, 0, maxActivityWidth + appBounds.left, maxActivityHeight + appBounds.top); + + if (service.mWindowManager.getNavBarPosition() == NAV_BAR_LEFT) { + // Position the activity frame on the opposite side of the nav bar. + outBounds.left = appBounds.right - maxActivityWidth; + outBounds.right = appBounds.right; + } } boolean ensureActivityConfiguration(int globalChanges, boolean preserveWindow) {