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

Commit c2dcd47a authored by Piotr Wilczyński's avatar Piotr Wilczyński
Browse files

Configure doze brightness in the float scale in the DDC

Fall back to int brightness if the values are not defined in the DDC overlay.

Create methods in DisplayManager to pass the config from DDC to SysUI.

Bug: 326981871
Bug: 343796384
Test: DisplayPowerControllerTest, DisplayDeviceConfigTest
Flag: com.android.server.display.feature.flags.doze_brightness_float
Change-Id: Iae205440aeaa542b3653a07724523a480372423d
parent fdf9784b
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -1668,6 +1668,46 @@ public final class DisplayManager {
        mGlobal.requestDisplayModes(displayId, modeIds);
    }

    /**
     * Gets the mapping between the doze brightness sensor values and brightness values. The doze
     * brightness sensor is a light sensor used to determine the brightness while the device is
     * dozing. Light sensor values are typically integers in the rage of 0-4. The returned values
     * are between {@link PowerManager#BRIGHTNESS_MIN} and {@link PowerManager#BRIGHTNESS_MAX}, or
     * -1 meaning that the current brightness should be kept.
     * <p>
     * Requires the {@link android.Manifest.permission#CONTROL_DISPLAY_BRIGHTNESS}
     * permission.
     * </p>
     *
     * @param displayId The ID of the display
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS)
    @Nullable
    public float[] getDozeBrightnessSensorValueToBrightness(int displayId) {
        return mGlobal.getDozeBrightnessSensorValueToBrightness(displayId);
    }

    /**
     * Gets the default doze brightness.
     * The returned values are between {@link PowerManager#BRIGHTNESS_MIN} and
     * {@link PowerManager#BRIGHTNESS_MAX}.
     * <p>
     * Requires the {@link android.Manifest.permission#CONTROL_DISPLAY_BRIGHTNESS}
     * permission.
     * </p>
     *
     * @param displayId The ID of the display
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS)
    @FloatRange(from = 0f, to = 1f)
    public float getDefaultDozeBrightness(int displayId) {
        return mGlobal.getDefaultDozeBrightness(displayId);
    }

    /**
     * Listens for changes in available display devices.
     */
+27 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.hardware.display.DisplayManager.EventsMask;
import static android.view.Display.HdrCapabilities.HdrType;

import android.Manifest;
import android.annotation.FloatRange;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -1226,6 +1227,32 @@ public final class DisplayManagerGlobal {
        }
    }

    /**
     * @see DisplayManager#getDozeBrightnessSensorValueToBrightness
     */
    @RequiresPermission(Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS)
    @Nullable
    public float[] getDozeBrightnessSensorValueToBrightness(int displayId) {
        try {
            return mDm.getDozeBrightnessSensorValueToBrightness(displayId);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * @see DisplayManager#getDefaultDozeBrightness
     */
    @RequiresPermission(Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS)
    @FloatRange(from = 0f, to = 1f)
    public float getDefaultDozeBrightness(int displayId) {
        try {
            return mDm.getDefaultDozeBrightness(displayId);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    private final class DisplayManagerCallback extends IDisplayManagerCallback.Stub {
        @Override
        public void onDisplayEvent(int displayId, @DisplayEvent int event) {
+8 −0
Original line number Diff line number Diff line
@@ -246,4 +246,12 @@ interface IDisplayManager {
    // Restricts display modes to specified modeIds.
    @EnforcePermission("RESTRICT_DISPLAY_MODES")
    void requestDisplayModes(in IBinder token, int displayId, in @nullable int[] modeIds);

    // Get the mapping between the doze brightness sensor values and brightness values
    @EnforcePermission("CONTROL_DISPLAY_BRIGHTNESS")
    float[] getDozeBrightnessSensorValueToBrightness(int displayId);

    // Get the default doze brightness
    @EnforcePermission("CONTROL_DISPLAY_BRIGHTNESS")
    float getDefaultDozeBrightness(int displayId);
}
+1 −8
Original line number Diff line number Diff line
@@ -564,8 +564,7 @@ public final class PowerManager {
            BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM,
            BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM,
            BRIGHTNESS_CONSTRAINT_TYPE_DEFAULT,
            BRIGHTNESS_CONSTRAINT_TYPE_DIM,
            BRIGHTNESS_CONSTRAINT_TYPE_DOZE
            BRIGHTNESS_CONSTRAINT_TYPE_DIM
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface BrightnessConstraint{}
@@ -593,12 +592,6 @@ public final class PowerManager {
     */
    public static final int BRIGHTNESS_CONSTRAINT_TYPE_DIM = 3;

    /**
     * Brightness constraint type: minimum allowed value.
     * @hide
     */
    public static final int BRIGHTNESS_CONSTRAINT_TYPE_DOZE = 4;

    /**
     * @hide
     */
+2 −1
Original line number Diff line number Diff line
@@ -287,7 +287,8 @@
    <integer name="doze_small_icon_alpha">222</integer><!-- 87% of 0xff -->

    <!-- Doze: Table that translates sensor values from the doze_brightness_sensor_type sensor
               to brightness values; -1 means keeping the current brightness. -->
               to brightness values in the integer scale [1, 255]; -1 means keeping the current
               brightness. -->
    <integer-array name="config_doze_brightness_sensor_to_brightness">
        <item>-1</item> <!-- 0: OFF -->
        <item>2</item> <!-- 1: NIGHT -->
Loading