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

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

Add display config for configuring the idle state refresh rate timeout

bands

This is a step forward to attain the functionality where if the screen
is idle for a configurable time, we would want to switch the screen to
a lower refresh rate to preserve the battery

Bug: 310026579
Test: atest DisplayDeviceConfigTest
Change-Id: I92435cb355e0538171a07cc08c56bae561ab0ce4
parent 2b870922
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
@@ -57,6 +57,9 @@ import com.android.server.display.config.DisplayQuirks;
import com.android.server.display.config.HbmTiming;
import com.android.server.display.config.HdrBrightnessData;
import com.android.server.display.config.HighBrightnessMode;
import com.android.server.display.config.IdleScreenRefreshRateTimeout;
import com.android.server.display.config.IdleScreenRefreshRateTimeoutLuxThresholdPoint;
import com.android.server.display.config.IdleScreenRefreshRateTimeoutLuxThresholds;
import com.android.server.display.config.IntegerArray;
import com.android.server.display.config.LuxThrottling;
import com.android.server.display.config.NitsMap;
@@ -553,6 +556,18 @@ import javax.xml.datatype.DatatypeConfigurationException;
 *         <minorVersion>0</minorVersion>
 *     </usiVersion>
 *     <screenBrightnessCapForWearBedtimeMode>0.1</screenBrightnessCapForWearBedtimeMode>
 *     <idleScreenRefreshRateTimeout>
 *          <luxThresholds>
 *              <point>
 *                  <lux>6</lux>
 *                  <timeout>1000</timeout>
 *              </point>
 *              <point>
 *                  <lux>10</lux>
 *                  <timeout>800</timeout>
 *              </point>
 *          </luxThresholds>
 *     </idleScreenRefreshRateTimeout>
 *    </displayConfiguration>
 *  }
 *  </pre>
