Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c7f1d37c authored by Santos Cordon's avatar Santos Cordon
Browse files

Clean up LogicalDisplayMapper

Organize the code so that it is easier to read.
Add lots of display-related tests.

Test: atest com.android.server.display
Bug: 168208162
Change-Id: I72a4eb6677e346f615e4730f4888d56333645844
parent 55908812
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -810,6 +810,9 @@ public final class DisplayInfo implements Parcelable {
        if ((flags & Display.FLAG_TRUSTED) != 0) {
            result.append(", FLAG_TRUSTED");
        }
        if ((flags & Display.FLAG_OWN_DISPLAY_GROUP) != 0) {
            result.append(", FLAG_OWN_DISPLAY_GROUP");
        }
        return result.toString();
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -673,6 +673,15 @@
        -->
    </integer-array>

    <!-- The device states (supplied by DeviceStateManager) that should be treated as unfolded by
         the display fold controller. Default is empty. -->
    <integer-array name="config_unfoldedDeviceStates">
        <!-- Example:
        <item>3</item>
        <item>4</item>
        -->
    </integer-array>

    <!-- Indicate the display area rect for foldable devices in folded state. -->
    <string name="config_foldedArea"></string>

+1 −0
Original line number Diff line number Diff line
@@ -3762,6 +3762,7 @@

  <!-- For Foldables -->
  <java-symbol type="array" name="config_foldedDeviceStates" />
  <java-symbol type="array" name="config_unfoldedDeviceStates" />
  <java-symbol type="string" name="config_foldedArea" />

  <java-symbol type="array" name="config_disableApksUnlessMatchedSku_apk_list" />
+17 −15
Original line number Diff line number Diff line
@@ -39,10 +39,6 @@ class DeviceStateToLayoutMap {

    public static final int STATE_DEFAULT = DeviceStateManager.INVALID_DEVICE_STATE;

    // TODO - b/168208162 - Remove these when we check in static definitions for layouts
    public static final int STATE_FOLDED = 100;
    public static final int STATE_UNFOLDED = 101;

    private final SparseArray<Layout> mLayoutMap = new SparseArray<>();

    DeviceStateToLayoutMap(Context context) {
@@ -68,7 +64,7 @@ class DeviceStateToLayoutMap {
        return layout;
    }

    private Layout create(int state) {
    private Layout createLayout(int state) {
        if (mLayoutMap.contains(state)) {
            Slog.e(TAG, "Attempted to create a second layout for state " + state);
            return null;
@@ -79,10 +75,12 @@ class DeviceStateToLayoutMap {
        return layout;
    }

    /**
     * Loads config.xml-specified folded configurations for foldable devices.
     */
    private void loadFoldedDisplayConfig(Context context) {
        final String[] strDisplayIds = context.getResources().getStringArray(
                com.android.internal.R.array.config_internalFoldedPhysicalDisplayIds);

        if (strDisplayIds.length != 2 || TextUtils.isEmpty(strDisplayIds[0])
                || TextUtils.isEmpty(strDisplayIds[1])) {
            Slog.w(TAG, "Folded display configuration invalid: [" + Arrays.toString(strDisplayIds)
@@ -103,19 +101,23 @@ class DeviceStateToLayoutMap {

        final int[] foldedDeviceStates = context.getResources().getIntArray(
                com.android.internal.R.array.config_foldedDeviceStates);
        final int[] unfoldedDeviceStates = context.getResources().getIntArray(
                com.android.internal.R.array.config_unfoldedDeviceStates);
        // Only add folded states if folded state config is not empty
        if (foldedDeviceStates.length == 0) {
        if (foldedDeviceStates.length == 0 || unfoldedDeviceStates.length == 0) {
            return;
        }

        for (int state : foldedDeviceStates) {
            // Create the folded state layout
        final Layout foldedLayout = create(STATE_FOLDED);
        foldedLayout.createDisplayLocked(
            createLayout(state).createDisplayLocked(
                    DisplayAddress.fromPhysicalDisplayId(displayIds[0]), true /*isDefault*/);
        }

        for (int state : unfoldedDeviceStates) {
            // Create the unfolded state layout
        final Layout unfoldedLayout = create(STATE_UNFOLDED);
        unfoldedLayout.createDisplayLocked(
            createLayout(state).createDisplayLocked(
                    DisplayAddress.fromPhysicalDisplayId(displayIds[1]), true /*isDefault*/);
        }
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ public class DisplayGroup {
    private final List<LogicalDisplay> mDisplays = new ArrayList<>();
    private final int mGroupId;

    private int mChangeCount;

    DisplayGroup(int groupId) {
        mGroupId = groupId;
    }
@@ -45,11 +47,16 @@ public class DisplayGroup {
     * @param display the {@link LogicalDisplay} to add to the Group
     */
    void addDisplayLocked(LogicalDisplay display) {
        if (!mDisplays.contains(display)) {
        if (!containsLocked(display)) {
            mChangeCount++;
            mDisplays.add(display);
        }
    }

    boolean containsLocked(LogicalDisplay display) {
        return mDisplays.contains(display);
    }

    /**
     * Removes the provided {@code display} from the Group.
     *
@@ -57,6 +64,7 @@ public class DisplayGroup {
     * @return {@code true} if the {@code display} was removed; otherwise {@code false}
     */
    boolean removeDisplayLocked(LogicalDisplay display) {
        mChangeCount++;
        return mDisplays.remove(display);
    }

@@ -65,6 +73,11 @@ public class DisplayGroup {
        return mDisplays.isEmpty();
    }

    /** Returns a count of the changes made to this display group. */
    int getChangeCountLocked() {
        return mChangeCount;
    }

    /** Returns the number of {@link LogicalDisplay LogicalDisplays} in the Group. */
    int getSizeLocked() {
        return mDisplays.size();
Loading