• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
17 package com.android.server.display;
18 
19 
20 import static com.android.internal.display.BrightnessSynchronizer.brightnessIntToFloat;
21 import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_BEDTIME_WEAR;
22 import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT;
23 import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DOZE;
24 import static com.android.server.display.config.SensorData.TEMPERATURE_TYPE_SKIN;
25 import static com.android.server.display.utils.DeviceConfigParsingUtils.ambientBrightnessThresholdsIntToFloat;
26 import static com.android.server.display.utils.DeviceConfigParsingUtils.displayBrightnessThresholdsIntToFloat;
27 
28 import static com.google.common.truth.Truth.assertThat;
29 
30 import static org.junit.Assert.assertArrayEquals;
31 import static org.junit.Assert.assertEquals;
32 import static org.junit.Assert.assertFalse;
33 import static org.junit.Assert.assertNotNull;
34 import static org.junit.Assert.assertNull;
35 import static org.junit.Assert.assertTrue;
36 import static org.mockito.ArgumentMatchers.anyFloat;
37 import static org.mockito.ArgumentMatchers.anyInt;
38 import static org.mockito.Mockito.mock;
39 import static org.mockito.Mockito.when;
40 
41 import android.content.Context;
42 import android.content.res.Resources;
43 import android.content.res.TypedArray;
44 import android.hardware.display.DisplayManagerInternal;
45 import android.os.PowerManager;
46 import android.os.Temperature;
47 import android.platform.test.annotations.RequiresFlagsEnabled;
48 import android.provider.Settings;
49 import android.util.SparseArray;
50 import android.util.Spline;
51 import android.view.SurfaceControl;
52 
53 import androidx.test.ext.junit.runners.AndroidJUnit4;
54 import androidx.test.filters.SmallTest;
55 
56 import com.android.internal.R;
57 import com.android.server.display.config.HdrBrightnessData;
58 import com.android.server.display.config.HighBrightnessModeData;
59 import com.android.server.display.config.HysteresisLevels;
60 import com.android.server.display.config.IdleScreenRefreshRateTimeoutLuxThresholdPoint;
61 import com.android.server.display.config.RefreshRateData;
62 import com.android.server.display.config.SupportedModeData;
63 import com.android.server.display.config.ThermalStatus;
64 import com.android.server.display.feature.DisplayManagerFlags;
65 import com.android.server.display.feature.flags.Flags;
66 
67 import org.junit.Before;
68 import org.junit.Test;
69 import org.junit.runner.RunWith;
70 import org.mockito.Mock;
71 import org.mockito.MockitoAnnotations;
72 
73 import java.io.IOException;
74 import java.nio.charset.StandardCharsets;
75 import java.nio.file.Files;
76 import java.nio.file.Path;
77 import java.util.ArrayList;
78 import java.util.HashMap;
79 import java.util.List;
80 import java.util.Map;
81 
82 @SmallTest
83 @RunWith(AndroidJUnit4.class)
84 public final class DisplayDeviceConfigTest {
85     private static final int DEFAULT_PEAK_REFRESH_RATE = 75;
86     private static final int DEFAULT_REFRESH_RATE = 120;
87     private static final int DEFAULT_HIGH_BLOCKING_ZONE_REFRESH_RATE = 55;
88     private static final int DEFAULT_LOW_BLOCKING_ZONE_REFRESH_RATE = 95;
89     private static final int DEFAULT_REFRESH_RATE_IN_HBM_HDR = 90;
90     private static final int DEFAULT_REFRESH_RATE_IN_HBM_SUNLIGHT = 100;
91     private static final int[] LOW_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE =
92             new int[]{10, 30, -1};
93     private static final int[] LOW_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE = new int[]{-1, 1, 21};
94     private static final int[] HIGH_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE = new int[]{160, -1};
95     private static final int[] HIGH_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE = new int[]{-1, 30000};
96     private static final float[] NITS = {2, 500, 800};
97     private static final float[] BRIGHTNESS = {0, 0.62f, 1};
98     private static final Spline NITS_TO_BRIGHTNESS_SPLINE = Spline.createSpline(NITS, BRIGHTNESS);
99 
100     private DisplayDeviceConfig mDisplayDeviceConfig;
101     private static final float ZERO_DELTA = 0.0f;
102     private static final float SMALL_DELTA = 0.0001f;
103     @Mock
104     private Context mContext;
105 
106     @Mock
107     private Resources mResources;
108 
109     @Mock
110     private DisplayManagerFlags mFlags;
111 
112     @Before
setUp()113     public void setUp() {
114         MockitoAnnotations.initMocks(this);
115         when(mContext.getResources()).thenReturn(mResources);
116         when(mFlags.areAutoBrightnessModesEnabled()).thenReturn(true);
117         when(mFlags.isSensorBasedBrightnessThrottlingEnabled()).thenReturn(true);
118         when(mFlags.isIdleScreenRefreshRateTimeoutEnabled()).thenReturn(true);
119         mockDeviceConfigs();
120     }
121 
122     @Test
testDefaultValues()123     public void testDefaultValues() {
124         when(mResources.getString(com.android.internal.R.string.config_displayLightSensorType))
125                 .thenReturn("test_light_sensor");
126         when(mResources.getBoolean(R.bool.config_automatic_brightness_available)).thenReturn(true);
127 
128         mDisplayDeviceConfig = DisplayDeviceConfig.create(mContext, /* useConfigXml= */ false,
129                 mFlags);
130 
131         assertEquals(DisplayDeviceConfig.BRIGHTNESS_DEFAULT,
132                 mDisplayDeviceConfig.getBrightnessDefault(), ZERO_DELTA);
133         assertEquals(PowerManager.BRIGHTNESS_MAX,
134                 mDisplayDeviceConfig.getBrightnessRampFastDecrease(), ZERO_DELTA);
135         assertEquals(PowerManager.BRIGHTNESS_MAX,
136                 mDisplayDeviceConfig.getBrightnessRampFastIncrease(), ZERO_DELTA);
137         assertEquals(PowerManager.BRIGHTNESS_MAX,
138                 mDisplayDeviceConfig.getBrightnessRampSlowDecrease(), ZERO_DELTA);
139         assertEquals(PowerManager.BRIGHTNESS_MAX,
140                 mDisplayDeviceConfig.getBrightnessRampSlowIncrease(), ZERO_DELTA);
141         assertEquals(PowerManager.BRIGHTNESS_MAX,
142                 mDisplayDeviceConfig.getBrightnessRampSlowDecreaseIdle(), ZERO_DELTA);
143         assertEquals(PowerManager.BRIGHTNESS_MAX,
144                 mDisplayDeviceConfig.getBrightnessRampSlowIncreaseIdle(), ZERO_DELTA);
145         assertEquals(0, mDisplayDeviceConfig.getBrightnessRampDecreaseMaxMillis());
146         assertEquals(0, mDisplayDeviceConfig.getBrightnessRampIncreaseMaxMillis());
147         assertEquals(0, mDisplayDeviceConfig.getBrightnessRampDecreaseMaxIdleMillis());
148         assertEquals(0, mDisplayDeviceConfig.getBrightnessRampIncreaseMaxIdleMillis());
149         assertNull(mDisplayDeviceConfig.getNits());
150         assertNull(mDisplayDeviceConfig.getBacklight());
151         assertEquals(0.3f, mDisplayDeviceConfig.getBacklightFromBrightness(0.3f), ZERO_DELTA);
152         assertEquals("test_light_sensor", mDisplayDeviceConfig.getAmbientLightSensor().type);
153         assertEquals("", mDisplayDeviceConfig.getAmbientLightSensor().name);
154         assertNull(mDisplayDeviceConfig.getProximitySensor().type);
155         assertNull(mDisplayDeviceConfig.getProximitySensor().name);
156         assertEquals(TEMPERATURE_TYPE_SKIN, mDisplayDeviceConfig.getTempSensor().type);
157         assertEquals(List.of(), mDisplayDeviceConfig
158                 .getIdleScreenRefreshRateTimeoutLuxThresholdPoint());
159         assertNull(mDisplayDeviceConfig.getTempSensor().name);
160         assertTrue(mDisplayDeviceConfig.isAutoBrightnessAvailable());
161         assertEquals(0, mDisplayDeviceConfig.getIdleStylusTimeoutMillis());
162     }
163 
164     @Test
testConfigValuesFromDisplayConfig()165     public void testConfigValuesFromDisplayConfig() throws IOException {
166         setupDisplayDeviceConfigFromDisplayConfigFile();
167 
168         assertEquals(mDisplayDeviceConfig.getName(), "Example Display");
169         assertEquals(mDisplayDeviceConfig.getAmbientHorizonLong(), 5000);
170         assertEquals(mDisplayDeviceConfig.getAmbientHorizonShort(), 50);
171         assertEquals(mDisplayDeviceConfig.getBrightnessDefault(), 0.5f, ZERO_DELTA);
172         assertArrayEquals(mDisplayDeviceConfig.getBrightness(), BRIGHTNESS, ZERO_DELTA);
173         assertArrayEquals(mDisplayDeviceConfig.getNits(), NITS, ZERO_DELTA);
174         assertArrayEquals(mDisplayDeviceConfig.getBacklight(), BRIGHTNESS, ZERO_DELTA);
175 
176         // Test thresholds
177         HysteresisLevels ambientHysteresis = mDisplayDeviceConfig.getAmbientBrightnessHysteresis();
178         HysteresisLevels ambientIdleHysteresis =
179                 mDisplayDeviceConfig.getAmbientBrightnessIdleHysteresis();
180         HysteresisLevels screenHysteresis = mDisplayDeviceConfig.getScreenBrightnessHysteresis();
181         HysteresisLevels screenIdleHysteresis =
182                 mDisplayDeviceConfig.getScreenBrightnessIdleHysteresis();
183         assertEquals(10, ambientHysteresis.getMinBrightening(), ZERO_DELTA);
184         assertEquals(20, ambientIdleHysteresis.getMinBrightening(), ZERO_DELTA);
185         assertEquals(30, ambientHysteresis.getMinDarkening(), ZERO_DELTA);
186         assertEquals(40, ambientIdleHysteresis.getMinDarkening(), ZERO_DELTA);
187 
188         assertEquals(0.1f, screenHysteresis.getMinBrightening(), ZERO_DELTA);
189         assertEquals(0.2f, screenIdleHysteresis.getMinBrightening(), ZERO_DELTA);
190         assertEquals(0.3f, screenHysteresis.getMinDarkening(), ZERO_DELTA);
191         assertEquals(0.4f, screenIdleHysteresis.getMinDarkening(), ZERO_DELTA);
192 
193         assertArrayEquals(new float[]{0, 0.10f, 0.20f},
194                 screenHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
195         assertArrayEquals(new float[]{0.09f, 0.10f, 0.11f},
196                 screenHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
197         assertArrayEquals(new float[]{0, 0.11f, 0.21f},
198                 screenHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
199         assertArrayEquals(new float[]{0.11f, 0.12f, 0.13f},
200                 screenHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
201 
202         assertArrayEquals(new float[]{0, 100, 200},
203                 ambientHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
204         assertArrayEquals(new float[]{0.13f, 0.14f, 0.15f},
205                 ambientHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
206         assertArrayEquals(new float[]{0, 300, 400},
207                 ambientHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
208         assertArrayEquals(new float[]{0.15f, 0.16f, 0.17f},
209                 ambientHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
210 
211         assertArrayEquals(new float[]{0, 0.12f, 0.22f},
212                 screenIdleHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
213         assertArrayEquals(new float[]{0.17f, 0.18f, 0.19f},
214                 screenIdleHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
215         assertArrayEquals(new float[]{0, 0.13f, 0.23f},
216                 screenIdleHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
217         assertArrayEquals(new float[]{0.19f, 0.20f, 0.21f},
218                 screenIdleHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
219 
220         assertArrayEquals(new float[]{0, 500, 600},
221                 ambientIdleHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
222         assertArrayEquals(new float[]{0.21f, 0.22f, 0.23f},
223                 ambientIdleHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
224         assertArrayEquals(new float[]{0, 700, 800},
225                 ambientIdleHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
226         assertArrayEquals(new float[]{0.23f, 0.24f, 0.25f},
227                 ambientIdleHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
228 
229         RefreshRateData refreshRateData = mDisplayDeviceConfig.getRefreshRateData();
230         assertEquals(75, mDisplayDeviceConfig.getDefaultLowBlockingZoneRefreshRate());
231         assertEquals(90, mDisplayDeviceConfig.getDefaultHighBlockingZoneRefreshRate());
232         assertEquals(85, refreshRateData.defaultPeakRefreshRate);
233         assertEquals(45, refreshRateData.defaultRefreshRate);
234         assertEquals(2, mDisplayDeviceConfig.getRefreshRangeProfiles().size());
235         assertEquals(60, mDisplayDeviceConfig.getRefreshRange("test1").min, SMALL_DELTA);
236         assertEquals(60, mDisplayDeviceConfig.getRefreshRange("test1").max, SMALL_DELTA);
237         assertEquals(80, mDisplayDeviceConfig.getRefreshRange("test2").min, SMALL_DELTA);
238         assertEquals(90, mDisplayDeviceConfig.getRefreshRange("test2").max, SMALL_DELTA);
239         assertEquals(82, refreshRateData.defaultRefreshRateInHbmHdr);
240         assertEquals(83, refreshRateData.defaultRefreshRateInHbmSunlight);
241 
242         assertNotNull(mDisplayDeviceConfig.getHostUsiVersion());
243         assertEquals(mDisplayDeviceConfig.getHostUsiVersion().getMajorVersion(), 2);
244         assertEquals(mDisplayDeviceConfig.getHostUsiVersion().getMinorVersion(), 0);
245 
246         List<IdleScreenRefreshRateTimeoutLuxThresholdPoint>
247                 idleScreenRefreshRateTimeoutLuxThresholdPoints =
248                 mDisplayDeviceConfig.getIdleScreenRefreshRateTimeoutLuxThresholdPoint();
249         assertEquals(2, idleScreenRefreshRateTimeoutLuxThresholdPoints.size());
250         assertEquals(6, idleScreenRefreshRateTimeoutLuxThresholdPoints.get(0).getLux()
251                 .intValue());
252         assertEquals(1000, idleScreenRefreshRateTimeoutLuxThresholdPoints.get(0)
253                 .getTimeout().intValue());
254         assertEquals(10, idleScreenRefreshRateTimeoutLuxThresholdPoints.get(1)
255                 .getLux().intValue());
256         assertEquals(800, idleScreenRefreshRateTimeoutLuxThresholdPoints.get(1)
257                 .getTimeout().intValue());
258         assertEquals(1000, mDisplayDeviceConfig.getIdleStylusTimeoutMillis());
259     }
260 
261     @Test
testPowerThrottlingConfigFromDisplayConfig()262     public void testPowerThrottlingConfigFromDisplayConfig() throws IOException {
263         setupDisplayDeviceConfigFromDisplayConfigFile();
264 
265         DisplayDeviceConfig.PowerThrottlingConfigData powerThrottlingConfigData =
266                 mDisplayDeviceConfig.getPowerThrottlingConfigData();
267         assertNotNull(powerThrottlingConfigData);
268         assertEquals(0.1f, powerThrottlingConfigData.brightnessLowestCapAllowed, SMALL_DELTA);
269         assertEquals(15f, powerThrottlingConfigData.customAnimationRate, SMALL_DELTA);
270         assertEquals(20000, powerThrottlingConfigData.pollingWindowMaxMillis);
271         assertEquals(10000, powerThrottlingConfigData.pollingWindowMinMillis);
272     }
273 
274     @Test
testPowerThrottlingDataFromDisplayConfig()275     public void testPowerThrottlingDataFromDisplayConfig() throws IOException {
276         setupDisplayDeviceConfigFromDisplayConfigFile();
277 
278         List<DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel>
279                 defaultThrottlingLevels = new ArrayList<>();
280         defaultThrottlingLevels.add(
281                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
282                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.light), 800f
283                 ));
284         defaultThrottlingLevels.add(
285                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
286                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.moderate), 600f
287                 ));
288         defaultThrottlingLevels.add(
289                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
290                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.severe), 400f
291                 ));
292         defaultThrottlingLevels.add(
293                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
294                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.critical), 200f
295                 ));
296         defaultThrottlingLevels.add(
297                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
298                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.emergency), 100f
299                 ));
300         defaultThrottlingLevels.add(
301                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
302                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.shutdown), 50f
303                 ));
304 
305         DisplayDeviceConfig.PowerThrottlingData defaultThrottlingData =
306                 new DisplayDeviceConfig.PowerThrottlingData(defaultThrottlingLevels);
307 
308         List<DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel>
309                 concurrentThrottlingLevels = new ArrayList<>();
310         concurrentThrottlingLevels.add(
311                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
312                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.light), 800f
313                 ));
314         concurrentThrottlingLevels.add(
315                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
316                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.moderate), 600f
317                 ));
318         concurrentThrottlingLevels.add(
319                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
320                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.severe), 400f
321                 ));
322         concurrentThrottlingLevels.add(
323                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
324                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.critical), 200f
325                 ));
326         concurrentThrottlingLevels.add(
327                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
328                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.emergency), 100f
329                 ));
330         concurrentThrottlingLevels.add(
331                 new DisplayDeviceConfig.PowerThrottlingData.ThrottlingLevel(
332                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.shutdown), 50f
333                 ));
334         DisplayDeviceConfig.PowerThrottlingData concurrentThrottlingData =
335                 new DisplayDeviceConfig.PowerThrottlingData(concurrentThrottlingLevels);
336 
337         HashMap<String, DisplayDeviceConfig.PowerThrottlingData> throttlingDataMap =
338                 new HashMap<>(2);
339         throttlingDataMap.put("default", defaultThrottlingData);
340         throttlingDataMap.put("concurrent", concurrentThrottlingData);
341 
342         assertEquals(throttlingDataMap,
343                 mDisplayDeviceConfig.getPowerThrottlingDataMapByThrottlingId());
344     }
345 
346     @Test
testConfigValuesFromConfigResource()347     public void testConfigValuesFromConfigResource() {
348         setupDisplayDeviceConfigFromConfigResourceFile();
349         verifyConfigValuesFromConfigResource();
350     }
351 
352     @Test
testThermalRefreshRateThrottlingFromDisplayConfig()353     public void testThermalRefreshRateThrottlingFromDisplayConfig() throws IOException {
354         setupDisplayDeviceConfigFromDisplayConfigFile();
355 
356         SparseArray<SurfaceControl.RefreshRateRange> defaultMap =
357                 mDisplayDeviceConfig.getThermalRefreshRateThrottlingData(null);
358         assertNotNull(defaultMap);
359         assertEquals(2, defaultMap.size());
360         assertEquals(30, defaultMap.get(Temperature.THROTTLING_CRITICAL).min, SMALL_DELTA);
361         assertEquals(60, defaultMap.get(Temperature.THROTTLING_CRITICAL).max, SMALL_DELTA);
362         assertEquals(0, defaultMap.get(Temperature.THROTTLING_SHUTDOWN).min, SMALL_DELTA);
363         assertEquals(30, defaultMap.get(Temperature.THROTTLING_SHUTDOWN).max, SMALL_DELTA);
364 
365         SparseArray<SurfaceControl.RefreshRateRange> testMap =
366                 mDisplayDeviceConfig.getThermalRefreshRateThrottlingData("test");
367         assertNotNull(testMap);
368         assertEquals(1, testMap.size());
369         assertEquals(60, testMap.get(Temperature.THROTTLING_EMERGENCY).min, SMALL_DELTA);
370         assertEquals(90, testMap.get(Temperature.THROTTLING_EMERGENCY).max, SMALL_DELTA);
371     }
372 
373     @Test
testValidLuxThrottling()374     public void testValidLuxThrottling() throws Exception {
375         setupDisplayDeviceConfigFromDisplayConfigFile();
376 
377         Map<DisplayDeviceConfig.BrightnessLimitMapType, Map<Float, Float>> luxThrottlingData =
378                 mDisplayDeviceConfig.getLuxThrottlingData();
379         assertEquals(2, luxThrottlingData.size());
380 
381         Map<Float, Float> adaptiveOnBrightnessPoints = luxThrottlingData.get(
382                 DisplayDeviceConfig.BrightnessLimitMapType.ADAPTIVE);
383         assertEquals(2, adaptiveOnBrightnessPoints.size());
384         assertEquals(0.3f, adaptiveOnBrightnessPoints.get(1000f), SMALL_DELTA);
385         assertEquals(0.5f, adaptiveOnBrightnessPoints.get(5000f), SMALL_DELTA);
386 
387         Map<Float, Float> adaptiveOffBrightnessPoints = luxThrottlingData.get(
388                 DisplayDeviceConfig.BrightnessLimitMapType.DEFAULT);
389         assertEquals(2, adaptiveOffBrightnessPoints.size());
390         assertEquals(0.35f, adaptiveOffBrightnessPoints.get(1500f), SMALL_DELTA);
391         assertEquals(0.55f, adaptiveOffBrightnessPoints.get(5500f), SMALL_DELTA);
392     }
393 
394     @Test
testInvalidLuxThrottling()395     public void testInvalidLuxThrottling() throws Exception {
396         setupDisplayDeviceConfigFromDisplayConfigFile(
397                 getContent(getInvalidLuxThrottling(), getValidProxSensor(),
398                         /* includeIdleMode= */ true, /* enableEvenDimmer= */ false));
399 
400         Map<DisplayDeviceConfig.BrightnessLimitMapType, Map<Float, Float>> luxThrottlingData =
401                 mDisplayDeviceConfig.getLuxThrottlingData();
402         assertEquals(1, luxThrottlingData.size());
403 
404         Map<Float, Float> adaptiveOnBrightnessPoints = luxThrottlingData.get(
405                 DisplayDeviceConfig.BrightnessLimitMapType.ADAPTIVE);
406         assertEquals(1, adaptiveOnBrightnessPoints.size());
407         assertEquals(0.3f, adaptiveOnBrightnessPoints.get(1000f), SMALL_DELTA);
408     }
409 
410     @Test
testFallbackToConfigResource()411     public void testFallbackToConfigResource() throws IOException {
412         setupDisplayDeviceConfigFromConfigResourceFile();
413 
414         // Empty display config file
415         setupDisplayDeviceConfigFromDisplayConfigFile(
416                 "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n"
417                 + "<displayConfiguration />\n");
418 
419         // We should fall back to the config resource
420         verifyConfigValuesFromConfigResource();
421         assertEquals(3000, mDisplayDeviceConfig.getAutoBrightnessBrighteningLightDebounce());
422         assertEquals(4000, mDisplayDeviceConfig.getAutoBrightnessDarkeningLightDebounce());
423         assertEquals(3000, mDisplayDeviceConfig.getAutoBrightnessBrighteningLightDebounceIdle());
424         assertEquals(4000, mDisplayDeviceConfig.getAutoBrightnessDarkeningLightDebounceIdle());
425     }
426 
427     @Test
testDensityMappingFromDisplayConfig()428     public void testDensityMappingFromDisplayConfig() throws IOException {
429         setupDisplayDeviceConfigFromDisplayConfigFile();
430 
431         assertEquals(120, mDisplayDeviceConfig.getDensityMapping()
432                 .getDensityForResolution(720, 480));
433         assertEquals(213, mDisplayDeviceConfig.getDensityMapping()
434                 .getDensityForResolution(1280, 720));
435         assertEquals(320, mDisplayDeviceConfig.getDensityMapping()
436                 .getDensityForResolution(1920, 1080));
437         assertEquals(640, mDisplayDeviceConfig.getDensityMapping()
438                 .getDensityForResolution(3840, 2160));
439     }
440 
441     @Test
testHighBrightnessModeDataFromDisplayConfig()442     public void testHighBrightnessModeDataFromDisplayConfig() throws IOException {
443         setupDisplayDeviceConfigFromDisplayConfigFile();
444 
445         HighBrightnessModeData hbmData =
446                 mDisplayDeviceConfig.getHighBrightnessModeData();
447         assertNotNull(hbmData);
448         assertEquals(BRIGHTNESS[1], hbmData.transitionPoint, ZERO_DELTA);
449         assertEquals(10000, hbmData.minimumLux, ZERO_DELTA);
450         assertEquals(1800 * 1000, hbmData.timeWindowMillis);
451         assertEquals(300 * 1000, hbmData.timeMaxMillis);
452         assertEquals(60 * 1000, hbmData.timeMinMillis);
453         assertFalse(hbmData.allowInLowPowerMode);
454         assertEquals(0.6f, hbmData.minimumHdrPercentOfScreen, ZERO_DELTA);
455 
456         List<DisplayManagerInternal.RefreshRateLimitation> refreshRateLimitations =
457                 mDisplayDeviceConfig.getRefreshRateLimitations();
458         assertEquals(1, refreshRateLimitations.size());
459         assertEquals(DisplayManagerInternal.REFRESH_RATE_LIMIT_HIGH_BRIGHTNESS_MODE,
460                 refreshRateLimitations.get(0).type);
461         assertEquals(120, refreshRateLimitations.get(0).range.min, ZERO_DELTA);
462         assertEquals(120, refreshRateLimitations.get(0).range.max, ZERO_DELTA);
463 
464         // Max desired Hdr/SDR ratio upper-bounds the HDR brightness.
465         assertTrue(mDisplayDeviceConfig.hasSdrToHdrRatioSpline());
466         assertEquals(NITS_TO_BRIGHTNESS_SPLINE.interpolate(500 * 1.6f),
467                 mDisplayDeviceConfig.getHdrBrightnessFromSdr(
468                         NITS_TO_BRIGHTNESS_SPLINE.interpolate(500), Float.POSITIVE_INFINITY),
469                 ZERO_DELTA);
470         assertEquals(NITS_TO_BRIGHTNESS_SPLINE.interpolate(500),
471                 mDisplayDeviceConfig.getHdrBrightnessFromSdr(
472                         NITS_TO_BRIGHTNESS_SPLINE.interpolate(500), 1.0f),
473                 ZERO_DELTA);
474         assertEquals(NITS_TO_BRIGHTNESS_SPLINE.interpolate(500 * 1.25f),
475                 mDisplayDeviceConfig.getHdrBrightnessFromSdr(
476                         NITS_TO_BRIGHTNESS_SPLINE.interpolate(500), 1.25f),
477                 SMALL_DELTA);
478         assertEquals(NITS_TO_BRIGHTNESS_SPLINE.interpolate(2 * 4),
479                 mDisplayDeviceConfig.getHdrBrightnessFromSdr(
480                         NITS_TO_BRIGHTNESS_SPLINE.interpolate(2), Float.POSITIVE_INFINITY),
481                 SMALL_DELTA);
482     }
483 
484     @Test
testThermalBrightnessThrottlingDataFromDisplayConfig()485     public void testThermalBrightnessThrottlingDataFromDisplayConfig() throws IOException {
486         setupDisplayDeviceConfigFromDisplayConfigFile();
487 
488         List<DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel>
489                 defaultThrottlingLevels = new ArrayList<>();
490         defaultThrottlingLevels.add(
491                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
492                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.light), 0.4f
493                 ));
494         defaultThrottlingLevels.add(
495                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
496                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.moderate), 0.3f
497                 ));
498         defaultThrottlingLevels.add(
499                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
500                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.severe), 0.2f
501                 ));
502         defaultThrottlingLevels.add(
503                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
504                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.critical), 0.1f
505                 ));
506         defaultThrottlingLevels.add(
507                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
508                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.emergency), 0.05f
509                 ));
510         defaultThrottlingLevels.add(
511                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
512                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.shutdown), 0.025f
513                 ));
514 
515         DisplayDeviceConfig.ThermalBrightnessThrottlingData defaultThrottlingData =
516                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData(defaultThrottlingLevels);
517 
518         List<DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel>
519                 concurrentThrottlingLevels = new ArrayList<>();
520         concurrentThrottlingLevels.add(
521                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
522                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.light), 0.2f
523                 ));
524         concurrentThrottlingLevels.add(
525                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
526                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.moderate), 0.15f
527                 ));
528         concurrentThrottlingLevels.add(
529                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
530                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.severe), 0.1f
531                 ));
532         concurrentThrottlingLevels.add(
533                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
534                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.critical), 0.05f
535                 ));
536         concurrentThrottlingLevels.add(
537                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
538                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.emergency), 0.025f
539                 ));
540         concurrentThrottlingLevels.add(
541                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel(
542                         DisplayDeviceConfig.convertThermalStatus(ThermalStatus.shutdown), 0.0125f
543                 ));
544         DisplayDeviceConfig.ThermalBrightnessThrottlingData concurrentThrottlingData =
545                 new DisplayDeviceConfig.ThermalBrightnessThrottlingData(concurrentThrottlingLevels);
546 
547         HashMap<String, DisplayDeviceConfig.ThermalBrightnessThrottlingData> throttlingDataMap =
548                 new HashMap<>(2);
549         throttlingDataMap.put("default", defaultThrottlingData);
550         throttlingDataMap.put("concurrent", concurrentThrottlingData);
551 
552         assertEquals(throttlingDataMap,
553                 mDisplayDeviceConfig.getThermalBrightnessThrottlingDataMapByThrottlingId());
554     }
555 
556     @Test
testAmbientLightSensorFromDisplayConfig()557     public void testAmbientLightSensorFromDisplayConfig() throws IOException {
558         setupDisplayDeviceConfigFromDisplayConfigFile();
559 
560         assertEquals("test_light_sensor",
561                 mDisplayDeviceConfig.getAmbientLightSensor().type);
562         assertEquals("Test Ambient Light Sensor",
563                 mDisplayDeviceConfig.getAmbientLightSensor().name);
564         assertEquals(60, mDisplayDeviceConfig.getAmbientLightSensor().minRefreshRate, ZERO_DELTA);
565         assertEquals(120, mDisplayDeviceConfig.getAmbientLightSensor().maxRefreshRate, ZERO_DELTA);
566     }
567 
568     @Test
testScreenOffBrightnessSensorFromDisplayConfig()569     public void testScreenOffBrightnessSensorFromDisplayConfig() throws IOException {
570         setupDisplayDeviceConfigFromDisplayConfigFile();
571 
572         assertEquals("test_binned_brightness_sensor",
573                 mDisplayDeviceConfig.getScreenOffBrightnessSensor().type);
574         assertEquals("Test Binned Brightness Sensor",
575                 mDisplayDeviceConfig.getScreenOffBrightnessSensor().name);
576 
577         assertArrayEquals(new int[]{ -1, 10, 20, 30, 40 },
578                 mDisplayDeviceConfig.getScreenOffBrightnessSensorValueToLux());
579 
580         // Low/High zone thermal maps
581         assertEquals(new SurfaceControl.RefreshRateRange(30, 40),
582                 mDisplayDeviceConfig.getLowBlockingZoneThermalMap()
583                 .get(Temperature.THROTTLING_CRITICAL));
584         assertEquals(new SurfaceControl.RefreshRateRange(40, 60),
585                 mDisplayDeviceConfig.getHighBlockingZoneThermalMap()
586                 .get(Temperature.THROTTLING_EMERGENCY));
587 
588         // Todo: Add asserts for DensityMapping,
589         // HighBrightnessModeData AmbientLightSensor, RefreshRateLimitations and ProximitySensor.
590     }
591 
592     @Test
testProximitySensorFromDisplayConfig()593     public void testProximitySensorFromDisplayConfig() throws IOException {
594         setupDisplayDeviceConfigFromDisplayConfigFile();
595 
596         assertEquals("test_proximity_sensor",
597                 mDisplayDeviceConfig.getProximitySensor().type);
598         assertEquals("Test Proximity Sensor",
599                 mDisplayDeviceConfig.getProximitySensor().name);
600     }
601 
602     @Test
testProximitySensorWithEmptyValuesFromDisplayConfig()603     public void testProximitySensorWithEmptyValuesFromDisplayConfig() throws IOException {
604         setupDisplayDeviceConfigFromDisplayConfigFile(
605                 getContent(getValidLuxThrottling(), getProxSensorWithEmptyValues(),
606                         /* includeIdleMode= */ true, /* enableEvenDimmer= */ false));
607         assertNull(mDisplayDeviceConfig.getProximitySensor());
608     }
609 
610     @Test
testProximitySensorWithRefreshRatesFromDisplayConfig()611     public void testProximitySensorWithRefreshRatesFromDisplayConfig() throws IOException {
612         setupDisplayDeviceConfigFromDisplayConfigFile(
613                 getContent(getValidLuxThrottling(), getValidProxSensorWithRefreshRateAndVsyncRate(),
614                         /* includeIdleMode= */ true, /* enableEvenDimmer= */ false));
615         assertEquals("test_proximity_sensor",
616                 mDisplayDeviceConfig.getProximitySensor().type);
617         assertEquals("Test Proximity Sensor",
618                 mDisplayDeviceConfig.getProximitySensor().name);
619         assertEquals(mDisplayDeviceConfig.getProximitySensor().minRefreshRate, 60, SMALL_DELTA);
620         assertEquals(mDisplayDeviceConfig.getProximitySensor().maxRefreshRate, 90, SMALL_DELTA);
621         assertThat(mDisplayDeviceConfig.getProximitySensor().supportedModes).hasSize(2);
622         SupportedModeData mode = mDisplayDeviceConfig.getProximitySensor().supportedModes.get(0);
623         assertEquals(mode.refreshRate, 60, SMALL_DELTA);
624         assertEquals(mode.vsyncRate, 65, SMALL_DELTA);
625         mode = mDisplayDeviceConfig.getProximitySensor().supportedModes.get(1);
626         assertEquals(mode.refreshRate, 120, SMALL_DELTA);
627         assertEquals(mode.vsyncRate, 125, SMALL_DELTA);
628     }
629 
630     @Test
testTempSensorFromDisplayConfig()631     public void testTempSensorFromDisplayConfig() throws IOException {
632         setupDisplayDeviceConfigFromDisplayConfigFile();
633         assertEquals("DISPLAY", mDisplayDeviceConfig.getTempSensor().type);
634         assertEquals("VIRTUAL-SKIN-DISPLAY", mDisplayDeviceConfig.getTempSensor().name);
635     }
636 
637     @Test
testBlockingZoneThresholdsFromDisplayConfig()638     public void testBlockingZoneThresholdsFromDisplayConfig() throws IOException {
639         setupDisplayDeviceConfigFromDisplayConfigFile();
640 
641         assertArrayEquals(new float[]{ NITS_TO_BRIGHTNESS_SPLINE.interpolate(50),
642                         NITS_TO_BRIGHTNESS_SPLINE.interpolate(300),
643                         NITS_TO_BRIGHTNESS_SPLINE.interpolate(300), -1},
644                 mDisplayDeviceConfig.getLowDisplayBrightnessThresholds(), SMALL_DELTA);
645         assertArrayEquals(new float[]{50, 60, -1, 60},
646                 mDisplayDeviceConfig.getLowAmbientBrightnessThresholds(), ZERO_DELTA);
647         assertArrayEquals(new float[]{ NITS_TO_BRIGHTNESS_SPLINE.interpolate(80),
648                         NITS_TO_BRIGHTNESS_SPLINE.interpolate(100),
649                         NITS_TO_BRIGHTNESS_SPLINE.interpolate(100), -1},
650                 mDisplayDeviceConfig.getHighDisplayBrightnessThresholds(), SMALL_DELTA);
651         assertArrayEquals(new float[]{70, 80, -1, 80},
652                 mDisplayDeviceConfig.getHighAmbientBrightnessThresholds(), ZERO_DELTA);
653     }
654 
655     @Test
testBlockingZoneThresholdsFromConfigResource()656     public void testBlockingZoneThresholdsFromConfigResource() {
657         setupDisplayDeviceConfigFromConfigResourceFile();
658 
659         assertArrayEquals(displayBrightnessThresholdsIntToFloat(
660                         LOW_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE),
661                 mDisplayDeviceConfig.getLowDisplayBrightnessThresholds(), SMALL_DELTA);
662         assertArrayEquals(ambientBrightnessThresholdsIntToFloat(
663                         LOW_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE),
664                 mDisplayDeviceConfig.getLowAmbientBrightnessThresholds(), ZERO_DELTA);
665         assertArrayEquals(displayBrightnessThresholdsIntToFloat(
666                         HIGH_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE),
667                 mDisplayDeviceConfig.getHighDisplayBrightnessThresholds(), SMALL_DELTA);
668         assertArrayEquals(ambientBrightnessThresholdsIntToFloat(
669                         HIGH_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE),
670                 mDisplayDeviceConfig.getHighAmbientBrightnessThresholds(), ZERO_DELTA);
671     }
672 
673     @Test
testHdrBrightnessDataFromDisplayConfig()674     public void testHdrBrightnessDataFromDisplayConfig() throws IOException {
675         setupDisplayDeviceConfigFromDisplayConfigFile();
676 
677         HdrBrightnessData data = mDisplayDeviceConfig.getHdrBrightnessData();
678 
679         assertNotNull(data);
680         assertEquals(2, data.maxBrightnessLimits.size());
681         assertEquals(13000, data.brightnessDecreaseDebounceMillis);
682         assertEquals(0.1f, data.screenBrightnessRampDecrease, SMALL_DELTA);
683         assertEquals(1000, data.brightnessIncreaseDebounceMillis);
684         assertEquals(0.11f, data.screenBrightnessRampIncrease, SMALL_DELTA);
685 
686         assertEquals(0.3f, data.maxBrightnessLimits.get(500f), SMALL_DELTA);
687         assertEquals(0.6f, data.maxBrightnessLimits.get(1200f), SMALL_DELTA);
688     }
689 
verifyConfigValuesFromConfigResource()690     private void verifyConfigValuesFromConfigResource() {
691         assertNull(mDisplayDeviceConfig.getName());
692         assertArrayEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsNits(),
693                 new float[]{2.0f, 200.0f, 600.0f}, ZERO_DELTA);
694         assertArrayEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
695                 AUTO_BRIGHTNESS_MODE_DEFAULT, Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL),
696                 new float[]{0.0f, 110.0f, 500.0f}, ZERO_DELTA);
697         assertArrayEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
698                 AUTO_BRIGHTNESS_MODE_DEFAULT, Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL),
699                 new float[]{brightnessIntToFloat(50), brightnessIntToFloat(100),
700                         brightnessIntToFloat(150)}, SMALL_DELTA);
701 
702         HysteresisLevels ambientHysteresis = mDisplayDeviceConfig.getAmbientBrightnessHysteresis();
703         HysteresisLevels ambientIdleHysteresis =
704                 mDisplayDeviceConfig.getAmbientBrightnessIdleHysteresis();
705         HysteresisLevels screenHysteresis = mDisplayDeviceConfig.getScreenBrightnessHysteresis();
706         HysteresisLevels screenIdleHysteresis =
707                 mDisplayDeviceConfig.getScreenBrightnessIdleHysteresis();
708 
709         // Test thresholds
710         assertEquals(0, ambientHysteresis.getMinBrightening(), ZERO_DELTA);
711         assertEquals(0, ambientIdleHysteresis.getMinBrightening(), ZERO_DELTA);
712         assertEquals(0, ambientHysteresis.getMinDarkening(), ZERO_DELTA);
713         assertEquals(0, ambientIdleHysteresis.getMinDarkening(), ZERO_DELTA);
714 
715         assertEquals(0, screenHysteresis.getMinBrightening(), ZERO_DELTA);
716         assertEquals(0, screenIdleHysteresis.getMinBrightening(), ZERO_DELTA);
717         assertEquals(0, screenHysteresis.getMinDarkening(), ZERO_DELTA);
718         assertEquals(0, screenIdleHysteresis.getMinDarkening(), ZERO_DELTA);
719 
720         // screen levels will be considered "old screen brightness scale"
721         // and therefore will divide by 255
722         assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f},
723                 screenHysteresis.getBrighteningThresholdLevels(), SMALL_DELTA);
724         assertArrayEquals(new float[]{0.35f, 0.36f, 0.37f},
725                 screenHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
726         assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f},
727                 screenHysteresis.getDarkeningThresholdLevels(), SMALL_DELTA);
728         assertArrayEquals(new float[]{0.37f, 0.38f, 0.39f},
729                 screenHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
730 
731         assertArrayEquals(new float[]{0, 30, 31},
732                 ambientHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
733         assertArrayEquals(new float[]{0.27f, 0.28f, 0.29f},
734                 ambientHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
735         assertArrayEquals(new float[]{0, 30, 31},
736                 ambientHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
737         assertArrayEquals(new float[]{0.29f, 0.30f, 0.31f},
738                 ambientHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
739 
740         assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f},
741                 screenIdleHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
742         assertArrayEquals(new float[]{0.35f, 0.36f, 0.37f},
743                 screenIdleHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
744         assertArrayEquals(new float[]{0, 42 / 255f, 43 / 255f},
745                 screenIdleHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
746         assertArrayEquals(new float[]{0.37f, 0.38f, 0.39f},
747                 screenIdleHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
748 
749         RefreshRateData refreshRateData = mDisplayDeviceConfig.getRefreshRateData();
750 
751         assertArrayEquals(new float[]{0, 30, 31},
752                 ambientIdleHysteresis.getBrighteningThresholdLevels(), ZERO_DELTA);
753         assertArrayEquals(new float[]{0.27f, 0.28f, 0.29f},
754                 ambientIdleHysteresis.getBrighteningThresholdsPercentages(), ZERO_DELTA);
755         assertArrayEquals(new float[]{0, 30, 31},
756                 ambientIdleHysteresis.getDarkeningThresholdLevels(), ZERO_DELTA);
757         assertArrayEquals(new float[]{0.29f, 0.30f, 0.31f},
758                 ambientIdleHysteresis.getDarkeningThresholdsPercentages(), ZERO_DELTA);
759         assertEquals(mDisplayDeviceConfig.getDefaultLowBlockingZoneRefreshRate(),
760                 DEFAULT_LOW_BLOCKING_ZONE_REFRESH_RATE);
761         assertEquals(mDisplayDeviceConfig.getDefaultHighBlockingZoneRefreshRate(),
762                 DEFAULT_HIGH_BLOCKING_ZONE_REFRESH_RATE);
763         assertEquals(refreshRateData.defaultPeakRefreshRate, DEFAULT_PEAK_REFRESH_RATE);
764         assertEquals(refreshRateData.defaultRefreshRate, DEFAULT_REFRESH_RATE);
765         assertEquals(0, mDisplayDeviceConfig.getRefreshRangeProfiles().size());
766         assertEquals(refreshRateData.defaultRefreshRateInHbmSunlight,
767                 DEFAULT_REFRESH_RATE_IN_HBM_SUNLIGHT);
768         assertEquals(refreshRateData.defaultRefreshRateInHbmHdr, DEFAULT_REFRESH_RATE_IN_HBM_HDR);
769 
770         assertEquals("test_light_sensor", mDisplayDeviceConfig.getAmbientLightSensor().type);
771         assertEquals("", mDisplayDeviceConfig.getAmbientLightSensor().name);
772         assertTrue(mDisplayDeviceConfig.isAutoBrightnessAvailable());
773 
774         assertEquals(brightnessIntToFloat(35),
775                 mDisplayDeviceConfig.getBrightnessCapForWearBedtimeMode(), ZERO_DELTA);
776         assertEquals(List.of(), mDisplayDeviceConfig
777                 .getIdleScreenRefreshRateTimeoutLuxThresholdPoint());
778     }
779 
780     @Test
testLightDebounceFromDisplayConfig()781     public void testLightDebounceFromDisplayConfig() throws IOException {
782         setupDisplayDeviceConfigFromDisplayConfigFile();
783 
784         assertEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLightDebounce(), 2000);
785         assertEquals(mDisplayDeviceConfig.getAutoBrightnessDarkeningLightDebounce(), 1000);
786         assertEquals(mDisplayDeviceConfig.getAutoBrightnessBrighteningLightDebounceIdle(), 2500);
787         assertEquals(mDisplayDeviceConfig.getAutoBrightnessDarkeningLightDebounceIdle(), 1500);
788     }
789 
790     @Test
testBrightnessRamps()791     public void testBrightnessRamps() throws IOException {
792         setupDisplayDeviceConfigFromDisplayConfigFile();
793 
794         assertEquals(mDisplayDeviceConfig.getBrightnessRampDecreaseMaxMillis(), 3000);
795         assertEquals(mDisplayDeviceConfig.getBrightnessRampIncreaseMaxMillis(), 2000);
796         assertEquals(mDisplayDeviceConfig.getBrightnessRampDecreaseMaxIdleMillis(), 5000);
797         assertEquals(mDisplayDeviceConfig.getBrightnessRampIncreaseMaxIdleMillis(), 4000);
798         assertEquals(mDisplayDeviceConfig.getBrightnessRampFastDecrease(), 0.01f, ZERO_DELTA);
799         assertEquals(mDisplayDeviceConfig.getBrightnessRampFastIncrease(), 0.02f, ZERO_DELTA);
800         assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowDecrease(), 0.03f, ZERO_DELTA);
801         assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowIncrease(), 0.04f, ZERO_DELTA);
802         assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowDecreaseIdle(), 0.05f, ZERO_DELTA);
803         assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowIncreaseIdle(), 0.06f, ZERO_DELTA);
804     }
805 
806     @Test
testBrightnessRamps_IdleFallsBackToConfigInteractive()807     public void testBrightnessRamps_IdleFallsBackToConfigInteractive() throws IOException {
808         setupDisplayDeviceConfigFromDisplayConfigFile(getContent(getValidLuxThrottling(),
809                 getValidProxSensor(), /* includeIdleMode= */ false, /* enableEvenDimmer= */ false));
810 
811         assertEquals(mDisplayDeviceConfig.getBrightnessRampDecreaseMaxMillis(), 3000);
812         assertEquals(mDisplayDeviceConfig.getBrightnessRampIncreaseMaxMillis(), 2000);
813         assertEquals(mDisplayDeviceConfig.getBrightnessRampDecreaseMaxIdleMillis(), 3000);
814         assertEquals(mDisplayDeviceConfig.getBrightnessRampIncreaseMaxIdleMillis(), 2000);
815         assertEquals(mDisplayDeviceConfig.getBrightnessRampFastDecrease(), 0.01f, ZERO_DELTA);
816         assertEquals(mDisplayDeviceConfig.getBrightnessRampFastIncrease(), 0.02f, ZERO_DELTA);
817         assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowDecrease(), 0.03f, ZERO_DELTA);
818         assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowIncrease(), 0.04f, ZERO_DELTA);
819         assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowDecreaseIdle(), 0.03f, ZERO_DELTA);
820         assertEquals(mDisplayDeviceConfig.getBrightnessRampSlowIncreaseIdle(), 0.04f, ZERO_DELTA);
821     }
822 
823     @Test
testBrightnessCapForWearBedtimeMode()824     public void testBrightnessCapForWearBedtimeMode() throws IOException {
825         setupDisplayDeviceConfigFromDisplayConfigFile(getContent(getValidLuxThrottling(),
826                 getValidProxSensor(), /* includeIdleMode= */ false, /* enableEvenDimmer= */ false));
827         assertEquals(0.1f, mDisplayDeviceConfig.getBrightnessCapForWearBedtimeMode(), ZERO_DELTA);
828     }
829 
830     @Test
testAutoBrightnessBrighteningLevels()831     public void testAutoBrightnessBrighteningLevels() throws IOException {
832         setupDisplayDeviceConfigFromDisplayConfigFile(getContent(getValidLuxThrottling(),
833                 getValidProxSensor(), /* includeIdleMode= */ false, /* enableEvenDimmer= */ false));
834 
835         assertArrayEquals(new float[]{0.0f, 80},
836                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
837                         AUTO_BRIGHTNESS_MODE_DEFAULT,
838                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL), ZERO_DELTA);
839         assertArrayEquals(new float[]{0.2f, 0.3f},
840                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
841                         AUTO_BRIGHTNESS_MODE_DEFAULT,
842                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL), SMALL_DELTA);
843 
844         assertArrayEquals(new float[]{0.0f, 90},
845                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
846                         AUTO_BRIGHTNESS_MODE_DEFAULT,
847                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_DIM), ZERO_DELTA);
848         assertArrayEquals(new float[]{0.3f, 0.4f},
849                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
850                         AUTO_BRIGHTNESS_MODE_DEFAULT,
851                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_DIM), SMALL_DELTA);
852 
853         assertArrayEquals(new float[]{0.0f, 80},
854                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
855                         AUTO_BRIGHTNESS_MODE_DEFAULT,
856                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_BRIGHT), ZERO_DELTA);
857         assertArrayEquals(new float[]{0.6f, 0.7f},
858                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
859                         AUTO_BRIGHTNESS_MODE_DEFAULT,
860                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_BRIGHT), SMALL_DELTA);
861 
862         assertArrayEquals(new float[]{0.0f, 95},
863                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
864                         AUTO_BRIGHTNESS_MODE_DOZE,
865                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL), ZERO_DELTA);
866         assertArrayEquals(new float[]{0.35f, 0.45f},
867                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
868                         AUTO_BRIGHTNESS_MODE_DOZE,
869                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL), SMALL_DELTA);
870 
871         assertArrayEquals(new float[]{0.0f, 100},
872                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
873                         AUTO_BRIGHTNESS_MODE_DOZE,
874                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_BRIGHT), ZERO_DELTA);
875         assertArrayEquals(new float[]{0.4f, 0.5f},
876                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
877                         AUTO_BRIGHTNESS_MODE_DOZE,
878                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_BRIGHT), SMALL_DELTA);
879 
880         // Should fall back to the normal preset
881         assertArrayEquals(new float[]{0.0f, 95},
882                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
883                         AUTO_BRIGHTNESS_MODE_DOZE,
884                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_DIM), ZERO_DELTA);
885         assertArrayEquals(new float[]{0.35f, 0.45f},
886                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
887                         AUTO_BRIGHTNESS_MODE_DOZE,
888                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_DIM), SMALL_DELTA);
889 
890         // Wear Bedtime mode curve
891         assertArrayEquals(new float[]{0.0f, 10.0f},
892                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
893                         AUTO_BRIGHTNESS_MODE_BEDTIME_WEAR,
894                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_DIM), ZERO_DELTA);
895         assertArrayEquals(new float[]{0.20f, 0.30f},
896                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
897                         AUTO_BRIGHTNESS_MODE_BEDTIME_WEAR,
898                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_DIM), SMALL_DELTA);
899 
900         assertArrayEquals(new float[]{0.0f, 20.0f},
901                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
902                         AUTO_BRIGHTNESS_MODE_BEDTIME_WEAR,
903                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL), ZERO_DELTA);
904         assertArrayEquals(new float[]{0.30f, 0.65f},
905                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
906                         AUTO_BRIGHTNESS_MODE_BEDTIME_WEAR,
907                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL), SMALL_DELTA);
908 
909         assertArrayEquals(new float[]{0.0f, 30.0f},
910                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
911                         AUTO_BRIGHTNESS_MODE_BEDTIME_WEAR,
912                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_BRIGHT), ZERO_DELTA);
913         assertArrayEquals(new float[]{0.65f, 0.95f},
914                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
915                         AUTO_BRIGHTNESS_MODE_BEDTIME_WEAR,
916                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_BRIGHT), SMALL_DELTA);
917     }
918 
919     @Test
testAutoBrightnessBrighteningLevels_FeatureFlagOff()920     public void testAutoBrightnessBrighteningLevels_FeatureFlagOff() throws IOException {
921         when(mFlags.areAutoBrightnessModesEnabled()).thenReturn(false);
922         setupDisplayDeviceConfigFromConfigResourceFile();
923         setupDisplayDeviceConfigFromDisplayConfigFile(getContent(getValidLuxThrottling(),
924                 getValidProxSensor(), /* includeIdleMode= */ false, /* enableEvenDimmer= */ false));
925 
926         assertArrayEquals(new float[]{brightnessIntToFloat(50), brightnessIntToFloat(100),
927                         brightnessIntToFloat(150)},
928                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevels(
929                         AUTO_BRIGHTNESS_MODE_DEFAULT,
930                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL), SMALL_DELTA);
931         assertArrayEquals(new float[]{0, 110, 500},
932                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsLux(
933                         AUTO_BRIGHTNESS_MODE_DEFAULT,
934                         Settings.System.SCREEN_BRIGHTNESS_AUTOMATIC_NORMAL), ZERO_DELTA);
935         assertArrayEquals(new float[]{2, 200, 600},
936                 mDisplayDeviceConfig.getAutoBrightnessBrighteningLevelsNits(), SMALL_DELTA);
937     }
938 
939     @Test
testIsAutoBrightnessAvailable_EnabledInConfigResource()940     public void testIsAutoBrightnessAvailable_EnabledInConfigResource() throws IOException {
941         when(mResources.getBoolean(R.bool.config_automatic_brightness_available)).thenReturn(true);
942 
943         setupDisplayDeviceConfigFromDisplayConfigFile();
944 
945         assertTrue(mDisplayDeviceConfig.isAutoBrightnessAvailable());
946     }
947 
948     @Test
testIsAutoBrightnessAvailable_DisabledInConfigResource()949     public void testIsAutoBrightnessAvailable_DisabledInConfigResource() throws IOException {
950         when(mResources.getBoolean(R.bool.config_automatic_brightness_available)).thenReturn(false);
951 
952         setupDisplayDeviceConfigFromDisplayConfigFile();
953 
954         assertFalse(mDisplayDeviceConfig.isAutoBrightnessAvailable());
955     }
956 
957     @RequiresFlagsEnabled(Flags.FLAG_EVEN_DIMMER)
958     @Test
testEvenDimmer()959     public void testEvenDimmer() throws IOException {
960         when(mFlags.isEvenDimmerEnabled()).thenReturn(true);
961         when(mResources.getBoolean(R.bool.config_evenDimmerEnabled)).thenReturn(true);
962         setupDisplayDeviceConfigFromDisplayConfigFile(getContent(getValidLuxThrottling(),
963                 getValidProxSensor(), /* includeIdleMode= */ false, /* enableEvenDimmer= */ true));
964 
965         assertTrue(mDisplayDeviceConfig.isEvenDimmerAvailable());
966         assertEquals(0.01f, mDisplayDeviceConfig.getBacklightFromBrightness(0.002f), ZERO_DELTA);
967         assertEquals(0.2f, mDisplayDeviceConfig.getNitsFromBacklight(0.0f), ZERO_DELTA);
968     }
969 
970     @Test
testLowPowerSupportedModesFromConfigFile()971     public void testLowPowerSupportedModesFromConfigFile() throws IOException {
972         setupDisplayDeviceConfigFromDisplayConfigFile();
973 
974         RefreshRateData refreshRateData = mDisplayDeviceConfig.getRefreshRateData();
975         assertNotNull(refreshRateData);
976         assertThat(refreshRateData.lowPowerSupportedModes).hasSize(2);
977         SupportedModeData supportedModeData = refreshRateData.lowPowerSupportedModes.get(0);
978         assertThat(supportedModeData.refreshRate).isEqualTo(60);
979         assertThat(supportedModeData.vsyncRate).isEqualTo(60);
980         supportedModeData = refreshRateData.lowPowerSupportedModes.get(1);
981         assertThat(supportedModeData.refreshRate).isEqualTo(60);
982         assertThat(supportedModeData.vsyncRate).isEqualTo(120);
983     }
984 
985     @Test
testLowLightBlockingZoneSupportedModesFromConfigFile()986     public void testLowLightBlockingZoneSupportedModesFromConfigFile() throws IOException {
987         setupDisplayDeviceConfigFromDisplayConfigFile();
988 
989         RefreshRateData refreshRateData = mDisplayDeviceConfig.getRefreshRateData();
990         assertNotNull(refreshRateData);
991         assertThat(refreshRateData.lowLightBlockingZoneSupportedModes).hasSize(2);
992         SupportedModeData supportedModeData =
993                 refreshRateData.lowLightBlockingZoneSupportedModes.get(0);
994         assertThat(supportedModeData.refreshRate).isEqualTo(60);
995         assertThat(supportedModeData.vsyncRate).isEqualTo(60);
996         supportedModeData = refreshRateData.lowLightBlockingZoneSupportedModes.get(1);
997         assertThat(supportedModeData.refreshRate).isEqualTo(240);
998         assertThat(supportedModeData.vsyncRate).isEqualTo(240);
999     }
1000 
1001     @Test
testDozeBrightness_Ddc()1002     public void testDozeBrightness_Ddc() throws IOException {
1003         when(mFlags.isDozeBrightnessFloatEnabled()).thenReturn(true);
1004         setupDisplayDeviceConfigFromDisplayConfigFile();
1005 
1006         assertArrayEquals(new float[]{ -1, 0.1f, 0.2f, 0.3f, 0.4f },
1007                 mDisplayDeviceConfig.getDozeBrightnessSensorValueToBrightness(), SMALL_DELTA);
1008         assertEquals(0.25f, mDisplayDeviceConfig.getDefaultDozeBrightness(), SMALL_DELTA);
1009     }
1010 
1011     @Test
testDefaultDozeBrightness_FallBackToConfigXmlFloat()1012     public void testDefaultDozeBrightness_FallBackToConfigXmlFloat() throws IOException {
1013         setupDisplayDeviceConfigFromConfigResourceFile();
1014         when(mFlags.isDozeBrightnessFloatEnabled()).thenReturn(true);
1015         when(mResources.getFloat(com.android.internal.R.dimen.config_screenBrightnessDozeFloat))
1016                 .thenReturn(0.31f);
1017         when(mResources.getInteger(com.android.internal.R.integer.config_screenBrightnessDoze))
1018                 .thenReturn(90);
1019 
1020         // Empty display config file
1021         setupDisplayDeviceConfigFromDisplayConfigFile(
1022                 "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n"
1023                         + "<displayConfiguration />\n");
1024 
1025         assertEquals(0.31f, mDisplayDeviceConfig.getDefaultDozeBrightness(), ZERO_DELTA);
1026     }
1027 
1028     @Test
testDefaultDozeBrightness_FallBackToConfigXmlInt()1029     public void testDefaultDozeBrightness_FallBackToConfigXmlInt() throws IOException {
1030         setupDisplayDeviceConfigFromConfigResourceFile();
1031         when(mFlags.isDozeBrightnessFloatEnabled()).thenReturn(true);
1032         when(mResources.getFloat(com.android.internal.R.dimen.config_screenBrightnessDozeFloat))
1033                 .thenReturn(DisplayDeviceConfig.INVALID_BRIGHTNESS_IN_CONFIG);
1034         when(mResources.getInteger(com.android.internal.R.integer.config_screenBrightnessDoze))
1035                 .thenReturn(90);
1036 
1037         // Empty display config file
1038         setupDisplayDeviceConfigFromDisplayConfigFile(
1039                 "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n"
1040                         + "<displayConfiguration />\n");
1041 
1042         assertEquals(brightnessIntToFloat(90),
1043                 mDisplayDeviceConfig.getDefaultDozeBrightness(), ZERO_DELTA);
1044     }
1045 
getValidLuxThrottling()1046     private String getValidLuxThrottling() {
1047         return "<luxThrottling>\n"
1048                 + "    <brightnessLimitMap>\n"
1049                 + "        <type>adaptive</type>\n"
1050                 + "        <map>\n"
1051                 + "            <point>"
1052                 + "                <first>1000</first>\n"
1053                 + "                <second>0.3</second>\n"
1054                 + "            </point>"
1055                 + "            <point>"
1056                 + "                <first>5000</first>\n"
1057                 + "                <second>0.5</second>\n"
1058                 + "            </point>"
1059                 + "        </map>\n"
1060                 + "    </brightnessLimitMap>\n"
1061                 + "    <brightnessLimitMap>\n"
1062                 + "        <type>default</type>\n"
1063                 + "        <map>\n"
1064                 + "            <point>"
1065                 + "                <first>1500</first>\n"
1066                 + "                <second>0.35</second>\n"
1067                 + "            </point>"
1068                 + "            <point>"
1069                 + "                <first>5500</first>\n"
1070                 + "                <second>0.55</second>\n"
1071                 + "            </point>"
1072                 + "        </map>\n"
1073                 + "    </brightnessLimitMap>\n"
1074                 + "</luxThrottling>";
1075     }
1076 
getInvalidLuxThrottling()1077     private String getInvalidLuxThrottling() {
1078         return "<luxThrottling>\n"
1079                 + "    <brightnessLimitMap>\n"
1080                 + "        <type>adaptive</type>\n"
1081                 + "        <map>\n"
1082                 + "            <point>"
1083                 + "                <first>1000</first>\n"
1084                 + "                <second>0.3</second>\n"
1085                 + "            </point>"
1086                 + "            <point>" // second > hbm.transitionPoint, skipped
1087                 + "                <first>1500</first>\n"
1088                 + "                <second>0.9</second>\n"
1089                 + "            </point>"
1090                 + "            <point>" // same lux value, skipped
1091                 + "                <first>1000</first>\n"
1092                 + "                <second>0.5</second>\n"
1093                 + "            </point>"
1094                 + "        </map>\n"
1095                 + "    </brightnessLimitMap>\n"
1096                 + "    <brightnessLimitMap>\n" // Same type, skipped
1097                 + "        <type>adaptive</type>\n"
1098                 + "        <map>\n"
1099                 + "            <point>"
1100                 + "                <first>2000</first>\n"
1101                 + "                <second>0.35</second>\n"
1102                 + "            </point>"
1103                 + "            <point>"
1104                 + "                <first>6000</first>\n"
1105                 + "                <second>0.55</second>\n"
1106                 + "            </point>"
1107                 + "        </map>\n"
1108                 + "    </brightnessLimitMap>\n"
1109                 + "    <brightnessLimitMap>\n" // Invalid points only, skipped
1110                 + "        <type>default</type>\n"
1111                 + "        <map>\n"
1112                 + "            <point>"
1113                 + "                <first>2500</first>\n"
1114                 + "                <second>0.99</second>\n"
1115                 + "            </point>"
1116                 + "        </map>\n"
1117                 + "    </brightnessLimitMap>\n"
1118                 + "</luxThrottling>";
1119     }
1120 
getRefreshThermalThrottlingMaps()1121     private String getRefreshThermalThrottlingMaps() {
1122         return "<refreshRateThrottlingMap>\n"
1123                + "    <refreshRateThrottlingPoint>\n"
1124                + "        <thermalStatus>critical</thermalStatus>\n"
1125                + "        <refreshRateRange>\n"
1126                + "            <minimum>30</minimum>\n"
1127                + "            <maximum>60</maximum>\n"
1128                + "        </refreshRateRange>\n"
1129                + "    </refreshRateThrottlingPoint>\n"
1130                + "    <refreshRateThrottlingPoint>\n"
1131                + "        <thermalStatus>shutdown</thermalStatus>\n"
1132                + "        <refreshRateRange>\n"
1133                + "            <minimum>0</minimum>\n"
1134                + "            <maximum>30</maximum>\n"
1135                + "        </refreshRateRange>\n"
1136                + "    </refreshRateThrottlingPoint>\n"
1137                + "</refreshRateThrottlingMap>\n"
1138                + "<refreshRateThrottlingMap id=\"thermalLow\">\n"
1139                + "    <refreshRateThrottlingPoint>\n"
1140                + "        <thermalStatus>critical</thermalStatus>\n"
1141                + "        <refreshRateRange>\n"
1142                + "            <minimum>30</minimum>\n"
1143                + "            <maximum>40</maximum>\n"
1144                + "        </refreshRateRange>\n"
1145                + "    </refreshRateThrottlingPoint>\n"
1146                + "</refreshRateThrottlingMap>\n"
1147                + "<refreshRateThrottlingMap id=\"thermalHigh\">\n"
1148                + "    <refreshRateThrottlingPoint>\n"
1149                + "        <thermalStatus>emergency</thermalStatus>\n"
1150                + "        <refreshRateRange>\n"
1151                + "            <minimum>40</minimum>\n"
1152                + "            <maximum>60</maximum>\n"
1153                + "        </refreshRateRange>\n"
1154                + "    </refreshRateThrottlingPoint>\n"
1155                + "</refreshRateThrottlingMap>\n"
1156                + "<refreshRateThrottlingMap id=\"test\">\n"
1157                + "    <refreshRateThrottlingPoint>\n"
1158                + "        <thermalStatus>emergency</thermalStatus>\n"
1159                + "        <refreshRateRange>\n"
1160                + "            <minimum>60</minimum>\n"
1161                + "            <maximum>90</maximum>\n"
1162                + "        </refreshRateRange>\n"
1163                + "    </refreshRateThrottlingPoint>\n"
1164                + "</refreshRateThrottlingMap>\n";
1165     }
1166 
getValidProxSensor()1167     private String getValidProxSensor() {
1168         return "<proxSensor>\n"
1169                 +   "<type>test_proximity_sensor</type>\n"
1170                 +   "<name>Test Proximity Sensor</name>\n"
1171                 + "</proxSensor>\n";
1172     }
1173 
getValidProxSensorWithRefreshRateAndVsyncRate()1174     private String getValidProxSensorWithRefreshRateAndVsyncRate() {
1175         return "<proxSensor>\n"
1176                 +   "<type>test_proximity_sensor</type>\n"
1177                 +   "<name>Test Proximity Sensor</name>\n"
1178                 +   "<refreshRate>\n"
1179                 +       "<minimum>60</minimum>\n"
1180                 +       "<maximum>90</maximum>\n"
1181                 +   "</refreshRate>\n"
1182                 +   "<supportedModes>\n"
1183                 +       "<point>\n"
1184                 +           "<first>60</first>\n"   // refreshRate
1185                 +           "<second>65</second>\n" //vsyncRate
1186                 +       "</point>\n"
1187                 +       "<point>\n"
1188                 +           "<first>120</first>\n"   // refreshRate
1189                 +           "<second>125</second>\n" //vsyncRate
1190                 +       "</point>\n"
1191                 +   "</supportedModes>"
1192                 + "</proxSensor>\n";
1193     }
1194 
getProxSensorWithEmptyValues()1195     private String getProxSensorWithEmptyValues() {
1196         return "<proxSensor>\n"
1197                 +   "<type></type>\n"
1198                 +   "<name></name>\n"
1199                 + "</proxSensor>\n";
1200     }
1201 
getLowPowerConfig()1202     private String getLowPowerConfig() {
1203         return "<lowPowerSupportedModes>\n"
1204                 + "    <point>\n"
1205                 + "        <first>60</first>\n"
1206                 + "        <second>60</second>\n"
1207                 + "    </point>\n"
1208                 + "    <point>\n"
1209                 + "        <first>60</first>\n"
1210                 + "        <second>120</second>\n"
1211                 + "    </point>\n"
1212                 + "</lowPowerSupportedModes>\n";
1213     }
1214 
getLowLightVrrSupportedModesConfig()1215     private String getLowLightVrrSupportedModesConfig() {
1216         return "<supportedModes>\n"
1217                 + "    <point>\n"
1218                 + "        <first>60</first>\n"
1219                 + "        <second>60</second>\n"
1220                 + "    </point>\n"
1221                 + "    <point>\n"
1222                 + "        <first>240</first>\n"
1223                 + "        <second>240</second>\n"
1224                 + "    </point>\n"
1225                 + "</supportedModes>\n";
1226     }
1227 
getHdrBrightnessConfig()1228     private String getHdrBrightnessConfig() {
1229         return "<hdrBrightnessConfig>\n"
1230               + "    <brightnessMap>\n"
1231               + "        <point>\n"
1232               + "            <first>500</first>\n"
1233               + "            <second>0.3</second>\n"
1234               + "        </point>\n"
1235               + "        <point>\n"
1236               + "           <first>1200</first>\n"
1237               + "           <second>0.6</second>\n"
1238               + "        </point>\n"
1239               + "    </brightnessMap>\n"
1240               + "    <brightnessIncreaseDebounceMillis>1000</brightnessIncreaseDebounceMillis>\n"
1241               + "    <screenBrightnessRampIncrease>0.11</screenBrightnessRampIncrease>\n"
1242               + "    <brightnessDecreaseDebounceMillis>13000</brightnessDecreaseDebounceMillis>\n"
1243               + "    <screenBrightnessRampDecrease>0.1</screenBrightnessRampDecrease>\n"
1244               + "</hdrBrightnessConfig>";
1245     }
1246 
getRampSpeedsIdle()1247     private String getRampSpeedsIdle() {
1248         return "<brighteningLightDebounceIdleMillis>"
1249                 +           "2500"
1250                 +       "</brighteningLightDebounceIdleMillis>\n"
1251                 +       "<darkeningLightDebounceIdleMillis>"
1252                 +           "1500"
1253                 +       "</darkeningLightDebounceIdleMillis>\n";
1254     }
1255 
getThresholdsIdle()1256     private String getThresholdsIdle() {
1257         return  "<ambientBrightnessChangeThresholdsIdle>\n"
1258                 +       "<brighteningThresholds>\n"
1259                 +           "<minimum>20</minimum>\n"
1260                 +           "<brightnessThresholdPoints>\n"
1261                 +               "<brightnessThresholdPoint>\n"
1262                 +                   "<threshold>0</threshold><percentage>21</percentage>\n"
1263                 +               "</brightnessThresholdPoint>\n"
1264                 +               "<brightnessThresholdPoint>\n"
1265                 +                   "<threshold>500</threshold><percentage>22</percentage>\n"
1266                 +               "</brightnessThresholdPoint>\n"
1267                 +               "<brightnessThresholdPoint>\n"
1268                 +                   "<threshold>600</threshold><percentage>23</percentage>\n"
1269                 +               "</brightnessThresholdPoint>\n"
1270                 +           "</brightnessThresholdPoints>\n"
1271                 +       "</brighteningThresholds>\n"
1272                 +       "<darkeningThresholds>\n"
1273                 +           "<minimum>40</minimum>\n"
1274                 +           "<brightnessThresholdPoints>\n"
1275                 +               "<brightnessThresholdPoint>\n"
1276                 +                   "<threshold>0</threshold><percentage>23</percentage>\n"
1277                 +               "</brightnessThresholdPoint>\n"
1278                 +               "<brightnessThresholdPoint>\n"
1279                 +                   "<threshold>700</threshold><percentage>24</percentage>\n"
1280                 +               "</brightnessThresholdPoint>\n"
1281                 +               "<brightnessThresholdPoint>\n"
1282                 +                   "<threshold>800</threshold><percentage>25</percentage>\n"
1283                 +               "</brightnessThresholdPoint>\n"
1284                 +           "</brightnessThresholdPoints>\n"
1285                 +       "</darkeningThresholds>\n"
1286                 +   "</ambientBrightnessChangeThresholdsIdle>\n"
1287                 +   "<displayBrightnessChangeThresholdsIdle>\n"
1288                 +       "<brighteningThresholds>\n"
1289                 +           "<minimum>0.2</minimum>\n"
1290                 +           "<brightnessThresholdPoints>\n"
1291                 +               "<brightnessThresholdPoint>\n"
1292                 +                   "<threshold>0</threshold><percentage>17</percentage>\n"
1293                 +               "</brightnessThresholdPoint>\n"
1294                 +               "<brightnessThresholdPoint>\n"
1295                 +                   "<threshold>0.12</threshold><percentage>18</percentage>\n"
1296                 +               "</brightnessThresholdPoint>\n"
1297                 +               "<brightnessThresholdPoint>\n"
1298                 +                   "<threshold>0.22</threshold><percentage>19</percentage>\n"
1299                 +               "</brightnessThresholdPoint>\n"
1300                 +           "</brightnessThresholdPoints>\n"
1301                 +       "</brighteningThresholds>\n"
1302                 +       "<darkeningThresholds>\n"
1303                 +           "<minimum>0.4</minimum>\n"
1304                 +           "<brightnessThresholdPoints>\n"
1305                 +               "<brightnessThresholdPoint>\n"
1306                 +                   "<threshold>0</threshold><percentage>19</percentage>\n"
1307                 +               "</brightnessThresholdPoint>\n"
1308                 +               "<brightnessThresholdPoint>\n"
1309                 +                   "<threshold>0.13</threshold><percentage>20</percentage>\n"
1310                 +               "</brightnessThresholdPoint>\n"
1311                 +               "<brightnessThresholdPoint>\n"
1312                 +                   "<threshold>0.23</threshold><percentage>21</percentage>\n"
1313                 +               "</brightnessThresholdPoint>\n"
1314                 +           "</brightnessThresholdPoints>\n"
1315                 +       "</darkeningThresholds>\n"
1316                 +   "</displayBrightnessChangeThresholdsIdle>\n";
1317     }
1318 
getScreenBrightnessRampSlowIdle()1319     private String getScreenBrightnessRampSlowIdle() {
1320         return "<screenBrightnessRampSlowDecreaseIdle>"
1321                 +       "0.05"
1322                 +   "</screenBrightnessRampSlowDecreaseIdle>\n"
1323                 +   "<screenBrightnessRampSlowIncreaseIdle>"
1324                 +       "0.06"
1325                 +   "</screenBrightnessRampSlowIncreaseIdle>\n";
1326     }
1327 
getBedTimeModeWearCurveConfig()1328     private String getBedTimeModeWearCurveConfig() {
1329         return  "<luxToBrightnessMapping>\n"
1330                 +           "<mode>bedtime_wear</mode>\n"
1331                 +           "<setting>dim</setting>\n"
1332                 +           "<map>\n"
1333                 +               "<point>\n"
1334                 +                   "<first>0</first>\n"
1335                 +                   "<second>0.2</second>\n"
1336                 +               "</point>\n"
1337                 +               "<point>\n"
1338                 +                   "<first>10</first>\n"
1339                 +                   "<second>0.3</second>\n"
1340                 +               "</point>\n"
1341                 +           "</map>\n"
1342                 +       "</luxToBrightnessMapping>\n"
1343                 +       "<luxToBrightnessMapping>\n"
1344                 +           "<mode>bedtime_wear</mode>\n"
1345                 +           "<setting>normal</setting>\n"
1346                 +           "<map>\n"
1347                 +               "<point>\n"
1348                 +                   "<first>0</first>\n"
1349                 +                   "<second>0.3</second>\n"
1350                 +               "</point>\n"
1351                 +               "<point>\n"
1352                 +                   "<first>20</first>\n"
1353                 +                   "<second>0.65</second>\n"
1354                 +               "</point>\n"
1355                 +           "</map>\n"
1356                 +       "</luxToBrightnessMapping>\n"
1357                 +       "<luxToBrightnessMapping>\n"
1358                 +           "<mode>bedtime_wear</mode>\n"
1359                 +           "<setting>bright</setting>\n"
1360                 +           "<map>\n"
1361                 +               "<point>\n"
1362                 +                   "<first>0</first>\n"
1363                 +                   "<second>0.65</second>\n"
1364                 +               "</point>\n"
1365                 +               "<point>\n"
1366                 +                   "<first>30</first>\n"
1367                 +                   "<second>0.95</second>\n"
1368                 +               "</point>\n"
1369                 +           "</map>\n"
1370                 +       "</luxToBrightnessMapping>\n";
1371     }
1372 
getPowerThrottlingConfig()1373     private String getPowerThrottlingConfig() {
1374         return  "<powerThrottlingConfig >\n"
1375                 +       "<brightnessLowestCapAllowed>0.1</brightnessLowestCapAllowed>\n"
1376                 +       "<customAnimationRate>15</customAnimationRate>\n"
1377                 +       "<pollingWindowMaxMillis>20000</pollingWindowMaxMillis>\n"
1378                 +       "<pollingWindowMinMillis>10000</pollingWindowMinMillis>\n"
1379                 +       "<powerThrottlingMap>\n"
1380                 +           "<powerThrottlingPoint>\n"
1381                 +               "<thermalStatus>light</thermalStatus>\n"
1382                 +               "<powerQuotaMilliWatts>800</powerQuotaMilliWatts>\n"
1383                 +        "</powerThrottlingPoint>\n"
1384                 +           "<powerThrottlingPoint>\n"
1385                 +               "<thermalStatus>moderate</thermalStatus>\n"
1386                 +               "<powerQuotaMilliWatts>600</powerQuotaMilliWatts>\n"
1387                 +           "</powerThrottlingPoint>\n"
1388                 +           "<powerThrottlingPoint>\n"
1389                 +               "<thermalStatus>severe</thermalStatus>\n"
1390                 +               "<powerQuotaMilliWatts>400</powerQuotaMilliWatts>\n"
1391                 +           "</powerThrottlingPoint>\n"
1392                 +           "<powerThrottlingPoint>\n"
1393                 +               "<thermalStatus>critical</thermalStatus>\n"
1394                 +               "<powerQuotaMilliWatts>200</powerQuotaMilliWatts>\n"
1395                 +           "</powerThrottlingPoint>\n"
1396                 +           "<powerThrottlingPoint>\n"
1397                 +               "<thermalStatus>emergency</thermalStatus>\n"
1398                 +               "<powerQuotaMilliWatts>100</powerQuotaMilliWatts>\n"
1399                 +           "</powerThrottlingPoint>\n"
1400                 +           "<powerThrottlingPoint>\n"
1401                 +               "<thermalStatus>shutdown</thermalStatus>\n"
1402                 +               "<powerQuotaMilliWatts>50</powerQuotaMilliWatts>\n"
1403                 +           "</powerThrottlingPoint>\n"
1404                 +       "</powerThrottlingMap>\n"
1405                 +       "<powerThrottlingMap id=\"concurrent\">\n"
1406                 +           "<powerThrottlingPoint>\n"
1407                 +               "<thermalStatus>light</thermalStatus>\n"
1408                 +               "<powerQuotaMilliWatts>800</powerQuotaMilliWatts>\n"
1409                 +           "</powerThrottlingPoint>\n"
1410                 +           "<powerThrottlingPoint>\n"
1411                 +               "<thermalStatus>moderate</thermalStatus>\n"
1412                 +               "<powerQuotaMilliWatts>600</powerQuotaMilliWatts>\n"
1413                 +           "</powerThrottlingPoint>\n"
1414                 +           "<powerThrottlingPoint>\n"
1415                 +               "<thermalStatus>severe</thermalStatus>\n"
1416                 +               "<powerQuotaMilliWatts>400</powerQuotaMilliWatts>\n"
1417                 +           "</powerThrottlingPoint>\n"
1418                 +           "<powerThrottlingPoint>\n"
1419                 +               "<thermalStatus>critical</thermalStatus>\n"
1420                 +               "<powerQuotaMilliWatts>200</powerQuotaMilliWatts>\n"
1421                 +           "</powerThrottlingPoint>\n"
1422                 +           "<powerThrottlingPoint>\n"
1423                 +               "<thermalStatus>emergency</thermalStatus>\n"
1424                 +               "<powerQuotaMilliWatts>100</powerQuotaMilliWatts>\n"
1425                 +           "</powerThrottlingPoint>\n"
1426                 +           "<powerThrottlingPoint>\n"
1427                 +               "<thermalStatus>shutdown</thermalStatus>\n"
1428                 +               "<powerQuotaMilliWatts>50</powerQuotaMilliWatts>\n"
1429                 +           "</powerThrottlingPoint>\n"
1430                 +       "</powerThrottlingMap>\n"
1431                 +   "</powerThrottlingConfig>\n";
1432     }
getScreenBrightnessRampCapsIdle()1433     private String getScreenBrightnessRampCapsIdle() {
1434         return "<screenBrightnessRampIncreaseMaxIdleMillis>"
1435                 +       "4000"
1436                 +   "</screenBrightnessRampIncreaseMaxIdleMillis>\n"
1437                 +   "<screenBrightnessRampDecreaseMaxIdleMillis>"
1438                 +       "5000"
1439                 +   "</screenBrightnessRampDecreaseMaxIdleMillis>\n";
1440     }
1441 
getContent()1442     private String getContent() {
1443         return getContent(getValidLuxThrottling(), getValidProxSensor(),
1444                 /* includeIdleMode= */ true, /* enableEvenDimmer= */ false);
1445     }
1446 
getContent(String brightnessCapConfig, String proxSensor, boolean includeIdleMode, boolean enableEvenDimmer)1447     private String getContent(String brightnessCapConfig, String proxSensor,
1448             boolean includeIdleMode, boolean enableEvenDimmer) {
1449         return "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n"
1450                 + "<displayConfiguration>\n"
1451                 +   "<name>Example Display</name>\n"
1452                 +   "<densityMapping>\n"
1453                 +       "<density>\n"
1454                 +           "<height>480</height>\n"
1455                 +           "<width>720</width>\n"
1456                 +           "<density>120</density>\n"
1457                 +       "</density>\n"
1458                 +       "<density>\n"
1459                 +           "<height>720</height>\n"
1460                 +           "<width>1280</width>\n"
1461                 +           "<density>213</density>\n"
1462                 +       "</density>\n"
1463                 +       "<density>\n"
1464                 +           "<height>1080</height>\n"
1465                 +           "<width>1920</width>\n"
1466                 +           "<density>320</density>\n"
1467                 +       "</density>\n"
1468                 +       "<density>\n"
1469                 +           "<height>2160</height>\n"
1470                 +           "<width>3840</width>\n"
1471                 +           "<density>640</density>\n"
1472                 +       "</density>\n"
1473                 +   "</densityMapping>\n"
1474                 +   "<screenBrightnessMap>\n"
1475                 +       "<point>\n"
1476                 +           "<value>" + BRIGHTNESS[0] + "</value>\n"
1477                 +           "<nits>" + NITS[0] + "</nits>\n"
1478                 +       "</point>\n"
1479                 +       "<point>\n"
1480                 +           "<value>" + BRIGHTNESS[1] + "</value>\n"
1481                 +           "<nits>" + NITS[1] + "</nits>\n"
1482                 +       "</point>\n"
1483                 +       "<point>\n"
1484                 +           "<value>" + BRIGHTNESS[2] + "</value>\n"
1485                 +           "<nits>" + NITS[2] + "</nits>\n"
1486                 +       "</point>\n"
1487                 +   "</screenBrightnessMap>\n"
1488                 +   "<autoBrightness enabled=\"true\">\n"
1489                 +       "<brighteningLightDebounceMillis>2000</brighteningLightDebounceMillis>\n"
1490                 +       "<darkeningLightDebounceMillis>1000</darkeningLightDebounceMillis>\n"
1491                 + (includeIdleMode ? getRampSpeedsIdle() : "")
1492                 +       "<luxToBrightnessMapping>\n"
1493                 +           "<map>\n"
1494                 +               "<point>\n"
1495                 +                   "<first>0</first>\n"
1496                 +                   "<second>0.2</second>\n"
1497                 +               "</point>\n"
1498                 +               "<point>\n"
1499                 +                   "<first>80</first>\n"
1500                 +                   "<second>0.3</second>\n"
1501                 +               "</point>\n"
1502                 +           "</map>\n"
1503                 +       "</luxToBrightnessMapping>\n"
1504                 +       "<luxToBrightnessMapping>\n"
1505                 +           "<setting>dim</setting>\n"
1506                 +           "<map>\n"
1507                 +               "<point>\n"
1508                 +                   "<first>0</first>\n"
1509                 +                   "<second>0.3</second>\n"
1510                 +               "</point>\n"
1511                 +               "<point>\n"
1512                 +                   "<first>90</first>\n"
1513                 +                   "<second>0.4</second>\n"
1514                 +               "</point>\n"
1515                 +           "</map>\n"
1516                 +       "</luxToBrightnessMapping>\n"
1517                 +       "<luxToBrightnessMapping>\n"
1518                 +           "<mode>default</mode>\n"
1519                 +           "<setting>bright</setting>\n"
1520                 +           "<map>\n"
1521                 +               "<point>\n"
1522                 +                   "<first>0</first>\n"
1523                 +                   "<second>0.6</second>\n"
1524                 +               "</point>\n"
1525                 +               "<point>\n"
1526                 +                   "<first>80</first>\n"
1527                 +                   "<second>0.7</second>\n"
1528                 +               "</point>\n"
1529                 +           "</map>\n"
1530                 +       "</luxToBrightnessMapping>\n"
1531                 +       "<luxToBrightnessMapping>\n"
1532                 +           "<mode>doze</mode>\n"
1533                 +           "<map>\n"
1534                 +               "<point>\n"
1535                 +                   "<first>0</first>\n"
1536                 +                   "<second>0.35</second>\n"
1537                 +               "</point>\n"
1538                 +               "<point>\n"
1539                 +                   "<first>95</first>\n"
1540                 +                   "<second>0.45</second>\n"
1541                 +               "</point>\n"
1542                 +           "</map>\n"
1543                 +       "</luxToBrightnessMapping>\n"
1544                 +       "<luxToBrightnessMapping>\n"
1545                 +           "<mode>doze</mode>\n"
1546                 +           "<setting>bright</setting>\n"
1547                 +           "<map>\n"
1548                 +               "<point>\n"
1549                 +                   "<first>0</first>\n"
1550                 +                   "<second>0.4</second>\n"
1551                 +               "</point>\n"
1552                 +               "<point>\n"
1553                 +                   "<first>100</first>\n"
1554                 +                   "<second>0.5</second>\n"
1555                 +               "</point>\n"
1556                 +           "</map>\n"
1557                 +       "</luxToBrightnessMapping>\n"
1558                 +       getBedTimeModeWearCurveConfig()
1559                 +       "<idleStylusTimeoutMillis>1000</idleStylusTimeoutMillis>\n"
1560                 +   "</autoBrightness>\n"
1561                 +  getPowerThrottlingConfig()
1562                 +   "<highBrightnessMode enabled=\"true\">\n"
1563                 +       "<transitionPoint>" + BRIGHTNESS[1] + "</transitionPoint>\n"
1564                 +       "<minimumLux>10000</minimumLux>\n"
1565                 +       "<timing>\n"
1566                 +           "<!-- allow for 5 minutes out of every 30 minutes -->\n"
1567                 +           "<timeWindowSecs>1800</timeWindowSecs>\n"
1568                 +           "<timeMaxSecs>300</timeMaxSecs>\n"
1569                 +           "<timeMinSecs>60</timeMinSecs>\n"
1570                 +       "</timing>\n"
1571                 +       "<refreshRate>\n"
1572                 +           "<minimum>120</minimum>\n"
1573                 +           "<maximum>120</maximum>\n"
1574                 +       "</refreshRate>\n"
1575                 +       "<allowInLowPowerMode>false</allowInLowPowerMode>\n"
1576                 +       "<minimumHdrPercentOfScreen>0.6</minimumHdrPercentOfScreen>\n"
1577                 +       "<sdrHdrRatioMap>\n"
1578                 +            "<point>\n"
1579                 +                "<sdrNits>2.000</sdrNits>\n"
1580                 +                "<hdrRatio>4.000</hdrRatio>\n"
1581                 +            "</point>\n"
1582                 +            "<point>\n"
1583                 +                "<sdrNits>500.0</sdrNits>\n"
1584                 +                "<hdrRatio>1.6</hdrRatio>\n"
1585                 +            "</point>\n"
1586                 +       "</sdrHdrRatioMap>\n"
1587                 +   "</highBrightnessMode>\n"
1588                 + getHdrBrightnessConfig()
1589                 + brightnessCapConfig
1590                 +   "<lightSensor>\n"
1591                 +       "<type>test_light_sensor</type>\n"
1592                 +       "<name>Test Ambient Light Sensor</name>\n"
1593                 +       "<refreshRate>\n"
1594                 +           "<minimum>60</minimum>\n"
1595                 +           "<maximum>120</maximum>\n"
1596                 +       "</refreshRate>\n"
1597                 +   "</lightSensor>\n"
1598                 +   "<screenOffBrightnessSensor>\n"
1599                 +       "<type>test_binned_brightness_sensor</type>\n"
1600                 +       "<name>Test Binned Brightness Sensor</name>\n"
1601                 +   "</screenOffBrightnessSensor>\n"
1602                 + proxSensor
1603                 +   "<tempSensor>\n"
1604                 +       "<type>DISPLAY</type>\n"
1605                 +       "<name>VIRTUAL-SKIN-DISPLAY</name>\n"
1606                 +   "</tempSensor>\n"
1607                 +   "<ambientBrightnessChangeThresholds>\n"
1608                 +       "<brighteningThresholds>\n"
1609                 +           "<minimum>10</minimum>\n"
1610                 +           "<brightnessThresholdPoints>\n"
1611                 +               "<brightnessThresholdPoint>\n"
1612                 +                   "<threshold>0</threshold><percentage>13</percentage>\n"
1613                 +               "</brightnessThresholdPoint>\n"
1614                 +               "<brightnessThresholdPoint>\n"
1615                 +                   "<threshold>100</threshold><percentage>14</percentage>\n"
1616                 +               "</brightnessThresholdPoint>\n"
1617                 +               "<brightnessThresholdPoint>\n"
1618                 +                   "<threshold>200</threshold><percentage>15</percentage>\n"
1619                 +               "</brightnessThresholdPoint>\n"
1620                 +           "</brightnessThresholdPoints>\n"
1621                 +       "</brighteningThresholds>\n"
1622                 +       "<darkeningThresholds>\n"
1623                 +           "<minimum>30</minimum>\n"
1624                 +           "<brightnessThresholdPoints>\n"
1625                 +               "<brightnessThresholdPoint>\n"
1626                 +                   "<threshold>0</threshold><percentage>15</percentage>\n"
1627                 +               "</brightnessThresholdPoint>\n"
1628                 +               "<brightnessThresholdPoint>\n"
1629                 +                   "<threshold>300</threshold><percentage>16</percentage>\n"
1630                 +               "</brightnessThresholdPoint>\n"
1631                 +               "<brightnessThresholdPoint>\n"
1632                 +                   "<threshold>400</threshold><percentage>17</percentage>\n"
1633                 +               "</brightnessThresholdPoint>\n"
1634                 +           "</brightnessThresholdPoints>\n"
1635                 +       "</darkeningThresholds>\n"
1636                 +   "</ambientBrightnessChangeThresholds>\n"
1637                 +   "<displayBrightnessChangeThresholds>\n"
1638                 +       "<brighteningThresholds>\n"
1639                 +           "<minimum>0.1</minimum>\n"
1640                 +           "<brightnessThresholdPoints>\n"
1641                 +               "<brightnessThresholdPoint>\n"
1642                 +                   "<threshold>0</threshold>\n"
1643                 +                   "<percentage>9</percentage>\n"
1644                 +               "</brightnessThresholdPoint>\n"
1645                 +               "<brightnessThresholdPoint>\n"
1646                 +                   "<threshold>0.10</threshold>\n"
1647                 +                   "<percentage>10</percentage>\n"
1648                 +               "</brightnessThresholdPoint>\n"
1649                 +               "<brightnessThresholdPoint>\n"
1650                 +                   "<threshold>0.20</threshold>\n"
1651                 +                   "<percentage>11</percentage>\n"
1652                 +               "</brightnessThresholdPoint>\n"
1653                 +           "</brightnessThresholdPoints>\n"
1654                 +       "</brighteningThresholds>\n"
1655                 +       "<darkeningThresholds>\n"
1656                 +           "<minimum>0.3</minimum>\n"
1657                 +           "<brightnessThresholdPoints>\n"
1658                 +               "<brightnessThresholdPoint>\n"
1659                 +                   "<threshold>0</threshold><percentage>11</percentage>\n"
1660                 +               "</brightnessThresholdPoint>\n"
1661                 +               "<brightnessThresholdPoint>\n"
1662                 +                   "<threshold>0.11</threshold><percentage>12</percentage>\n"
1663                 +               "</brightnessThresholdPoint>\n"
1664                 +               "<brightnessThresholdPoint>\n"
1665                 +                   "<threshold>0.21</threshold><percentage>13</percentage>\n"
1666                 +               "</brightnessThresholdPoint>\n"
1667                 +           "</brightnessThresholdPoints>\n"
1668                 +       "</darkeningThresholds>\n"
1669                 +   "</displayBrightnessChangeThresholds>\n"
1670                 + (includeIdleMode ?  getThresholdsIdle() : "")
1671                 +   "<screenBrightnessRampFastDecrease>0.01</screenBrightnessRampFastDecrease>\n"
1672                 +   "<screenBrightnessRampFastIncrease>0.02</screenBrightnessRampFastIncrease>\n"
1673                 +   "<screenBrightnessRampSlowDecrease>0.03</screenBrightnessRampSlowDecrease>\n"
1674                 +   "<screenBrightnessRampSlowIncrease>0.04</screenBrightnessRampSlowIncrease>\n"
1675                 + (includeIdleMode ? getScreenBrightnessRampSlowIdle() : "")
1676                 +   "<screenBrightnessRampIncreaseMaxMillis>"
1677                 +       "2000"
1678                 +   "</screenBrightnessRampIncreaseMaxMillis>\n"
1679                 +   "<screenBrightnessRampDecreaseMaxMillis>"
1680                 +       "3000"
1681                 +   "</screenBrightnessRampDecreaseMaxMillis>\n"
1682                 + (includeIdleMode ?  getScreenBrightnessRampCapsIdle() : "")
1683                 +   "<ambientLightHorizonLong>5000</ambientLightHorizonLong>\n"
1684                 +   "<ambientLightHorizonShort>50</ambientLightHorizonShort>\n"
1685                 +   "<screenBrightnessRampIncreaseMaxMillis>"
1686                 +       "2000"
1687                 +   "</screenBrightnessRampIncreaseMaxMillis>\n"
1688                 +   "<thermalThrottling>\n"
1689                 +       "<brightnessThrottlingMap>\n"
1690                 +           "<brightnessThrottlingPoint>\n"
1691                 +               "<thermalStatus>light</thermalStatus>\n"
1692                 +               "<brightness>0.4</brightness>\n"
1693                 +           "</brightnessThrottlingPoint>\n"
1694                 +           "<brightnessThrottlingPoint>\n"
1695                 +               "<thermalStatus>moderate</thermalStatus>\n"
1696                 +               "<brightness>0.3</brightness>\n"
1697                 +           "</brightnessThrottlingPoint>\n"
1698                 +           "<brightnessThrottlingPoint>\n"
1699                 +               "<thermalStatus>severe</thermalStatus>\n"
1700                 +               "<brightness>0.2</brightness>\n"
1701                 +           "</brightnessThrottlingPoint>\n"
1702                 +           "<brightnessThrottlingPoint>\n"
1703                 +               "<thermalStatus>critical</thermalStatus>\n"
1704                 +               "<brightness>0.1</brightness>\n"
1705                 +           "</brightnessThrottlingPoint>\n"
1706                 +           "<brightnessThrottlingPoint>\n"
1707                 +               "<thermalStatus>emergency</thermalStatus>\n"
1708                 +               "<brightness>0.05</brightness>\n"
1709                 +           "</brightnessThrottlingPoint>\n"
1710                 +           "<brightnessThrottlingPoint>\n"
1711                 +               "<thermalStatus>shutdown</thermalStatus>\n"
1712                 +               "<brightness>0.025</brightness>\n"
1713                 +           "</brightnessThrottlingPoint>\n"
1714                 +       "</brightnessThrottlingMap>\n"
1715                 +       "<brightnessThrottlingMap id=\"concurrent\">\n"
1716                 +           "<brightnessThrottlingPoint>\n"
1717                 +               "<thermalStatus>light</thermalStatus>\n"
1718                 +               "<brightness>0.2</brightness>\n"
1719                 +           "</brightnessThrottlingPoint>\n"
1720                 +           "<brightnessThrottlingPoint>\n"
1721                 +               "<thermalStatus>moderate</thermalStatus>\n"
1722                 +               "<brightness>0.15</brightness>\n"
1723                 +           "</brightnessThrottlingPoint>\n"
1724                 +           "<brightnessThrottlingPoint>\n"
1725                 +               "<thermalStatus>severe</thermalStatus>\n"
1726                 +               "<brightness>0.1</brightness>\n"
1727                 +           "</brightnessThrottlingPoint>\n"
1728                 +           "<brightnessThrottlingPoint>\n"
1729                 +               "<thermalStatus>critical</thermalStatus>\n"
1730                 +               "<brightness>0.05</brightness>\n"
1731                 +           "</brightnessThrottlingPoint>\n"
1732                 +           "<brightnessThrottlingPoint>\n"
1733                 +               "<thermalStatus>emergency</thermalStatus>\n"
1734                 +               "<brightness>0.025</brightness>\n"
1735                 +           "</brightnessThrottlingPoint>\n"
1736                 +           "<brightnessThrottlingPoint>\n"
1737                 +               "<thermalStatus>shutdown</thermalStatus>\n"
1738                 +               "<brightness>0.0125</brightness>\n"
1739                 +           "</brightnessThrottlingPoint>\n"
1740                 +       "</brightnessThrottlingMap>\n"
1741                 +  getRefreshThermalThrottlingMaps()
1742                 +   "</thermalThrottling>\n"
1743                 +   "<refreshRate>\n"
1744                 +       "<defaultRefreshRate>45</defaultRefreshRate>\n"
1745                 +       "<defaultPeakRefreshRate>85</defaultPeakRefreshRate>\n"
1746                 +       "<refreshRateZoneProfiles>"
1747                 +           "<refreshRateZoneProfile id=\"test1\">"
1748                 +               "<refreshRateRange>\n"
1749                 +                   "<minimum>60</minimum>\n"
1750                 +                   "<maximum>60</maximum>\n"
1751                 +               "</refreshRateRange>\n"
1752                 +           "</refreshRateZoneProfile>\n"
1753                 +           "<refreshRateZoneProfile id=\"test2\">"
1754                 +               "<refreshRateRange>\n"
1755                 +                   "<minimum>80</minimum>\n"
1756                 +                   "<maximum>90</maximum>\n"
1757                 +               "</refreshRateRange>\n"
1758                 +           "</refreshRateZoneProfile>\n"
1759                 +       "</refreshRateZoneProfiles>"
1760                 +       "<defaultRefreshRateInHbmHdr>82</defaultRefreshRateInHbmHdr>\n"
1761                 +       "<defaultRefreshRateInHbmSunlight>83</defaultRefreshRateInHbmSunlight>\n"
1762                 +       "<lowerBlockingZoneConfigs>\n"
1763                 +           "<defaultRefreshRate>75</defaultRefreshRate>\n"
1764                 +           "<refreshRateThermalThrottlingId>thermalLow"
1765                 +           "</refreshRateThermalThrottlingId>\n"
1766                 +           "<blockingZoneThreshold>\n"
1767                 +               "<displayBrightnessPoint>\n"
1768                 +                   "<lux>50</lux>\n"
1769                 +                   "<nits>50</nits>\n"
1770                 +               "</displayBrightnessPoint>\n"
1771                 +               "<displayBrightnessPoint>\n"
1772                 +                   "<lux>60</lux>\n"
1773                 +                   "<nits>300</nits>\n"
1774                 +               "</displayBrightnessPoint>\n"
1775                 +               "<displayBrightnessPoint>\n"
1776                 +                   "<lux>-1</lux>\n"
1777                 +                   "<nits>300</nits>\n"
1778                 +               "</displayBrightnessPoint>\n"
1779                 +               "<displayBrightnessPoint>\n"
1780                 +                   "<lux>60</lux>\n"
1781                 +                   "<nits>-1</nits>\n"
1782                 +               "</displayBrightnessPoint>\n"
1783                 +           "</blockingZoneThreshold>\n"
1784                 + getLowLightVrrSupportedModesConfig()
1785                 +       "</lowerBlockingZoneConfigs>\n"
1786                 +       "<higherBlockingZoneConfigs>\n"
1787                 +           "<defaultRefreshRate>90</defaultRefreshRate>\n"
1788                 +           "<refreshRateThermalThrottlingId>thermalHigh"
1789                 +           "</refreshRateThermalThrottlingId>\n"
1790                 +           "<blockingZoneThreshold>\n"
1791                 +               "<displayBrightnessPoint>\n"
1792                 +                   "<lux>70</lux>\n"
1793                 +                   "<nits>80</nits>\n"
1794                 +               "</displayBrightnessPoint>\n"
1795                 +               "<displayBrightnessPoint>\n"
1796                 +                   "<lux>80</lux>\n"
1797                 +                   "<nits>100</nits>\n"
1798                 +               "</displayBrightnessPoint>\n"
1799                 +               "<displayBrightnessPoint>\n"
1800                 +                   "<lux>-1</lux>\n"
1801                 +                   "<nits>100</nits>\n"
1802                 +               "</displayBrightnessPoint>\n"
1803                 +               "<displayBrightnessPoint>\n"
1804                 +                   "<lux>80</lux>\n"
1805                 +                   "<nits>-1</nits>\n"
1806                 +               "</displayBrightnessPoint>\n"
1807                 +           "</blockingZoneThreshold>\n"
1808                 +       "</higherBlockingZoneConfigs>\n"
1809                 + getLowPowerConfig()
1810                 +   "</refreshRate>\n"
1811                 +   "<screenOffBrightnessSensorValueToLux>\n"
1812                 +       "<item>-1</item>\n"
1813                 +       "<item>10</item>\n"
1814                 +       "<item>20</item>\n"
1815                 +       "<item>30</item>\n"
1816                 +       "<item>40</item>\n"
1817                 +   "</screenOffBrightnessSensorValueToLux>\n"
1818                 +   "<usiVersion>\n"
1819                 +       "<majorVersion>2</majorVersion>\n"
1820                 +       "<minorVersion>0</minorVersion>\n"
1821                 +   "</usiVersion>\n"
1822                 + evenDimmerConfig(enableEvenDimmer)
1823                 +   "<screenBrightnessCapForWearBedtimeMode>"
1824                 +       "0.1"
1825                 +   "</screenBrightnessCapForWearBedtimeMode>"
1826                 +   "<idleScreenRefreshRateTimeout>"
1827                 +       "<luxThresholds>"
1828                 +           "<point>"
1829                 +               "<lux>6</lux>"
1830                 +               "<timeout>1000</timeout>"
1831                 +           "</point>"
1832                 +           "<point>"
1833                 +               "<lux>10</lux>"
1834                 +               "<timeout>800</timeout>"
1835                 +           "</point>"
1836                 +       "</luxThresholds>"
1837                 +   "</idleScreenRefreshRateTimeout>"
1838                 +   "<dozeBrightnessSensorValueToBrightness>\n"
1839                 +       "<item>-1</item>\n"
1840                 +       "<item>0.1</item>\n"
1841                 +       "<item>0.2</item>\n"
1842                 +       "<item>0.3</item>\n"
1843                 +       "<item>0.4</item>\n"
1844                 +   "</dozeBrightnessSensorValueToBrightness>\n"
1845                 +   "<defaultDozeBrightness>"
1846                 +       "0.25"
1847                 +   "</defaultDozeBrightness>\n"
1848                 + "</displayConfiguration>\n";
1849     }
1850 
evenDimmerConfig(boolean enabled)1851     private String evenDimmerConfig(boolean enabled) {
1852         return (enabled ? "<evenDimmer enabled=\"true\">" : "<evenDimmer enabled=\"false\">")
1853                 + "  <transitionPoint>0.1</transitionPoint>\n"
1854                 + "  <brightnessMapping>\n"
1855                 + "      <brightnessPoint>\n"
1856                 + "        <nits>0.2</nits>\n"
1857                 + "        <backlight>0</backlight>\n"
1858                 + "        <brightness>0</brightness>\n"
1859                 + "      </brightnessPoint>\n"
1860                 + "      <brightnessPoint>\n"
1861                 + "        <nits>2.0</nits>\n"
1862                 + "        <backlight>0.01</backlight>\n"
1863                 + "        <brightness>0.002</brightness>\n"
1864                 + "      </brightnessPoint>\n"
1865                 + "      <brightnessPoint>\n"
1866                 + "        <nits>500.0</nits>\n"
1867                 + "        <backlight>0.5</backlight>\n"
1868                 + "        <brightness>0.5</brightness>\n"
1869                 + "      </brightnessPoint>\n"
1870                 + "      <brightnessPoint>\n"
1871                 + "        <nits>1000</nits>\n"
1872                 + "        <backlight>1.0</backlight>\n"
1873                 + "        <brightness>1.0</brightness>\n"
1874                 + "      </brightnessPoint>\n"
1875                 + "  </brightnessMapping>\n"
1876                 + " <luxToMinimumNitsMap>\n"
1877                 + "     <point>\n"
1878                 + "         <value>10</value> <nits>0.3</nits>\n"
1879                 + "     </point>\n"
1880                 + "     <point>\n"
1881                 + "         <value>50</value> <nits>0.7</nits>\n"
1882                 + "     </point>\n"
1883                 + "     <point>\n"
1884                 + "         <value>100</value> <nits>1.0</nits>\n"
1885                 + "     </point>\n"
1886                 + " </luxToMinimumNitsMap>\n"
1887                 + "</evenDimmer>";
1888     }
1889 
mockDeviceConfigs()1890     private void mockDeviceConfigs() {
1891         when(mResources.getFloat(com.android.internal.R.dimen
1892                 .config_screenBrightnessSettingDefaultFloat)).thenReturn(0.5f);
1893         when(mResources.getFloat(com.android.internal.R.dimen
1894                 .config_screenBrightnessSettingMaximumFloat)).thenReturn(1.0f);
1895     }
1896 
setupDisplayDeviceConfigFromDisplayConfigFile()1897     private void setupDisplayDeviceConfigFromDisplayConfigFile() throws IOException {
1898         setupDisplayDeviceConfigFromDisplayConfigFile(getContent());
1899     }
1900 
setupDisplayDeviceConfigFromDisplayConfigFile(String content)1901     private void setupDisplayDeviceConfigFromDisplayConfigFile(String content) throws IOException {
1902         Path tempFile = Files.createTempFile("display_config", ".tmp");
1903         Files.write(tempFile, content.getBytes(StandardCharsets.UTF_8));
1904         mDisplayDeviceConfig = new DisplayDeviceConfig(mContext, mFlags);
1905         mDisplayDeviceConfig.initFromFile(tempFile.toFile());
1906     }
1907 
setupDisplayDeviceConfigFromConfigResourceFile()1908     private void setupDisplayDeviceConfigFromConfigResourceFile() {
1909         TypedArray screenBrightnessNits = createFloatTypedArray(new float[]{2.0f, 250.0f, 650.0f});
1910         when(mResources.obtainTypedArray(
1911                 com.android.internal.R.array.config_screenBrightnessNits))
1912                 .thenReturn(screenBrightnessNits);
1913         when(mResources.getIntArray(com.android.internal.R.array
1914                 .config_screenBrightnessBacklight)).thenReturn(new int[]{0, 120, 255});
1915 
1916         TypedArray screenBrightnessLevelNits = createFloatTypedArray(new
1917                 float[]{2.0f, 200.0f, 600.0f});
1918         when(mResources.obtainTypedArray(
1919                 com.android.internal.R.array.config_autoBrightnessDisplayValuesNits))
1920                 .thenReturn(screenBrightnessLevelNits);
1921         int[] screenBrightnessLevelLux = new int[]{110, 500};
1922         when(mResources.getIntArray(
1923                 com.android.internal.R.array.config_autoBrightnessLevels))
1924                 .thenReturn(screenBrightnessLevelLux);
1925         int[] screenBrightnessLevels = new int[]{50, 100, 150};
1926         when(mResources.getIntArray(
1927                 com.android.internal.R.array.config_autoBrightnessLcdBacklightValues))
1928                 .thenReturn(screenBrightnessLevels);
1929 
1930         // Thresholds
1931         // Config.xml requires the levels arrays to be of length N and the thresholds arrays to be
1932         // of length N+1
1933         when(mResources.getIntArray(com.android.internal.R.array.config_ambientThresholdLevels))
1934                 .thenReturn(new int[]{30, 31});
1935         when(mResources.getIntArray(com.android.internal.R.array.config_screenThresholdLevels))
1936                 .thenReturn(new int[]{42, 43});
1937         when(mResources.getIntArray(
1938                 com.android.internal.R.array.config_ambientBrighteningThresholds))
1939                 .thenReturn(new int[]{270, 280, 290});
1940         when(mResources.getIntArray(com.android.internal.R.array.config_ambientDarkeningThresholds))
1941                 .thenReturn(new int[]{290, 300, 310});
1942         when(mResources.getIntArray(R.array.config_screenBrighteningThresholds))
1943                 .thenReturn(new int[]{350, 360, 370});
1944         when(mResources.getIntArray(R.array.config_screenDarkeningThresholds))
1945                 .thenReturn(new int[]{370, 380, 390});
1946 
1947         // Configs related to refresh rates and blocking zones
1948         when(mResources.getInteger(R.integer.config_defaultPeakRefreshRate))
1949                 .thenReturn(DEFAULT_PEAK_REFRESH_RATE);
1950         when(mResources.getInteger(R.integer.config_defaultRefreshRate))
1951                 .thenReturn(DEFAULT_REFRESH_RATE);
1952         when(mResources.getInteger(R.integer.config_fixedRefreshRateInHighZone))
1953                 .thenReturn(DEFAULT_HIGH_BLOCKING_ZONE_REFRESH_RATE);
1954         when(mResources.getInteger(R.integer.config_defaultRefreshRateInZone))
1955                 .thenReturn(DEFAULT_LOW_BLOCKING_ZONE_REFRESH_RATE);
1956         when(mResources.getIntArray(R.array.config_brightnessThresholdsOfPeakRefreshRate))
1957                 .thenReturn(LOW_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE);
1958         when(mResources.getIntArray(R.array.config_ambientThresholdsOfPeakRefreshRate))
1959                 .thenReturn(LOW_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE);
1960         when(mResources.getIntArray(
1961                 R.array.config_highDisplayBrightnessThresholdsOfFixedRefreshRate))
1962                 .thenReturn(HIGH_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE);
1963         when(mResources.getIntArray(
1964                 R.array.config_highAmbientBrightnessThresholdsOfFixedRefreshRate))
1965                 .thenReturn(HIGH_AMBIENT_THRESHOLD_OF_PEAK_REFRESH_RATE);
1966         when(mResources.getInteger(
1967                 R.integer.config_defaultRefreshRateInHbmHdr))
1968                 .thenReturn(DEFAULT_REFRESH_RATE_IN_HBM_HDR);
1969         when(mResources.getInteger(
1970                 R.integer.config_defaultRefreshRateInHbmSunlight))
1971                 .thenReturn(DEFAULT_REFRESH_RATE_IN_HBM_SUNLIGHT);
1972 
1973         when(mResources.getString(com.android.internal.R.string.config_displayLightSensorType))
1974                 .thenReturn("test_light_sensor");
1975         when(mResources.getBoolean(R.bool.config_automatic_brightness_available)).thenReturn(true);
1976 
1977         when(mResources.getInteger(
1978                 R.integer.config_autoBrightnessBrighteningLightDebounce))
1979                 .thenReturn(3000);
1980         when(mResources.getInteger(
1981                 R.integer.config_autoBrightnessDarkeningLightDebounce))
1982                 .thenReturn(4000);
1983 
1984         when(mResources.getInteger(
1985                 R.integer.config_screenBrightnessCapForWearBedtimeMode))
1986                 .thenReturn(35);
1987 
1988         mDisplayDeviceConfig = DisplayDeviceConfig.create(mContext, /* useConfigXml= */ true,
1989                 mFlags);
1990     }
1991 
createFloatTypedArray(float[] vals)1992     private TypedArray createFloatTypedArray(float[] vals) {
1993         TypedArray mockArray = mock(TypedArray.class);
1994         when(mockArray.length()).thenAnswer(invocation -> {
1995             return vals.length;
1996         });
1997         when(mockArray.getFloat(anyInt(), anyFloat())).thenAnswer(invocation -> {
1998             final float def = (float) invocation.getArguments()[1];
1999             if (vals == null) {
2000                 return def;
2001             }
2002             int idx = (int) invocation.getArguments()[0];
2003             if (idx >= 0 && idx < vals.length) {
2004                 return vals[idx];
2005             } else {
2006                 return def;
2007             }
2008         });
2009         return mockArray;
2010     }
2011 }
2012