Merge "[DO NOT MERGE] Revert "[2/n] Display stack provides DisplayInfos"" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b0a2e9f742
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.hardware.devicestate;
|
||||
|
||||
/**
|
||||
* Device state manager local system service interface.
|
||||
*
|
||||
* @hide Only for use within the system server.
|
||||
*/
|
||||
public abstract class DeviceStateManagerInternal {
|
||||
|
||||
/** Returns the list of currently supported device state identifiers. */
|
||||
public abstract int[] getSupportedStateIdentifiers();
|
||||
}
|
||||
@@ -35,7 +35,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Display manager local system service interface.
|
||||
@@ -129,14 +128,6 @@ public abstract class DisplayManagerInternal {
|
||||
*/
|
||||
public abstract DisplayInfo getDisplayInfo(int displayId);
|
||||
|
||||
/**
|
||||
* Returns a set of DisplayInfo, for the states that may be assumed by either the given display,
|
||||
* or any other display within that display's group.
|
||||
*
|
||||
* @param displayId The logical display id to fetch DisplayInfo for.
|
||||
*/
|
||||
public abstract Set<DisplayInfo> getPossibleDisplayInfo(int displayId);
|
||||
|
||||
/**
|
||||
* Returns the position of the display's projection.
|
||||
*
|
||||
|
||||
@@ -374,8 +374,8 @@ public final class WindowManagerImpl implements WindowManager {
|
||||
currentDisplayInfo = possibleDisplayInfos.get(i);
|
||||
|
||||
// Calculate max bounds for this rotation and state.
|
||||
Rect maxBounds = new Rect(0, 0, currentDisplayInfo.logicalWidth,
|
||||
currentDisplayInfo.logicalHeight);
|
||||
Rect maxBounds = new Rect(0, 0, currentDisplayInfo.getNaturalWidth(),
|
||||
currentDisplayInfo.getNaturalHeight());
|
||||
|
||||
// Calculate insets for the rotated max bounds.
|
||||
// TODO(181127261) calculate insets for each display rotation and state.
|
||||
|
||||
@@ -31,7 +31,6 @@ import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.hardware.devicestate.DeviceStateInfo;
|
||||
import android.hardware.devicestate.DeviceStateManager;
|
||||
import android.hardware.devicestate.DeviceStateManagerInternal;
|
||||
import android.hardware.devicestate.IDeviceStateManager;
|
||||
import android.hardware.devicestate.IDeviceStateManagerCallback;
|
||||
import android.os.Binder;
|
||||
@@ -162,7 +161,6 @@ public final class DeviceStateManagerService extends SystemService {
|
||||
@Override
|
||||
public void onStart() {
|
||||
publishBinderService(Context.DEVICE_STATE_SERVICE, mBinderService);
|
||||
publishLocalService(DeviceStateManagerInternal.class, new LocalService());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -241,6 +239,13 @@ public final class DeviceStateManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the list of currently supported device state identifiers. */
|
||||
private int[] getSupportedStateIdentifiers() {
|
||||
synchronized (mLock) {
|
||||
return getSupportedStateIdentifiersLocked();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the list of currently supported device state identifiers. */
|
||||
private int[] getSupportedStateIdentifiersLocked() {
|
||||
int[] supportedStates = new int[mDeviceStates.size()];
|
||||
@@ -843,14 +848,4 @@ public final class DeviceStateManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Implementation of {@link DeviceStateManagerInternal} published as a local service. */
|
||||
private final class LocalService extends DeviceStateManagerInternal {
|
||||
@Override
|
||||
public int[] getSupportedStateIdentifiers() {
|
||||
synchronized (mLock) {
|
||||
return getSupportedStateIdentifiersLocked();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ import android.graphics.Point;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
import android.hardware.devicestate.DeviceStateManager;
|
||||
import android.hardware.devicestate.DeviceStateManagerInternal;
|
||||
import android.hardware.display.AmbientBrightnessDayStats;
|
||||
import android.hardware.display.BrightnessChangeEvent;
|
||||
import android.hardware.display.BrightnessConfiguration;
|
||||
@@ -132,7 +131,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Consumer;
|
||||
@@ -212,7 +210,6 @@ public final class DisplayManagerService extends SystemService {
|
||||
private WindowManagerInternal mWindowManagerInternal;
|
||||
private InputManagerInternal mInputManagerInternal;
|
||||
private IMediaProjectionManager mProjectionService;
|
||||
private DeviceStateManagerInternal mDeviceStateManager;
|
||||
private int[] mUserDisabledHdrTypes = {};
|
||||
private boolean mAreUserDisabledHdrTypesAllowed = true;
|
||||
|
||||
@@ -560,9 +557,10 @@ public final class DisplayManagerService extends SystemService {
|
||||
mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
|
||||
mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
|
||||
|
||||
mDeviceStateManager = LocalServices.getService(DeviceStateManagerInternal.class);
|
||||
mContext.getSystemService(DeviceStateManager.class).registerCallback(
|
||||
new HandlerExecutor(mHandler), new DeviceStateListener());
|
||||
DeviceStateManager deviceStateManager =
|
||||
mContext.getSystemService(DeviceStateManager.class);
|
||||
deviceStateManager.registerCallback(new HandlerExecutor(mHandler),
|
||||
new DeviceStateListener());
|
||||
|
||||
scheduleTraversalLocked(false);
|
||||
}
|
||||
@@ -3291,53 +3289,6 @@ public final class DisplayManagerService extends SystemService {
|
||||
return getDisplayInfoInternal(displayId, Process.myUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<DisplayInfo> getPossibleDisplayInfo(int displayId) {
|
||||
synchronized (mSyncRoot) {
|
||||
// Retrieve the group associated with this display id.
|
||||
final int displayGroupId =
|
||||
mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(displayId);
|
||||
if (displayGroupId == Display.INVALID_DISPLAY_GROUP) {
|
||||
Slog.w(TAG,
|
||||
"Can't get possible display info since display group for " + displayId
|
||||
+ " does not exist");
|
||||
return new ArraySet<>();
|
||||
}
|
||||
|
||||
// Assume any display in this group can be swapped out for the given display id.
|
||||
Set<DisplayInfo> possibleInfo = new ArraySet<>();
|
||||
final DisplayGroup group = mLogicalDisplayMapper.getDisplayGroupLocked(
|
||||
displayGroupId);
|
||||
for (int i = 0; i < group.getSizeLocked(); i++) {
|
||||
final int id = group.getIdLocked(i);
|
||||
final LogicalDisplay logical = mLogicalDisplayMapper.getDisplayLocked(id);
|
||||
if (logical == null) {
|
||||
Slog.w(TAG,
|
||||
"Can't get possible display info since logical display for "
|
||||
+ "display id " + id + " does not exist, as part of group "
|
||||
+ displayGroupId);
|
||||
} else {
|
||||
possibleInfo.add(logical.getDisplayInfoLocked());
|
||||
}
|
||||
}
|
||||
|
||||
// For the supported device states, retrieve the DisplayInfos for the logical
|
||||
// display layout.
|
||||
if (mDeviceStateManager == null) {
|
||||
Slog.w(TAG, "Can't get supported states since DeviceStateManager not ready");
|
||||
} else {
|
||||
final int[] supportedStates =
|
||||
mDeviceStateManager.getSupportedStateIdentifiers();
|
||||
for (int state : supportedStates) {
|
||||
possibleInfo.addAll(
|
||||
mLogicalDisplayMapper.getDisplayInfoForStateLocked(state, displayId,
|
||||
displayGroupId));
|
||||
}
|
||||
}
|
||||
return possibleInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getDisplayPosition(int displayId) {
|
||||
synchronized (mSyncRoot) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import android.os.PowerManager;
|
||||
import android.os.SystemClock;
|
||||
import android.os.SystemProperties;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.IndentingPrintWriter;
|
||||
import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
@@ -41,7 +40,6 @@ import com.android.server.display.layout.Layout;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@@ -267,61 +265,6 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
|
||||
return mDisplayGroups.get(groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set of {@link DisplayInfo} for this device state, only fetching the info that is
|
||||
* part of the same display group as the provided display id. The DisplayInfo represent the
|
||||
* logical display layouts possible for the given device state.
|
||||
*
|
||||
* @param deviceState the state to query possible layouts for
|
||||
* @param displayId the display id to apply to all displays within the group
|
||||
* @param groupId the display group to filter display info for. Must be the same group as
|
||||
* the display with the provided display id.
|
||||
*/
|
||||
public Set<DisplayInfo> getDisplayInfoForStateLocked(int deviceState, int displayId,
|
||||
int groupId) {
|
||||
Set<DisplayInfo> displayInfos = new ArraySet<>();
|
||||
final Layout layout = mDeviceStateToLayoutMap.get(deviceState);
|
||||
final int layoutSize = layout.size();
|
||||
for (int i = 0; i < layoutSize; i++) {
|
||||
Layout.Display displayLayout = layout.getAt(i);
|
||||
if (displayLayout == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the underlying display-device we want to use for this display
|
||||
// doesn't exist, then skip it. This can happen at startup as display-devices
|
||||
// trickle in one at a time. When the new display finally shows up, the layout is
|
||||
// recalculated so that the display is properly added to the current layout.
|
||||
final DisplayAddress address = displayLayout.getAddress();
|
||||
final DisplayDevice device = mDisplayDeviceRepo.getByAddressLocked(address);
|
||||
if (device == null) {
|
||||
Slog.w(TAG, "The display device (" + address + "), is not available"
|
||||
+ " for the display state " + deviceState);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find or create the LogicalDisplay to map the DisplayDevice to.
|
||||
final int logicalDisplayId = displayLayout.getLogicalDisplayId();
|
||||
final LogicalDisplay logicalDisplay = getDisplayLocked(logicalDisplayId);
|
||||
if (logicalDisplay == null) {
|
||||
Slog.w(TAG, "The logical display (" + address + "), is not available"
|
||||
+ " for the display state " + deviceState);
|
||||
continue;
|
||||
}
|
||||
final DisplayInfo temp = logicalDisplay.getDisplayInfoLocked();
|
||||
DisplayInfo displayInfo = new DisplayInfo(temp);
|
||||
if (displayInfo.displayGroupId != groupId) {
|
||||
// Ignore any displays not in the provided group.
|
||||
continue;
|
||||
}
|
||||
// A display in the same group can be swapped out at any point, so set the display id
|
||||
// for all results to the provided display id.
|
||||
displayInfo.displayId = displayId;
|
||||
displayInfos.add(displayInfo);
|
||||
}
|
||||
return displayInfos;
|
||||
}
|
||||
|
||||
public void dumpLocked(PrintWriter pw) {
|
||||
pw.println("LogicalDisplayMapper:");
|
||||
IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Maintains a map of possible {@link DisplayInfo} for displays and states that may be encountered
|
||||
* on a device. This is not guaranteed to include all possible device states for all displays.
|
||||
*
|
||||
* By 'possible', this class only handles device states for displays and display groups it is
|
||||
* currently aware of. It can not handle all eventual states the system may enter, for example, if
|
||||
* an external display is added, or a new display is added to the group.
|
||||
*/
|
||||
public class PossibleDisplayInfoMapper {
|
||||
private static final String TAG = "PossibleDisplayInfoMapper";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private final DisplayManagerInternal mDisplayManagerInternal;
|
||||
|
||||
/**
|
||||
* Map of all logical displays, indexed by logical display id.
|
||||
* Each logical display has multiple entries, one for each possible rotation and device
|
||||
* state.
|
||||
*
|
||||
* Emptied and re-calculated when a display is added, removed, or changed.
|
||||
*/
|
||||
private final SparseArray<Set<DisplayInfo>> mDisplayInfos = new SparseArray<>();
|
||||
|
||||
PossibleDisplayInfoMapper(DisplayManagerInternal displayManagerInternal) {
|
||||
mDisplayManagerInternal = displayManagerInternal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns, for the given displayId, a set of display infos. Set contains the possible rotations
|
||||
* for each supported device state.
|
||||
*/
|
||||
public Set<DisplayInfo> getPossibleDisplayInfos(int displayId) {
|
||||
// Update display infos before returning, since any cached values would have been removed
|
||||
// in response to any display event. This model avoids re-computing the cache for every
|
||||
// display change event (which occurs extremely frequently in the normal usage of the
|
||||
// device).
|
||||
updatePossibleDisplayInfos(displayId);
|
||||
if (!mDisplayInfos.contains(displayId)) {
|
||||
return new ArraySet<>();
|
||||
}
|
||||
return Set.copyOf(mDisplayInfos.get(displayId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the possible {@link DisplayInfo}s for the given display, by calculating the
|
||||
* DisplayInfo for each rotation 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 "
|
||||
+ displayInfos.size() + " on display " + displayId);
|
||||
}
|
||||
updateDisplayInfos(displayInfos);
|
||||
}
|
||||
|
||||
/**
|
||||
* For the given displayId, removes all possible {@link DisplayInfo}.
|
||||
*/
|
||||
public void removePossibleDisplayInfos(int displayId) {
|
||||
if (DEBUG && mDisplayInfos.get(displayId) != null) {
|
||||
Slog.v(TAG, "onDisplayRemoved, remove all DisplayInfo (" + mDisplayInfos.get(
|
||||
displayId).size() + ") with id " + displayId);
|
||||
}
|
||||
mDisplayInfos.remove(displayId);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
// Combine all results under the logical display id.
|
||||
Set<DisplayInfo> priorDisplayInfos = mDisplayInfos.get(di.displayId, new ArraySet<>());
|
||||
priorDisplayInfos.addAll(rotatedDisplayInfos);
|
||||
mDisplayInfos.put(di.displayId, priorDisplayInfos);
|
||||
}
|
||||
}
|
||||
|
||||
private static DisplayInfo applyRotation(DisplayInfo displayInfo,
|
||||
@Surface.Rotation int rotation) {
|
||||
DisplayInfo updatedDisplayInfo = new DisplayInfo();
|
||||
updatedDisplayInfo.copyFrom(displayInfo);
|
||||
updatedDisplayInfo.rotation = rotation;
|
||||
|
||||
final int naturalWidth = updatedDisplayInfo.getNaturalWidth();
|
||||
final int naturalHeight = updatedDisplayInfo.getNaturalHeight();
|
||||
updatedDisplayInfo.logicalWidth = naturalWidth;
|
||||
updatedDisplayInfo.logicalHeight = naturalHeight;
|
||||
return updatedDisplayInfo;
|
||||
}
|
||||
}
|
||||
@@ -2587,9 +2587,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|
||||
if (mService.isBooted() || mService.isBooting()) {
|
||||
startSystemDecorations(display);
|
||||
}
|
||||
// Drop any cached DisplayInfos associated with this display id - the values are now
|
||||
// out of date given this display added event.
|
||||
mWmService.mPossibleDisplayInfoMapper.removePossibleDisplayInfos(displayId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2610,8 +2607,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|
||||
if (displayContent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
displayContent.remove();
|
||||
mWmService.mPossibleDisplayInfoMapper.removePossibleDisplayInfos(displayId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2623,9 +2620,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|
||||
if (displayContent != null) {
|
||||
displayContent.onDisplayChanged();
|
||||
}
|
||||
// Drop any cached DisplayInfos associated with this display id - the values are now
|
||||
// out of date given this display changed event.
|
||||
mWmService.mPossibleDisplayInfoMapper.removePossibleDisplayInfos(displayId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ import static android.provider.Settings.Global.DEVELOPMENT_RENDER_SHADOWS_IN_COM
|
||||
import static android.provider.Settings.Global.DEVELOPMENT_WM_DISPLAY_SETTINGS_PATH;
|
||||
import static android.view.Display.DEFAULT_DISPLAY;
|
||||
import static android.view.Display.INVALID_DISPLAY;
|
||||
import static android.view.Surface.ROTATION_0;
|
||||
import static android.view.Surface.ROTATION_270;
|
||||
import static android.view.WindowManager.DISPLAY_IME_POLICY_FALLBACK_DISPLAY;
|
||||
import static android.view.WindowManager.DISPLAY_IME_POLICY_LOCAL;
|
||||
import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
|
||||
@@ -330,11 +332,13 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -1063,10 +1067,6 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
|
||||
final HighRefreshRateDenylist mHighRefreshRateDenylist;
|
||||
|
||||
// Maintainer of a collection of all possible DisplayInfo for all configurations of the
|
||||
// logical displays.
|
||||
final PossibleDisplayInfoMapper mPossibleDisplayInfoMapper;
|
||||
|
||||
// If true, only the core apps and services are being launched because the device
|
||||
// is in a special boot mode, such as being encrypted or waiting for a decryption password.
|
||||
// For example, when this flag is true, there will be no wallpaper service.
|
||||
@@ -1242,7 +1242,6 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
|
||||
mInputManager = inputManager; // Must be before createDisplayContentLocked.
|
||||
mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
|
||||
mPossibleDisplayInfoMapper = new PossibleDisplayInfoMapper(mDisplayManagerInternal);
|
||||
|
||||
mSurfaceControlFactory = surfaceControlFactory;
|
||||
mTransactionFactory = transactionFactory;
|
||||
@@ -8583,10 +8582,23 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
+ " for getPossibleMaximumWindowMetrics");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
// TODO(181127261) DisplayInfo should be pushed from DisplayManager.
|
||||
final DisplayContent dc = mRoot.getDisplayContent(displayId);
|
||||
if (dc == null) {
|
||||
Slog.e(TAG, "Invalid displayId " + displayId
|
||||
+ " for getPossibleMaximumWindowMetrics");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// Retrieve the DisplayInfo for all possible rotations across all possible display
|
||||
// layouts.
|
||||
return List.copyOf(mPossibleDisplayInfoMapper.getPossibleDisplayInfos(displayId));
|
||||
// TODO(181127261) DisplayManager should provide a DisplayInfo for each rotation
|
||||
DisplayInfo currentDisplayInfo = dc.getDisplayInfo();
|
||||
Set<DisplayInfo> displayInfoSet = new HashSet<>();
|
||||
for (int rotation = ROTATION_0; rotation <= ROTATION_270; rotation++) {
|
||||
currentDisplayInfo.rotation = rotation;
|
||||
// TODO(181127261) Retrieve the device state from display stack.
|
||||
displayInfoSet.add(new DisplayInfo(currentDisplayInfo));
|
||||
}
|
||||
return new ArrayList<DisplayInfo>(displayInfoSet);
|
||||
}
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(origId);
|
||||
|
||||
@@ -18,8 +18,6 @@ package com.android.server.devicestate;
|
||||
|
||||
import static android.hardware.devicestate.DeviceStateManager.INVALID_DEVICE_STATE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
@@ -183,10 +181,8 @@ public final class DeviceStateManagerServiceTest {
|
||||
assertEquals(mService.getCommittedState(), Optional.of(DEFAULT_DEVICE_STATE));
|
||||
assertEquals(mService.getPendingState(), Optional.empty());
|
||||
assertEquals(mService.getBaseState(), Optional.of(DEFAULT_DEVICE_STATE));
|
||||
assertThat(mService.getSupportedStates()).asList().containsExactly(DEFAULT_DEVICE_STATE,
|
||||
OTHER_DEVICE_STATE);
|
||||
|
||||
mProvider.notifySupportedDeviceStates(new DeviceState[]{DEFAULT_DEVICE_STATE});
|
||||
mProvider.notifySupportedDeviceStates(new DeviceState[]{ DEFAULT_DEVICE_STATE });
|
||||
flushHandler();
|
||||
|
||||
// The current committed and requests states do not change because the current state remains
|
||||
@@ -194,10 +190,9 @@ public final class DeviceStateManagerServiceTest {
|
||||
assertEquals(mService.getCommittedState(), Optional.of(DEFAULT_DEVICE_STATE));
|
||||
assertEquals(mService.getPendingState(), Optional.empty());
|
||||
assertEquals(mService.getBaseState(), Optional.of(DEFAULT_DEVICE_STATE));
|
||||
assertThat(mService.getSupportedStates()).asList().containsExactly(DEFAULT_DEVICE_STATE);
|
||||
|
||||
assertArrayEquals(callback.getLastNotifiedInfo().supportedStates,
|
||||
new int[]{DEFAULT_DEVICE_STATE.getIdentifier()});
|
||||
new int[] { DEFAULT_DEVICE_STATE.getIdentifier() });
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -212,11 +207,9 @@ public final class DeviceStateManagerServiceTest {
|
||||
assertEquals(mService.getCommittedState(), Optional.of(DEFAULT_DEVICE_STATE));
|
||||
assertEquals(mService.getPendingState(), Optional.empty());
|
||||
assertEquals(mService.getBaseState(), Optional.of(DEFAULT_DEVICE_STATE));
|
||||
assertThat(mService.getSupportedStates()).asList().containsExactly(DEFAULT_DEVICE_STATE,
|
||||
OTHER_DEVICE_STATE);
|
||||
|
||||
mProvider.notifySupportedDeviceStates(new DeviceState[]{DEFAULT_DEVICE_STATE,
|
||||
OTHER_DEVICE_STATE});
|
||||
mProvider.notifySupportedDeviceStates(new DeviceState[]{ DEFAULT_DEVICE_STATE,
|
||||
OTHER_DEVICE_STATE });
|
||||
flushHandler();
|
||||
|
||||
// The current committed and requests states do not change because the current state remains
|
||||
@@ -224,8 +217,6 @@ public final class DeviceStateManagerServiceTest {
|
||||
assertEquals(mService.getCommittedState(), Optional.of(DEFAULT_DEVICE_STATE));
|
||||
assertEquals(mService.getPendingState(), Optional.empty());
|
||||
assertEquals(mService.getBaseState(), Optional.of(DEFAULT_DEVICE_STATE));
|
||||
assertThat(mService.getSupportedStates()).asList().containsExactly(DEFAULT_DEVICE_STATE,
|
||||
OTHER_DEVICE_STATE);
|
||||
|
||||
// The callback wasn't notified about a change in supported states as the states have not
|
||||
// changed.
|
||||
|
||||
@@ -16,17 +16,12 @@
|
||||
|
||||
package com.android.server.display;
|
||||
|
||||
import static android.view.Display.DEFAULT_DISPLAY;
|
||||
import static android.view.Display.DEFAULT_DISPLAY_GROUP;
|
||||
|
||||
import static com.android.server.display.DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED;
|
||||
import static com.android.server.display.DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED;
|
||||
import static com.android.server.display.DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED;
|
||||
import static com.android.server.display.LogicalDisplayMapper.LOGICAL_DISPLAY_EVENT_ADDED;
|
||||
import static com.android.server.display.LogicalDisplayMapper.LOGICAL_DISPLAY_EVENT_REMOVED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -60,7 +55,6 @@ import org.mockito.MockitoAnnotations;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
@SmallTest
|
||||
@Presubmit
|
||||
@@ -129,14 +123,14 @@ public class LogicalDisplayMapperTest {
|
||||
// add
|
||||
LogicalDisplay displayAdded = add(device);
|
||||
assertEquals(info(displayAdded).address, info(device).address);
|
||||
assertEquals(DEFAULT_DISPLAY, id(displayAdded));
|
||||
assertEquals(Display.DEFAULT_DISPLAY, id(displayAdded));
|
||||
|
||||
// remove
|
||||
mDisplayDeviceRepo.onDisplayDeviceEvent(device, DISPLAY_DEVICE_EVENT_REMOVED);
|
||||
verify(mListenerMock).onLogicalDisplayEventLocked(
|
||||
mDisplayCaptor.capture(), eq(LOGICAL_DISPLAY_EVENT_REMOVED));
|
||||
LogicalDisplay displayRemoved = mDisplayCaptor.getValue();
|
||||
assertEquals(DEFAULT_DISPLAY, id(displayRemoved));
|
||||
assertEquals(Display.DEFAULT_DISPLAY, id(displayRemoved));
|
||||
assertEquals(displayAdded, displayRemoved);
|
||||
}
|
||||
|
||||
@@ -161,11 +155,11 @@ public class LogicalDisplayMapperTest {
|
||||
|
||||
LogicalDisplay display1 = add(device1);
|
||||
assertEquals(info(display1).address, info(device1).address);
|
||||
assertNotEquals(DEFAULT_DISPLAY, id(display1));
|
||||
assertNotEquals(Display.DEFAULT_DISPLAY, id(display1));
|
||||
|
||||
LogicalDisplay display2 = add(device2);
|
||||
assertEquals(info(display2).address, info(device2).address);
|
||||
assertEquals(DEFAULT_DISPLAY, id(display2));
|
||||
assertEquals(Display.DEFAULT_DISPLAY, id(display2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -177,12 +171,12 @@ public class LogicalDisplayMapperTest {
|
||||
|
||||
LogicalDisplay display1 = add(device1);
|
||||
assertEquals(info(display1).address, info(device1).address);
|
||||
assertEquals(DEFAULT_DISPLAY, id(display1));
|
||||
assertEquals(Display.DEFAULT_DISPLAY, id(display1));
|
||||
|
||||
LogicalDisplay display2 = add(device2);
|
||||
assertEquals(info(display2).address, info(device2).address);
|
||||
// Despite the flags, we can only have one default display
|
||||
assertNotEquals(DEFAULT_DISPLAY, id(display2));
|
||||
assertNotEquals(Display.DEFAULT_DISPLAY, id(display2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,67 +189,7 @@ public class LogicalDisplayMapperTest {
|
||||
int [] ids = mLogicalDisplayMapper.getDisplayIdsLocked(Process.SYSTEM_UID);
|
||||
assertEquals(3, ids.length);
|
||||
Arrays.sort(ids);
|
||||
assertEquals(DEFAULT_DISPLAY, ids[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDisplayInfoForStateLocked_oneDisplayGroup_internalType() {
|
||||
add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
|
||||
DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY));
|
||||
add(createDisplayDevice(Display.TYPE_INTERNAL, 200, 800,
|
||||
DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY));
|
||||
add(createDisplayDevice(Display.TYPE_INTERNAL, 700, 800,
|
||||
DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY));
|
||||
|
||||
Set<DisplayInfo> displayInfos = mLogicalDisplayMapper.getDisplayInfoForStateLocked(
|
||||
DeviceStateToLayoutMap.STATE_DEFAULT, DEFAULT_DISPLAY, DEFAULT_DISPLAY_GROUP);
|
||||
assertThat(displayInfos.size()).isEqualTo(3);
|
||||
for (DisplayInfo displayInfo : displayInfos) {
|
||||
assertThat(displayInfo.displayId).isEqualTo(DEFAULT_DISPLAY);
|
||||
assertThat(displayInfo.displayGroupId).isEqualTo(DEFAULT_DISPLAY_GROUP);
|
||||
assertThat(displayInfo.logicalWidth).isAnyOf(600, 200, 700);
|
||||
assertThat(displayInfo.logicalHeight).isEqualTo(800);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDisplayInfoForStateLocked_oneDisplayGroup_differentTypes() {
|
||||
add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
|
||||
DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY));
|
||||
add(createDisplayDevice(Display.TYPE_INTERNAL, 200, 800,
|
||||
DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY));
|
||||
add(createDisplayDevice(Display.TYPE_EXTERNAL, 700, 800,
|
||||
DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY));
|
||||
|
||||
Set<DisplayInfo> displayInfos = mLogicalDisplayMapper.getDisplayInfoForStateLocked(
|
||||
DeviceStateToLayoutMap.STATE_DEFAULT, DEFAULT_DISPLAY, DEFAULT_DISPLAY_GROUP);
|
||||
assertThat(displayInfos.size()).isEqualTo(2);
|
||||
for (DisplayInfo displayInfo : displayInfos) {
|
||||
assertThat(displayInfo.displayId).isEqualTo(DEFAULT_DISPLAY);
|
||||
assertThat(displayInfo.displayGroupId).isEqualTo(DEFAULT_DISPLAY_GROUP);
|
||||
assertThat(displayInfo.logicalWidth).isAnyOf(600, 200);
|
||||
assertThat(displayInfo.logicalHeight).isEqualTo(800);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDisplayInfoForStateLocked_multipleDisplayGroups_defaultGroup() {
|
||||
add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
|
||||
DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY));
|
||||
add(createDisplayDevice(Display.TYPE_INTERNAL, 200, 800,
|
||||
DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY));
|
||||
add(createDisplayDevice(Display.TYPE_VIRTUAL, 700, 800,
|
||||
DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP));
|
||||
|
||||
Set<DisplayInfo> displayInfos = mLogicalDisplayMapper.getDisplayInfoForStateLocked(
|
||||
DeviceStateToLayoutMap.STATE_DEFAULT, DEFAULT_DISPLAY, DEFAULT_DISPLAY_GROUP);
|
||||
assertThat(displayInfos.size()).isEqualTo(2);
|
||||
for (DisplayInfo displayInfo : displayInfos) {
|
||||
assertThat(displayInfo.displayId).isEqualTo(DEFAULT_DISPLAY);
|
||||
assertThat(displayInfo.displayGroupId).isEqualTo(DEFAULT_DISPLAY_GROUP);
|
||||
assertThat(displayInfo.logicalWidth).isAnyOf(600, 200);
|
||||
assertThat(displayInfo.logicalHeight).isEqualTo(800);
|
||||
}
|
||||
assertEquals(Display.DEFAULT_DISPLAY, ids[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -265,11 +199,11 @@ public class LogicalDisplayMapperTest {
|
||||
LogicalDisplay display2 = add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800, 0));
|
||||
LogicalDisplay display3 = add(createDisplayDevice(Display.TYPE_VIRTUAL, 600, 800, 0));
|
||||
|
||||
assertEquals(DEFAULT_DISPLAY_GROUP,
|
||||
assertEquals(Display.DEFAULT_DISPLAY_GROUP,
|
||||
mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(id(display1)));
|
||||
assertEquals(DEFAULT_DISPLAY_GROUP,
|
||||
assertEquals(Display.DEFAULT_DISPLAY_GROUP,
|
||||
mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(id(display2)));
|
||||
assertEquals(DEFAULT_DISPLAY_GROUP,
|
||||
assertEquals(Display.DEFAULT_DISPLAY_GROUP,
|
||||
mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(id(display3)));
|
||||
}
|
||||
|
||||
@@ -284,11 +218,11 @@ public class LogicalDisplayMapperTest {
|
||||
DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP);
|
||||
LogicalDisplay display3 = add(device3);
|
||||
|
||||
assertEquals(DEFAULT_DISPLAY_GROUP,
|
||||
assertEquals(Display.DEFAULT_DISPLAY_GROUP,
|
||||
mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(id(display1)));
|
||||
assertEquals(DEFAULT_DISPLAY_GROUP,
|
||||
assertEquals(Display.DEFAULT_DISPLAY_GROUP,
|
||||
mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(id(display2)));
|
||||
assertNotEquals(DEFAULT_DISPLAY_GROUP,
|
||||
assertNotEquals(Display.DEFAULT_DISPLAY_GROUP,
|
||||
mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(id(display3)));
|
||||
|
||||
// Now switch it back to the default group by removing the flag and issuing an update
|
||||
@@ -297,7 +231,7 @@ public class LogicalDisplayMapperTest {
|
||||
mDisplayDeviceRepo.onDisplayDeviceEvent(device3, DISPLAY_DEVICE_EVENT_CHANGED);
|
||||
|
||||
// Verify the new group is correct.
|
||||
assertEquals(DEFAULT_DISPLAY_GROUP,
|
||||
assertEquals(Display.DEFAULT_DISPLAY_GROUP,
|
||||
mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(id(display3)));
|
||||
}
|
||||
|
||||
@@ -353,14 +287,14 @@ public class LogicalDisplayMapperTest {
|
||||
// add
|
||||
LogicalDisplay displayAdded = add(device);
|
||||
assertEquals(info(displayAdded).address, info(device).address);
|
||||
assertNotEquals(DEFAULT_DISPLAY, id(displayAdded));
|
||||
assertNotEquals(Display.DEFAULT_DISPLAY, id(displayAdded));
|
||||
|
||||
// remove
|
||||
mDisplayDeviceRepo.onDisplayDeviceEvent(device, DISPLAY_DEVICE_EVENT_REMOVED);
|
||||
verify(mListenerMock).onLogicalDisplayEventLocked(
|
||||
mDisplayCaptor.capture(), eq(LOGICAL_DISPLAY_EVENT_REMOVED));
|
||||
LogicalDisplay displayRemoved = mDisplayCaptor.getValue();
|
||||
assertNotEquals(DEFAULT_DISPLAY, id(displayRemoved));
|
||||
assertNotEquals(Display.DEFAULT_DISPLAY, id(displayRemoved));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.util.ArraySet;
|
||||
import android.view.DisplayInfo;
|
||||
|
||||
import androidx.test.filters.MediumTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for {@link PossibleDisplayInfoMapper}.
|
||||
*
|
||||
* Build/Install/Run:
|
||||
* atest WmTests:PossibleDisplayInfoMapperTests
|
||||
*/
|
||||
@MediumTest
|
||||
@Presubmit
|
||||
@RunWith(WindowTestRunner.class)
|
||||
public class PossibleDisplayInfoMapperTests extends WindowTestsBase {
|
||||
|
||||
private PossibleDisplayInfoMapper mDisplayInfoMapper;
|
||||
private final Set<DisplayInfo> mPossibleDisplayInfo = new ArraySet<>();
|
||||
private DisplayInfo mDefaultDisplayInfo;
|
||||
private DisplayInfo mSecondDisplayInfo;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mDisplayInfoMapper = mWm.mPossibleDisplayInfoMapper;
|
||||
final DisplayInfo baseDisplayInfo = mWm.mRoot.getDisplayContent(
|
||||
DEFAULT_DISPLAY).getDisplayInfo();
|
||||
when(mWm.mDisplayManagerInternal.getPossibleDisplayInfo(anyInt())).thenReturn(
|
||||
mPossibleDisplayInfo);
|
||||
|
||||
mDefaultDisplayInfo = new DisplayInfo(baseDisplayInfo);
|
||||
initializeDisplayInfo(mDefaultDisplayInfo, DEFAULT_DISPLAY, new Rect(0, 0, 500, 800));
|
||||
mSecondDisplayInfo = new DisplayInfo(baseDisplayInfo);
|
||||
// Use the same display id for any display in the same group, due to the assumption that
|
||||
// any display in the same grouped can be swapped out for each other (while maintaining the
|
||||
// display id).
|
||||
initializeDisplayInfo(mSecondDisplayInfo, DEFAULT_DISPLAY, new Rect(0, 0, 600, 1600));
|
||||
mSecondDisplayInfo.flags |= FLAG_PRESENTATION;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitialization_isEmpty() {
|
||||
// Empty after initializing.
|
||||
assertThat(mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY)).isEmpty();
|
||||
|
||||
// Still empty after updating.
|
||||
mDisplayInfoMapper.updatePossibleDisplayInfos(DEFAULT_DISPLAY);
|
||||
assertThat(mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePossibleDisplayInfos_singleDisplay() {
|
||||
mPossibleDisplayInfo.add(mDefaultDisplayInfo);
|
||||
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);
|
||||
assertPossibleDisplayInfoEntries(displayInfos, mDefaultDisplayInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePossibleDisplayInfos_secondDisplayAdded_sameGroup() {
|
||||
mPossibleDisplayInfo.add(mDefaultDisplayInfo);
|
||||
mDisplayInfoMapper.updatePossibleDisplayInfos(DEFAULT_DISPLAY);
|
||||
|
||||
assertThat(mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY).size()).isEqualTo(4);
|
||||
|
||||
// Add another display layout to the set of supported states.
|
||||
mPossibleDisplayInfo.add(mSecondDisplayInfo);
|
||||
mDisplayInfoMapper.updatePossibleDisplayInfos(DEFAULT_DISPLAY);
|
||||
|
||||
Set<DisplayInfo> displayInfos = mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY);
|
||||
Set<DisplayInfo> defaultDisplayInfos = new ArraySet<>();
|
||||
Set<DisplayInfo> secondDisplayInfos = new ArraySet<>();
|
||||
for (DisplayInfo di : displayInfos) {
|
||||
if ((di.flags & FLAG_PRESENTATION) != 0) {
|
||||
secondDisplayInfos.add(di);
|
||||
} else {
|
||||
defaultDisplayInfos.add(di);
|
||||
}
|
||||
}
|
||||
// An entry for each possible rotation, for the default display.
|
||||
assertThat(defaultDisplayInfos).hasSize(4);
|
||||
assertPossibleDisplayInfoEntries(defaultDisplayInfos, mDefaultDisplayInfo);
|
||||
|
||||
// An entry for each possible rotation, for the second display.
|
||||
assertThat(secondDisplayInfos).hasSize(4);
|
||||
assertPossibleDisplayInfoEntries(secondDisplayInfos, mSecondDisplayInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePossibleDisplayInfos_secondDisplayAdded_differentGroup() {
|
||||
mPossibleDisplayInfo.add(mDefaultDisplayInfo);
|
||||
mDisplayInfoMapper.updatePossibleDisplayInfos(DEFAULT_DISPLAY);
|
||||
|
||||
assertThat(mDisplayInfoMapper.getPossibleDisplayInfos(DEFAULT_DISPLAY).size()).isEqualTo(4);
|
||||
|
||||
// Add another display to a different group.
|
||||
mSecondDisplayInfo.displayId = DEFAULT_DISPLAY + 1;
|
||||
mSecondDisplayInfo.displayGroupId = mDefaultDisplayInfo.displayGroupId + 1;
|
||||
mPossibleDisplayInfo.add(mSecondDisplayInfo);
|
||||
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);
|
||||
assertPossibleDisplayInfoEntries(displayInfos, mDefaultDisplayInfo);
|
||||
|
||||
Set<DisplayInfo> secondStateEntries =
|
||||
mDisplayInfoMapper.getPossibleDisplayInfos(mSecondDisplayInfo.displayId);
|
||||
// An entry for each possible rotation, for the second display.
|
||||
assertThat(secondStateEntries).hasSize(4);
|
||||
assertPossibleDisplayInfoEntries(secondStateEntries, mSecondDisplayInfo);
|
||||
}
|
||||
|
||||
private static void initializeDisplayInfo(DisplayInfo outDisplayInfo, int displayId,
|
||||
Rect logicalBounds) {
|
||||
outDisplayInfo.displayId = displayId;
|
||||
outDisplayInfo.rotation = ROTATION_0;
|
||||
outDisplayInfo.logicalWidth = logicalBounds.width();
|
||||
outDisplayInfo.logicalHeight = logicalBounds.height();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user