Loading services/core/java/com/android/server/display/DisplayManagerService.java +12 −35 Original line number Diff line number Diff line Loading @@ -3652,44 +3652,21 @@ public final class DisplayManagerService extends SystemService { @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. // For each of supported device states, retrieve the display layout of that state, // and return all of the DisplayInfos (one per state) for the given display id. if (mDeviceStateManager == null) { Slog.w(TAG, "Can't get supported states since DeviceStateManager not ready"); } else { return possibleInfo; } final int[] supportedStates = mDeviceStateManager.getSupportedStateIdentifiers(); DisplayInfo displayInfo; for (int state : supportedStates) { possibleInfo.addAll( mLogicalDisplayMapper.getDisplayInfoForStateLocked(state, displayId, displayGroupId)); displayInfo = mLogicalDisplayMapper.getDisplayInfoForStateLocked(state, displayId); if (displayInfo != null) { possibleInfo.add(displayInfo); } } return possibleInfo; Loading services/core/java/com/android/server/display/LogicalDisplayMapper.java +34 −49 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.display; import static android.view.Display.DEFAULT_DISPLAY; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.Context; import android.hardware.devicestate.DeviceStateManager; import android.os.Handler; Loading @@ -28,7 +29,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; Loading @@ -43,7 +43,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; /** Loading Loading @@ -304,58 +303,44 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener { } /** * 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. * Returns the {@link DisplayInfo} for this device state, indicated by the given display id. The * DisplayInfo represents the attributes of the indicated display in the layout associated with * this state. This is used to get display information for various displays in various states; * e.g. to help apps preload resources for the possible display states. * * @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. * @param displayId the display id to retrieve * @return {@code null} if no corresponding {@link DisplayInfo} could be found, or the * {@link DisplayInfo} with a matching display id. */ public Set<DisplayInfo> getDisplayInfoForStateLocked(int deviceState, int displayId, int groupId) { Set<DisplayInfo> displayInfos = new ArraySet<>(); @Nullable public DisplayInfo getDisplayInfoForStateLocked(int deviceState, int displayId) { // Retrieve the layout for this particular state. 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 (layout == null) { return null; } // 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); // Retrieve the details of the given display within this layout. Layout.Display display = layout.getById(displayId); if (display == null) { return null; } // Retrieve the display info for the display that matches the display id. final DisplayDevice device = mDisplayDeviceRepo.getByAddressLocked(display.getAddress()); if (device == null) { Slog.w(TAG, "The display device (" + address + "), is not available" + " for the display state " + deviceState); continue; Slog.w(TAG, "The display device (" + display.getAddress() + "), is not available" + " for the display state " + mDeviceState); return null; } // Find or create the LogicalDisplay to map the DisplayDevice to. final int logicalDisplayId = displayLayout.getLogicalDisplayId(); final LogicalDisplay logicalDisplay = getDisplayLocked(logicalDisplayId); LogicalDisplay logicalDisplay = getDisplayLocked(device, /* includeDisabled= */ true); 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; Slog.w(TAG, "The logical display associated with address (" + display.getAddress() + "), is not available for the display state " + mDeviceState); return null; } // 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 displayInfo = new DisplayInfo(logicalDisplay.getDisplayInfoLocked()); displayInfo.displayId = displayId; displayInfos.add(displayInfo); } return displayInfos; return displayInfo; } public void dumpLocked(PrintWriter pw) { Loading services/tests/servicestests/src/com/android/server/display/LogicalDisplayMapperTest.java +127 −89 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
services/core/java/com/android/server/display/DisplayManagerService.java +12 −35 Original line number Diff line number Diff line Loading @@ -3652,44 +3652,21 @@ public final class DisplayManagerService extends SystemService { @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. // For each of supported device states, retrieve the display layout of that state, // and return all of the DisplayInfos (one per state) for the given display id. if (mDeviceStateManager == null) { Slog.w(TAG, "Can't get supported states since DeviceStateManager not ready"); } else { return possibleInfo; } final int[] supportedStates = mDeviceStateManager.getSupportedStateIdentifiers(); DisplayInfo displayInfo; for (int state : supportedStates) { possibleInfo.addAll( mLogicalDisplayMapper.getDisplayInfoForStateLocked(state, displayId, displayGroupId)); displayInfo = mLogicalDisplayMapper.getDisplayInfoForStateLocked(state, displayId); if (displayInfo != null) { possibleInfo.add(displayInfo); } } return possibleInfo; Loading
services/core/java/com/android/server/display/LogicalDisplayMapper.java +34 −49 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.display; import static android.view.Display.DEFAULT_DISPLAY; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.Context; import android.hardware.devicestate.DeviceStateManager; import android.os.Handler; Loading @@ -28,7 +29,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; Loading @@ -43,7 +43,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; /** Loading Loading @@ -304,58 +303,44 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener { } /** * 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. * Returns the {@link DisplayInfo} for this device state, indicated by the given display id. The * DisplayInfo represents the attributes of the indicated display in the layout associated with * this state. This is used to get display information for various displays in various states; * e.g. to help apps preload resources for the possible display states. * * @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. * @param displayId the display id to retrieve * @return {@code null} if no corresponding {@link DisplayInfo} could be found, or the * {@link DisplayInfo} with a matching display id. */ public Set<DisplayInfo> getDisplayInfoForStateLocked(int deviceState, int displayId, int groupId) { Set<DisplayInfo> displayInfos = new ArraySet<>(); @Nullable public DisplayInfo getDisplayInfoForStateLocked(int deviceState, int displayId) { // Retrieve the layout for this particular state. 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 (layout == null) { return null; } // 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); // Retrieve the details of the given display within this layout. Layout.Display display = layout.getById(displayId); if (display == null) { return null; } // Retrieve the display info for the display that matches the display id. final DisplayDevice device = mDisplayDeviceRepo.getByAddressLocked(display.getAddress()); if (device == null) { Slog.w(TAG, "The display device (" + address + "), is not available" + " for the display state " + deviceState); continue; Slog.w(TAG, "The display device (" + display.getAddress() + "), is not available" + " for the display state " + mDeviceState); return null; } // Find or create the LogicalDisplay to map the DisplayDevice to. final int logicalDisplayId = displayLayout.getLogicalDisplayId(); final LogicalDisplay logicalDisplay = getDisplayLocked(logicalDisplayId); LogicalDisplay logicalDisplay = getDisplayLocked(device, /* includeDisabled= */ true); 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; Slog.w(TAG, "The logical display associated with address (" + display.getAddress() + "), is not available for the display state " + mDeviceState); return null; } // 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 displayInfo = new DisplayInfo(logicalDisplay.getDisplayInfoLocked()); displayInfo.displayId = displayId; displayInfos.add(displayInfo); } return displayInfos; return displayInfo; } public void dumpLocked(PrintWriter pw) { Loading
services/tests/servicestests/src/com/android/server/display/LogicalDisplayMapperTest.java +127 −89 File changed.Preview size limit exceeded, changes collapsed. Show changes