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

Commit 167c793e 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 PersistentDataStore
Test: adb pull /data/system/display-manager-state.xml
Test: atest PersistentDataStoreTest
Test: adb shell dumpsys display | grep mPersistBrightnessNitsForDefaultDisplay
Change-Id: I20a0a686ee1e4e945fbcd99d5b996534f8ef93b7
Merged-In: I20a0a686ee1e4e945fbcd99d5b996534f8ef93b7
parent 4dac733f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6092,4 +6092,8 @@

    <!-- Whether to show weather on the lock screen by default. -->
    <bool name="config_lockscreenWeatherEnabledByDefault">false</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
@@ -2282,6 +2282,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" />
+8 −0
Original line number Diff line number Diff line
@@ -1127,6 +1127,14 @@ class AutomaticBrightnessController {
        }
    }

    public float convertToFloatScale(float nits) {
        if (mCurrentBrightnessMapper != null) {
            return mCurrentBrightnessMapper.convertToFloatScale(nits);
        } else {
            return PowerManager.BRIGHTNESS_INVALID_FLOAT;
        }
    }

    public void recalculateSplines(boolean applyAdjustment, float[] adjustment) {
        mCurrentBrightnessMapper.recalculateSplines(applyAdjustment, adjustment);

+18 −0
Original line number Diff line number Diff line
@@ -321,6 +321,14 @@ public abstract class BrightnessMappingStrategy {
     */
    public abstract float convertToNits(float brightness);

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

    /**
     * Adds a user interaction data point to the brightness mapping.
     *
@@ -670,6 +678,11 @@ public abstract class BrightnessMappingStrategy {
            return -1.0f;
        }

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

        @Override
        public void addUserDataPoint(float lux, float brightness) {
            float unadjustedBrightness = getUnadjustedBrightness(lux);
@@ -912,6 +925,11 @@ public abstract class BrightnessMappingStrategy {
            return mBrightnessToNitsSpline.interpolate(brightness);
        }

        @Override
        public float convertToFloatScale(float nits) {
            return mNitsToBrightnessSpline.interpolate(nits);
        }

        @Override
        public void addUserDataPoint(float lux, float brightness) {
            float unadjustedBrightness = getUnadjustedBrightness(lux);
+17 −0
Original line number Diff line number Diff line
@@ -117,6 +117,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.
     */
    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
     */
    void setBrightnessNitsForDefaultDisplay(float nits) {
        mPersistentDataStore.setBrightnessNitsForDefaultDisplay(nits);
    }

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