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

Commit 015bb4ed authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Explicit registraton to refresh rate

To not break the applications using the older sdks, we are implicitly
subscribing the clients to refresh rate events when the
registerDisplayListener(DisplayListener, Handler) API is called.
However, in other variants on registerDisplayListener, we now expect
users to explicitly subscribe to EVENT_TYPE_DISPLAY_REFRESH_RATE to get
the refresh rate updates.

Bug: 387962667
Flag: EXEMPT trivial change
Test: atest DisplayEventTest
Change-Id: Iab8b3b1d8dc455e7fccf2b1ee1a65b8f175e81c3
parent e965e05a
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -641,6 +641,9 @@ public final class DisplayManager {
     * is triggered whenever the properties of a {@link android.view.Display}, such as size,
     * state, density are modified.
     *
     * This event is not triggered for refresh rate changes as they can change very often.
     * To monitor refresh rate changes, subscribe to {@link EVENT_TYPE_DISPLAY_REFRESH_RATE}.
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     *
     */
@@ -839,6 +842,9 @@ public final class DisplayManager {
     * Registers a display listener to receive notifications about when
     * displays are added, removed or changed.
     *
     * We encourage to use {@link #registerDisplayListener(Executor, long, DisplayListener)}
     * instead to subscribe for explicit events of interest
     *
     * @param listener The listener to register.
     * @param handler The handler on which the listener should be invoked, or null
     * if the listener should be invoked on the calling thread's looper.
@@ -847,7 +853,9 @@ public final class DisplayManager {
     */
    public void registerDisplayListener(DisplayListener listener, Handler handler) {
        registerDisplayListener(listener, handler, EVENT_TYPE_DISPLAY_ADDED
                | EVENT_TYPE_DISPLAY_CHANGED | EVENT_TYPE_DISPLAY_REMOVED);
                | EVENT_TYPE_DISPLAY_CHANGED
                | EVENT_TYPE_DISPLAY_REFRESH_RATE
                | EVENT_TYPE_DISPLAY_REMOVED);
    }

    /**
+6 −12
Original line number Diff line number Diff line
@@ -1766,29 +1766,23 @@ public final class DisplayManagerGlobal {
        }

        if ((eventFlags & DisplayManager.EVENT_TYPE_DISPLAY_CHANGED) != 0) {
            // For backward compatibility, a client subscribing to
            // DisplayManager.EVENT_FLAG_DISPLAY_CHANGED will be enrolled to both Basic and
            // RR changes
            baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_BASIC_CHANGED
                    | INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE;
            baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_BASIC_CHANGED;
        }

        if ((eventFlags
                & DisplayManager.EVENT_TYPE_DISPLAY_REMOVED) != 0) {
        if ((eventFlags & DisplayManager.EVENT_TYPE_DISPLAY_REMOVED) != 0) {
            baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_REMOVED;
        }

        if (Flags.displayListenerPerformanceImprovements()) {
        if ((eventFlags & DisplayManager.EVENT_TYPE_DISPLAY_REFRESH_RATE) != 0) {
            baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE;
        }

        if (Flags.displayListenerPerformanceImprovements()) {
            if ((eventFlags & DisplayManager.EVENT_TYPE_DISPLAY_STATE) != 0) {
                baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_STATE;
            }
        }


        return baseEventMask;
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -307,8 +307,10 @@ public class DisplayManagerGlobalTest {
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_ADDED,
                mDisplayManagerGlobal
                        .mapFiltersToInternalEventFlag(DisplayManager.EVENT_TYPE_DISPLAY_ADDED, 0));
        assertEquals(DISPLAY_CHANGE_EVENTS, mDisplayManagerGlobal
                .mapFiltersToInternalEventFlag(DisplayManager.EVENT_TYPE_DISPLAY_CHANGED, 0));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_BASIC_CHANGED,
                mDisplayManagerGlobal
                        .mapFiltersToInternalEventFlag(DisplayManager.EVENT_TYPE_DISPLAY_CHANGED,
                                0));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_REMOVED,
                mDisplayManagerGlobal.mapFiltersToInternalEventFlag(
                        DisplayManager.EVENT_TYPE_DISPLAY_REMOVED, 0));