blob: 02ec10e2d49d36fee1e01698de87f9b1323e8ea9 [file] [log] [blame]
Dan Gittik8dbd7e92018-12-03 15:35:53 +00001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.display.whitebalance;
18
19import android.annotation.NonNull;
20import android.util.Slog;
Daniel Solomonfb393e52019-02-08 20:26:27 -080021import android.util.Spline;
Dan Gittik8dbd7e92018-12-03 15:35:53 +000022
Anthony Han04c78a92019-05-03 13:34:57 -070023import com.android.internal.annotations.VisibleForTesting;
Dan Gittik8dbd7e92018-12-03 15:35:53 +000024import com.android.internal.util.Preconditions;
25import com.android.server.LocalServices;
Christine Franks0ada2772019-02-25 13:54:57 -080026import com.android.server.display.color.ColorDisplayService.ColorDisplayServiceInternal;
Dan Gittik8dbd7e92018-12-03 15:35:53 +000027import com.android.server.display.utils.History;
28
29import java.io.PrintWriter;
30
31/**
32 * The DisplayWhiteBalanceController drives display white-balance (automatically correcting the
Dan Gittik1151ac02019-02-13 14:05:37 +000033 * display color temperature depending on the ambient color temperature).
Dan Gittik8dbd7e92018-12-03 15:35:53 +000034 *
35 * The DisplayWhiteBalanceController:
36 * - Uses the AmbientColorTemperatureSensor to detect changes in the ambient color temperature;
37 * - Uses the AmbientColorTemperatureFilter to average these changes over time, filter out the
38 * noise, and arrive at an estimate of the actual ambient color temperature;
Dan Gittik1151ac02019-02-13 14:05:37 +000039 * - Uses the DisplayWhiteBalanceThrottler to decide whether the display color tempearture should
40 * be updated, suppressing changes that are too frequent or too minor.
Dan Gittik8dbd7e92018-12-03 15:35:53 +000041 */
42public class DisplayWhiteBalanceController implements
43 AmbientSensor.AmbientBrightnessSensor.Callbacks,
44 AmbientSensor.AmbientColorTemperatureSensor.Callbacks {
45
46 protected static final String TAG = "DisplayWhiteBalanceController";
47 protected boolean mLoggingEnabled;
48
49 private boolean mEnabled;
50
51 // To decouple the DisplayPowerController from the DisplayWhiteBalanceController, the DPC
52 // implements Callbacks and passes itself to the DWBC so it can call back into it without
53 // knowing about it.
54 private Callbacks mCallbacks;
55
56 private AmbientSensor.AmbientBrightnessSensor mBrightnessSensor;
Anthony Han04c78a92019-05-03 13:34:57 -070057
58 @VisibleForTesting
59 AmbientFilter mBrightnessFilter;
Dan Gittik8dbd7e92018-12-03 15:35:53 +000060 private AmbientSensor.AmbientColorTemperatureSensor mColorTemperatureSensor;
Anthony Han04c78a92019-05-03 13:34:57 -070061
62 @VisibleForTesting
63 AmbientFilter mColorTemperatureFilter;
Dan Gittik8dbd7e92018-12-03 15:35:53 +000064 private DisplayWhiteBalanceThrottler mThrottler;
65
Dan Gittik8dbd7e92018-12-03 15:35:53 +000066 private final float mLowLightAmbientColorTemperature;
Anthony Han0c8297c2019-06-18 16:56:11 -070067 private final float mHighLightAmbientColorTemperature;
Dan Gittik8dbd7e92018-12-03 15:35:53 +000068
69 private float mAmbientColorTemperature;
Anthony Han04c78a92019-05-03 13:34:57 -070070
71 @VisibleForTesting
72 float mPendingAmbientColorTemperature;
Dan Gittik8dbd7e92018-12-03 15:35:53 +000073 private float mLastAmbientColorTemperature;
74
75 private ColorDisplayServiceInternal mColorDisplayServiceInternal;
76
77 // The most recent ambient color temperature values are kept for debugging purposes.
78 private static final int HISTORY_SIZE = 50;
79 private History mAmbientColorTemperatureHistory;
80
81 // Override the ambient color temperature for debugging purposes.
82 private float mAmbientColorTemperatureOverride;
83
Dan Gittik1151ac02019-02-13 14:05:37 +000084 // A piecewise linear relationship between ambient and display color temperatures.
85 private Spline.LinearSpline mAmbientToDisplayColorTemperatureSpline;
Daniel Solomonfb393e52019-02-08 20:26:27 -080086
Anthony Han0c8297c2019-06-18 16:56:11 -070087 // In very low or very high brightness conditions ambient EQ should to set to a default
88 // instead of using mAmbientToDisplayColorTemperatureSpline. However, setting ambient EQ
89 // based on thresholds can cause the display to rapidly change color temperature. To solve
90 // this, mLowLightAmbientBrightnessToBiasSpline and mHighLightAmbientBrightnessToBiasSpline
91 // are used to smoothly interpolate from ambient color temperature to the defaults.
Anthony Han04c78a92019-05-03 13:34:57 -070092 // A piecewise linear relationship between low light brightness and low light bias.
93 private Spline.LinearSpline mLowLightAmbientBrightnessToBiasSpline;
94
Anthony Han0c8297c2019-06-18 16:56:11 -070095 // A piecewise linear relationship between high light brightness and high light bias.
96 private Spline.LinearSpline mHighLightAmbientBrightnessToBiasSpline;
97
Dan Gittik8dbd7e92018-12-03 15:35:53 +000098 /**
99 * @param brightnessSensor
100 * The sensor used to detect changes in the ambient brightness.
101 * @param brightnessFilter
102 * The filter used to avergae ambient brightness changes over time, filter out the noise
103 * and arrive at an estimate of the actual ambient brightness.
104 * @param colorTemperatureSensor
105 * The sensor used to detect changes in the ambient color temperature.
106 * @param colorTemperatureFilter
107 * The filter used to average ambient color temperature changes over time, filter out the
108 * noise and arrive at an estimate of the actual ambient color temperature.
109 * @param throttler
Dan Gittik1151ac02019-02-13 14:05:37 +0000110 * The throttler used to determine whether the new display color temperature should be
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000111 * updated or not.
Anthony Han0c8297c2019-06-18 16:56:11 -0700112 * @param lowLightAmbientBrightnesses
113 * The ambient brightness used to map the ambient brightnesses to the biases used to
114 * interpolate to lowLightAmbientColorTemperature.
115 * @param lowLightAmbientBiases
116 * The biases used to map the ambient brightnesses to the biases used to interpolate to
117 * lowLightAmbientColorTemperature.
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000118 * @param lowLightAmbientColorTemperature
Anthony Han0c8297c2019-06-18 16:56:11 -0700119 * The ambient color temperature to which we interpolate to based on the low light curve.
120 * @param highLightAmbientBrightnesses
121 * The ambient brightness used to map the ambient brightnesses to the biases used to
122 * interpolate to highLightAmbientColorTemperature.
123 * @param highLightAmbientBiases
124 * The biases used to map the ambient brightnesses to the biases used to interpolate to
125 * highLightAmbientColorTemperature.
126 * @param highLightAmbientColorTemperature
127 * The ambient color temperature to which we interpolate to based on the high light curve.
Dan Gittik1151ac02019-02-13 14:05:37 +0000128 * @param ambientColorTemperatures
129 * The ambient color tempeartures used to map the ambient color temperature to the display
130 * color temperature (or null if no mapping is necessary).
131 * @param displayColorTemperatures
132 * The display color temperatures used to map the ambient color temperature to the display
133 * color temperature (or null if no mapping is necessary).
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000134 *
135 * @throws NullPointerException
136 * - brightnessSensor is null;
137 * - brightnessFilter is null;
138 * - colorTemperatureSensor is null;
139 * - colorTemperatureFilter is null;
140 * - throttler is null.
141 */
142 public DisplayWhiteBalanceController(
143 @NonNull AmbientSensor.AmbientBrightnessSensor brightnessSensor,
144 @NonNull AmbientFilter brightnessFilter,
145 @NonNull AmbientSensor.AmbientColorTemperatureSensor colorTemperatureSensor,
146 @NonNull AmbientFilter colorTemperatureFilter,
147 @NonNull DisplayWhiteBalanceThrottler throttler,
Anthony Han04c78a92019-05-03 13:34:57 -0700148 float[] lowLightAmbientBrightnesses, float[] lowLightAmbientBiases,
149 float lowLightAmbientColorTemperature,
Anthony Han0c8297c2019-06-18 16:56:11 -0700150 float[] highLightAmbientBrightnesses, float[] highLightAmbientBiases,
151 float highLightAmbientColorTemperature,
Dan Gittik1151ac02019-02-13 14:05:37 +0000152 float[] ambientColorTemperatures, float[] displayColorTemperatures) {
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000153 validateArguments(brightnessSensor, brightnessFilter, colorTemperatureSensor,
154 colorTemperatureFilter, throttler);
155 mLoggingEnabled = false;
156 mEnabled = false;
157 mCallbacks = null;
158 mBrightnessSensor = brightnessSensor;
159 mBrightnessFilter = brightnessFilter;
160 mColorTemperatureSensor = colorTemperatureSensor;
161 mColorTemperatureFilter = colorTemperatureFilter;
162 mThrottler = throttler;
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000163 mLowLightAmbientColorTemperature = lowLightAmbientColorTemperature;
Anthony Han0c8297c2019-06-18 16:56:11 -0700164 mHighLightAmbientColorTemperature = highLightAmbientColorTemperature;
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000165 mAmbientColorTemperature = -1.0f;
166 mPendingAmbientColorTemperature = -1.0f;
167 mLastAmbientColorTemperature = -1.0f;
168 mAmbientColorTemperatureHistory = new History(HISTORY_SIZE);
169 mAmbientColorTemperatureOverride = -1.0f;
Daniel Solomonfb393e52019-02-08 20:26:27 -0800170
171 try {
Anthony Han04c78a92019-05-03 13:34:57 -0700172 mLowLightAmbientBrightnessToBiasSpline = new Spline.LinearSpline(
173 lowLightAmbientBrightnesses, lowLightAmbientBiases);
174 } catch (Exception e) {
175 Slog.e(TAG, "failed to create low light ambient brightness to bias spline.", e);
176 mLowLightAmbientBrightnessToBiasSpline = null;
177 }
178 if (mLowLightAmbientBrightnessToBiasSpline != null) {
179 if (mLowLightAmbientBrightnessToBiasSpline.interpolate(0.0f) != 0.0f ||
180 mLowLightAmbientBrightnessToBiasSpline.interpolate(Float.POSITIVE_INFINITY)
181 != 1.0f) {
182 Slog.d(TAG, "invalid low light ambient brightness to bias spline, "
Anthony Han0c8297c2019-06-18 16:56:11 -0700183 + "bias must begin at 0.0 and end at 1.0.");
Anthony Han04c78a92019-05-03 13:34:57 -0700184 mLowLightAmbientBrightnessToBiasSpline = null;
185 }
186 }
187
188 try {
Anthony Han0c8297c2019-06-18 16:56:11 -0700189 mHighLightAmbientBrightnessToBiasSpline = new Spline.LinearSpline(
190 highLightAmbientBrightnesses, highLightAmbientBiases);
191 } catch (Exception e) {
192 Slog.e(TAG, "failed to create high light ambient brightness to bias spline.", e);
193 mHighLightAmbientBrightnessToBiasSpline = null;
194 }
195 if (mHighLightAmbientBrightnessToBiasSpline != null) {
196 if (mHighLightAmbientBrightnessToBiasSpline.interpolate(0.0f) != 0.0f ||
197 mHighLightAmbientBrightnessToBiasSpline.interpolate(Float.POSITIVE_INFINITY)
198 != 1.0f) {
199 Slog.d(TAG, "invalid high light ambient brightness to bias spline, "
200 + "bias must begin at 0.0 and end at 1.0.");
201 mHighLightAmbientBrightnessToBiasSpline = null;
202 }
203 }
204
205 if (mLowLightAmbientBrightnessToBiasSpline != null &&
206 mHighLightAmbientBrightnessToBiasSpline != null) {
207 if (lowLightAmbientBrightnesses[lowLightAmbientBrightnesses.length - 1] >
208 highLightAmbientBrightnesses[0]) {
209 Slog.d(TAG, "invalid low light and high light ambient brightness to bias spline "
210 + "combination, defined domains must not intersect.");
211 mLowLightAmbientBrightnessToBiasSpline = null;
212 mHighLightAmbientBrightnessToBiasSpline = null;
213 }
214 }
215
216 try {
Dan Gittik1151ac02019-02-13 14:05:37 +0000217 mAmbientToDisplayColorTemperatureSpline = new Spline.LinearSpline(
218 ambientColorTemperatures, displayColorTemperatures);
Daniel Solomonfb393e52019-02-08 20:26:27 -0800219 } catch (Exception e) {
Anthony Han04c78a92019-05-03 13:34:57 -0700220 Slog.e(TAG, "failed to create ambient to display color temperature spline.", e);
Dan Gittik1151ac02019-02-13 14:05:37 +0000221 mAmbientToDisplayColorTemperatureSpline = null;
Daniel Solomonfb393e52019-02-08 20:26:27 -0800222 }
223
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000224 mColorDisplayServiceInternal = LocalServices.getService(ColorDisplayServiceInternal.class);
225 }
226
227 /**
228 * Enable/disable the controller.
229 *
230 * @param enabled
231 * Whether the controller should be on/off.
232 *
233 * @return Whether the method succeeded or not.
234 */
235 public boolean setEnabled(boolean enabled) {
236 if (enabled) {
237 return enable();
238 } else {
239 return disable();
240 }
241 }
242
243 /**
Dan Gittik1151ac02019-02-13 14:05:37 +0000244 * Set an object to call back to when the display color temperature should be updated.
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000245 *
246 * @param callbacks
247 * The object to call back to.
248 *
249 * @return Whether the method succeeded or not.
250 */
251 public boolean setCallbacks(Callbacks callbacks) {
252 if (mCallbacks == callbacks) {
253 return false;
254 }
255 mCallbacks = callbacks;
256 return true;
257 }
258
259 /**
260 * Enable/disable logging.
261 *
262 * @param loggingEnabled
263 * Whether logging should be on/off.
264 *
265 * @return Whether the method succeeded or not.
266 */
267 public boolean setLoggingEnabled(boolean loggingEnabled) {
268 if (mLoggingEnabled == loggingEnabled) {
269 return false;
270 }
271 mLoggingEnabled = loggingEnabled;
272 mBrightnessSensor.setLoggingEnabled(loggingEnabled);
273 mBrightnessFilter.setLoggingEnabled(loggingEnabled);
274 mColorTemperatureSensor.setLoggingEnabled(loggingEnabled);
275 mColorTemperatureFilter.setLoggingEnabled(loggingEnabled);
276 mThrottler.setLoggingEnabled(loggingEnabled);
277 return true;
278 }
279
280 /**
281 * Set the ambient color temperature override.
282 *
283 * This is only applied when the ambient color temperature changes or is updated (in which case
284 * it overrides the ambient color temperature estimate); in other words, it doesn't necessarily
Dan Gittik1151ac02019-02-13 14:05:37 +0000285 * change the display color temperature immediately.
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000286 *
287 * @param ambientColorTemperatureOverride
288 * The ambient color temperature override.
289 *
290 * @return Whether the method succeeded or not.
291 */
292 public boolean setAmbientColorTemperatureOverride(float ambientColorTemperatureOverride) {
293 if (mAmbientColorTemperatureOverride == ambientColorTemperatureOverride) {
294 return false;
295 }
296 mAmbientColorTemperatureOverride = ambientColorTemperatureOverride;
297 return true;
298 }
299
300 /**
301 * Dump the state.
302 *
303 * @param writer
304 * The writer used to dump the state.
305 */
306 public void dump(PrintWriter writer) {
307 writer.println("DisplayWhiteBalanceController");
308 writer.println(" mLoggingEnabled=" + mLoggingEnabled);
309 writer.println(" mEnabled=" + mEnabled);
310 writer.println(" mCallbacks=" + mCallbacks);
311 mBrightnessSensor.dump(writer);
312 mBrightnessFilter.dump(writer);
313 mColorTemperatureSensor.dump(writer);
314 mColorTemperatureFilter.dump(writer);
315 mThrottler.dump(writer);
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000316 writer.println(" mLowLightAmbientColorTemperature=" + mLowLightAmbientColorTemperature);
Anthony Han0c8297c2019-06-18 16:56:11 -0700317 writer.println(" mHighLightAmbientColorTemperature=" + mHighLightAmbientColorTemperature);
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000318 writer.println(" mAmbientColorTemperature=" + mAmbientColorTemperature);
319 writer.println(" mPendingAmbientColorTemperature=" + mPendingAmbientColorTemperature);
320 writer.println(" mLastAmbientColorTemperature=" + mLastAmbientColorTemperature);
321 writer.println(" mAmbientColorTemperatureHistory=" + mAmbientColorTemperatureHistory);
322 writer.println(" mAmbientColorTemperatureOverride=" + mAmbientColorTemperatureOverride);
Dan Gittik1151ac02019-02-13 14:05:37 +0000323 writer.println(" mAmbientToDisplayColorTemperatureSpline="
324 + mAmbientToDisplayColorTemperatureSpline);
Anthony Han04c78a92019-05-03 13:34:57 -0700325 writer.println(" mLowLightAmbientBrightnessToBiasSpline="
326 + mLowLightAmbientBrightnessToBiasSpline);
Anthony Han0c8297c2019-06-18 16:56:11 -0700327 writer.println(" mHighLightAmbientBrightnessToBiasSpline="
328 + mHighLightAmbientBrightnessToBiasSpline);
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000329 }
330
331 @Override // AmbientSensor.AmbientBrightnessSensor.Callbacks
332 public void onAmbientBrightnessChanged(float value) {
333 final long time = System.currentTimeMillis();
334 mBrightnessFilter.addValue(time, value);
335 updateAmbientColorTemperature();
336 }
337
338 @Override // AmbientSensor.AmbientColorTemperatureSensor.Callbacks
339 public void onAmbientColorTemperatureChanged(float value) {
340 final long time = System.currentTimeMillis();
341 mColorTemperatureFilter.addValue(time, value);
342 updateAmbientColorTemperature();
343 }
344
345 /**
346 * Updates the ambient color temperature.
347 */
348 public void updateAmbientColorTemperature() {
349 final long time = System.currentTimeMillis();
350 float ambientColorTemperature = mColorTemperatureFilter.getEstimate(time);
351
Daniel Solomondff8b1b2019-04-08 14:30:51 -0700352 if (mAmbientToDisplayColorTemperatureSpline != null && ambientColorTemperature != -1.0f) {
Daniel Solomonfb393e52019-02-08 20:26:27 -0800353 ambientColorTemperature =
Dan Gittik1151ac02019-02-13 14:05:37 +0000354 mAmbientToDisplayColorTemperatureSpline.interpolate(ambientColorTemperature);
Daniel Solomonfb393e52019-02-08 20:26:27 -0800355 }
356
Anthony Han04c78a92019-05-03 13:34:57 -0700357 float ambientBrightness = mBrightnessFilter.getEstimate(time);
358
Anthony Han35df7e22019-06-27 17:27:24 -0700359 if (ambientColorTemperature != -1.0f &&
360 mLowLightAmbientBrightnessToBiasSpline != null) {
Anthony Han04c78a92019-05-03 13:34:57 -0700361 float bias = mLowLightAmbientBrightnessToBiasSpline.interpolate(ambientBrightness);
362 ambientColorTemperature =
363 bias * ambientColorTemperature + (1.0f - bias)
364 * mLowLightAmbientColorTemperature;
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000365 }
Anthony Han35df7e22019-06-27 17:27:24 -0700366 if (ambientColorTemperature != -1.0f &&
367 mHighLightAmbientBrightnessToBiasSpline != null) {
Anthony Han0c8297c2019-06-18 16:56:11 -0700368 float bias = mHighLightAmbientBrightnessToBiasSpline.interpolate(ambientBrightness);
369 ambientColorTemperature =
370 (1.0f - bias) * ambientColorTemperature + bias
371 * mHighLightAmbientColorTemperature;
372 }
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000373
374 if (mAmbientColorTemperatureOverride != -1.0f) {
375 if (mLoggingEnabled) {
376 Slog.d(TAG, "override ambient color temperature: " + ambientColorTemperature
377 + " => " + mAmbientColorTemperatureOverride);
378 }
379 ambientColorTemperature = mAmbientColorTemperatureOverride;
380 }
381
Dan Gittik1151ac02019-02-13 14:05:37 +0000382 // When the display color temperature needs to be updated, we call DisplayPowerController to
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000383 // call our updateColorTemperature. The reason we don't call it directly is that we want
384 // all changes to the system to happen in a predictable order in DPC's main loop
385 // (updatePowerState).
386 if (ambientColorTemperature == -1.0f || mThrottler.throttle(ambientColorTemperature)) {
387 return;
388 }
389
390 if (mLoggingEnabled) {
391 Slog.d(TAG, "pending ambient color temperature: " + ambientColorTemperature);
392 }
393 mPendingAmbientColorTemperature = ambientColorTemperature;
394 if (mCallbacks != null) {
395 mCallbacks.updateWhiteBalance();
396 }
397 }
398
399 /**
Dan Gittik1151ac02019-02-13 14:05:37 +0000400 * Updates the display color temperature.
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000401 */
Dan Gittik1151ac02019-02-13 14:05:37 +0000402 public void updateDisplayColorTemperature() {
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000403 float ambientColorTemperature = -1.0f;
404
405 // If both the pending and the current ambient color temperatures are -1, it means the DWBC
406 // was just enabled, and we use the last ambient color temperature until new sensor events
407 // give us a better estimate.
408 if (mAmbientColorTemperature == -1.0f && mPendingAmbientColorTemperature == -1.0f) {
409 ambientColorTemperature = mLastAmbientColorTemperature;
410 }
411
412 // Otherwise, we use the pending ambient color temperature, but only if it's non-trivial
413 // and different than the current one.
414 if (mPendingAmbientColorTemperature != -1.0f
415 && mPendingAmbientColorTemperature != mAmbientColorTemperature) {
416 ambientColorTemperature = mPendingAmbientColorTemperature;
417 }
418
419 if (ambientColorTemperature == -1.0f) {
420 return;
421 }
422
423 mAmbientColorTemperature = ambientColorTemperature;
424 if (mLoggingEnabled) {
425 Slog.d(TAG, "ambient color temperature: " + mAmbientColorTemperature);
426 }
427 mPendingAmbientColorTemperature = -1.0f;
428 mAmbientColorTemperatureHistory.add(mAmbientColorTemperature);
429 mColorDisplayServiceInternal.setDisplayWhiteBalanceColorTemperature(
430 (int) mAmbientColorTemperature);
431 mLastAmbientColorTemperature = mAmbientColorTemperature;
432 }
433
434 /**
435 * The DisplayWhiteBalanceController decouples itself from its parent (DisplayPowerController)
436 * by providing this interface to implement (and a method to set its callbacks object), and
437 * calling these methods.
438 */
439 public interface Callbacks {
440
441 /**
442 * Called whenever the display white-balance state has changed.
443 *
444 * Usually, this means the estimated ambient color temperature has changed enough, and the
Dan Gittik1151ac02019-02-13 14:05:37 +0000445 * display color temperature should be updated; but it is also called if settings change.
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000446 */
447 void updateWhiteBalance();
448 }
449
450 private void validateArguments(AmbientSensor.AmbientBrightnessSensor brightnessSensor,
451 AmbientFilter brightnessFilter,
452 AmbientSensor.AmbientColorTemperatureSensor colorTemperatureSensor,
453 AmbientFilter colorTemperatureFilter,
454 DisplayWhiteBalanceThrottler throttler) {
455 Preconditions.checkNotNull(brightnessSensor, "brightnessSensor must not be null");
456 Preconditions.checkNotNull(brightnessFilter, "brightnessFilter must not be null");
457 Preconditions.checkNotNull(colorTemperatureSensor,
458 "colorTemperatureSensor must not be null");
459 Preconditions.checkNotNull(colorTemperatureFilter,
460 "colorTemperatureFilter must not be null");
461 Preconditions.checkNotNull(throttler, "throttler cannot be null");
462 }
463
464 private boolean enable() {
465 if (mEnabled) {
466 return false;
467 }
468 if (mLoggingEnabled) {
469 Slog.d(TAG, "enabling");
470 }
471 mEnabled = true;
472 mBrightnessSensor.setEnabled(true);
473 mColorTemperatureSensor.setEnabled(true);
474 return true;
475 }
476
477 private boolean disable() {
478 if (!mEnabled) {
479 return false;
480 }
481 if (mLoggingEnabled) {
482 Slog.d(TAG, "disabling");
483 }
484 mEnabled = false;
485 mBrightnessSensor.setEnabled(false);
486 mBrightnessFilter.clear();
487 mColorTemperatureSensor.setEnabled(false);
488 mColorTemperatureFilter.clear();
489 mThrottler.clear();
490 mAmbientColorTemperature = -1.0f;
491 mPendingAmbientColorTemperature = -1.0f;
Daniel Solomon37816412019-04-10 15:17:41 -0700492 mColorDisplayServiceInternal.resetDisplayWhiteBalanceColorTemperature();
Dan Gittik8dbd7e92018-12-03 15:35:53 +0000493 return true;
494 }
495
496}