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

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

Doze brightness float

Use the float doze brightness if the flag is enabled and the config is provided by Display Manager. Pass the computed float brightness down to Power Manager.

Use config_screenBrightnessDimFloat.

Additionally, correct the docs with the int brightness range 1-255. 0 is BRIGHTNESS_OFF, currently, the framework doesn't allow turning the screen off by setting that brightness.

Bug: 326981871
Bug: 343796384
Test: DreamServiceTest, AlwaysOnDisplayPolicyTest, DozeScreenBrightnessTest, NotificationShadeWindowControllerImplTest, DozeServiceHostTest, DreamManagerServiceTests, PowerManagerServiceTest
Flag: com.android.server.display.feature.flags.doze_brightness_float
Change-Id: Iefa68b36dc325434e1d7fcfd5c4d8d6b92dab99b
parent 937b6dc7
Loading
Loading
Loading
Loading
+8 −3
Original line number Original line Diff line number Diff line
@@ -139,11 +139,16 @@ public abstract class PowerManagerInternal {
     * @param screenState The overridden screen state, or {@link Display#STATE_UNKNOWN}
     * @param screenState The overridden screen state, or {@link Display#STATE_UNKNOWN}
     * to disable the override.
     * to disable the override.
     * @param reason The reason for overriding the screen state.
     * @param reason The reason for overriding the screen state.
     * @param screenBrightness The overridden screen brightness, or
     * @param screenBrightnessFloat The overridden screen brightness between
     * {@link PowerManager#BRIGHTNESS_DEFAULT} to disable the override.
     * {@link PowerManager#BRIGHTNESS_MIN} and {@link PowerManager#BRIGHTNESS_MAX}, or
     * {@link PowerManager#BRIGHTNESS_INVALID_FLOAT} if screenBrightnessInt should be used instead.
     * @param screenBrightnessInt The overridden screen brightness between 1 and 255, or
     * {@link PowerManager#BRIGHTNESS_DEFAULT} to disable the override. Not used if
     *                            screenBrightnessFloat is provided (is not NaN).
     */
     */
    public abstract void setDozeOverrideFromDreamManager(
    public abstract void setDozeOverrideFromDreamManager(
            int screenState, @Display.StateReason int reason, int screenBrightness);
            int screenState, @Display.StateReason int reason, float screenBrightnessFloat,
            int screenBrightnessInt);


    /**
    /**
     * Used by sidekick manager to tell the power manager if it shouldn't change the display state
     * Used by sidekick manager to tell the power manager if it shouldn't change the display state
+1 −1
Original line number Original line Diff line number Diff line
@@ -15820,7 +15820,7 @@ public final class Settings {
         * The following keys are supported:
         * The following keys are supported:
         *
         *
         * <pre>
         * <pre>
         * screen_brightness_array         (int[])
         * screen_brightness_array         (int[], values in range [1, 255])
         * dimming_scrim_array             (int[])
         * dimming_scrim_array             (int[])
         * prox_screen_off_delay           (long)
         * prox_screen_off_delay           (long)
         * prox_cooldown_trigger           (long)
         * prox_cooldown_trigger           (long)
+56 −9
Original line number Original line Diff line number Diff line
@@ -74,6 +74,7 @@ import android.view.accessibility.AccessibilityEvent;


import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.display.BrightnessSynchronizer;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.DumpUtils;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
@@ -269,6 +270,7 @@ public class DreamService extends Service implements Window.Callback {
    private volatile int mDozeScreenState = Display.STATE_UNKNOWN;
    private volatile int mDozeScreenState = Display.STATE_UNKNOWN;
    private volatile @Display.StateReason int mDozeScreenStateReason = Display.STATE_REASON_UNKNOWN;
    private volatile @Display.StateReason int mDozeScreenStateReason = Display.STATE_REASON_UNKNOWN;
    private volatile int mDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
    private volatile int mDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
    private volatile float mDozeScreenBrightnessFloat = PowerManager.BRIGHTNESS_INVALID_FLOAT;


    private boolean mDebug = false;
    private boolean mDebug = false;


@@ -928,11 +930,11 @@ public class DreamService extends Service implements Window.Callback {
                if (startAndStopDozingInBackground()) {
                if (startAndStopDozingInBackground()) {
                    mDreamManager.startDozingOneway(
                    mDreamManager.startDozingOneway(
                            mDreamToken, mDozeScreenState, mDozeScreenStateReason,
                            mDreamToken, mDozeScreenState, mDozeScreenStateReason,
                        mDozeScreenBrightness);
                            mDozeScreenBrightnessFloat, mDozeScreenBrightness);
                } else {
                } else {
                    mDreamManager.startDozing(
                    mDreamManager.startDozing(
                            mDreamToken, mDozeScreenState, mDozeScreenStateReason,
                            mDreamToken, mDozeScreenState, mDozeScreenStateReason,
                            mDozeScreenBrightness);
                            mDozeScreenBrightnessFloat, mDozeScreenBrightness);
                }
                }


            } catch (RemoteException ex) {
            } catch (RemoteException ex) {
@@ -1057,7 +1059,7 @@ public class DreamService extends Service implements Window.Callback {
     * Gets the screen brightness to use while dozing.
     * Gets the screen brightness to use while dozing.
     *
     *
     * @return The screen brightness while dozing as a value between
     * @return The screen brightness while dozing as a value between
     * {@link PowerManager#BRIGHTNESS_OFF} (0) and {@link PowerManager#BRIGHTNESS_ON} (255),
     * {@link PowerManager#BRIGHTNESS_OFF + 1} (1) and {@link PowerManager#BRIGHTNESS_ON} (255),
     * or {@link PowerManager#BRIGHTNESS_DEFAULT} (-1) to ask the system to apply
     * or {@link PowerManager#BRIGHTNESS_DEFAULT} (-1) to ask the system to apply
     * its default policy based on the screen state.
     * its default policy based on the screen state.
     *
     *
@@ -1078,11 +1080,11 @@ public class DreamService extends Service implements Window.Callback {
     * The dream may set a different brightness before starting to doze and may adjust
     * The dream may set a different brightness before starting to doze and may adjust
     * the brightness while dozing to conserve power and achieve various effects.
     * the brightness while dozing to conserve power and achieve various effects.
     * </p><p>
     * </p><p>
     * Note that dream may specify any brightness in the full 0-255 range, including
     * Note that dream may specify any brightness in the full 1-255 range, including
     * values that are less than the minimum value for manual screen brightness
     * values that are less than the minimum value for manual screen brightness
     * adjustments by the user. In particular, the value may be set to 0 which may
     * adjustments by the user. In particular, the value may be set to
     * turn off the backlight entirely while still leaving the screen on although
     * {@link PowerManager.BRIGHTNESS_OFF} which may turn off the backlight entirely while still
     * this behavior is device dependent and not guaranteed.
     * leaving the screen on although this behavior is device dependent and not guaranteed.
     * </p><p>
     * </p><p>
     * The available range of display brightness values and their behavior while dozing is
     * The available range of display brightness values and their behavior while dozing is
     * hardware dependent and may vary across devices. The dream may therefore
     * hardware dependent and may vary across devices. The dream may therefore
@@ -1090,7 +1092,7 @@ public class DreamService extends Service implements Window.Callback {
     * </p>
     * </p>
     *
     *
     * @param brightness The screen brightness while dozing as a value between
     * @param brightness The screen brightness while dozing as a value between
     * {@link PowerManager#BRIGHTNESS_OFF} (0) and {@link PowerManager#BRIGHTNESS_ON} (255),
     * {@link PowerManager#BRIGHTNESS_OFF + 1} (1) and {@link PowerManager#BRIGHTNESS_ON} (255),
     * or {@link PowerManager#BRIGHTNESS_DEFAULT} (-1) to ask the system to apply
     * or {@link PowerManager#BRIGHTNESS_DEFAULT} (-1) to ask the system to apply
     * its default policy based on the screen state.
     * its default policy based on the screen state.
     *
     *
@@ -1107,6 +1109,44 @@ public class DreamService extends Service implements Window.Callback {
        }
        }
    }
    }


    /**
     * Sets the screen brightness to use while dozing.
     * <p>
     * The value of this property determines the power state of the primary display
     * once {@link #startDozing} has been called. The default value is
     * {@link PowerManager#BRIGHTNESS_INVALID_FLOAT} which lets the system decide.
     * The dream may set a different brightness before starting to doze and may adjust
     * the brightness while dozing to conserve power and achieve various effects.
     * </p><p>
     * Note that dream may specify any brightness in the full 0-1 range, including
     * values that are less than the minimum value for manual screen brightness
     * adjustments by the user. In particular, the value may be set to
     * {@link PowerManager#BRIGHTNESS_OFF_FLOAT} which may turn off the backlight entirely while
     * still leaving the screen on although this behavior is device dependent and not guaranteed.
     * </p><p>
     * The available range of display brightness values and their behavior while dozing is
     * hardware dependent and may vary across devices. The dream may therefore
     * need to be modified or configured to correctly support the hardware.
     * </p>
     *
     * @param brightness The screen brightness while dozing as a value between
     * {@link PowerManager#BRIGHTNESS_MIN} (0) and {@link PowerManager#BRIGHTNESS_MAX} (1),
     * or {@link PowerManager#BRIGHTNESS_INVALID_FLOAT} (Float.NaN) to ask the system to apply
     * its default policy based on the screen state.
     *
     * @hide For use by system UI components only.
     */
    @UnsupportedAppUsage
    public void setDozeScreenBrightnessFloat(float brightness) {
        if (!Float.isNaN(brightness)) {
            brightness = clampAbsoluteBrightnessFloat(brightness);
        }
        if (!BrightnessSynchronizer.floatEquals(mDozeScreenBrightnessFloat, brightness)) {
            mDozeScreenBrightnessFloat = brightness;
            updateDoze();
        }
    }

    /**
    /**
     * Called when this Dream is constructed.
     * Called when this Dream is constructed.
     */
     */
@@ -1751,6 +1791,13 @@ public class DreamService extends Service implements Window.Callback {
        return MathUtils.constrain(value, PowerManager.BRIGHTNESS_OFF, PowerManager.BRIGHTNESS_ON);
        return MathUtils.constrain(value, PowerManager.BRIGHTNESS_OFF, PowerManager.BRIGHTNESS_ON);
    }
    }


    private static float clampAbsoluteBrightnessFloat(float value) {
        if (value == PowerManager.BRIGHTNESS_OFF_FLOAT) {
            return value;
        }
        return MathUtils.constrain(value, PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX);
    }

    /**
    /**
     * The DreamServiceWrapper is used as a gateway to the system_server, where DreamController
     * The DreamServiceWrapper is used as a gateway to the system_server, where DreamController
     * uses it to control the DreamService. It is also used to receive callbacks from the
     * uses it to control the DreamService. It is also used to receive callbacks from the
+4 −2
Original line number Original line Diff line number Diff line
@@ -42,7 +42,8 @@ interface IDreamManager {
    /** @deprecated Please use finishSelfOneway instead. */
    /** @deprecated Please use finishSelfOneway instead. */
    void finishSelf(in IBinder token, boolean immediate);
    void finishSelf(in IBinder token, boolean immediate);
    /** @deprecated Please use startDozingOneway instead. */
    /** @deprecated Please use startDozingOneway instead. */
    void startDozing(in IBinder token, int screenState, int reason, int screenBrightness);
    void startDozing(in IBinder token, int screenState, int reason, float screenBrightnessFloat,
            int screenBrightnessInt);
    void stopDozing(in IBinder token);
    void stopDozing(in IBinder token);
    void forceAmbientDisplayEnabled(boolean enabled);
    void forceAmbientDisplayEnabled(boolean enabled);
    ComponentName[] getDreamComponentsForUser(int userId);
    ComponentName[] getDreamComponentsForUser(int userId);
@@ -52,6 +53,7 @@ interface IDreamManager {
    void startDreamActivity(in Intent intent);
    void startDreamActivity(in Intent intent);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE)")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE)")
    oneway void setDreamIsObscured(in boolean isObscured);
    oneway void setDreamIsObscured(in boolean isObscured);
    oneway void startDozingOneway(in IBinder token, int screenState, int reason, int screenBrightness);
    oneway void startDozingOneway(in IBinder token, int screenState, int reason,
            float screenBrightnessFloat, int screenBrightnessInt);
    oneway void finishSelfOneway(in IBinder token, boolean immediate);
    oneway void finishSelfOneway(in IBinder token, boolean immediate);
}
}
+13 −3
Original line number Original line Diff line number Diff line
@@ -57,21 +57,29 @@ public class AlwaysOnDisplayPolicy {




    /**
    /**
     * Integer used to dim the screen while dozing.
     * Integer in the scale [1, 255] used to dim the screen while dozing.
     *
     *
     * @see R.integer.config_screenBrightnessDoze
     * @see R.integer.config_screenBrightnessDoze
     */
     */
    public int defaultDozeBrightness;
    public int defaultDozeBrightness;


    /**
    /**
     * Integer used to dim the screen just before the screen turns off.
     * Integer in the scale [1, 255] used to dim the screen just before the screen turns off.
     *
     *
     * @see R.integer.config_screenBrightnessDim
     * @see R.integer.config_screenBrightnessDim
     */
     */
    public int dimBrightness;
    public int dimBrightness;


    /**
    /**
     * Integer array to map ambient brightness type to real screen brightness.
     * Float in the scale [0, 1] used to dim the screen just before the screen turns off.
     *
     * @see R.integer.config_screenBrightnessDimFloat
     */
    public float dimBrightnessFloat;

    /**
     * Integer array to map ambient brightness type to real screen brightness in the integer scale
     * [1, 255].
     *
     *
     * @see Settings.Global#ALWAYS_ON_DISPLAY_CONSTANTS
     * @see Settings.Global#ALWAYS_ON_DISPLAY_CONSTANTS
     * @see #KEY_SCREEN_BRIGHTNESS_ARRAY
     * @see #KEY_SCREEN_BRIGHTNESS_ARRAY
@@ -189,6 +197,8 @@ public class AlwaysOnDisplayPolicy {
                        com.android.internal.R.integer.config_screenBrightnessDoze);
                        com.android.internal.R.integer.config_screenBrightnessDoze);
                dimBrightness = resources.getInteger(
                dimBrightness = resources.getInteger(
                        com.android.internal.R.integer.config_screenBrightnessDim);
                        com.android.internal.R.integer.config_screenBrightnessDim);
                dimBrightnessFloat = resources.getFloat(
                        com.android.internal.R.dimen.config_screenBrightnessDimFloat);
                screenBrightnessArray = mParser.getIntArray(KEY_SCREEN_BRIGHTNESS_ARRAY,
                screenBrightnessArray = mParser.getIntArray(KEY_SCREEN_BRIGHTNESS_ARRAY,
                        resources.getIntArray(
                        resources.getIntArray(
                                R.array.config_doze_brightness_sensor_to_brightness));
                                R.array.config_doze_brightness_sensor_to_brightness));
Loading