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

Commit babbcd96 authored by Chuong Hoang's avatar Chuong Hoang Committed by Android (Google) Code Review
Browse files

Merge "Initial doze brightness for offload" into main

parents 111c0cd7 d039a763
Loading
Loading
Loading
Loading
+46 −7
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.display;

import static com.android.server.display.BrightnessMappingStrategy.INVALID_LUX;
import static com.android.server.display.config.DisplayBrightnessMappingConfig.autoBrightnessModeToString;

import android.annotation.IntDef;
@@ -202,7 +203,7 @@ public class AutomaticBrightnessController {
    private float mScreenBrighteningThreshold;
    private float mScreenDarkeningThreshold;
    // The most recent light sample.
    private float mLastObservedLux;
    private float mLastObservedLux = INVALID_LUX;

    // The time of the most light recent sample.
    private long mLastObservedLuxTime;
@@ -403,8 +404,8 @@ public class AutomaticBrightnessController {
            brightnessEvent.setFlags(brightnessEvent.getFlags()
                    | (!mAmbientLuxValid ? BrightnessEvent.FLAG_INVALID_LUX : 0)
                    | (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE
                        ? BrightnessEvent.FLAG_DOZE_SCALE : 0)
                    | (isInIdleMode() ? BrightnessEvent.FLAG_IDLE_CURVE : 0));
                        ? BrightnessEvent.FLAG_DOZE_SCALE : 0));
            brightnessEvent.setAutoBrightnessMode(getMode());
        }

        if (!mAmbientLuxValid) {
@@ -420,6 +421,35 @@ public class AutomaticBrightnessController {
        return mRawScreenAutoBrightness;
    }

    /**
     * Get the automatic screen brightness based on the last observed lux reading. Used e.g. when
     * entering doze - we disable the light sensor, invalidate the lux, but we still need to set
     * the initial brightness in doze mode.
     */
    public float getAutomaticScreenBrightnessBasedOnLastObservedLux(
            BrightnessEvent brightnessEvent) {
        if (mLastObservedLux == INVALID_LUX) {
            return PowerManager.BRIGHTNESS_INVALID_FLOAT;
        }

        float brightness = mCurrentBrightnessMapper.getBrightness(mLastObservedLux,
                mForegroundAppPackageName, mForegroundAppCategory);
        if (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE) {
            brightness *= mDozeScaleFactor;
        }

        if (brightnessEvent != null) {
            brightnessEvent.setLux(mLastObservedLux);
            brightnessEvent.setRecommendedBrightness(brightness);
            brightnessEvent.setFlags(brightnessEvent.getFlags()
                    | (mLastObservedLux == INVALID_LUX ? BrightnessEvent.FLAG_INVALID_LUX : 0)
                    | (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE
                    ? BrightnessEvent.FLAG_DOZE_SCALE : 0));
            brightnessEvent.setAutoBrightnessMode(getMode());
        }
        return brightness;
    }

    public boolean hasValidAmbientLux() {
        return mAmbientLuxValid;
    }
@@ -539,7 +569,7 @@ public class AutomaticBrightnessController {
    }

    private boolean setScreenBrightnessByUser(float lux, float brightness) {
        if (lux == BrightnessMappingStrategy.INVALID_LUX || Float.isNaN(brightness)) {
        if (lux == INVALID_LUX || Float.isNaN(brightness)) {
            return false;
        }
        mCurrentBrightnessMapper.addUserDataPoint(lux, brightness);
@@ -564,6 +594,15 @@ public class AutomaticBrightnessController {
        return false;
    }

    /**
     * @return The auto-brightness mode of the current mapping strategy. Different modes use
     * different brightness curves.
     */
    @AutomaticBrightnessController.AutomaticBrightnessMode
    public int getMode() {
        return mCurrentBrightnessMapper.getMode();
    }

    public boolean isInIdleMode() {
        return mCurrentBrightnessMapper.getMode() == AUTO_BRIGHTNESS_MODE_IDLE;
    }
@@ -1236,12 +1275,12 @@ public class AutomaticBrightnessController {
        // light.
        // The anchor determines what were the light levels when the user has set their preference,
        // and we use a relative threshold to determine when to revert to the OEM curve.
        private float mAnchor = BrightnessMappingStrategy.INVALID_LUX;
        private float mAnchor = INVALID_LUX;
        private float mBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        private boolean mIsValid = false;

        private void reset() {
            mAnchor = BrightnessMappingStrategy.INVALID_LUX;
            mAnchor = INVALID_LUX;
            mBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
            mIsValid = false;
        }
@@ -1265,7 +1304,7 @@ public class AutomaticBrightnessController {
        private boolean maybeReset(float currentLux) {
            // If the short term model was invalidated and the change is drastic enough, reset it.
            // Otherwise, we revalidate it.
            if (!mIsValid && mAnchor != BrightnessMappingStrategy.INVALID_LUX) {
            if (!mIsValid && mAnchor != INVALID_LUX) {
                if (mCurrentBrightnessMapper.shouldResetShortTermModel(currentLux, mAnchor)) {
                    resetShortTermModel();
                } else {
+22 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.display;

import static android.hardware.display.DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE;

import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT;
import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DOZE;
import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_IDLE;
@@ -37,7 +39,6 @@ import android.hardware.display.AmbientBrightnessDayStats;
import android.hardware.display.BrightnessChangeEvent;
import android.hardware.display.BrightnessConfiguration;
import android.hardware.display.BrightnessInfo;
import android.hardware.display.DisplayManagerInternal;
import android.hardware.display.DisplayManagerInternal.DisplayOffloadSession;
import android.hardware.display.DisplayManagerInternal.DisplayPowerCallbacks;
import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
@@ -1378,7 +1379,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        // Switch to doze auto-brightness mode if needed
        if (mFlags.areAutoBrightnessModesEnabled() && mAutomaticBrightnessController != null
                && !mAutomaticBrightnessController.isInIdleMode()) {
            setAutomaticScreenBrightnessMode(Display.isDozeState(state)
            mAutomaticBrightnessController.switchMode(mPowerRequest.policy == POLICY_DOZE
                    ? AUTO_BRIGHTNESS_MODE_DOZE : AUTO_BRIGHTNESS_MODE_DEFAULT);
        }

@@ -1466,6 +1467,22 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            mAutomaticBrightnessStrategy.setAutoBrightnessApplied(false);
        }

        // If there's an offload session and auto-brightness is on, we need to set the initial doze
        // brightness using the doze auto-brightness curve before the offload session starts
        // controlling the brightness.
        if (Float.isNaN(brightnessState) && mFlags.areAutoBrightnessModesEnabled()
                && mFlags.isDisplayOffloadEnabled()
                && mPowerRequest.policy == POLICY_DOZE
                && mDisplayOffloadSession != null
                && mAutomaticBrightnessStrategy.shouldUseAutoBrightness()) {
            rawBrightnessState = mAutomaticBrightnessController
                    .getAutomaticScreenBrightnessBasedOnLastObservedLux(mTempBrightnessEvent);
            if (BrightnessUtils.isValidBrightnessValue(rawBrightnessState)) {
                brightnessState = clampScreenBrightness(rawBrightnessState);
                mBrightnessReasonTemp.setReason(BrightnessReason.REASON_DOZE_INITIAL);
            }
        }

        // Use default brightness when dozing unless overridden.
        if ((Float.isNaN(brightnessState))
                && Display.isDozeState(state)) {
@@ -1618,7 +1635,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

            // if doze or suspend state is requested, we want to finish brightnes animation fast
            // to allow state animation to start
            if (mPowerRequest.policy == DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE
            if (mPowerRequest.policy == POLICY_DOZE
                    && (mPowerRequest.dozeScreenState == Display.STATE_UNKNOWN  // dozing
                    || mPowerRequest.dozeScreenState == Display.STATE_DOZE_SUSPEND
                    || mPowerRequest.dozeScreenState == Display.STATE_ON_SUSPEND)) {
@@ -1706,6 +1723,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mTempBrightnessEvent.setTime(System.currentTimeMillis());
        mTempBrightnessEvent.setBrightness(brightnessState);
        mTempBrightnessEvent.setPhysicalDisplayId(mUniqueDisplayId);
        mTempBrightnessEvent.setDisplayState(state);
        mTempBrightnessEvent.setReason(mBrightnessReason);
        mTempBrightnessEvent.setHbmMax(mBrightnessRangeController.getCurrentBrightnessMax());
        mTempBrightnessEvent.setHbmMode(mBrightnessRangeController.getHighBrightnessMode());
@@ -2879,7 +2897,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    (flags & BrightnessEvent.FLAG_INVALID_LUX) > 0,
                    (flags & BrightnessEvent.FLAG_DOZE_SCALE) > 0,
                    (flags & BrightnessEvent.FLAG_USER_SET) > 0,
                    (flags & BrightnessEvent.FLAG_IDLE_CURVE) > 0,
                    event.getAutoBrightnessMode() == AUTO_BRIGHTNESS_MODE_IDLE,
                    (flags & BrightnessEvent.FLAG_LOW_POWER_MODE) > 0);
        }
    }
+32 −4
Original line number Diff line number Diff line
@@ -16,11 +16,16 @@

package com.android.server.display.brightness;

import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT;
import static com.android.server.display.config.DisplayBrightnessMappingConfig.autoBrightnessModeToString;

import android.hardware.display.BrightnessInfo;
import android.os.PowerManager;
import android.os.SystemClock;
import android.view.Display;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.display.AutomaticBrightnessController;

import java.text.SimpleDateFormat;
import java.util.Date;
@@ -33,7 +38,6 @@ public final class BrightnessEvent {
    public static final int FLAG_INVALID_LUX = 0x2;
    public static final int FLAG_DOZE_SCALE = 0x4;
    public static final int FLAG_USER_SET = 0x8;
    public static final int FLAG_IDLE_CURVE = 0x10;
    public static final int FLAG_LOW_POWER_MODE = 0x20;

    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS");
@@ -41,6 +45,7 @@ public final class BrightnessEvent {
    private BrightnessReason mReason = new BrightnessReason();
    private int mDisplayId;
    private String mPhysicalDisplayId;
    private int mDisplayState;
    private long mTime;
    private float mLux;
    private float mPreThresholdLux;
@@ -58,6 +63,8 @@ public final class BrightnessEvent {
    private int mAdjustmentFlags;
    private boolean mAutomaticBrightnessEnabled;
    private String mDisplayBrightnessStrategyName;
    @AutomaticBrightnessController.AutomaticBrightnessMode
    private int mAutoBrightnessMode;

    public BrightnessEvent(BrightnessEvent that) {
        copyFrom(that);
@@ -77,6 +84,7 @@ public final class BrightnessEvent {
        mReason.set(that.getReason());
        mDisplayId = that.getDisplayId();
        mPhysicalDisplayId = that.getPhysicalDisplayId();
        mDisplayState = that.mDisplayState;
        mTime = that.getTime();
        // Lux values
        mLux = that.getLux();
@@ -98,6 +106,7 @@ public final class BrightnessEvent {
        // Auto-brightness setting
        mAutomaticBrightnessEnabled = that.isAutomaticBrightnessEnabled();
        mDisplayBrightnessStrategyName = that.getDisplayBrightnessStrategyName();
        mAutoBrightnessMode = that.mAutoBrightnessMode;
    }

    /**
@@ -107,6 +116,7 @@ public final class BrightnessEvent {
        mReason = new BrightnessReason();
        mTime = SystemClock.uptimeMillis();
        mPhysicalDisplayId = "";
        mDisplayState = Display.STATE_UNKNOWN;
        // Lux values
        mLux = 0;
        mPreThresholdLux = 0;
@@ -127,6 +137,7 @@ public final class BrightnessEvent {
        // Auto-brightness setting
        mAutomaticBrightnessEnabled = true;
        mDisplayBrightnessStrategyName = "";
        mAutoBrightnessMode = AUTO_BRIGHTNESS_MODE_DEFAULT;
    }

    /**
@@ -143,6 +154,7 @@ public final class BrightnessEvent {
        return mReason.equals(that.mReason)
                && mDisplayId == that.mDisplayId
                && mPhysicalDisplayId.equals(that.mPhysicalDisplayId)
                && mDisplayState == that.mDisplayState
                && Float.floatToRawIntBits(mLux) == Float.floatToRawIntBits(that.mLux)
                && Float.floatToRawIntBits(mPreThresholdLux)
                == Float.floatToRawIntBits(that.mPreThresholdLux)
@@ -163,7 +175,8 @@ public final class BrightnessEvent {
                && mFlags == that.mFlags
                && mAdjustmentFlags == that.mAdjustmentFlags
                && mAutomaticBrightnessEnabled == that.mAutomaticBrightnessEnabled
                && mDisplayBrightnessStrategyName.equals(that.mDisplayBrightnessStrategyName);
                && mDisplayBrightnessStrategyName.equals(that.mDisplayBrightnessStrategyName)
                && mAutoBrightnessMode == that.mAutoBrightnessMode;
    }

    /**
@@ -177,6 +190,7 @@ public final class BrightnessEvent {
                + "BrightnessEvent: "
                + "disp=" + mDisplayId
                + ", physDisp=" + mPhysicalDisplayId
                + ", displayState=" + Display.stateToString(mDisplayState)
                + ", brt=" + mBrightness + ((mFlags & FLAG_USER_SET) != 0 ? "(user_set)" : "")
                + ", initBrt=" + mInitialBrightness
                + ", rcmdBrt=" + mRecommendedBrightness
@@ -192,7 +206,8 @@ public final class BrightnessEvent {
                + ", flags=" + flagsToString()
                + ", reason=" + mReason.toString(mAdjustmentFlags)
                + ", autoBrightness=" + mAutomaticBrightnessEnabled
                + ", strategy=" + mDisplayBrightnessStrategyName;
                + ", strategy=" + mDisplayBrightnessStrategyName
                + ", autoBrightnessMode=" + autoBrightnessModeToString(mAutoBrightnessMode);
    }

    @Override
@@ -232,6 +247,10 @@ public final class BrightnessEvent {
        this.mPhysicalDisplayId = mPhysicalDisplayId;
    }

    public void setDisplayState(int state) {
        mDisplayState = state;
    }

    public float getLux() {
        return mLux;
    }
@@ -374,6 +393,16 @@ public final class BrightnessEvent {
        this.mAutomaticBrightnessEnabled = mAutomaticBrightnessEnabled;
    }

    @AutomaticBrightnessController.AutomaticBrightnessMode
    public int getAutoBrightnessMode() {
        return mAutoBrightnessMode;
    }

    public void setAutoBrightnessMode(
            @AutomaticBrightnessController.AutomaticBrightnessMode int mode) {
        mAutoBrightnessMode = mode;
    }

    /**
     * A utility to stringify flags from a BrightnessEvent
     * @return Stringified flags from BrightnessEvent
@@ -384,7 +413,6 @@ public final class BrightnessEvent {
                + ((mFlags & FLAG_RBC) != 0 ? "rbc " : "")
                + ((mFlags & FLAG_INVALID_LUX) != 0 ? "invalid_lux " : "")
                + ((mFlags & FLAG_DOZE_SCALE) != 0 ? "doze_scale " : "")
                + ((mFlags & FLAG_IDLE_CURVE) != 0 ? "idle_curve " : "")
                + ((mFlags & FLAG_LOW_POWER_MODE) != 0 ? "low_power_mode " : "");
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -40,7 +40,8 @@ public final class BrightnessReason {
    public static final int REASON_SCREEN_OFF_BRIGHTNESS_SENSOR = 9;
    public static final int REASON_FOLLOWER = 10;
    public static final int REASON_OFFLOAD = 11;
    public static final int REASON_MAX = REASON_OFFLOAD;
    public static final int REASON_DOZE_INITIAL = 12;
    public static final int REASON_MAX = REASON_DOZE_INITIAL;

    public static final int MODIFIER_DIMMED = 0x1;
    public static final int MODIFIER_LOW_POWER = 0x2;
@@ -207,6 +208,8 @@ public final class BrightnessReason {
                return "follower";
            case REASON_OFFLOAD:
                return "offload";
            case REASON_DOZE_INITIAL:
                return "doze_initial";
            default:
                return Integer.toString(reason);
        }
+17 −0
Original line number Diff line number Diff line
@@ -266,6 +266,23 @@ public class AutomaticBrightnessStrategy {
        return brightness;
    }

    /**
     * Get the automatic screen brightness based on the last observed lux reading. Used e.g. when
     * entering doze - we disable the light sensor, invalidate the lux, but we still need to set
     * the initial brightness in doze mode.
     * @param brightnessEvent Event object to populate with details about why the specific
     *                        brightness was chosen.
     */
    public float getAutomaticScreenBrightnessBasedOnLastObservedLux(
            BrightnessEvent brightnessEvent) {
        float brightness = (mAutomaticBrightnessController != null)
                ? mAutomaticBrightnessController
                .getAutomaticScreenBrightnessBasedOnLastObservedLux(brightnessEvent)
                : PowerManager.BRIGHTNESS_INVALID_FLOAT;
        adjustAutomaticBrightnessStateIfValid(brightness);
        return brightness;
    }

    /**
     * Gets the auto-brightness adjustment flag change reason
     */
Loading