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

Commit 31ebcf92 authored by Manali Bhutiyani's avatar Manali Bhutiyani
Browse files

Support power-based throttling.

This change adds a smart throttler based on power-consumed
by the display. We use the power IC HAL apis to provide the
power consumed, and throttle brightness in order for display to stay
within budget for power-consumption.

This feature is feature-flag protected.

Bug: 261221454
Bug: 294777007

Test: multiple tests were added. Also manually tested.
Change-Id: Ia7d3e54073b0855200818a47d0029d715cd1b27e
parent 4d2514cc
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -59,7 +59,8 @@ public final class BrightnessInfo implements Parcelable {

    @IntDef(prefix = {"BRIGHTNESS_MAX_REASON_"}, value = {
            BRIGHTNESS_MAX_REASON_NONE,
            BRIGHTNESS_MAX_REASON_THERMAL
            BRIGHTNESS_MAX_REASON_THERMAL,
            BRIGHTNESS_MAX_REASON_POWER_IC
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface BrightnessMaxReason {}
@@ -74,6 +75,11 @@ public final class BrightnessInfo implements Parcelable {
     */
    public static final int BRIGHTNESS_MAX_REASON_THERMAL = 1;

    /**
     * Maximum brightness is restricted due to power throttling.
     */
    public static final int BRIGHTNESS_MAX_REASON_POWER_IC = 2;

    /** Brightness */
    public final float brightness;

@@ -144,6 +150,8 @@ public final class BrightnessInfo implements Parcelable {
                return "none";
            case BRIGHTNESS_MAX_REASON_THERMAL:
                return "thermal";
            case BRIGHTNESS_MAX_REASON_POWER_IC:
                return "power IC";
        }
        return "invalid";
    }
+6 −0
Original line number Diff line number Diff line
@@ -1818,6 +1818,12 @@ public final class DisplayManager {
         */
        String KEY_BRIGHTNESS_THROTTLING_DATA = "brightness_throttling_data";

        /**
         * Key for the power throttling data as a String formatted, from the display
         * device config.
         */
        String KEY_POWER_THROTTLING_DATA = "power_throttling_data";

        /**
         * Key for new power controller feature flag. If enabled new DisplayPowerController will
         * be used.
+2 −1
Original line number Diff line number Diff line
@@ -135,7 +135,8 @@ class DeviceStateToLayoutMap {
                            leadDisplayAddress,
                            d.getBrightnessThrottlingMapId(),
                            d.getRefreshRateZoneId(),
                            d.getRefreshRateThermalThrottlingMapId());
                            d.getRefreshRateThermalThrottlingMapId(),
                            d.getPowerThrottlingMapId());
                }
                layout.postProcessLocked();
            }
+12 −7
Original line number Diff line number Diff line
@@ -506,7 +506,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        mTag = "DisplayPowerController2[" + mDisplayId + "]";
        mThermalBrightnessThrottlingDataId =
                logicalDisplay.getDisplayInfoLocked().thermalBrightnessThrottlingDataId;

        mDisplayDevice = mLogicalDisplay.getPrimaryDisplayDeviceLocked();
        mUniqueDisplayId = logicalDisplay.getPrimaryDisplayDeviceLocked().getUniqueId();
        mDisplayStatsId = mUniqueDisplayId.hashCode();
@@ -566,8 +565,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                modeChangeCallback::run, new BrightnessClamperController.DisplayDeviceData(
                mUniqueDisplayId,
                mThermalBrightnessThrottlingDataId,
                mDisplayDeviceConfig
        ), mContext);
                logicalDisplay.getPowerThrottlingDataIdLocked(),
                mDisplayDeviceConfig), mContext, flags);
        // Seed the cached brightness
        saveBrightnessInfo(getScreenBrightnessSetting());
        mAutomaticBrightnessStrategy =
@@ -821,10 +820,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                .getDisplayDeviceInfoLocked().type == Display.TYPE_INTERNAL;
        final String thermalBrightnessThrottlingDataId =
                mLogicalDisplay.getDisplayInfoLocked().thermalBrightnessThrottlingDataId;

        mBrightnessClamperController.onDisplayChanged(
                new BrightnessClamperController.DisplayDeviceData(mUniqueDisplayId,
                        mThermalBrightnessThrottlingDataId, config));
        final String powerThrottlingDataId =
                mLogicalDisplay.getPowerThrottlingDataIdLocked();

        mHandler.postAtTime(() -> {
            boolean changed = false;
@@ -858,6 +855,14 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            }

            mIsDisplayInternal = isDisplayInternal;
            // using local variables here, when mBrightnessThrottler is removed,
            // mThermalBrightnessThrottlingDataId could be removed as well
            // changed = true will be not needed - clampers are maintaining their state and
            // will call updatePowerState if needed.
            mBrightnessClamperController.onDisplayChanged(
                    new BrightnessClamperController.DisplayDeviceData(uniqueId,
                        thermalBrightnessThrottlingDataId, powerThrottlingDataId, config));

            if (changed) {
                updatePowerState();
            }
+26 −0
Original line number Diff line number Diff line
@@ -189,6 +189,11 @@ final class LogicalDisplay {
    @Nullable
    private SurfaceControl.RefreshRateRange mLayoutLimitedRefreshRate;

    /**
     * The ID of the power throttling data that should be used.
     */
    private String mPowerThrottlingDataId;

    /**
     * RefreshRateRange limitation for @Temperature.ThrottlingStatus
     */
@@ -205,6 +210,7 @@ final class LogicalDisplay {
        mIsEnabled = true;
        mIsInTransition = false;
        mThermalBrightnessThrottlingDataId = DisplayDeviceConfig.DEFAULT_ID;
        mPowerThrottlingDataId = DisplayDeviceConfig.DEFAULT_ID;
        mBaseDisplayInfo.thermalBrightnessThrottlingDataId = mThermalBrightnessThrottlingDataId;
    }

@@ -910,6 +916,25 @@ final class LogicalDisplay {
        }
    }

    /**
     * @param powerThrottlingDataId The ID of the brightness throttling data that this
     *                                  display should use.
     */
    public void setPowerThrottlingDataIdLocked(String powerThrottlingDataId) {
        if (!Objects.equals(powerThrottlingDataId, mPowerThrottlingDataId)) {
            mPowerThrottlingDataId = powerThrottlingDataId;
            mDirty = true;
        }
    }

    /**
     * Returns powerThrottlingDataId which is the ID of the brightness
     * throttling data that this display should use.
     */
    public String getPowerThrottlingDataIdLocked() {
        return mPowerThrottlingDataId;
    }

    /**
     * Sets the display of which this display is a follower, regarding brightness or other
     * properties. If set to {@link Layout#NO_LEAD_DISPLAY}, this display does not follow any
@@ -976,6 +1001,7 @@ final class LogicalDisplay {
        pw.println("mLeadDisplayId=" + mLeadDisplayId);
        pw.println("mLayoutLimitedRefreshRate=" + mLayoutLimitedRefreshRate);
        pw.println("mThermalRefreshRateThrottling=" + mThermalRefreshRateThrottling);
        pw.println("mPowerThrottlingDataId=" + mPowerThrottlingDataId);
    }

    @Override
Loading