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

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

Fix UserHandle

LowLuxModifier, DMD and DPC register observer while the system is starting (current user = system), but on some devices, later the current user switches. When Smooth Display for example is enabled with the UI, it's enabled by the new user and not the system user. We should therefore use USER_ALL when registering observers.

When reading the settings, we should use USER_CURRENT instead of getting the user id from the context associated with the system.

We should also re-read the settings if the user switches.

Additionally, update the stale evenDimmer comment in DDC.

Bug: 353645971
Test: AutomaticBrightnessControllerTest, BrightnessClamperControllerTest, BrightnessLowLuxModifierTest, BrightnessMappingStrategyTest, DisplayManagerServiceTest, DisplayModeDirectorTest, DisplayPowerControllerTest
Flag: EXEMPT bugfix
Change-Id: I204478b6f356aea72f50bf9130f92e53b2758202
parent 03860432
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -579,6 +579,14 @@ public class AutomaticBrightnessController {
        return mCurrentBrightnessMapper.getMode();
    }

    /**
     * @return The preset for this mapping strategy. Presets are used on devices that allow users
     * to choose from a set of predefined options in display auto-brightness settings.
     */
    public int getPreset() {
        return mCurrentBrightnessMapper.getPreset();
    }

    public boolean isInIdleMode() {
        return mCurrentBrightnessMapper.getMode() == AUTO_BRIGHTNESS_MODE_IDLE;
    }
+27 −4
Original line number Diff line number Diff line
@@ -140,10 +140,10 @@ public abstract class BrightnessMappingStrategy {
            builder.setShortTermModelLowerLuxMultiplier(SHORT_TERM_MODEL_THRESHOLD_RATIO);
            builder.setShortTermModelUpperLuxMultiplier(SHORT_TERM_MODEL_THRESHOLD_RATIO);
            return new PhysicalMappingStrategy(builder.build(), nitsRange, brightnessRange,
                    autoBrightnessAdjustmentMaxGamma, mode, displayWhiteBalanceController);
                    autoBrightnessAdjustmentMaxGamma, mode, preset, displayWhiteBalanceController);
        } else if (isValidMapping(luxLevels, brightnessLevels)) {
            return new SimpleMappingStrategy(luxLevels, brightnessLevels,
                    autoBrightnessAdjustmentMaxGamma, shortTermModelTimeout, mode);
                    autoBrightnessAdjustmentMaxGamma, shortTermModelTimeout, mode, preset);
        } else {
            return null;
        }
