一. Android系统源码中的参数配置
MTK6771平台MTK重写了背光曲线的参数,路径在s0_vnd/vendor/mediatek/proprietary/packages/overlay/vendor/FrameworkResOverlayExt/brightness_adaptive_support/res/values/config.xml
不过MTK的其他平台可能不是在这个路径
来看 config.xml 这个文件中需要配置的两个参数:
config_autoBrightnessLevels // 环境光对应的值
config_autoBrightnessLcdBacklightValues // 显示屏对应的亮度值(范围 0-255)
这两个参数在文件 t0_sys\frameworks\base\services\core\java\com\android\server\display\BrightnessMappingStrategy.java
中被加载
@Nullableprivate static BrightnessMappingStrategy create(Resources resources,DisplayDeviceConfig displayDeviceConfig, boolean isForIdleMode,DisplayWhiteBalanceController displayWhiteBalanceController) {// Display independent, mode dependent valuesfloat[] brightnessLevelsNits;float[] luxLevels;if (isForIdleMode) {brightnessLevelsNits = getFloatArray(resources.obtainTypedArray(com.android.internal.R.array.config_autoBrightnessDisplayValuesNitsIdle)); luxLevels = getLuxLevels(resources.getIntArray(com.android.internal.R.array.config_autoBrightnessLevelsIdle)); } else {brightnessLevelsNits = getFloatArray(resources.obtainTypedArray(com.android.internal.R.array.config_autoBrightnessDisplayValuesNits));// 从资源文件中获取环境光参数luxLevels = getLuxLevels(resources.getIntArray(com.android.internal.R.array.config_autoBrightnessLevels));}// Display independent, mode independent valuesint[] brightnessLevelsBacklight = resources.getIntArray(com.android.internal.R.array.config_autoBrightnessLcdBacklightValues);float autoBrightnessAdjustmentMaxGamma = resources.getFraction(com.android.internal.R.fraction.config_autoBrightnessAdjustmentMaxGamma,1, 1);long shortTermModelTimeout = resources.getInteger(com.android.internal.R.integer.config_autoBrightnessShortTermModelTimeout);// Display dependent values - used for physical mapping strategy nits -> brightnessfinal float[] nitsRange = displayDeviceConfig.getNits();final float[] brightnessRange = displayDeviceConfig.getBrightness();// 判断是否是有效的映射if (isValidMapping(nitsRange, brightnessRange)&& isValidMapping(luxLevels, brightnessLevelsNits)) {BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder(luxLevels, brightnessLevelsNits);builder.setShortTermModelTimeoutMillis(shortTermModelTimeout);builder.setShortTermModelLowerLuxMultiplier(SHORT_TERM_MODEL_THRESHOLD_RATIO);builder.setShortTermModelUpperLuxMultiplier(SHORT_TERM_MODEL_THRESHOLD_RATIO);// 物理映射策略 映射Lux值和Nits值,而非Lux值和直接显示的背光值,物理映射return new PhysicalMappingStrategy(builder.build(), nitsRange, brightnessRange,autoBrightnessAdjustmentMaxGamma, isForIdleMode, displayWhiteBalanceController);} else if (isValidMapping(luxLevels, brightnessLevelsBacklight) && !isForIdleMode) {// 简单映射,直接映射Lux值和Backlight值return new SimpleMappingStrategy(luxLevels, brightnessLevelsBacklight,autoBrightnessAdjustmentMaxGamma, shortTermModelTimeout);} else {return null;}}
通过打印得知最终是使用简单映射的方法形成背光曲线,即通过SimpleMappingStrategy方法来将lux值跟Brightness值直接映射
接下来咋们直接配置config.xml文件中的两个参数
<integer-array name="config_autoBrightnessLevels"><item>128</item><item>256</item><item>512</item><item>1024</item><item>2048</item><item>4096</item><item>6144</item><item>8192</item><item>10240</item><item>12288</item><item>14336</item><item>18432</item><item>22528</item><item>30720</item><item>47104</item><item>79872</item><item>145408</item></integer-array><integer-array name="config_autoBrightnessLcdBacklightValues"><item>2</item><item>15</item><item>22</item><item>35</item><item>52</item><item>75</item><item>110</item><item>137</item><item>160</item><item>182</item><item>200</item><item>221</item><item>255</item><item>255</item><item>255</item><item>255</item><item>255</item><item>255</item></integer-array>
在上述参数配置中,当环境光的值是128时,那么显示屏的亮度值将调节到15
config_autoBrightnessLevels 有17个参数,config_autoBrightnessLcdBacklightValues有18个参数
获取config_autoBrightnessLevels 的数组在初始化的时候会将第一个参数设置为0,资源文件中配置17个参数即可
config_autoBrightnessLcdBacklightValues 中的数据是显示屏的亮度值,范围为0-255,也就是说按亮度百分比来算的话
1%的亮度他的亮度值是2.55
二. adb命令查看display相关信息
进入adb shell 后,使用 dumpsys display 命令查看display的相关信息。如下图所示输入dumpsys display 命令后可以查看配置好的背光曲线
三. 一些bug
- 当环境光大于20000lux时,显示屏亮度被调到1%了…
查看 t0_sys\frameworks\base\services\core\java\com\android\server\display\AutomaticBrightnessController.java
这个文件中光传感器监听到的数据
private final SensorEventListener mLightSensorListener = new SensorEventListener() {@Overridepublic void onSensorChanged(SensorEvent event) {if (mLightSensorEnabled) {final long time = mClock.uptimeMillis();final float lux = event.values[0];Slog.i("test","testlux:" + lux);handleLightSensorEvent(time, lux);}}@Overridepublic void onAccuracyChanged(Sensor sensor, int accuracy) {// Not used.}};
将光传感器监听的数据打印后发现,环境光亮度是20000lux的时候,理论上mLightSensorListener 监听中打印lux的值也应该是20000,但实际上打印的值是0,这就好理解了,环境光大于20000lux的但是光感上报的值是0lux,是0的话那么显示屏亮度就被调到1%了…
查看代码修改记录,发现光感驱动的环境光等级和值被人改了
默认是:
.als_level = {0, 50, 200, 500, 2500, 7721, 7767, 12621, 23062, 28430, 33274, 47116, 57694, 57694, 65535},.als_value = {0, 2, 200, 450, 800, 1100, 1600, 6000, 8200, 8800, 12000, 13000, 16000, 20000, 20000},
被改成:
.als_level = {0, 23, 46, 93, 186, 214, 290, 450, 621, 845, 1136, 1545, 2364, 4655, 6982}, //0-4096.als_value = {0, 2, 20, 80, 200, 320, 800, 1100, 1600, 6000, 8200, 8800, 12000, 13000, 16000},
将被修改的内容还原后这个Bug就没了…