Only return ROTATION_0 for WM#getPossibleMaximumWindowMetrics
Do not return every rotation for window metrics. Bug: 228288352 Test: atest WmTests:PossibleDisplayInfoMapperTests Change-Id: I756b079bfce09cf618500f3d07547ec94ac60694
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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<DisplayInfo> 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<DisplayInfo> 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<DisplayInfo> 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<DisplayInfo> 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<DisplayInfo> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<DisplayInfo> 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<DisplayInfo> 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<DisplayInfo> 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<DisplayInfo> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user