@@ -843,6 +858,14 @@ public class DisplayDeviceConfig {
    private final Map<BrightnessLimitMapType, Map<Float, Float>>
            mLuxThrottlingData = new HashMap<>();

    /**
     * The idle screen timeout configuration for switching to lower refresh rate
     */
    @NonNull
    private List<IdleScreenRefreshRateTimeoutLuxThresholdPoint>
            mIdleScreenRefreshRateTimeoutLuxThresholds = new ArrayList<>();


    @Nullable
    private HostUsiVersion mHostUsiVersion;

@@ -1999,6 +2022,7 @@ public class DisplayDeviceConfig {
                loadUsiVersion(config);
                mHdrBrightnessData = HdrBrightnessData.loadConfig(config);
                loadBrightnessCapForWearBedtimeMode(config);
                loadIdleScreenRefreshRateTimeoutConfigs(config);
            } else {
                Slog.w(TAG, "DisplayDeviceConfig file is null");
            }
@@ -2024,6 +2048,7 @@ public class DisplayDeviceConfig {
        loadAutoBrightnessAvailableFromConfigXml();
        loadRefreshRateSetting(null);
        loadBrightnessCapForWearBedtimeModeFromConfigXml();
        loadIdleScreenRefreshRateTimeoutConfigs(null);
        mLoadedFrom = "<config.xml>";
    }

@@ -3326,6 +3351,47 @@ public class DisplayDeviceConfig {
        }
    }

    private void loadIdleScreenRefreshRateTimeoutConfigs(@Nullable DisplayConfiguration config) {
        if (mFlags.isIdleScreenRefreshRateTimeoutEnabled()
                && config != null && config.getIdleScreenRefreshRateTimeout() != null) {
            validateIdleScreenRefreshRateTimeoutConfig(
                    config.getIdleScreenRefreshRateTimeout());
            mIdleScreenRefreshRateTimeoutLuxThresholds = config
                    .getIdleScreenRefreshRateTimeout().getLuxThresholds().getPoint();
        }
    }

    private void validateIdleScreenRefreshRateTimeoutConfig(
            IdleScreenRefreshRateTimeout idleScreenRefreshRateTimeoutConfig) {
        IdleScreenRefreshRateTimeoutLuxThresholds idleScreenRefreshRateTimeoutLuxThresholds =
                idleScreenRefreshRateTimeoutConfig.getLuxThresholds();

        if (idleScreenRefreshRateTimeoutLuxThresholds != null) {
            int previousLux = -1;
            // Validate that the lux values are in the increasing order
            for (IdleScreenRefreshRateTimeoutLuxThresholdPoint point :
                    idleScreenRefreshRateTimeoutLuxThresholds.getPoint()) {
                int newLux = point.getLux().intValue();
                if (previousLux >= newLux) {
                    throw new RuntimeException("Lux values should be in ascending order in the"
                            + " idle screen refresh rate timeout config");
                }
                previousLux = newLux;
            }
        }
    }

    /**
     * Gets the idle screen refresh rate timeout(in ms) configuration list. For each entry, the lux
     * value represent the lower bound of the lux range, and the value of the lux in the next
     * point(INF if not present) represents the upper bound for the corresponding timeout(in ms)
     */
    @NonNull
    public List<IdleScreenRefreshRateTimeoutLuxThresholdPoint>
            getIdleScreenRefreshRateTimeoutLuxThresholdPoint() {
        return mIdleScreenRefreshRateTimeoutLuxThresholds;
    }

    /**
     * Extracts a float array from the specified {@link TypedArray}.
     *
+10 −0
Original line number Diff line number Diff line
@@ -126,6 +126,11 @@ public class DisplayManagerFlags {
            Flags::sensorBasedBrightnessThrottling
    );

    private final FlagState mIdleScreenRefreshRateTimeout = new FlagState(
            Flags.FLAG_IDLE_SCREEN_REFRESH_RATE_TIMEOUT,
            Flags::idleScreenRefreshRateTimeout
    );


    private final FlagState mRefactorDisplayPowerController = new FlagState(
            Flags.FLAG_REFACTOR_DISPLAY_POWER_CONTROLLER,
@@ -263,6 +268,10 @@ public class DisplayManagerFlags {
        return mSensorBasedBrightnessThrottling.isEnabled();
    }

    public boolean isIdleScreenRefreshRateTimeoutEnabled() {
        return mIdleScreenRefreshRateTimeout.isEnabled();
    }

    public boolean isRefactorDisplayPowerControllerEnabled() {
        return mRefactorDisplayPowerController.isEnabled();
    }
@@ -291,6 +300,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mFastHdrTransitions);
        pw.println(" " + mRefreshRateVotingTelemetry);
        pw.println(" " + mSensorBasedBrightnessThrottling);
        pw.println(" " + mIdleScreenRefreshRateTimeout);
        pw.println(" " + mRefactorDisplayPowerController);
    }

+8 −0
Original line number Diff line number Diff line
@@ -200,3 +200,11 @@ flag {
    bug: "294444204"
    is_fixed_read_only: true
}

flag {
    name: "idle_screen_refresh_rate_timeout"
    namespace: "display_manager"
    description: "Feature flag for reducing the refresh rate when the screen is idle after a timeout"
    bug: "310026579"
    is_fixed_read_only: true
}
+28 −0
Original line number Diff line number Diff line
@@ -168,6 +168,10 @@
                <xs:element type="nonNegativeDecimal" name="screenBrightnessCapForWearBedtimeMode">
                    <xs:annotation name="final"/>
                </xs:element>
                <!-- Timeout after which we reduce the refresh rate if the screen has been idle, in order to save power. -->
                <xs:element type="idleScreenRefreshRateTimeout" name="idleScreenRefreshRateTimeout" minOccurs="0">
                    <xs:annotation name="final"/>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
@@ -772,6 +776,30 @@
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="idleScreenRefreshRateTimeout">
        <xs:element name="luxThresholds" type="idleScreenRefreshRateTimeoutLuxThresholds" minOccurs="0">
            <xs:annotation name="final"/>
        </xs:element>
    </xs:complexType>

    <!-- Lux based timeout after which we reduce the refresh rate if the screen has been idle, in order to save power. -->
    <xs:complexType name="idleScreenRefreshRateTimeoutLuxThresholds">
        <xs:sequence>
            <xs:element name="point" type="idleScreenRefreshRateTimeoutLuxThresholdPoint" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>

    <!-- Represents a tuple of lux and timeout(in ms), which represents the timeout value for the lux in
    the [luxValue, nextLuxValue (INF if missing))  -->
    <xs:complexType name="idleScreenRefreshRateTimeoutLuxThresholdPoint">
        <xs:element name="lux" type="xs:nonNegativeInteger">
            <xs:annotation name="final"/>
        </xs:element>
        <xs:element name="timeout" type="xs:nonNegativeInteger">
            <xs:annotation name="final"/>
        </xs:element>
    </xs:complexType>

    <!-- Predefined type names as defined by
    AutomaticBrightnessController.AutomaticBrightnessMode -->
    <xs:simpleType  name="AutoBrightnessModeName">
+21 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ package com.android.server.display.config {
    method public final com.android.server.display.config.Thresholds getDisplayBrightnessChangeThresholdsIdle();
    method @Nullable public final com.android.server.display.config.HdrBrightnessConfig getHdrBrightnessConfig();
    method public com.android.server.display.config.HighBrightnessMode getHighBrightnessMode();
    method public final com.android.server.display.config.IdleScreenRefreshRateTimeout getIdleScreenRefreshRateTimeout();
    method public final com.android.server.display.config.SensorDetails getLightSensor();
    method public com.android.server.display.config.LuxThrottling getLuxThrottling();
    method @Nullable public final String getName();
@@ -146,6 +147,7 @@ package com.android.server.display.config {
    method public final void setDisplayBrightnessChangeThresholdsIdle(com.android.server.display.config.Thresholds);
    method public final void setHdrBrightnessConfig(@Nullable com.android.server.display.config.HdrBrightnessConfig);
    method public void setHighBrightnessMode(com.android.server.display.config.HighBrightnessMode);
    method public final void setIdleScreenRefreshRateTimeout(com.android.server.display.config.IdleScreenRefreshRateTimeout);
    method public final void setLightSensor(com.android.server.display.config.SensorDetails);
    method public void setLuxThrottling(com.android.server.display.config.LuxThrottling);
    method public final void setName(@Nullable String);
@@ -222,6 +224,25 @@ package com.android.server.display.config {
    method public final void setTransitionPoint_all(@NonNull java.math.BigDecimal);
  }

  public class IdleScreenRefreshRateTimeout {
    ctor public IdleScreenRefreshRateTimeout();
    method public final com.android.server.display.config.IdleScreenRefreshRateTimeoutLuxThresholds getLuxThresholds();
    method public final void setLuxThresholds(com.android.server.display.config.IdleScreenRefreshRateTimeoutLuxThresholds);
  }

  public class IdleScreenRefreshRateTimeoutLuxThresholdPoint {
    ctor public IdleScreenRefreshRateTimeoutLuxThresholdPoint();
    method public final java.math.BigInteger getLux();
    method public final java.math.BigInteger getTimeout();
    method public final void setLux(java.math.BigInteger);
    method public final void setTimeout(java.math.BigInteger);
  }

  public class IdleScreenRefreshRateTimeoutLuxThresholds {
    ctor public IdleScreenRefreshRateTimeoutLuxThresholds();
    method public java.util.List<com.android.server.display.config.IdleScreenRefreshRateTimeoutLuxThresholdPoint> getPoint();
  }

  public class IntegerArray {
    ctor public IntegerArray();
    method public java.util.List<java.math.BigInteger> getItem();
Loading