Commit ad82b0dd authored by Jia's avatar Jia Committed by Commit Bot

[On-device adaptive brightness] Change default global curve and brightness thresholds.

The global curve has been updated based on preliminary experiments and current
device-specific ALS->brightness config.

Bug: 881215
Change-Id: I19e00e328e0f3dd8afff86766127d268a9f58248
Reviewed-on: https://chromium-review.googlesource.com/c/1351332
Commit-Queue: Jia Meng <jiameng@chromium.org>
Reviewed-by: default avatarAndrew Moylan <amoylan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611434}
parent 4f5dba5b
...@@ -48,13 +48,13 @@ class Adapter : public AlsReader::Observer, ...@@ -48,13 +48,13 @@ class Adapter : public AlsReader::Observer,
kMaxValue = kLatest kMaxValue = kLatest
}; };
// TODO(jiameng): we currently use past 2 seconds of ambient values to // TODO(jiameng): we currently use past 5 seconds of ambient values to
// calculate average ambient when we predict optimal brightness. This is // calculate average ambient when we predict optimal brightness. This is
// shorter than the duration used for training data (10 seconds), because it's // shorter than the duration used for training data (10 seconds), because it's
// important that we can quickly adjust the brightness when ambient value // important that we can quickly adjust the brightness when ambient value
// changes. This duration should be revised. // changes. This duration should be revised.
static constexpr base::TimeDelta kAmbientLightShortHorizon = static constexpr base::TimeDelta kAmbientLightShortHorizon =
base::TimeDelta::FromSeconds(2); base::TimeDelta::FromSeconds(5);
// Size of |ambient_light_values_|. // Size of |ambient_light_values_|.
static constexpr int kNumberAmbientValuesToTrack = static constexpr int kNumberAmbientValuesToTrack =
...@@ -69,16 +69,16 @@ class Adapter : public AlsReader::Observer, ...@@ -69,16 +69,16 @@ class Adapter : public AlsReader::Observer,
// from the current value before brightness could be changed: brightness // from the current value before brightness could be changed: brightness
// will actually be changed if |min_time_between_brightness_changes| has // will actually be changed if |min_time_between_brightness_changes| has
// passed from the previous change. // passed from the previous change.
double brightening_lux_threshold_ratio = 0.1; double brightening_lux_threshold_ratio = 0.3;
double darkening_lux_threshold_ratio = 0.2; double darkening_lux_threshold_ratio = 0.4;
// If average ambient value changes by more than the "immediate" thresholds // If average ambient value changes by more than the "immediate" thresholds
// then brightness transition will happen immediately, without waiting for // then brightness transition will happen immediately, without waiting for
// |min_time_between_brightness_changes| to elapse. This value should be // |min_time_between_brightness_changes| to elapse. This value should be
// greater than or equal to the max of brightening/darkening thresholds // greater than or equal to the max of brightening/darkening thresholds
// above. // above.
double immediate_brightening_lux_threshold_ratio = 0.3; double immediate_brightening_lux_threshold_ratio = 0.4;
double immediate_darkening_lux_threshold_ratio = 0.4; double immediate_darkening_lux_threshold_ratio = 0.5;
// Whether brightness should be set to the predicted value when the first // Whether brightness should be set to the predicted value when the first
// ambient reading comes in. If false, we'll wait for // ambient reading comes in. If false, we'll wait for
......
...@@ -427,6 +427,7 @@ TEST_F(AdapterTest, UserBrightnessRequestBeforeAnyModelUpdate) { ...@@ -427,6 +427,7 @@ TEST_F(AdapterTest, UserBrightnessRequestBeforeAnyModelUpdate) {
TEST_F(AdapterTest, BrightnessLuxThresholds) { TEST_F(AdapterTest, BrightnessLuxThresholds) {
Init(AlsReader::AlsInitStatus::kSuccess, BrightnessMonitor::Status::kSuccess, Init(AlsReader::AlsInitStatus::kSuccess, BrightnessMonitor::Status::kSuccess,
global_curve_, personal_curve_, default_params_); global_curve_, personal_curve_, default_params_);
EXPECT_EQ(Adapter::kNumberAmbientValuesToTrack, 5);
EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kSuccess); EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kSuccess);
EXPECT_TRUE(adapter_->GetGlobalCurveForTesting()); EXPECT_TRUE(adapter_->GetGlobalCurveForTesting());
...@@ -457,7 +458,8 @@ TEST_F(AdapterTest, BrightnessLuxThresholds) { ...@@ -457,7 +458,8 @@ TEST_F(AdapterTest, BrightnessLuxThresholds) {
// A 3rd ALS comes in, but still not enough to trigger brightness change. // A 3rd ALS comes in, but still not enough to trigger brightness change.
fake_als_reader_.ReportAmbientLightUpdate(15); fake_als_reader_.ReportAmbientLightUpdate(15);
EXPECT_EQ(test_observer_.num_changes(), 1); EXPECT_EQ(test_observer_.num_changes(), 1);
EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(), (21 + 15) / 2.0); EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(),
(20 + 21 + 15) / 3.0);
EXPECT_DOUBLE_EQ(adapter_->GetBrighteningThresholdForTesting(), 22); EXPECT_DOUBLE_EQ(adapter_->GetBrighteningThresholdForTesting(), 22);
EXPECT_DOUBLE_EQ(adapter_->GetDarkeningThresholdForTesting(), 16); EXPECT_DOUBLE_EQ(adapter_->GetDarkeningThresholdForTesting(), 16);
...@@ -467,15 +469,26 @@ TEST_F(AdapterTest, BrightnessLuxThresholds) { ...@@ -467,15 +469,26 @@ TEST_F(AdapterTest, BrightnessLuxThresholds) {
scoped_task_environment_.RunUntilIdle(); scoped_task_environment_.RunUntilIdle();
EXPECT_EQ(test_observer_.num_changes(), 2); EXPECT_EQ(test_observer_.num_changes(), 2);
EXPECT_EQ(Adapter::kNumberAmbientValuesToTrack, 2); const double expected_average_ambient = (20 + 21 + 15 + 7) / 4.0;
const double expected_average_ambient =
(15.0 + 7.0) / Adapter::kNumberAmbientValuesToTrack;
EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(), EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(),
expected_average_ambient); expected_average_ambient);
EXPECT_DOUBLE_EQ(adapter_->GetBrighteningThresholdForTesting(), EXPECT_DOUBLE_EQ(adapter_->GetBrighteningThresholdForTesting(),
expected_average_ambient * 1.1); expected_average_ambient * 1.1);
EXPECT_DOUBLE_EQ(adapter_->GetDarkeningThresholdForTesting(), EXPECT_DOUBLE_EQ(adapter_->GetDarkeningThresholdForTesting(),
expected_average_ambient * 0.8); expected_average_ambient * 0.8);
// Next check |ambient_light_values_| has capacity
// |Adapter::kNumberAmbientValuesToTrack|.
fake_als_reader_.ReportAmbientLightUpdate(8);
scoped_task_environment_.RunUntilIdle();
EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(),
(20 + 21 + 15 + 7 + 8) / 5.0);
fake_als_reader_.ReportAmbientLightUpdate(9);
scoped_task_environment_.RunUntilIdle();
EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(),
(21 + 15 + 7 + 8 + 9) / 5.0);
} }
TEST_F(AdapterTest, ImmediateBrightnessTransitionThresholds) { TEST_F(AdapterTest, ImmediateBrightnessTransitionThresholds) {
...@@ -530,7 +543,7 @@ TEST_F(AdapterTest, BrightnessNotUpdatedOnStartup) { ...@@ -530,7 +543,7 @@ TEST_F(AdapterTest, BrightnessNotUpdatedOnStartup) {
scoped_task_environment_.RunUntilIdle(); scoped_task_environment_.RunUntilIdle();
EXPECT_EQ(test_observer_.num_changes(), 0); EXPECT_EQ(test_observer_.num_changes(), 0);
scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(2)); scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(5));
EXPECT_EQ(test_observer_.num_changes(), 0); EXPECT_EQ(test_observer_.num_changes(), 0);
// 2nd ALS comes in so that we have |kAmbientLightShortHorizonSeconds| of // 2nd ALS comes in so that we have |kAmbientLightShortHorizonSeconds| of
......
...@@ -31,7 +31,8 @@ namespace auto_screen_brightness { ...@@ -31,7 +31,8 @@ namespace auto_screen_brightness {
namespace { namespace {
// Creates a global/default brightness curve. // Creates a global/default brightness curve.
// TODO(crbug.com/881215): add actual default curve and then add unit test too. // TODO(crbug.com/881215): default curve may be revised, if so, need to update
// unit tests as well.
MonotoneCubicSpline CreateGlobalCurve() { MonotoneCubicSpline CreateGlobalCurve() {
const std::string global_curve = GetFieldTrialParamValueByFeature( const std::string global_curve = GetFieldTrialParamValueByFeature(
features::kAutoScreenBrightness, "global_curve"); features::kAutoScreenBrightness, "global_curve");
...@@ -43,8 +44,14 @@ MonotoneCubicSpline CreateGlobalCurve() { ...@@ -43,8 +44,14 @@ MonotoneCubicSpline CreateGlobalCurve() {
// TODO(jiameng): log error to UMA. // TODO(jiameng): log error to UMA.
} }
const std::vector<double> default_log_lux = {0, 100}; const std::vector<double> default_log_lux = {
const std::vector<double> default_brightness = {50, 100}; 3.69, 4.83, 6.54, 7.68, 8.25, 8.82,
};
const std::vector<double> default_brightness = {
36.14, 47.62, 85.83, 93.27, 93.27, 100,
};
return MonotoneCubicSpline(default_log_lux, default_brightness); return MonotoneCubicSpline(default_log_lux, default_brightness);
} }
......
...@@ -561,7 +561,13 @@ TEST_F(ModellerImplTest, GlobaCurveFromInvalidExperimentParam) { ...@@ -561,7 +561,13 @@ TEST_F(ModellerImplTest, GlobaCurveFromInvalidExperimentParam) {
features::kAutoScreenBrightness, {{"global_curve", global_curve_spec}}); features::kAutoScreenBrightness, {{"global_curve", global_curve_spec}});
// Defined by default values. // Defined by default values.
const MonotoneCubicSpline expected_global_curve({0, 100}, {50, 100}); const MonotoneCubicSpline expected_global_curve(
{
3.69, 4.83, 6.54, 7.68, 8.25, 8.82,
},
{
36.14, 47.62, 85.83, 93.27, 93.27, 100,
});
Init(AlsReader::AlsInitStatus::kSuccess, BrightnessMonitor::Status::kSuccess); Init(AlsReader::AlsInitStatus::kSuccess, BrightnessMonitor::Status::kSuccess);
EXPECT_EQ(modeller_->GetGlobalCurveForTesting(), expected_global_curve); EXPECT_EQ(modeller_->GetGlobalCurveForTesting(), expected_global_curve);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment