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

Commit abf969a4 authored by Danae Savvidi's avatar Danae Savvidi
Browse files

Update getBasicChangedGroups method to handle comparisons of subgroups.

Can now compare two DisplayInfo objects based on as subset of fields.

Bug: 435146856
Bug: 431149632
Flag: com.android.server.display.feature.flags.enable_logging_for_display_events
Test: atest DisplayInfoTest
Change-Id: I01fbab0321f5bc459335bb8cf8dfd3629dc068c9
parent bd3fea96
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.internal.display.BrightnessSynchronizer;
import com.android.server.display.feature.flags.Flags;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.Objects;

/**
@@ -958,6 +959,23 @@ public final class DisplayInfo implements Parcelable {
        }
    }

    /**
     * Same as {@link #getBasicChangedGroups(DisplayInfo)} except here we only compare
     * the specified groups i.e. if changes happen to other groups they will not be identified.
     */
    public int getBasicChangedGroups(@Nullable DisplayInfo other,
            EnumSet<DisplayInfoGroup> groupsToCompare) {
        int changedGroups = 0;

        for (DisplayInfoGroup group : groupsToCompare) {
            if (hasDisplayInfoGroupChanged(group, other)) {
                changedGroups |= group.getMask();
            }
        }

        return changedGroups;
    }

    /**
     * Compares this {@link DisplayInfo} with another for "basic" changes
     * (i.e. when a {@link android.hardware.display.DisplayManager.EVENT_TYPE_DISPLAY_CHANGED}
@@ -970,15 +988,7 @@ public final class DisplayInfo implements Parcelable {
     * changed. If none have changed, the bitmask will be 0.
     */
    public int getBasicChangedGroups(@Nullable DisplayInfo other) {
        int changedGroups = 0;

        for (DisplayInfoGroup group : DisplayInfoGroup.values()) {
            if (hasDisplayInfoGroupChanged(group, other)) {
                changedGroups |= group.getMask();
            }
        }

        return changedGroups;
        return getBasicChangedGroups(other, EnumSet.allOf(DisplayInfoGroup.class));
    }

    /**
+64 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.EnumSet;

@RunWith(AndroidJUnit4.class)
@SmallTest
public class DisplayInfoTest {
@@ -318,6 +320,68 @@ public class DisplayInfoTest {
        );
    }

    @Test
    public void getBasicChangedGroups_otherIsNull_returns_some_groups() {
        DisplayInfo base = new DisplayInfo();
        int changedGroups = base.getBasicChangedGroups(null,
                EnumSet.of(DisplayInfo.DisplayInfoGroup.BASIC_PROPERTIES,
                        DisplayInfo.DisplayInfoGroup.ORIENTATION_AND_ROTATION));
        assertThat(changedGroups).isEqualTo(
                DisplayInfo.DisplayInfoGroup.BASIC_PROPERTIES.getMask()
                        | DisplayInfo.DisplayInfoGroup.ORIENTATION_AND_ROTATION.getMask()
        );
    }

    @Test
    public void getBasicChangedGroups_withGroupsToCompare_singleGroupChanged_Matches() {
        DisplayInfo base = new DisplayInfo();
        DisplayInfo other = new DisplayInfo(base);
        other.logicalWidth = 1440; // Belongs to DIMENSIONS_AND_SHAPES

        EnumSet<DisplayInfo.DisplayInfoGroup> groupsToCompare =
                EnumSet.of(DisplayInfo.DisplayInfoGroup.DIMENSIONS_AND_SHAPES);

        int changedGroups = base.getBasicChangedGroups(other, groupsToCompare);

        assertThat(changedGroups)
                .isEqualTo(DisplayInfo.DisplayInfoGroup.DIMENSIONS_AND_SHAPES.getMask());
    }

    @Test
    public void getBasicChangedGroups_withGroupsToCompare_singleGroupChanged_DoesNotMatch() {
        DisplayInfo base = new DisplayInfo();
        DisplayInfo other = new DisplayInfo(base);
        other.logicalWidth = 1440; // Belongs to DIMENSIONS_AND_SHAPES

        // Compare a different group that has not changed.
        EnumSet<DisplayInfo.DisplayInfoGroup> groupsToCompare =
                EnumSet.of(DisplayInfo.DisplayInfoGroup.BASIC_PROPERTIES);

        int changedGroups = base.getBasicChangedGroups(other, groupsToCompare);

        assertThat(changedGroups).isEqualTo(0);
    }

    @Test
    public void getBasicChangedGroups_withGroupsToCompare_multipleGroupsChanged() {
        DisplayInfo base = new DisplayInfo();
        DisplayInfo other = new DisplayInfo(base);
        other.flags = Display.FLAG_PRIVATE; // BASIC_PROPERTIES
        other.rotation = Surface.ROTATION_180; // ORIENTATION_AND_ROTATION
        other.state = Display.STATE_VR; // STATE

        // Only compare two of the three changed groups.
        EnumSet<DisplayInfo.DisplayInfoGroup> groupsToCompare =
                EnumSet.of(DisplayInfo.DisplayInfoGroup.BASIC_PROPERTIES,
                        DisplayInfo.DisplayInfoGroup.STATE);

        int changedGroups = base.getBasicChangedGroups(other, groupsToCompare);

        assertThat(changedGroups).isEqualTo(
                DisplayInfo.DisplayInfoGroup.BASIC_PROPERTIES.getMask()
                        | DisplayInfo.DisplayInfoGroup.STATE.getMask());
    }

    private void setSupportedModes(DisplayInfo info, Display.Mode[] modes, int modeId) {
        info.supportedModes = modes;
        info.modeId = modeId;
+1 −1
Original line number Diff line number Diff line
@@ -6469,7 +6469,7 @@ public final class DisplayManagerService extends SystemService {
                        .setDeviceStateLocked(deviceState);
            }
        }
    };
    }

    private static class BrightnessPair {
        public float brightness;
+0 −1
Original line number Diff line number Diff line
@@ -1096,7 +1096,6 @@ final class LogicalDisplay {
     * Swap the underlying {@link DisplayDevice} with the specified LogicalDisplay.
     *
     * @param targetDisplay The display with which to swap display-devices.
     * @return {@code true} if the displays were swapped, {@code false} otherwise.
     */
    public void swapDisplaysLocked(@NonNull LogicalDisplay targetDisplay) {
        final DisplayDevice oldTargetDevice =