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

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

Persist the nit brightness for the default display

Store the brightness for the default display in nits in persistent data store so that it can be persisted if the device reboots or the display device changes.

Bug: 258455654
Test: adb shell dumpsys display | grep -A30 PersistentDataStore
Test: adb pull /data/system/display-manager-state.xml
Test: atest com.android.server.display
Test: adb shell dumpsys display | grep mPersistBrightnessNitsForDefaultDisplay
Change-Id: I20a0a686ee1e4e945fbcd99d5b996534f8ef93b7
parent dd887408
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6346,4 +6346,8 @@
    <bool name="config_batteryStatsResetOnUnplugHighBatteryLevel">true</bool>
    <!-- Whether to reset Battery Stats on unplug if the battery was significantly charged -->
    <bool name="config_batteryStatsResetOnUnplugAfterSignificantCharge">true</bool>

    <!-- Whether we should persist the brightness value in nits for the default display even if
         the underlying display device changes. -->
    <bool name="config_persistBrightnessNitsForDefaultDisplay">false</bool>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -2229,6 +2229,7 @@
  <java-symbol type="bool" name="config_preventImeStartupUnlessTextEditor" />
  <java-symbol type="array" name="config_nonPreemptibleInputMethods" />
  <java-symbol type="bool" name="config_enhancedConfirmationModeEnabled" />
  <java-symbol type="bool" name="config_persistBrightnessNitsForDefaultDisplay" />

  <java-symbol type="layout" name="resolver_list" />
  <java-symbol type="id" name="resolver_list" />
+7 −2
Original line number Diff line number Diff line
@@ -50,7 +50,12 @@ import com.android.server.display.brightness.BrightnessEvent;

import java.io.PrintWriter;

class AutomaticBrightnessController {
/**
 * Manages the associated display brightness when in auto-brightness mode. This is also
 * responsible for managing the brightness lux-nits mapping strategies. Internally also listens to
 * the LightSensor and adjusts the system brightness in case of changes in the surrounding lux.
 */
public class AutomaticBrightnessController {
    private static final String TAG = "AutomaticBrightnessController";

    private static final boolean DEBUG_PRETEND_LIGHT_SENSOR_ABSENT = false;
@@ -1140,7 +1145,7 @@ class AutomaticBrightnessController {
        if (mCurrentBrightnessMapper != null) {
            return mCurrentBrightnessMapper.convertToFloatScale(nits);
        } else {
            return -1.0f;
            return PowerManager.BRIGHTNESS_INVALID_FLOAT;
        }
    }

+4 −3
Original line number Diff line number Diff line
@@ -322,9 +322,10 @@ public abstract class BrightnessMappingStrategy {
    public abstract float convertToNits(float brightness);

    /**
     * Converts the provided nits value to a float value if possible.
     * Converts the provided nit value to a float scale value if possible.
     *
     * Returns -1.0f if there's no available mapping for the nits to float.
     * Returns {@link PowerManager.BRIGHTNESS_INVALID_FLOAT} if there's no available mapping for
     * the nits to float scale.
     */
    public abstract float convertToFloatScale(float nits);

@@ -679,7 +680,7 @@ public abstract class BrightnessMappingStrategy {

        @Override
        public float convertToFloatScale(float nits) {
            return -1.0f;
            return PowerManager.BRIGHTNESS_INVALID_FLOAT;
        }

        @Override
+17 −0
Original line number Diff line number Diff line
@@ -121,6 +121,23 @@ public class BrightnessSetting {
        }
    }

    /**
     * @return The brightness for the default display in nits. Used when the underlying display
     * device has changed but we want to persist the nit value.
     */
    public float getBrightnessNitsForDefaultDisplay() {
        return mPersistentDataStore.getBrightnessNitsForDefaultDisplay();
    }

    /**
     * Set brightness in nits for the default display. Used when we want to persist the nit value
     * even if the underlying display device changes.
     * @param nits The brightness value in nits
     */
    public void setBrightnessNitsForDefaultDisplay(float nits) {
        mPersistentDataStore.setBrightnessNitsForDefaultDisplay(nits);
    }

    private void notifyListeners(float brightness) {
        for (BrightnessSettingListener l : mListeners) {
            l.onBrightnessChanged(brightness);
Loading