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

Commit 52a9dabf authored by Long Ling's avatar Long Ling Committed by android-build-merger
Browse files

Merge "Add brightness threshold for peak refresh rate" into qt-r1-dev

am: c09ec50c

Change-Id: I4b13ed352602635b66c812ddcf7e905c3b759ad5
parents 48bc2f55 c09ec50c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -4068,6 +4068,9 @@
         for higher refresh rates to be automatically used out of the box -->
    <integer name="config_defaultPeakRefreshRate">60</integer>

    <!-- The default brightness threshold that allows to switch to higher refresh rate -->
    <integer name="config_brightnessThresholdOfPeakRefreshRate">-1</integer>

    <!-- The type of the light sensor to be used by the display framework for things like
         auto-brightness. If unset, then it just gets the default sensor of type TYPE_LIGHT. -->
    <string name="config_displayLightSensorType" translatable="false" />
+1 −0
Original line number Diff line number Diff line
@@ -3767,6 +3767,7 @@

  <!-- For high refresh rate displays -->
  <java-symbol type="integer" name="config_defaultPeakRefreshRate" />
  <java-symbol type="integer" name="config_brightnessThresholdOfPeakRefreshRate" />

  <!-- For Auto-Brightness -->
  <java-symbol type="string" name="config_displayLightSensorType" />
+31 −1
Original line number Diff line number Diff line
@@ -407,7 +407,8 @@ public class DisplayModeDirector {
        // the other.
        public static final int PRIORITY_APP_REQUEST_REFRESH_RATE = 1;
        public static final int PRIORITY_APP_REQUEST_SIZE = 2;
        public static final int PRIORITY_LOW_POWER_MODE = 3;
        public static final int PRIORITY_LOW_BRIGHTNESS = 3;
        public static final int PRIORITY_LOW_POWER_MODE = 4;

        // Whenever a new priority is added, remember to update MIN_PRIORITY and/or MAX_PRIORITY as
        // appropriate, as well as priorityToString.
@@ -485,15 +486,20 @@ public class DisplayModeDirector {
                Settings.System.getUriFor(Settings.System.PEAK_REFRESH_RATE);
        private final Uri mLowPowerModeSetting =
                Settings.Global.getUriFor(Settings.Global.LOW_POWER_MODE);
        private final Uri mBrightnessSetting =
                Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS);

        private final Context mContext;
        private final float mDefaultPeakRefreshRate;
        private final int mBrightnessThreshold;

        SettingsObserver(@NonNull Context context, @NonNull Handler handler) {
            super(handler);
            mContext = context;
            mDefaultPeakRefreshRate = (float) context.getResources().getInteger(
                    R.integer.config_defaultPeakRefreshRate);
            mBrightnessThreshold = context.getResources().getInteger(
                    R.integer.config_brightnessThresholdOfPeakRefreshRate);
        }

        public void observe() {
@@ -502,9 +508,14 @@ public class DisplayModeDirector {
                    UserHandle.USER_SYSTEM);
            cr.registerContentObserver(mLowPowerModeSetting, false /*notifyDescendants*/, this,
                    UserHandle.USER_SYSTEM);
            if (mBrightnessThreshold >= 0) {
                cr.registerContentObserver(mBrightnessSetting, false /*notifyDescendants*/, this,
                    UserHandle.USER_SYSTEM);
            }
            synchronized (mLock) {
                updateRefreshRateSettingLocked();
                updateLowPowerModeSettingLocked();
                updateBrightnessSettingLocked();
            }
        }

@@ -515,6 +526,8 @@ public class DisplayModeDirector {
                    updateRefreshRateSettingLocked();
                } else if (mLowPowerModeSetting.equals(uri)) {
                    updateLowPowerModeSettingLocked();
                } else if (mBrightnessThreshold >=0 && mBrightnessSetting.equals(uri)) {
                    updateBrightnessSettingLocked();
                }
            }
        }
@@ -538,6 +551,23 @@ public class DisplayModeDirector {
            updateVoteLocked(Vote.PRIORITY_USER_SETTING, vote);
        }

        private void updateBrightnessSettingLocked() {
            int brightness = Settings.System.getInt(mContext.getContentResolver(),
                    Settings.System.SCREEN_BRIGHTNESS, -1);

            if (brightness < 0) {
                return;
            }

            final Vote vote;
            if (brightness <= mBrightnessThreshold) {
                vote = Vote.forRefreshRates(0f, 60f);
            } else {
                vote = null;
            }
            updateVoteLocked(Vote.PRIORITY_LOW_BRIGHTNESS, vote);
        }

        public void dumpLocked(PrintWriter pw) {
            pw.println("  SettingsObserver");
            pw.println("    mDefaultPeakRefreshRate: " + mDefaultPeakRefreshRate);