From 86e40f73a064827c2f22f0de73d517868a9ebf06 Mon Sep 17 00:00:00 2001 From: Naomi Musgrave Date: Mon, 25 Apr 2022 16:55:16 +0100 Subject: [PATCH] Only return ROTATION_0 for WM#getPossibleMaximumWindowMetrics Do not return every rotation for window metrics. Bug: 228288352 Test: atest WmTests:PossibleDisplayInfoMapperTests Change-Id: I756b079bfce09cf618500f3d07547ec94ac60694 --- core/java/android/view/WindowManager.java | 4 +- .../server/wm/PossibleDisplayInfoMapper.java | 49 +++---------------- .../server/wm/WindowManagerService.java | 3 +- .../wm/PossibleDisplayInfoMapperTests.java | 42 ++++++---------- 4 files changed, 25 insertions(+), 73 deletions(-) diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 3774dacfa5ffc..5bc340b76f560 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -725,8 +725,8 @@ public interface WindowManager extends ViewManager { /** * Returns a set of {@link WindowMetrics} for the given display. Each WindowMetrics instance - * is the maximum WindowMetrics for a device state, including rotations. This is not guaranteed - * to include all possible device states. + * is the maximum WindowMetrics for a device state. This is not guaranteed to include all + * possible device states. * * This API can only be used by Launcher. * diff --git a/services/core/java/com/android/server/wm/PossibleDisplayInfoMapper.java b/services/core/java/com/android/server/wm/PossibleDisplayInfoMapper.java index 11a27c593d9ee..3f6fb622481f0 100644 --- a/services/core/java/com/android/server/wm/PossibleDisplayInfoMapper.java +++ b/services/core/java/com/android/server/wm/PossibleDisplayInfoMapper.java @@ -16,15 +16,11 @@ package com.android.server.wm; -import static android.view.Surface.ROTATION_0; -import static android.view.Surface.ROTATION_270; - import android.hardware.display.DisplayManagerInternal; import android.util.ArraySet; import android.util.Slog; import android.util.SparseArray; import android.view.DisplayInfo; -import android.view.Surface; import java.util.Set; @@ -44,8 +40,7 @@ public class PossibleDisplayInfoMapper { /** * Map of all logical displays, indexed by logical display id. - * Each logical display has multiple entries, one for each possible rotation and device - * state. + * Each logical display has multiple entries, one for each device state. * * Emptied and re-calculated when a display is added, removed, or changed. */ @@ -57,8 +52,8 @@ public class PossibleDisplayInfoMapper { /** - * Returns, for the given displayId, a set of display infos. Set contains the possible rotations - * for each supported device state. + * Returns, for the given displayId, a set of display infos. Set contains each supported device + * state. */ public Set getPossibleDisplayInfos(int displayId) { // Update display infos before returning, since any cached values would have been removed @@ -73,13 +68,13 @@ public class PossibleDisplayInfoMapper { } /** - * Updates the possible {@link DisplayInfo}s for the given display, by calculating the - * DisplayInfo for each rotation across supported device states. + * Updates the possible {@link DisplayInfo}s for the given display, by saving the DisplayInfo + * across supported device states. */ public void updatePossibleDisplayInfos(int displayId) { Set displayInfos = mDisplayManagerInternal.getPossibleDisplayInfo(displayId); if (DEBUG) { - Slog.v(TAG, "updatePossibleDisplayInfos, calculate rotations for given DisplayInfo " + Slog.v(TAG, "updatePossibleDisplayInfos, given DisplayInfo " + displayInfos.size() + " on display " + displayId); } updateDisplayInfos(displayInfos); @@ -99,40 +94,12 @@ public class PossibleDisplayInfoMapper { private void updateDisplayInfos(Set displayInfos) { // Empty out cache before re-computing. mDisplayInfos.clear(); - DisplayInfo[] originalDisplayInfos = new DisplayInfo[displayInfos.size()]; - displayInfos.toArray(originalDisplayInfos); // Iterate over each logical display layout for the current state. - Set rotatedDisplayInfos; - for (DisplayInfo di : originalDisplayInfos) { - rotatedDisplayInfos = new ArraySet<>(); - // Calculate all possible rotations for each logical display. - for (int rotation = ROTATION_0; rotation <= ROTATION_270; rotation++) { - rotatedDisplayInfos.add(applyRotation(di, rotation)); - } + for (DisplayInfo di : displayInfos) { // Combine all results under the logical display id. Set priorDisplayInfos = mDisplayInfos.get(di.displayId, new ArraySet<>()); - priorDisplayInfos.addAll(rotatedDisplayInfos); + priorDisplayInfos.add(di); mDisplayInfos.put(di.displayId, priorDisplayInfos); } } - - private static DisplayInfo applyRotation(DisplayInfo displayInfo, - @Surface.Rotation int rotation) { - DisplayInfo updatedDisplayInfo = new DisplayInfo(); - updatedDisplayInfo.copyFrom(displayInfo); - // Apply rotations before updating width and height - updatedDisplayInfo.roundedCorners = updatedDisplayInfo.roundedCorners.rotate(rotation, - updatedDisplayInfo.logicalWidth, updatedDisplayInfo.logicalHeight); - updatedDisplayInfo.displayCutout = - DisplayContent.calculateDisplayCutoutForRotationAndDisplaySizeUncached( - updatedDisplayInfo.displayCutout, rotation, updatedDisplayInfo.logicalWidth, - updatedDisplayInfo.logicalHeight).getDisplayCutout(); - - updatedDisplayInfo.rotation = rotation; - final int naturalWidth = updatedDisplayInfo.getNaturalWidth(); - final int naturalHeight = updatedDisplayInfo.getNaturalHeight(); - updatedDisplayInfo.logicalWidth = naturalWidth; - updatedDisplayInfo.logicalHeight = naturalHeight; - return updatedDisplayInfo; - } } diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index a9b0f0dc28ad7..48168a08a5433 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -8755,8 +8755,7 @@ public class WindowManagerService extends IWindowManager.Stub return new ArrayList<>(); } - // Retrieve the DisplayInfo for all possible rotations across all possible display - // layouts. + // Retrieve the DisplayInfo across all possible display layouts. return List.copyOf(mPossibleDisplayInfoMapper.getPossibleDisplayInfos(displayId)); } } finally { diff --git a/services/tests/wmtests/src/com/android/server/wm/PossibleDisplayInfoMapperTests.java b/services/tests/wmtests/src/com/android/server/wm/PossibleDisplayInfoMapperTests.java index 6e0056821aab2..8b0a54050c3c8 100644 --- a/services/tests/wmtests/src/com/android/server/wm/PossibleDisplayInfoMapperTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/PossibleDisplayInfoMapperTests.java @@ -19,7 +19,6 @@ package com.android.server.wm; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.FLAG_PRESENTATION; import static android.view.Surface.ROTATION_0; -import static android.view.Surface.ROTATION_180; import static com.google.common.truth.Truth.assertThat; @@ -90,8 +89,8 @@ public class PossibleDisplayInfoMapperTests extends WindowTestsBase { mDisplayInfoMapper.updatePossibleDisplayInfos(DEFAULT_DISPLAY); Set displayInfos = mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY); - // An entry for each possible rotation, for a display that can be in a single state. - assertThat(displayInfos.size()).isEqualTo(4); + // An entry for rotation 0, for a display that can be in a single state. + assertThat(displayInfos.size()).isEqualTo(1); assertPossibleDisplayInfoEntries(displayInfos, mDefaultDisplayInfo); } @@ -100,7 +99,7 @@ public class PossibleDisplayInfoMapperTests extends WindowTestsBase { mPossibleDisplayInfo.add(mDefaultDisplayInfo); mDisplayInfoMapper.updatePossibleDisplayInfos(DEFAULT_DISPLAY); - assertThat(mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY).size()).isEqualTo(4); + assertThat(mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY).size()).isEqualTo(1); // Add another display layout to the set of supported states. mPossibleDisplayInfo.add(mSecondDisplayInfo); @@ -116,12 +115,12 @@ public class PossibleDisplayInfoMapperTests extends WindowTestsBase { defaultDisplayInfos.add(di); } } - // An entry for each possible rotation, for the default display. - assertThat(defaultDisplayInfos).hasSize(4); + // An entry for rotation 0, for the default display. + assertThat(defaultDisplayInfos).hasSize(1); assertPossibleDisplayInfoEntries(defaultDisplayInfos, mDefaultDisplayInfo); - // An entry for each possible rotation, for the second display. - assertThat(secondDisplayInfos).hasSize(4); + // An entry for rotation 0, for the second display. + assertThat(secondDisplayInfos).hasSize(1); assertPossibleDisplayInfoEntries(secondDisplayInfos, mSecondDisplayInfo); } @@ -130,7 +129,7 @@ public class PossibleDisplayInfoMapperTests extends WindowTestsBase { mPossibleDisplayInfo.add(mDefaultDisplayInfo); mDisplayInfoMapper.updatePossibleDisplayInfos(DEFAULT_DISPLAY); - assertThat(mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY).size()).isEqualTo(4); + assertThat(mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY).size()).isEqualTo(1); // Add another display to a different group. mSecondDisplayInfo.displayId = DEFAULT_DISPLAY + 1; @@ -139,14 +138,14 @@ public class PossibleDisplayInfoMapperTests extends WindowTestsBase { mDisplayInfoMapper.updatePossibleDisplayInfos(mSecondDisplayInfo.displayId); Set displayInfos = mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY); - // An entry for each possible rotation, for the default display. - assertThat(displayInfos).hasSize(4); + // An entry for rotation 0, for the default display. + assertThat(displayInfos).hasSize(1); assertPossibleDisplayInfoEntries(displayInfos, mDefaultDisplayInfo); Set secondStateEntries = mDisplayInfoMapper.getPossibleDisplayInfos(mSecondDisplayInfo.displayId); - // An entry for each possible rotation, for the second display. - assertThat(secondStateEntries).hasSize(4); + // An entry for rotation 0, for the second display. + assertThat(secondStateEntries).hasSize(1); assertPossibleDisplayInfoEntries(secondStateEntries, mSecondDisplayInfo); } @@ -160,23 +159,10 @@ public class PossibleDisplayInfoMapperTests extends WindowTestsBase { private static void assertPossibleDisplayInfoEntries(Set displayInfos, DisplayInfo expectedDisplayInfo) { - boolean[] seenEveryRotation = new boolean[4]; for (DisplayInfo displayInfo : displayInfos) { - final int rotation = displayInfo.rotation; - seenEveryRotation[rotation] = true; assertThat(displayInfo.displayId).isEqualTo(expectedDisplayInfo.displayId); - assertEqualsRotatedDisplayInfo(displayInfo, expectedDisplayInfo); - } - assertThat(seenEveryRotation).isEqualTo(new boolean[]{true, true, true, true}); - } - - private static void assertEqualsRotatedDisplayInfo(DisplayInfo actual, DisplayInfo expected) { - if (actual.rotation == ROTATION_0 || actual.rotation == ROTATION_180) { - assertThat(actual.logicalWidth).isEqualTo(expected.logicalWidth); - assertThat(actual.logicalHeight).isEqualTo(expected.logicalHeight); - } else { - assertThat(actual.logicalWidth).isEqualTo(expected.logicalHeight); - assertThat(actual.logicalHeight).isEqualTo(expected.logicalWidth); + assertThat(displayInfo.logicalWidth).isEqualTo(expectedDisplayInfo.logicalWidth); + assertThat(displayInfo.logicalHeight).isEqualTo(expectedDisplayInfo.logicalHeight); } } }