Loading core/res/res/values/config.xml +101 −0 Original line number Diff line number Diff line Loading @@ -3781,4 +3781,105 @@ <!-- Whether or not aware is enabled by default --> <bool name="config_awareSettingAvailable">false</bool> <!-- Display White-Balance --> <!-- See AmbientSensor.AmbientBrightnessSensor. The ambient brightness sensor rate (in milliseconds). Must be positive. --> <integer name="config_displayWhiteBalanceBrightnessSensorRate">250</integer> <!-- See AmbientFilter. How long ambient brightness changes are kept and taken into consideration (in milliseconds). Must be positive. --> <integer name="config_displayWhiteBalanceBrightnessFilterHorizon">10000</integer> <!-- See AmbientFilter.WeightedMovingAverageAmbientFilter. Recent changes are prioritised by integrating their duration over y = x + intercept (the higher it is, the less prioritised recent changes are). Must be a non-negative number, or NaN to avoid this implementation. --> <item name="config_displayWhiteBalanceBrightnessFilterIntercept" format="float" type="dimen">10.0</item> <!-- See AmbientSensor.AmbientColorTemperatureSensor. The ambient color temperature sensor name. --> <string name="config_displayWhiteBalanceColorTemperatureSensorName">com.google.sensor.color</string> <!-- See AmbientSensor.AmbientColorTemperatureSensor. The ambient color temperature sensor rate (in milliseconds). Must be positive. --> <integer name="config_displayWhiteBalanceColorTemperatureSensorRate">250</integer> <!-- See AmbientFilter. How long ambient color temperature changes are kept and taken into consideration (in milliseconds). Must be positive. --> <integer name="config_displayWhiteBalanceColorTemperatureFilterHorizon">10000</integer> <!-- See AmbientFilter.WeightedMovingAverageAmbientFilter. Recent changes are prioritised by integrating their duration over y = x + intercept (the higher it is, the less prioritised recent changes are). Must be a non-negative number, or NaN to avoid this implementation. --> <item name="config_displayWhiteBalanceColorTemperatureFilterIntercept" format="float" type="dimen">10.0</item> <!-- See DisplayWhiteBalanceThrottler. The debounce time (in milliseconds) for increasing the screen color temperature, throttled if time > lastTime + debounce. Must be non-negative. --> <integer name="config_displayWhiteBalanceIncreaseDebounce">5000</integer> <!-- See DisplayWhiteBalanceThrottler. The debounce time (in milliseconds) for decreasing the screen color tempearture, throttled if time < lastTime - debounce. Must be non-negative. --> <integer name="config_displayWhiteBalanceDecreaseDebounce">5000</integer> <!-- See DisplayWhiteBalanceThrottler. The ambient color temperature values used to determine the threshold as the corresponding value in config_displayWhiteBalance{Increase,Decrease}Threholds. Must be non-empty, the same length as config_displayWhiteBalance{Increase,Decrease}Thresholds, and contain non-negative, strictly increasing numbers. For example, if: - baseThresolds = [0, 100, 1000]; - increaseThresholds = [0.1, 0.15, 0.2]; - decreaseThresholds = [0.1, 0.05, 0.0]; Then, given the ambient color temperature INCREASED from X to Y (so X < Y): - If 0 <= Y < 100, we require Y > (1 + 0.1) * X = 1.1X; - If 100 <= Y < 1000, we require Y > (1 + 0.15) * X = 1.15X; - If 1000 <= Y, we require Y > (1 + 0.2) * X = 1.2X. Or, if the ambient color temperature DECREASED from X to Y (so X > Y): - If 0 <= Y < 100, we require Y < (1 - 0.1) * X = 0.9X; - If 100 <= Y < 1000, we require Y < (1 - 0.05) * X = 0.95X; - If 1000 <= Y, we require Y < (1 - 0) * X = X. NOTE: the numbers in this example are made up, and don't represent how actual base, increase or decrease thresholds would look like. --> <array name="config_displayWhiteBalanceBaseThresholds"> <item>0.0</item> </array> <!-- See DisplayWhiteBalanceThrottler. The increase threshold values, throttled if value < value * (1 + threshold). Must be non-empty, the same length as config_displayWhiteBalanceBaseThresholds, and contain non-negative numbers. --> <array name="config_displayWhiteBalanceIncreaseThresholds"> <item>0.1</item> </array> <!-- See DisplayWhiteBalanceThrottler. The decrease threshold values, throttled if value > value * (1 - threshold). Must be non-empty, the same length as config_displayWhiteBalanceBaseThresholds, and contain non-negative numbers. --> <array name="config_displayWhiteBalanceDecreaseThresholds"> <item>0.1</item> </array> <!-- See DisplayWhiteBalanceController. The ambient brightness threshold (in lux) beneath which we fall back to a fixed ambient color temperature. --> <item name="config_displayWhiteBalanceLowLightAmbientBrightnessThreshold" format="float" type="dimen">10.0</item> <!-- See DisplayWhiteBalanceController. The ambient color temperature (in cct) to which we fall back when the ambient brightness drops beneath a certain threshold. --> <item name="config_displayWhiteBalanceLowLightAmbientColorTemperature" format="float" type="dimen">6500.0</item> </resources> core/res/res/values/symbols.xml +16 −0 Original line number Diff line number Diff line Loading @@ -3591,4 +3591,20 @@ <java-symbol type="integer" name="config_attentionApiTimeout" /> <java-symbol type="string" name="config_incidentReportApproverPackage" /> <!-- Display White-Balance --> <java-symbol type="integer" name="config_displayWhiteBalanceBrightnessSensorRate" /> <java-symbol type="integer" name="config_displayWhiteBalanceBrightnessFilterHorizon" /> <java-symbol type="dimen" name="config_displayWhiteBalanceBrightnessFilterIntercept" /> <java-symbol type="string" name="config_displayWhiteBalanceColorTemperatureSensorName" /> <java-symbol type="integer" name="config_displayWhiteBalanceColorTemperatureSensorRate" /> <java-symbol type="integer" name="config_displayWhiteBalanceColorTemperatureFilterHorizon" /> <java-symbol type="dimen" name="config_displayWhiteBalanceColorTemperatureFilterIntercept" /> <java-symbol type="integer" name="config_displayWhiteBalanceIncreaseDebounce" /> <java-symbol type="integer" name="config_displayWhiteBalanceDecreaseDebounce" /> <java-symbol type="array" name="config_displayWhiteBalanceBaseThresholds" /> <java-symbol type="array" name="config_displayWhiteBalanceIncreaseThresholds" /> <java-symbol type="array" name="config_displayWhiteBalanceDecreaseThresholds" /> <java-symbol type="dimen" name="config_displayWhiteBalanceLowLightAmbientBrightnessThreshold" /> <java-symbol type="dimen" name="config_displayWhiteBalanceLowLightAmbientColorTemperature" /> </resources> services/core/java/com/android/server/display/DisplayManagerService.java +16 −0 Original line number Diff line number Diff line Loading @@ -2196,6 +2196,22 @@ public final class DisplayManagerService extends SystemService { } } void setDisplayWhiteBalanceLoggingEnabled(boolean enabled) { if (mDisplayPowerController != null) { synchronized (mSyncRoot) { mDisplayPowerController.setDisplayWhiteBalanceLoggingEnabled(enabled); } } } void setAmbientColorTemperatureOverride(float cct) { if (mDisplayPowerController != null) { synchronized (mSyncRoot) { mDisplayPowerController.setAmbientColorTemperatureOverride(cct); } } } private boolean validatePackageName(int uid, String packageName) { if (packageName != null) { String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid); Loading services/core/java/com/android/server/display/DisplayManagerShellCommand.java +36 −2 Original line number Diff line number Diff line Loading @@ -45,6 +45,12 @@ class DisplayManagerShellCommand extends ShellCommand { return setAutoBrightnessLoggingEnabled(true); case "ab-logging-disable": return setAutoBrightnessLoggingEnabled(false); case "dwb-logging-enable": return setDisplayWhiteBalanceLoggingEnabled(true); case "dwb-logging-disable": return setDisplayWhiteBalanceLoggingEnabled(false); case "dwb-set-cct": return setAmbientColorTemperatureOverride(); default: return handleDefaultCommands(cmd); } Loading @@ -65,6 +71,12 @@ class DisplayManagerShellCommand extends ShellCommand { pw.println(" Enable auto-brightness logging."); pw.println(" ab-logging-disable"); pw.println(" Disable auto-brightness logging."); pw.println(" dwb-logging-enable"); pw.println(" Enable display white-balance logging."); pw.println(" dwb-logging-disable"); pw.println(" Disable display white-balance logging."); pw.println(" dwb-set-cct CCT"); pw.println(" Sets the ambient color temperature override to CCT (use -1 to disable)."); pw.println(); Intent.printIntentArgsHelp(pw , ""); } Loading @@ -75,7 +87,7 @@ class DisplayManagerShellCommand extends ShellCommand { getErrPrintWriter().println("Error: no brightness specified"); return 1; } float brightness = -1; float brightness = -1.0f; try { brightness = Float.parseFloat(brightnessText); } catch (NumberFormatException e) { Loading @@ -84,7 +96,7 @@ class DisplayManagerShellCommand extends ShellCommand { getErrPrintWriter().println("Error: brightness should be a number between 0 and 1"); return 1; } mService.setBrightness((int) brightness * 255); mService.setBrightness((int) (brightness * 255)); return 0; } Loading @@ -97,4 +109,26 @@ class DisplayManagerShellCommand extends ShellCommand { mService.setAutoBrightnessLoggingEnabled(enabled); return 0; } private int setDisplayWhiteBalanceLoggingEnabled(boolean enabled) { mService.setDisplayWhiteBalanceLoggingEnabled(enabled); return 0; } private int setAmbientColorTemperatureOverride() { String cctText = getNextArg(); if (cctText == null) { getErrPrintWriter().println("Error: no cct specified"); return 1; } float cct; try { cct = Float.parseFloat(cctText); } catch (NumberFormatException e) { getErrPrintWriter().println("Error: cct should be a number"); return 1; } mService.setAmbientColorTemperatureOverride(cct); return 0; } } services/core/java/com/android/server/display/DisplayPowerController.java +66 −1 Original line number Diff line number Diff line Loading @@ -52,6 +52,9 @@ import android.view.Display; import com.android.internal.app.IBatteryStats; import com.android.server.LocalServices; import com.android.server.am.BatteryStatsService; import com.android.server.display.whitebalance.DisplayWhiteBalanceController; import com.android.server.display.whitebalance.DisplayWhiteBalanceFactory; import com.android.server.display.whitebalance.DisplayWhiteBalanceSettings; import com.android.server.policy.WindowManagerPolicy; import java.io.PrintWriter; Loading @@ -78,7 +81,8 @@ import java.io.PrintWriter; * For debugging, you can make the color fade and brightness animations run * slower by changing the "animator duration scale" option in Development Settings. */ final class DisplayPowerController implements AutomaticBrightnessController.Callbacks { final class DisplayPowerController implements AutomaticBrightnessController.Callbacks, DisplayWhiteBalanceController.Callbacks { private static final String TAG = "DisplayPowerController"; private static final String SCREEN_ON_BLOCKED_TRACE_NAME = "Screen on blocked"; private static final String SCREEN_OFF_BLOCKED_TRACE_NAME = "Screen off blocked"; Loading Loading @@ -307,6 +311,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // Whether or not to skip the initial brightness ramps into STATE_ON. private final boolean mSkipScreenOnBrightnessRamp; // Display white balance components. @Nullable private final DisplayWhiteBalanceSettings mDisplayWhiteBalanceSettings; @Nullable private final DisplayWhiteBalanceController mDisplayWhiteBalanceController; // A record of state for skipping brightness ramps. private int mSkipRampState = RAMP_STATE_SKIP_NONE; Loading Loading @@ -504,6 +514,20 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mPendingScreenBrightnessSetting = -1; mTemporaryAutoBrightnessAdjustment = Float.NaN; mPendingAutoBrightnessAdjustment = Float.NaN; DisplayWhiteBalanceSettings displayWhiteBalanceSettings = null; DisplayWhiteBalanceController displayWhiteBalanceController = null; try { displayWhiteBalanceSettings = new DisplayWhiteBalanceSettings(mContext, mHandler); displayWhiteBalanceController = DisplayWhiteBalanceFactory.create(mHandler, mSensorManager, resources); displayWhiteBalanceSettings.setCallbacks(this); displayWhiteBalanceController.setCallbacks(this); } catch (Exception e) { Slog.e(TAG, "failed to set up display white-balance: " + e); } mDisplayWhiteBalanceSettings = displayWhiteBalanceSettings; mDisplayWhiteBalanceController = displayWhiteBalanceController; } /** Loading @@ -526,6 +550,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call public void onSwitchUser(@UserIdInt int newUserId) { handleSettingsChange(true /* userSwitch */); mBrightnessTracker.onSwitchUser(newUserId); if (mDisplayWhiteBalanceSettings != null) { mDisplayWhiteBalanceSettings.onSwitchUser(); } } public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats( Loading Loading @@ -988,6 +1015,16 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } // Update display white-balance. if (mDisplayWhiteBalanceController != null) { if (state == Display.STATE_ON && mDisplayWhiteBalanceSettings.isEnabled()) { mDisplayWhiteBalanceController.setEnabled(true); mDisplayWhiteBalanceController.updateScreenColorTemperature(); } else { mDisplayWhiteBalanceController.setEnabled(false); } } // Determine whether the display is ready for use in the newly requested state. // Note that we do not wait for the brightness ramp animation to complete before // reporting the display is ready because we only need to ensure the screen is in the Loading Loading @@ -1702,6 +1739,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call pw.println(); mBrightnessTracker.dump(pw); } pw.println(); if (mDisplayWhiteBalanceController != null) { mDisplayWhiteBalanceController.dump(pw); mDisplayWhiteBalanceSettings.dump(pw); } } private static String proximityToString(int state) { Loading Loading @@ -1848,4 +1891,26 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAutomaticBrightnessController.setLoggingEnabled(enabled); } } @Override // DisplayWhiteBalanceController.Callbacks public void updateWhiteBalance() { sendUpdatePowerState(); } void setDisplayWhiteBalanceLoggingEnabled(boolean enabled) { if (mDisplayWhiteBalanceController != null) { mDisplayWhiteBalanceController.setLoggingEnabled(enabled); mDisplayWhiteBalanceSettings.setLoggingEnabled(enabled); } } void setAmbientColorTemperatureOverride(float cct) { if (mDisplayWhiteBalanceController != null) { mDisplayWhiteBalanceController.setAmbientColorTemperatureOverride(cct); // The ambient color temperature override is only applied when the ambient color // temperature changes or is updated, so it doesn't necessarily change the screen color // temperature immediately. So, let's make it! sendUpdatePowerState(); } } } Loading
core/res/res/values/config.xml +101 −0 Original line number Diff line number Diff line Loading @@ -3781,4 +3781,105 @@ <!-- Whether or not aware is enabled by default --> <bool name="config_awareSettingAvailable">false</bool> <!-- Display White-Balance --> <!-- See AmbientSensor.AmbientBrightnessSensor. The ambient brightness sensor rate (in milliseconds). Must be positive. --> <integer name="config_displayWhiteBalanceBrightnessSensorRate">250</integer> <!-- See AmbientFilter. How long ambient brightness changes are kept and taken into consideration (in milliseconds). Must be positive. --> <integer name="config_displayWhiteBalanceBrightnessFilterHorizon">10000</integer> <!-- See AmbientFilter.WeightedMovingAverageAmbientFilter. Recent changes are prioritised by integrating their duration over y = x + intercept (the higher it is, the less prioritised recent changes are). Must be a non-negative number, or NaN to avoid this implementation. --> <item name="config_displayWhiteBalanceBrightnessFilterIntercept" format="float" type="dimen">10.0</item> <!-- See AmbientSensor.AmbientColorTemperatureSensor. The ambient color temperature sensor name. --> <string name="config_displayWhiteBalanceColorTemperatureSensorName">com.google.sensor.color</string> <!-- See AmbientSensor.AmbientColorTemperatureSensor. The ambient color temperature sensor rate (in milliseconds). Must be positive. --> <integer name="config_displayWhiteBalanceColorTemperatureSensorRate">250</integer> <!-- See AmbientFilter. How long ambient color temperature changes are kept and taken into consideration (in milliseconds). Must be positive. --> <integer name="config_displayWhiteBalanceColorTemperatureFilterHorizon">10000</integer> <!-- See AmbientFilter.WeightedMovingAverageAmbientFilter. Recent changes are prioritised by integrating their duration over y = x + intercept (the higher it is, the less prioritised recent changes are). Must be a non-negative number, or NaN to avoid this implementation. --> <item name="config_displayWhiteBalanceColorTemperatureFilterIntercept" format="float" type="dimen">10.0</item> <!-- See DisplayWhiteBalanceThrottler. The debounce time (in milliseconds) for increasing the screen color temperature, throttled if time > lastTime + debounce. Must be non-negative. --> <integer name="config_displayWhiteBalanceIncreaseDebounce">5000</integer> <!-- See DisplayWhiteBalanceThrottler. The debounce time (in milliseconds) for decreasing the screen color tempearture, throttled if time < lastTime - debounce. Must be non-negative. --> <integer name="config_displayWhiteBalanceDecreaseDebounce">5000</integer> <!-- See DisplayWhiteBalanceThrottler. The ambient color temperature values used to determine the threshold as the corresponding value in config_displayWhiteBalance{Increase,Decrease}Threholds. Must be non-empty, the same length as config_displayWhiteBalance{Increase,Decrease}Thresholds, and contain non-negative, strictly increasing numbers. For example, if: - baseThresolds = [0, 100, 1000]; - increaseThresholds = [0.1, 0.15, 0.2]; - decreaseThresholds = [0.1, 0.05, 0.0]; Then, given the ambient color temperature INCREASED from X to Y (so X < Y): - If 0 <= Y < 100, we require Y > (1 + 0.1) * X = 1.1X; - If 100 <= Y < 1000, we require Y > (1 + 0.15) * X = 1.15X; - If 1000 <= Y, we require Y > (1 + 0.2) * X = 1.2X. Or, if the ambient color temperature DECREASED from X to Y (so X > Y): - If 0 <= Y < 100, we require Y < (1 - 0.1) * X = 0.9X; - If 100 <= Y < 1000, we require Y < (1 - 0.05) * X = 0.95X; - If 1000 <= Y, we require Y < (1 - 0) * X = X. NOTE: the numbers in this example are made up, and don't represent how actual base, increase or decrease thresholds would look like. --> <array name="config_displayWhiteBalanceBaseThresholds"> <item>0.0</item> </array> <!-- See DisplayWhiteBalanceThrottler. The increase threshold values, throttled if value < value * (1 + threshold). Must be non-empty, the same length as config_displayWhiteBalanceBaseThresholds, and contain non-negative numbers. --> <array name="config_displayWhiteBalanceIncreaseThresholds"> <item>0.1</item> </array> <!-- See DisplayWhiteBalanceThrottler. The decrease threshold values, throttled if value > value * (1 - threshold). Must be non-empty, the same length as config_displayWhiteBalanceBaseThresholds, and contain non-negative numbers. --> <array name="config_displayWhiteBalanceDecreaseThresholds"> <item>0.1</item> </array> <!-- See DisplayWhiteBalanceController. The ambient brightness threshold (in lux) beneath which we fall back to a fixed ambient color temperature. --> <item name="config_displayWhiteBalanceLowLightAmbientBrightnessThreshold" format="float" type="dimen">10.0</item> <!-- See DisplayWhiteBalanceController. The ambient color temperature (in cct) to which we fall back when the ambient brightness drops beneath a certain threshold. --> <item name="config_displayWhiteBalanceLowLightAmbientColorTemperature" format="float" type="dimen">6500.0</item> </resources>
core/res/res/values/symbols.xml +16 −0 Original line number Diff line number Diff line Loading @@ -3591,4 +3591,20 @@ <java-symbol type="integer" name="config_attentionApiTimeout" /> <java-symbol type="string" name="config_incidentReportApproverPackage" /> <!-- Display White-Balance --> <java-symbol type="integer" name="config_displayWhiteBalanceBrightnessSensorRate" /> <java-symbol type="integer" name="config_displayWhiteBalanceBrightnessFilterHorizon" /> <java-symbol type="dimen" name="config_displayWhiteBalanceBrightnessFilterIntercept" /> <java-symbol type="string" name="config_displayWhiteBalanceColorTemperatureSensorName" /> <java-symbol type="integer" name="config_displayWhiteBalanceColorTemperatureSensorRate" /> <java-symbol type="integer" name="config_displayWhiteBalanceColorTemperatureFilterHorizon" /> <java-symbol type="dimen" name="config_displayWhiteBalanceColorTemperatureFilterIntercept" /> <java-symbol type="integer" name="config_displayWhiteBalanceIncreaseDebounce" /> <java-symbol type="integer" name="config_displayWhiteBalanceDecreaseDebounce" /> <java-symbol type="array" name="config_displayWhiteBalanceBaseThresholds" /> <java-symbol type="array" name="config_displayWhiteBalanceIncreaseThresholds" /> <java-symbol type="array" name="config_displayWhiteBalanceDecreaseThresholds" /> <java-symbol type="dimen" name="config_displayWhiteBalanceLowLightAmbientBrightnessThreshold" /> <java-symbol type="dimen" name="config_displayWhiteBalanceLowLightAmbientColorTemperature" /> </resources>
services/core/java/com/android/server/display/DisplayManagerService.java +16 −0 Original line number Diff line number Diff line Loading @@ -2196,6 +2196,22 @@ public final class DisplayManagerService extends SystemService { } } void setDisplayWhiteBalanceLoggingEnabled(boolean enabled) { if (mDisplayPowerController != null) { synchronized (mSyncRoot) { mDisplayPowerController.setDisplayWhiteBalanceLoggingEnabled(enabled); } } } void setAmbientColorTemperatureOverride(float cct) { if (mDisplayPowerController != null) { synchronized (mSyncRoot) { mDisplayPowerController.setAmbientColorTemperatureOverride(cct); } } } private boolean validatePackageName(int uid, String packageName) { if (packageName != null) { String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid); Loading
services/core/java/com/android/server/display/DisplayManagerShellCommand.java +36 −2 Original line number Diff line number Diff line Loading @@ -45,6 +45,12 @@ class DisplayManagerShellCommand extends ShellCommand { return setAutoBrightnessLoggingEnabled(true); case "ab-logging-disable": return setAutoBrightnessLoggingEnabled(false); case "dwb-logging-enable": return setDisplayWhiteBalanceLoggingEnabled(true); case "dwb-logging-disable": return setDisplayWhiteBalanceLoggingEnabled(false); case "dwb-set-cct": return setAmbientColorTemperatureOverride(); default: return handleDefaultCommands(cmd); } Loading @@ -65,6 +71,12 @@ class DisplayManagerShellCommand extends ShellCommand { pw.println(" Enable auto-brightness logging."); pw.println(" ab-logging-disable"); pw.println(" Disable auto-brightness logging."); pw.println(" dwb-logging-enable"); pw.println(" Enable display white-balance logging."); pw.println(" dwb-logging-disable"); pw.println(" Disable display white-balance logging."); pw.println(" dwb-set-cct CCT"); pw.println(" Sets the ambient color temperature override to CCT (use -1 to disable)."); pw.println(); Intent.printIntentArgsHelp(pw , ""); } Loading @@ -75,7 +87,7 @@ class DisplayManagerShellCommand extends ShellCommand { getErrPrintWriter().println("Error: no brightness specified"); return 1; } float brightness = -1; float brightness = -1.0f; try { brightness = Float.parseFloat(brightnessText); } catch (NumberFormatException e) { Loading @@ -84,7 +96,7 @@ class DisplayManagerShellCommand extends ShellCommand { getErrPrintWriter().println("Error: brightness should be a number between 0 and 1"); return 1; } mService.setBrightness((int) brightness * 255); mService.setBrightness((int) (brightness * 255)); return 0; } Loading @@ -97,4 +109,26 @@ class DisplayManagerShellCommand extends ShellCommand { mService.setAutoBrightnessLoggingEnabled(enabled); return 0; } private int setDisplayWhiteBalanceLoggingEnabled(boolean enabled) { mService.setDisplayWhiteBalanceLoggingEnabled(enabled); return 0; } private int setAmbientColorTemperatureOverride() { String cctText = getNextArg(); if (cctText == null) { getErrPrintWriter().println("Error: no cct specified"); return 1; } float cct; try { cct = Float.parseFloat(cctText); } catch (NumberFormatException e) { getErrPrintWriter().println("Error: cct should be a number"); return 1; } mService.setAmbientColorTemperatureOverride(cct); return 0; } }
services/core/java/com/android/server/display/DisplayPowerController.java +66 −1 Original line number Diff line number Diff line Loading @@ -52,6 +52,9 @@ import android.view.Display; import com.android.internal.app.IBatteryStats; import com.android.server.LocalServices; import com.android.server.am.BatteryStatsService; import com.android.server.display.whitebalance.DisplayWhiteBalanceController; import com.android.server.display.whitebalance.DisplayWhiteBalanceFactory; import com.android.server.display.whitebalance.DisplayWhiteBalanceSettings; import com.android.server.policy.WindowManagerPolicy; import java.io.PrintWriter; Loading @@ -78,7 +81,8 @@ import java.io.PrintWriter; * For debugging, you can make the color fade and brightness animations run * slower by changing the "animator duration scale" option in Development Settings. */ final class DisplayPowerController implements AutomaticBrightnessController.Callbacks { final class DisplayPowerController implements AutomaticBrightnessController.Callbacks, DisplayWhiteBalanceController.Callbacks { private static final String TAG = "DisplayPowerController"; private static final String SCREEN_ON_BLOCKED_TRACE_NAME = "Screen on blocked"; private static final String SCREEN_OFF_BLOCKED_TRACE_NAME = "Screen off blocked"; Loading Loading @@ -307,6 +311,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // Whether or not to skip the initial brightness ramps into STATE_ON. private final boolean mSkipScreenOnBrightnessRamp; // Display white balance components. @Nullable private final DisplayWhiteBalanceSettings mDisplayWhiteBalanceSettings; @Nullable private final DisplayWhiteBalanceController mDisplayWhiteBalanceController; // A record of state for skipping brightness ramps. private int mSkipRampState = RAMP_STATE_SKIP_NONE; Loading Loading @@ -504,6 +514,20 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mPendingScreenBrightnessSetting = -1; mTemporaryAutoBrightnessAdjustment = Float.NaN; mPendingAutoBrightnessAdjustment = Float.NaN; DisplayWhiteBalanceSettings displayWhiteBalanceSettings = null; DisplayWhiteBalanceController displayWhiteBalanceController = null; try { displayWhiteBalanceSettings = new DisplayWhiteBalanceSettings(mContext, mHandler); displayWhiteBalanceController = DisplayWhiteBalanceFactory.create(mHandler, mSensorManager, resources); displayWhiteBalanceSettings.setCallbacks(this); displayWhiteBalanceController.setCallbacks(this); } catch (Exception e) { Slog.e(TAG, "failed to set up display white-balance: " + e); } mDisplayWhiteBalanceSettings = displayWhiteBalanceSettings; mDisplayWhiteBalanceController = displayWhiteBalanceController; } /** Loading @@ -526,6 +550,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call public void onSwitchUser(@UserIdInt int newUserId) { handleSettingsChange(true /* userSwitch */); mBrightnessTracker.onSwitchUser(newUserId); if (mDisplayWhiteBalanceSettings != null) { mDisplayWhiteBalanceSettings.onSwitchUser(); } } public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats( Loading Loading @@ -988,6 +1015,16 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } // Update display white-balance. if (mDisplayWhiteBalanceController != null) { if (state == Display.STATE_ON && mDisplayWhiteBalanceSettings.isEnabled()) { mDisplayWhiteBalanceController.setEnabled(true); mDisplayWhiteBalanceController.updateScreenColorTemperature(); } else { mDisplayWhiteBalanceController.setEnabled(false); } } // Determine whether the display is ready for use in the newly requested state. // Note that we do not wait for the brightness ramp animation to complete before // reporting the display is ready because we only need to ensure the screen is in the Loading Loading @@ -1702,6 +1739,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call pw.println(); mBrightnessTracker.dump(pw); } pw.println(); if (mDisplayWhiteBalanceController != null) { mDisplayWhiteBalanceController.dump(pw); mDisplayWhiteBalanceSettings.dump(pw); } } private static String proximityToString(int state) { Loading Loading @@ -1848,4 +1891,26 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAutomaticBrightnessController.setLoggingEnabled(enabled); } } @Override // DisplayWhiteBalanceController.Callbacks public void updateWhiteBalance() { sendUpdatePowerState(); } void setDisplayWhiteBalanceLoggingEnabled(boolean enabled) { if (mDisplayWhiteBalanceController != null) { mDisplayWhiteBalanceController.setLoggingEnabled(enabled); mDisplayWhiteBalanceSettings.setLoggingEnabled(enabled); } } void setAmbientColorTemperatureOverride(float cct) { if (mDisplayWhiteBalanceController != null) { mDisplayWhiteBalanceController.setAmbientColorTemperatureOverride(cct); // The ambient color temperature override is only applied when the ambient color // temperature changes or is updated, so it doesn't necessarily change the screen color // temperature immediately. So, let's make it! sendUpdatePowerState(); } } }