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

Commit 6f1cac99 authored by Ady Abraham's avatar Ady Abraham
Browse files

DisplayManagerGlobal: suppress redundant onDisplayChanged events

With Frame Rate Override enabled, an app could get an onDisplayChanged
events which seems redundant. An example would be:
1. Display changed refresh rate to 60Hz - onDisplayChanged was called
2. App's frame rate override changed to 60Hz - onDisplayChanged was called

To avoid sending these redundant events, DisplayManagerGlobal caches
the last DisplayInfo that was reported to the app and based on it it
decides whether to send the event or not.

Bug: 184588343
Test: atest SetFrameRateTest
Test: atest FrameRateOverrideHostTest
Change-Id: I97c7b2b9a799424998b1b717a4311d3d08b3178f
parent 27ec0f6a
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -391,8 +391,9 @@ public final class DisplayManagerGlobal {
            }

            final int numListeners = mDisplayListeners.size();
            DisplayInfo info = getDisplayInfo(displayId);
            for (int i = 0; i < numListeners; i++) {
                mDisplayListeners.get(i).sendDisplayEvent(displayId, event);
                mDisplayListeners.get(i).sendDisplayEvent(displayId, event, info);
            }
            if (event == EVENT_DISPLAY_CHANGED && mDispatchNativeCallbacks) {
                // Choreographer only supports a single display, so only dispatch refresh rate
@@ -894,6 +895,8 @@ public final class DisplayManagerGlobal {
        public final DisplayListener mListener;
        public long mEventsMask;

        private final DisplayInfo mDisplayInfo = new DisplayInfo();

        DisplayListenerDelegate(DisplayListener listener, @NonNull Looper looper,
                @EventsMask long eventsMask) {
            super(looper, null, true /*async*/);
@@ -901,8 +904,8 @@ public final class DisplayManagerGlobal {
            mEventsMask = eventsMask;
        }

        public void sendDisplayEvent(int displayId, @DisplayEvent int event) {
            Message msg = obtainMessage(event, displayId, 0);
        public void sendDisplayEvent(int displayId, @DisplayEvent int event, DisplayInfo info) {
            Message msg = obtainMessage(event, displayId, 0, info);
            sendMessage(msg);
        }

@@ -924,8 +927,12 @@ public final class DisplayManagerGlobal {
                    break;
                case EVENT_DISPLAY_CHANGED:
                    if ((mEventsMask & DisplayManager.EVENT_FLAG_DISPLAY_CHANGED) != 0) {
                        DisplayInfo newInfo = (DisplayInfo) msg.obj;
                        if (newInfo != null && !newInfo.equals(mDisplayInfo)) {
                            mDisplayInfo.copyFrom(newInfo);
                            mListener.onDisplayChanged(msg.arg1);
                        }
                    }
                    break;
                case EVENT_DISPLAY_REMOVED:
                    if ((mEventsMask & DisplayManager.EVENT_FLAG_DISPLAY_REMOVED) != 0) {
+1 −1
Original line number Diff line number Diff line
@@ -377,7 +377,7 @@ public final class DisplayInfo implements Parcelable {
                && ownerUid == other.ownerUid
                && Objects.equals(ownerPackageName, other.ownerPackageName)
                && removeMode == other.removeMode
                && refreshRateOverride == other.refreshRateOverride
                && getRefreshRate() == other.getRefreshRate()
                && brightnessMinimum == other.brightnessMinimum
                && brightnessMaximum == other.brightnessMaximum
                && brightnessDefault == other.brightnessDefault
+3 −0
Original line number Diff line number Diff line
@@ -346,6 +346,9 @@ public class DisplayManagerServiceTest {
        DisplayDeviceInfo displayDeviceInfo = new DisplayDeviceInfo();
        displayDeviceInfo.width = 100;
        displayDeviceInfo.height = 200;
        displayDeviceInfo.supportedModes = new Display.Mode[1];
        displayDeviceInfo.supportedModes[0] = new Display.Mode(1, 100, 200, 60f);
        displayDeviceInfo.modeId = 1;
        final Rect zeroRect = new Rect();
        displayDeviceInfo.displayCutout = new DisplayCutout(
                Insets.of(0, 10, 0, 0),
+3 −0
Original line number Diff line number Diff line
@@ -239,6 +239,9 @@ public class LogicalDisplayMapperTest {
        displayDeviceInfo.width = width;
        displayDeviceInfo.height = height;
        displayDeviceInfo.flags = flags;
        displayDeviceInfo.supportedModes = new Display.Mode[1];
        displayDeviceInfo.supportedModes[0] = new Display.Mode(1, width, height, 60f);
        displayDeviceInfo.modeId = 1;
        displayDeviceInfo.address = new DisplayAddressImpl();
        return device;
    }