@@ -393,6 +393,12 @@ public abstract class BrightnessMappingStrategy {
    @AutomaticBrightnessController.AutomaticBrightnessMode
    abstract int getMode();

    /**
     * @return The preset for this mapping strategy. Presets are used on devices that allow users
     * to choose from a set of predefined options in display auto-brightness settings.
     */
    abstract int getPreset();

    /**
     * Check if the short term model should be reset given the anchor lux the last
     * brightness change was made at and the current ambient lux.
@@ -598,6 +604,8 @@ public abstract class BrightnessMappingStrategy {
        @AutomaticBrightnessController.AutomaticBrightnessMode
        private final int mMode;

        private final int mPreset;

        private Spline mSpline;
        private float mMaxGamma;
        private float mAutoBrightnessAdjustment;
@@ -606,7 +614,8 @@ public abstract class BrightnessMappingStrategy {
        private long mShortTermModelTimeout;

        private SimpleMappingStrategy(float[] lux, float[] brightness, float maxGamma,
                long timeout, @AutomaticBrightnessController.AutomaticBrightnessMode int mode) {
                long timeout, @AutomaticBrightnessController.AutomaticBrightnessMode int mode,
                int preset) {
            Preconditions.checkArgument(lux.length != 0 && brightness.length != 0,
                    "Lux and brightness arrays must not be empty!");
            Preconditions.checkArgument(lux.length == brightness.length,
@@ -633,6 +642,7 @@ public abstract class BrightnessMappingStrategy {
            computeSpline();
            mShortTermModelTimeout = timeout;
            mMode = mode;
            mPreset = preset;
        }

        @Override
@@ -765,6 +775,11 @@ public abstract class BrightnessMappingStrategy {
            return mMode;
        }

        @Override
        int getPreset() {
            return mPreset;
        }

        @Override
        float getUserLux() {
            return mUserLux;
@@ -837,6 +852,8 @@ public abstract class BrightnessMappingStrategy {
        @AutomaticBrightnessController.AutomaticBrightnessMode
        private final int mMode;

        private final int mPreset;

        // Previous short-term models and the times that they were computed stored for debugging
        // purposes
        private List<Spline> mPreviousBrightnessSplines = new ArrayList<>();
@@ -846,7 +863,7 @@ public abstract class BrightnessMappingStrategy {

        public PhysicalMappingStrategy(BrightnessConfiguration config, float[] nits,
                float[] brightness, float maxGamma,
                @AutomaticBrightnessController.AutomaticBrightnessMode int mode,
                @AutomaticBrightnessController.AutomaticBrightnessMode int mode, int preset,
                @Nullable DisplayWhiteBalanceController displayWhiteBalanceController) {

            Preconditions.checkArgument(nits.length != 0 && brightness.length != 0,
@@ -860,6 +877,7 @@ public abstract class BrightnessMappingStrategy {
                    PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX, "brightness");

            mMode = mode;
            mPreset = preset;
            mMaxGamma = maxGamma;
            mAutoBrightnessAdjustment = 0;
            mUserLux = INVALID_LUX;
@@ -1072,6 +1090,11 @@ public abstract class BrightnessMappingStrategy {
            return mMode;
        }

        @Override
        int getPreset() {
            return mPreset;
        }

        @Override
        float getUserLux() {
            return mUserLux;
+37 −16
Original line number Diff line number Diff line
@@ -589,21 +589,42 @@ import javax.xml.datatype.DatatypeConfigurationException;
 *     </usiVersion>
 *     <evenDimmer enabled="true">
 *         <transitionPoint>0.1</transitionPoint>
 *
 *         <brightnessMapping>
 *             <brightnessPoint>
 *                 <nits>0.2</nits>
 *                 <backlight>0</backlight>
 *                 <brightness>0</brightness>
 *                 </brightnessPoint>
 *             <brightnessPoint>
 *                 <nits>2.0</nits>
 *                 <backlight>0.01</backlight>
 *                 <brightness>0.002</brightness>
 *             </brightnessPoint>
 *             <brightnessPoint>
 *                 <nits>500.0</nits>
 *       <nits>1000.0</nits>
 *
 *       <backlight>0</backlight>
 *       <backlight>0.0001</backlight>
 *                 <backlight>0.5</backlight>
 *       <backlight>1.0</backlight>
 *
 *       <brightness>0</brightness>
 *       <brightness>0.1</brightness>
 *                 <brightness>0.5</brightness>
 *             </brightnessPoint>
 *             <brightnessPoint>
 *                 <nits>1000</nits>
 *                 <backlight>1.0</backlight>
 *                 <brightness>1.0</brightness>
 *             </brightnessPoint>
 *         </brightnessMapping>
 *         <luxToMinimumNitsMap>
 *             <point>
 *                 <value>10</value>
 *                 <nits>0.3</nits>
 *             </point>
 *             <point>
 *                 <value>50</value>
 *                 <nits>0.7</nits>
 *             </point>
 *             <point>
 *                 <value>100</value>
 *                 <nits>1.0</nits>
 *             </point>
 *         </luxToMinimumNitsMap>
 *     </evenDimmer>
 *     <screenBrightnessCapForWearBedtimeMode>0.1</screenBrightnessCapForWearBedtimeMode>
 *     <idleScreenRefreshRateTimeout>
+1 −0
Original line number Diff line number Diff line
@@ -722,6 +722,7 @@ public final class DisplayManagerService extends SystemService {
            if (userSwitching) {
                mCurrentUserId = newUserId;
            }
            mDisplayModeDirector.onSwitchUser();
            mLogicalDisplayMapper.forEachLocked(logicalDisplay -> {
                if (logicalDisplay.getDisplayInfoLocked().type != Display.TYPE_INTERNAL) {
                    return;
+13 −1
Original line number Diff line number Diff line
@@ -702,6 +702,17 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    private void handleOnSwitchUser(@UserIdInt int newUserId, int userSerial, float newBrightness) {
        Slog.i(mTag, "Switching user newUserId=" + newUserId + " userSerial=" + userSerial
                + " newBrightness=" + newBrightness);

        if (mAutomaticBrightnessController != null) {
            int autoBrightnessPreset = Settings.System.getIntForUser(mContext.getContentResolver(),
                    Settings.System.SCREEN_BRIGHTNESS_FOR_ALS,
                    Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL,
                    UserHandle.USER_CURRENT);
            if (autoBrightnessPreset != mAutomaticBrightnessController.getPreset()) {
                setUpAutoBrightness(mContext, mHandler);
            }
        }

        handleBrightnessModeChange();
        if (mBrightnessTracker != null) {
            mBrightnessTracker.onSwitchUser(newUserId);
@@ -714,6 +725,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        if (mAutomaticBrightnessController != null) {
            mAutomaticBrightnessController.resetShortTermModel();
        }
        mBrightnessClamperController.onUserSwitch();
        sendUpdatePowerState();
    }

@@ -1009,7 +1021,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        if (mFlags.areAutoBrightnessModesEnabled()) {
            mContext.getContentResolver().registerContentObserver(
                    Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_FOR_ALS),
                    /* notifyForDescendants= */ false, mSettingsObserver, UserHandle.USER_CURRENT);
                    /* notifyForDescendants= */ false, mSettingsObserver, UserHandle.USER_ALL);
        }
        handleBrightnessModeChange();
    }
Loading