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

Commit 8a29d28c authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Changing eventFlags to eventFilter

This is to address the API council feedback

Bug: 379313664
Flag: EXEMPT minor change
Test: EXEMPT minor change
Change-Id: Ifa8d052bdf91356612e72a3a85de7efc39081bb0
parent a708f2bc
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -20781,11 +20781,11 @@ package android.hardware.display {
    method @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public void registerDisplayListener(@NonNull java.util.concurrent.Executor, long, @NonNull android.hardware.display.DisplayManager.DisplayListener);
    method public void unregisterDisplayListener(android.hardware.display.DisplayManager.DisplayListener);
    field public static final String DISPLAY_CATEGORY_PRESENTATION = "android.hardware.display.category.PRESENTATION";
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_FLAG_DISPLAY_ADDED = 1L; // 0x1L
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_FLAG_DISPLAY_CHANGED = 4L; // 0x4L
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_FLAG_DISPLAY_REFRESH_RATE = 8L; // 0x8L
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_FLAG_DISPLAY_REMOVED = 2L; // 0x2L
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_FLAG_DISPLAY_STATE = 16L; // 0x10L
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_TYPE_DISPLAY_ADDED = 1L; // 0x1L
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_TYPE_DISPLAY_CHANGED = 4L; // 0x4L
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_TYPE_DISPLAY_REFRESH_RATE = 8L; // 0x8L
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_TYPE_DISPLAY_REMOVED = 2L; // 0x2L
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_TYPE_DISPLAY_STATE = 16L; // 0x10L
    field public static final int MATCH_CONTENT_FRAMERATE_ALWAYS = 2; // 0x2
    field public static final int MATCH_CONTENT_FRAMERATE_NEVER = 0; // 0x0
    field public static final int MATCH_CONTENT_FRAMERATE_SEAMLESSS_ONLY = 1; // 0x1
+51 −42
Original line number Diff line number Diff line
@@ -578,73 +578,82 @@ public final class DisplayManager {
    /**
     * @hide
     */
    @LongDef(flag = true, prefix = {"EVENT_FLAG_"}, value = {
            EVENT_FLAG_DISPLAY_ADDED,
            EVENT_FLAG_DISPLAY_CHANGED,
            EVENT_FLAG_DISPLAY_REMOVED,
            EVENT_FLAG_DISPLAY_REFRESH_RATE,
            EVENT_FLAG_DISPLAY_STATE
    @LongDef(flag = true, prefix = {"EVENT_TYPE_"}, value = {
            EVENT_TYPE_DISPLAY_ADDED,
            EVENT_TYPE_DISPLAY_CHANGED,
            EVENT_TYPE_DISPLAY_REMOVED,
            EVENT_TYPE_DISPLAY_REFRESH_RATE,
            EVENT_TYPE_DISPLAY_STATE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface EventFlag {}
    public @interface EventType {}

    /**
     * @hide
     */
    @LongDef(flag = true, prefix = {"PRIVATE_EVENT_FLAG_"}, value = {
            PRIVATE_EVENT_FLAG_DISPLAY_BRIGHTNESS,
            PRIVATE_EVENT_FLAG_HDR_SDR_RATIO_CHANGED,
            PRIVATE_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED,
    @LongDef(flag = true, prefix = {"PRIVATE_EVENT_TYPE_"}, value = {
            PRIVATE_EVENT_TYPE_DISPLAY_BRIGHTNESS,
            PRIVATE_EVENT_TYPE_HDR_SDR_RATIO_CHANGED,
            PRIVATE_EVENT_TYPE_DISPLAY_CONNECTION_CHANGED,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface PrivateEventFlag {}
    public @interface PrivateEventType {}

    /**
     * Event type for when a new display is added.
     * Event type for when a new display is added. This notification is sent
     * through the {@link DisplayListener#onDisplayAdded} callback method
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     *
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public static final long EVENT_FLAG_DISPLAY_ADDED = 1L << 0;
    public static final long EVENT_TYPE_DISPLAY_ADDED = 1L << 0;

    /**
     * Event type for when a display is removed.
     * Event type for when a display is removed. This notification is sent
     * through the {@link DisplayListener#onDisplayRemoved} callback method
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     *
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public static final long EVENT_FLAG_DISPLAY_REMOVED = 1L << 1;
    public static final long EVENT_TYPE_DISPLAY_REMOVED = 1L << 1;

    /**
     * Event type for when a display is changed.
     * Event type for when a display is changed. {@link DisplayListener#onDisplayChanged} callback
     * is triggered whenever the properties of a {@link android.view.Display}, such as size,
     * state, density are modified.
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     *
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public static final long EVENT_FLAG_DISPLAY_CHANGED = 1L << 2;

    public static final long EVENT_TYPE_DISPLAY_CHANGED = 1L << 2;

    /**
     * Event flag to register for a display's refresh rate changes.
     * Event type for when a display's refresh rate changes.
     * {@link DisplayListener#onDisplayChanged} callback is triggered whenever the refresh rate
     * of the display changes. New refresh rate values can be retrieved via
     * {@link Display#getRefreshRate()}.
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public static final long EVENT_FLAG_DISPLAY_REFRESH_RATE = 1L << 3;
    public static final long EVENT_TYPE_DISPLAY_REFRESH_RATE = 1L << 3;

    /**
     * Event flag to register for a display state changes.
     * Event type for when a display state changes.
     * {@link DisplayListener#onDisplayChanged} callback is triggered whenever the state
     * of the display changes. New state values can be retrieved via
     * {@link Display#getState()}.
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public static final long EVENT_FLAG_DISPLAY_STATE = 1L << 4;
    public static final long EVENT_TYPE_DISPLAY_STATE = 1L << 4;

    /**
     * Event flag to register for a display's brightness changes. This notification is sent
     * Event type to register for a display's brightness changes. This notification is sent
     * through the {@link DisplayListener#onDisplayChanged} callback method. New brightness
     * values can be retrieved via {@link android.view.Display#getBrightnessInfo()}.
     *
@@ -652,10 +661,10 @@ public final class DisplayManager {
     *
     * @hide
     */
    public static final long PRIVATE_EVENT_FLAG_DISPLAY_BRIGHTNESS = 1L << 0;
    public static final long PRIVATE_EVENT_TYPE_DISPLAY_BRIGHTNESS = 1L << 0;

    /**
     * Event flag to register for a display's hdr/sdr ratio changes. This notification is sent
     * Event type to register for a display's hdr/sdr ratio changes. This notification is sent
     * through the {@link DisplayListener#onDisplayChanged} callback method. New hdr/sdr
     * values can be retrieved via {@link Display#getHdrSdrRatio()}.
     *
@@ -665,15 +674,15 @@ public final class DisplayManager {
     *
     * @hide
     */
    public static final long PRIVATE_EVENT_FLAG_HDR_SDR_RATIO_CHANGED = 1L << 1;
    public static final long PRIVATE_EVENT_TYPE_HDR_SDR_RATIO_CHANGED = 1L << 1;

    /**
     * Event flag to register for a display's connection changed.
     * Event type to register for a display's connection changed.
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     * @hide
     */
    public static final long PRIVATE_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED = 1L << 2;
    public static final long PRIVATE_EVENT_TYPE_DISPLAY_CONNECTION_CHANGED = 1L << 2;


    /** @hide */
@@ -800,8 +809,8 @@ public final class DisplayManager {
     * @see #unregisterDisplayListener
     */
    public void registerDisplayListener(DisplayListener listener, Handler handler) {
        registerDisplayListener(listener, handler, EVENT_FLAG_DISPLAY_ADDED
                | EVENT_FLAG_DISPLAY_CHANGED | EVENT_FLAG_DISPLAY_REMOVED);
        registerDisplayListener(listener, handler, EVENT_TYPE_DISPLAY_ADDED
                | EVENT_TYPE_DISPLAY_CHANGED | EVENT_TYPE_DISPLAY_REMOVED);
    }

    /**
@@ -810,7 +819,7 @@ public final class DisplayManager {
     * @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.
     * @param eventFlags A bitmask of the event types for which this listener is subscribed.
     * @param eventFilter A bitmask of the event types for which this listener is subscribed.
     *
     * @see #registerDisplayListener(DisplayListener, Handler)
     * @see #unregisterDisplayListener
@@ -818,9 +827,9 @@ public final class DisplayManager {
     * @hide
     */
    public void registerDisplayListener(@NonNull DisplayListener listener,
            @Nullable Handler handler, @EventFlag long eventFlags) {
            @Nullable Handler handler, @EventType long eventFilter) {
        mGlobal.registerDisplayListener(listener, handler,
                mGlobal.mapFlagsToInternalEventFlag(eventFlags, 0),
                mGlobal.mapFiltersToInternalEventFlag(eventFilter, 0),
                ActivityThread.currentPackageName());
    }

@@ -829,17 +838,17 @@ public final class DisplayManager {
     *
     * @param listener The listener to register.
     * @param executor Executor for the thread that will be receiving the callbacks. Cannot be null.
     * @param eventFlags A bitmask of the event types for which this listener is subscribed.
     * @param eventFilter A bitmask of the event types for which this listener is subscribed.
     *
     * @see #registerDisplayListener(DisplayListener, Handler)
     * @see #unregisterDisplayListener
     *
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public void registerDisplayListener(@NonNull Executor executor, @EventFlag long eventFlags,
    public void registerDisplayListener(@NonNull Executor executor, @EventType long eventFilter,
            @NonNull DisplayListener listener) {
        mGlobal.registerDisplayListener(listener, executor,
                mGlobal.mapFlagsToInternalEventFlag(eventFlags, 0),
                mGlobal.mapFiltersToInternalEventFlag(eventFilter, 0),
                ActivityThread.currentPackageName());
    }

@@ -849,8 +858,8 @@ public final class DisplayManager {
     * @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.
     * @param eventFlags A bitmask of the event types for which this listener is subscribed.
     * @param privateEventFlags A bitmask of the private event types for which this listener
     * @param eventFilter A bitmask of the event types for which this listener is subscribed.
     * @param privateEventFilter A bitmask of the private event types for which this listener
     *                          is subscribed.
     *
     * @see #registerDisplayListener(DisplayListener, Handler)
@@ -859,10 +868,10 @@ public final class DisplayManager {
     * @hide
     */
    public void registerDisplayListener(@NonNull DisplayListener listener,
            @Nullable Handler handler, @EventFlag long eventFlags,
            @PrivateEventFlag long privateEventFlags) {
            @Nullable Handler handler, @EventType long eventFilter,
            @PrivateEventType long privateEventFilter) {
        mGlobal.registerDisplayListener(listener, handler,
                mGlobal.mapFlagsToInternalEventFlag(eventFlags, privateEventFlags),
                mGlobal.mapFiltersToInternalEventFlag(eventFilter, privateEventFilter),
                ActivityThread.currentPackageName());
    }

+13 −13
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package android.hardware.display;


import static android.app.PropertyInvalidatedCache.MODULE_SYSTEM;
import static android.hardware.display.DisplayManager.EventFlag;
import static android.hardware.display.DisplayManager.EventType;
import static android.Manifest.permission.MANAGE_DISPLAYS;
import static android.view.Display.HdrCapabilities.HdrType;

@@ -1737,35 +1737,35 @@ public final class DisplayManagerGlobal {
     * @return returns the bitmask of both public and private event flags unified to
     * InternalEventFlag
     */
    public @InternalEventFlag long mapFlagsToInternalEventFlag(@EventFlag long eventFlags,
            @DisplayManager.PrivateEventFlag long privateEventFlags) {
    public @InternalEventFlag long mapFiltersToInternalEventFlag(@EventType long eventFlags,
            @DisplayManager.PrivateEventType long privateEventFlags) {
        return mapPrivateEventFlags(privateEventFlags) | mapPublicEventFlags(eventFlags);
    }

    private long mapPrivateEventFlags(@DisplayManager.PrivateEventFlag long privateEventFlags) {
    private long mapPrivateEventFlags(@DisplayManager.PrivateEventType long privateEventFlags) {
        long baseEventMask = 0;
        if ((privateEventFlags & DisplayManager.PRIVATE_EVENT_FLAG_DISPLAY_BRIGHTNESS) != 0) {
        if ((privateEventFlags & DisplayManager.PRIVATE_EVENT_TYPE_DISPLAY_BRIGHTNESS) != 0) {
            baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_BRIGHTNESS_CHANGED;
        }

        if ((privateEventFlags & DisplayManager.PRIVATE_EVENT_FLAG_HDR_SDR_RATIO_CHANGED) != 0) {
        if ((privateEventFlags & DisplayManager.PRIVATE_EVENT_TYPE_HDR_SDR_RATIO_CHANGED) != 0) {
            baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_HDR_SDR_RATIO_CHANGED;
        }

        if ((privateEventFlags
                & DisplayManager.PRIVATE_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED) != 0) {
                & DisplayManager.PRIVATE_EVENT_TYPE_DISPLAY_CONNECTION_CHANGED) != 0) {
            baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED;
        }
        return baseEventMask;
    }

    private long mapPublicEventFlags(@EventFlag long eventFlags) {
    private long mapPublicEventFlags(@EventType long eventFlags) {
        long baseEventMask = 0;
        if ((eventFlags & DisplayManager.EVENT_FLAG_DISPLAY_ADDED) != 0) {
        if ((eventFlags & DisplayManager.EVENT_TYPE_DISPLAY_ADDED) != 0) {
            baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_ADDED;
        }

        if ((eventFlags & DisplayManager.EVENT_FLAG_DISPLAY_CHANGED) != 0) {
        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
@@ -1774,16 +1774,16 @@ public final class DisplayManagerGlobal {
        }

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

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

            if ((eventFlags & DisplayManager.EVENT_FLAG_DISPLAY_STATE) != 0) {
            if ((eventFlags & DisplayManager.EVENT_TYPE_DISPLAY_STATE) != 0) {
                baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_STATE;
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -601,7 +601,7 @@ public class BrightnessSynchronizer {
            cr.registerContentObserver(BRIGHTNESS_URI, false,
                    createBrightnessContentObserver(handler), UserHandle.USER_ALL);
            mDisplayManager.registerDisplayListener(mListener, handler, /* eventFlags */ 0,
                    DisplayManager.PRIVATE_EVENT_FLAG_DISPLAY_BRIGHTNESS);
                    DisplayManager.PRIVATE_EVENT_TYPE_DISPLAY_BRIGHTNESS);
            mIsObserving = true;
        }
    }
+18 −18
Original line number Diff line number Diff line
@@ -302,48 +302,48 @@ public class DisplayManagerGlobalTest {

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public void testMapFlagsToInternalEventFlag() {
    public void testMapFiltersToInternalEventFlag() {
        // Test public flags mapping
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_ADDED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(DisplayManager.EVENT_FLAG_DISPLAY_ADDED, 0));
                        .mapFiltersToInternalEventFlag(DisplayManager.EVENT_TYPE_DISPLAY_ADDED, 0));
        assertEquals(DISPLAY_CHANGE_EVENTS, mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(DisplayManager.EVENT_FLAG_DISPLAY_CHANGED, 0));
                .mapFiltersToInternalEventFlag(DisplayManager.EVENT_TYPE_DISPLAY_CHANGED, 0));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_REMOVED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(DisplayManager.EVENT_FLAG_DISPLAY_REMOVED, 0));
                mDisplayManagerGlobal.mapFiltersToInternalEventFlag(
                        DisplayManager.EVENT_TYPE_DISPLAY_REMOVED, 0));
        assertEquals(INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(
                                DisplayManager.EVENT_FLAG_DISPLAY_REFRESH_RATE,
                        .mapFiltersToInternalEventFlag(
                                DisplayManager.EVENT_TYPE_DISPLAY_REFRESH_RATE,
                                0));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_STATE,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(
                                DisplayManager.EVENT_FLAG_DISPLAY_STATE,
                        .mapFiltersToInternalEventFlag(
                                DisplayManager.EVENT_TYPE_DISPLAY_STATE,
                                0));

        // test private flags mapping
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(0,
                                DisplayManager.PRIVATE_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED));
                        .mapFiltersToInternalEventFlag(0,
                                DisplayManager.PRIVATE_EVENT_TYPE_DISPLAY_CONNECTION_CHANGED));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_HDR_SDR_RATIO_CHANGED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(0,
                                DisplayManager.PRIVATE_EVENT_FLAG_HDR_SDR_RATIO_CHANGED));
                        .mapFiltersToInternalEventFlag(0,
                                DisplayManager.PRIVATE_EVENT_TYPE_HDR_SDR_RATIO_CHANGED));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_BRIGHTNESS_CHANGED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(0,
                                DisplayManager.PRIVATE_EVENT_FLAG_DISPLAY_BRIGHTNESS));
                        .mapFiltersToInternalEventFlag(0,
                                DisplayManager.PRIVATE_EVENT_TYPE_DISPLAY_BRIGHTNESS));

        // Test both public and private flags mapping
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_BRIGHTNESS_CHANGED
                        | INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(
                                DisplayManager.EVENT_FLAG_DISPLAY_REFRESH_RATE,
                                DisplayManager.PRIVATE_EVENT_FLAG_DISPLAY_BRIGHTNESS));
                        .mapFiltersToInternalEventFlag(
                                DisplayManager.EVENT_TYPE_DISPLAY_REFRESH_RATE,
                                DisplayManager.PRIVATE_EVENT_TYPE_DISPLAY_BRIGHTNESS));
    }

    private void waitForHandler() {
Loading