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

Commit e9a51667 authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Add API to register for display property changes

We are adding support for users to subsbribe to refresh rate and display
state changes. In future, this can be extended to more specific
properties if a usecase arise

Bug: 372700957
Test: CTS linked with the topic
Flag: com.android.server.display.feature.flags.display_listener_performance_improvements
Change-Id: Ibe8573eb3ee34d3817b059bb092cb40fbf82239e
parent 7fb089df
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -20630,8 +20630,14 @@ package android.hardware.display {
    method @NonNull public android.hardware.display.HdrConversionMode getHdrConversionMode();
    method public int getMatchContentFrameRateUserPreference();
    method public void registerDisplayListener(android.hardware.display.DisplayManager.DisplayListener, android.os.Handler);
    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 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
+43 −12
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.HdrCapabilities.HdrType;
import static android.view.Display.INVALID_DISPLAY;

import static com.android.server.display.feature.flags.Flags.FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS;

import android.Manifest;
import android.annotation.FlaggedApi;
import android.annotation.FloatRange;
@@ -576,6 +578,8 @@ public final class DisplayManager {
            EVENT_FLAG_DISPLAY_ADDED,
            EVENT_FLAG_DISPLAY_CHANGED,
            EVENT_FLAG_DISPLAY_REMOVED,
            EVENT_FLAG_DISPLAY_REFRESH_RATE,
            EVENT_FLAG_DISPLAY_STATE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface EventFlag {}
@@ -596,8 +600,8 @@ public final class DisplayManager {
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     *
     * @hide
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public static final long EVENT_FLAG_DISPLAY_ADDED = 1L << 0;

    /**
@@ -605,8 +609,8 @@ public final class DisplayManager {
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     *
     * @hide
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public static final long EVENT_FLAG_DISPLAY_REMOVED = 1L << 1;

    /**
@@ -614,10 +618,27 @@ public final class DisplayManager {
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     *
     * @hide
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public static final long EVENT_FLAG_DISPLAY_CHANGED = 1L << 2;


    /**
     * Event flag to register for a display's refresh rate changes.
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public static final long EVENT_FLAG_DISPLAY_REFRESH_RATE = 1L << 3;

    /**
     * Event flag to register for a display state changes.
     *
     * @see #registerDisplayListener(DisplayListener, Handler, long)
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public static final long EVENT_FLAG_DISPLAY_STATE = 1L << 4;

    /**
     * Event flag to register for a display's brightness changes. This notification is sent
     * through the {@link DisplayListener#onDisplayChanged} callback method. New brightness
@@ -787,9 +808,6 @@ public final class DisplayManager {
     * 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.
     *
     * @see #EVENT_FLAG_DISPLAY_ADDED
     * @see #EVENT_FLAG_DISPLAY_CHANGED
     * @see #EVENT_FLAG_DISPLAY_REMOVED
     * @see #registerDisplayListener(DisplayListener, Handler)
     * @see #unregisterDisplayListener
     *
@@ -802,6 +820,25 @@ public final class DisplayManager {
                ActivityThread.currentPackageName());
    }

    /**
     * Registers a display listener to receive notifications about given display event types.
     *
     * @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.
     *
     * @see #registerDisplayListener(DisplayListener, Handler)
     * @see #unregisterDisplayListener
     *
     */
    @FlaggedApi(FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public void registerDisplayListener(@NonNull Executor executor, @EventFlag long eventFlags,
            @NonNull DisplayListener listener) {
        mGlobal.registerDisplayListener(listener, executor,
                mGlobal.mapFlagsToInternalEventFlag(eventFlags, 0),
                ActivityThread.currentPackageName());
    }

    /**
     * Registers a display listener to receive notifications about given display event types.
     *
@@ -812,12 +849,6 @@ public final class DisplayManager {
     * @param privateEventFlags A bitmask of the private event types for which this listener
     *                          is subscribed.
     *
     * @see #EVENT_FLAG_DISPLAY_ADDED
     * @see #EVENT_FLAG_DISPLAY_CHANGED
     * @see #EVENT_FLAG_DISPLAY_REMOVED
     * @see #PRIVATE_EVENT_FLAG_DISPLAY_BRIGHTNESS
     * @see #PRIVATE_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED
     * @see #PRIVATE_EVENT_FLAG_HDR_SDR_RATIO_CHANGED
     * @see #registerDisplayListener(DisplayListener, Handler)
     * @see #unregisterDisplayListener
     *
+16 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import android.view.DisplayInfo;
import android.view.Surface;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.display.feature.flags.Flags;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -127,6 +128,8 @@ public final class DisplayManagerGlobal {
            INTERNAL_EVENT_FLAG_DISPLAY_BRIGHTNESS_CHANGED,
            INTERNAL_EVENT_FLAG_DISPLAY_HDR_SDR_RATIO_CHANGED,
            INTERNAL_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED,
            INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE,
            INTERNAL_EVENT_FLAG_DISPLAY_STATE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface InternalEventFlag {}
@@ -137,6 +140,8 @@ public final class DisplayManagerGlobal {
    public static final long INTERNAL_EVENT_FLAG_DISPLAY_BRIGHTNESS_CHANGED = 1L << 3;
    public static final long INTERNAL_EVENT_FLAG_DISPLAY_HDR_SDR_RATIO_CHANGED = 1L << 4;
    public static final long INTERNAL_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED = 1L << 5;
    public static final long INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE = 1L << 6;
    public static final long INTERNAL_EVENT_FLAG_DISPLAY_STATE = 1L << 7;

    @UnsupportedAppUsage
    private static DisplayManagerGlobal sInstance;
@@ -1630,6 +1635,17 @@ public final class DisplayManagerGlobal {
            baseEventMask |= INTERNAL_EVENT_FLAG_DISPLAY_REMOVED;
        }

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

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


        return baseEventMask;
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -246,6 +246,10 @@ public class DisplayManagerFlags {
            Flags.FLAG_ENABLE_PLUGIN_MANAGER,
            Flags::enablePluginManager
    );
    private final FlagState mDisplayListenerPerformanceImprovementsFlagState = new FlagState(
            Flags.FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS,
            Flags::displayListenerPerformanceImprovements
    );

    /**
     * @return {@code true} if 'port' is allowed in display layout configuration file.
@@ -526,6 +530,13 @@ public class DisplayManagerFlags {
        return mEnablePluginManagerFlagState.isEnabled();
    }

    /**
     * @return {@code true} if the flag for display listener performance improvements is enabled
     */
    public boolean isDisplayListenerPerformanceImprovementsEnabled() {
        return mDisplayListenerPerformanceImprovementsFlagState.isEnabled();
    }

    /**
     * dumps all flagstates
     * @param pw printWriter
@@ -578,6 +589,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mHasArrSupport);
        pw.println(" " + mAutoBrightnessModeBedtimeWearFlagState);
        pw.println(" " + mEnablePluginManagerFlagState);
        pw.println(" " + mDisplayListenerPerformanceImprovementsFlagState);
    }

    private static class FlagState {
+8 −0
Original line number Diff line number Diff line
@@ -439,6 +439,14 @@ flag {
    is_fixed_read_only: true
}

flag {
    name: "display_listener_performance_improvements"
    namespace: "display_manager"
    description: "Feature flag for an API to let the apps subscribe to a specific property change of the Display."
    bug: "372700957"
    is_fixed_read_only: true
}

flag {
    name: "enable_get_supported_refresh_rates"
    namespace: "core_graphics"