Android11 亮度自动调节

news/2024/11/17 4:38:42/

关键代码在frameworks/base/services/core/java/com/android/server/display

BrightnessMappingStrategy.java

AutomaticBrightnessController.java

DisplayPowerController.java

这三个

AutomaticBrightnessController.java

private void updateAutoBrightness(boolean sendUpdate, boolean isManuallySet) {if (!mAmbientLuxValid) {return;}float value = mBrightnessMapper.getBrightness(mAmbientLux, mForegroundAppPackageName,mForegroundAppCategory);float newScreenAutoBrightness = clampScreenBrightness(value);// If screenAutoBrightness is set, we should have screen{Brightening,Darkening}Threshold,// in which case we ignore the new screen brightness if it doesn't differ enough from the// previous one.if (!Float.isNaN(mScreenAutoBrightness)&& !isManuallySet&& newScreenAutoBrightness > mScreenDarkeningThreshold&& newScreenAutoBrightness < mScreenBrighteningThreshold) {if (mLoggingEnabled) {Slog.d(TAG, "ignoring newScreenAutoBrightness: "+ mScreenDarkeningThreshold + " < " + newScreenAutoBrightness+ " < " + mScreenBrighteningThreshold);}Slog.d("aaron", "ignoring newScreenAutoBrightness: "+ mScreenDarkeningThreshold + " < " + newScreenAutoBrightness+ " < " + mScreenBrighteningThreshold);return;}if (!BrightnessSynchronizer.floatEquals(mScreenAutoBrightness,newScreenAutoBrightness)) {if (mLoggingEnabled) {Slog.d(TAG, "updateAutoBrightness: "+ "mScreenAutoBrightness=" + mScreenAutoBrightness + ", "+ "newScreenAutoBrightness=" + newScreenAutoBrightness);}mScreenAutoBrightness = newScreenAutoBrightness;mScreenBrighteningThreshold = clampScreenBrightness(mScreenBrightnessThresholds.getBrighteningThreshold(newScreenAutoBrightness));mScreenDarkeningThreshold = clampScreenBrightness(mScreenBrightnessThresholds.getDarkeningThreshold(newScreenAutoBrightness));if (sendUpdate) {Log.i("aaron","AutomaticBrightnessController --- updateAutoBrightness() 772 : updateBrightness()");mCallbacks.updateBrightness();}}}

一般走这。然后反过来看哪里调用它。

    private final SensorEventListener mLightSensorListener = new SensorEventListener() {@Overridepublic void onSensorChanged(SensorEvent event) {if (mLightSensorEnabled) {final long time = SystemClock.uptimeMillis();final float lux = event.values[0];handleLightSensorEvent(time, lux);}}@Overridepublic void onAccuracyChanged(Sensor sensor, int accuracy) {// Not used.}};

这边还会监听light sensor,最后也会调用

updateAutoBrightness
mCallbacks.updateBrightness();

这个回调会调用到

DisplayPowerController的
    @Overridepublic void updateBrightness() {sendUpdatePowerState();}

最后走到

private void updatePowerState() {//省略代码}

而  BrightnessMappingStrategy是会用到一些配置 环境亮度和 屏幕亮度的 对照表类似。

@Nullablepublic static BrightnessMappingStrategy create(Resources resources) {float[] luxLevels = getLuxLevels(resources.getIntArray(com.android.internal.R.array.config_autoBrightnessLevels));int[] brightnessLevelsBacklight = resources.getIntArray(com.android.internal.R.array.config_autoBrightnessLcdBacklightValues);float[] brightnessLevelsNits = getFloatArray(resources.obtainTypedArray(com.android.internal.R.array.config_autoBrightnessDisplayValuesNits));float autoBrightnessAdjustmentMaxGamma = resources.getFraction(com.android.internal.R.fraction.config_autoBrightnessAdjustmentMaxGamma,1, 1);float[] nitsRange = getFloatArray(resources.obtainTypedArray(com.android.internal.R.array.config_screenBrightnessNits));int[] backlightRange = resources.getIntArray(com.android.internal.R.array.config_screenBrightnessBacklight);long shortTermModelTimeout = resources.getInteger(com.android.internal.R.integer.config_autoBrightnessShortTermModelTimeout);if (isValidMapping(nitsRange, backlightRange)&& isValidMapping(luxLevels, brightnessLevelsNits)) {int minimumBacklight = resources.getInteger(com.android.internal.R.integer.config_screenBrightnessSettingMinimum);int maximumBacklight = resources.getInteger(com.android.internal.R.integer.config_screenBrightnessSettingMaximum);if (backlightRange[0] > minimumBacklight|| backlightRange[backlightRange.length - 1] < maximumBacklight) {Slog.w(TAG, "Screen brightness mapping does not cover whole range of available " +"backlight values, autobrightness functionality may be impaired.");}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);return new PhysicalMappingStrategy(builder.build(), nitsRange, backlightRange,autoBrightnessAdjustmentMaxGamma);} else if (isValidMapping(luxLevels, brightnessLevelsBacklight)) {return new SimpleMappingStrategy(luxLevels, brightnessLevelsBacklight,autoBrightnessAdjustmentMaxGamma, shortTermModelTimeout);} else {return null;}}

  这边会根据配置信息 new不同的对象。配置信息在 frameworks/base/res/values/config.xml中。


http://www.ppmy.cn/news/451212.html

相关文章

Win10关闭自动调节亮度

Win10关闭自动调节亮度问题 最近自己的笔记本电脑屏幕亮度总是自动调节&#xff0c;尤其是打开比较暗的应用&#xff0c;屏幕亮度也随之变暗了&#xff0c;让人很难受。解决方法如下 方法 看了很多解决方法。大致有这几种。 简单粗暴&#xff1a;拔了电源线再插上&#xff…

Win10关闭自动调节亮度问题

Win10关闭自动调节亮度问题 笔记本总是有个亮度自动调节&#xff0c;打开较暗的页面后就会慢慢地自动变暗&#xff0c;眼睛很难受。不知道是第多少次忍不住上网查这个问题了&#xff0c;最终用下面的最后一个方法成功解决。心情瞬间舒畅&#xff01; 方法 看了很多解决方法。…

亮度调节之自动调节

参考 https://blog.csdn.net/FightFightFight/article/details/83626332 自动调节和手动调节的分叉口在DisplayPowerController中的updatePowerState()方法处&#xff0c;这里先对自动调节控制器进行配置&#xff0c;然后若处于自动调节模式&#xff0c;那brightness就从自动调…

2306d的闭包问题

原文 首先,D的闭包是个好主意.我使用了C的成员函数指针;它们在语法上很糟糕,但概念很好,而闭包更好. D的闭包有些问题,有些是明显错误,有些是不应该不在语言中的改进. 不能调用某些闭包 这很奇怪,但这是真的. 一个问题是常和不变目前没有扩展到闭包环境.要求常和不变的传递性…

Qt 每月收支计算

Qt 每月收支计算&#xff0c;针对每月有支出&#xff08;房贷、车贷、花呗、借呗&#xff09;的情况&#xff0c;计算收支明细&#xff0c;直观看到未来的个人经济情况&#xff0c;培养良好的消费习惯&#xff0c;进行理性的财富支配&#xff0c;量入为出。 #include "mai…

哈希表--day3--(leetcode349/leetcode350)

leetcode349. 两个数组的交集 链接 基本思路 注意题目特意说明&#xff1a;输出结果中的每个元素一定是唯一的&#xff0c;也就是说输出的结果的去重的&#xff0c; 同时可以不考虑输出结果的顺序 这道题用暴力的解法时间复杂度是O(n^2)&#xff0c;那来看看使用哈希法进一…

mateRS能升级鸿蒙系统吗,为什么万元机华为maters保时捷玩吃鸡真么垃圾

满意答案 plae761576 2019.04.06 采纳率&#xff1a;45% 等级&#xff1a;8 已帮助&#xff1a;1160人 现在突然发现好多自媒体都在无下限的刷三观&#xff0c;为了点阅读量&#xff0c;想尽办法给网友们出玩《绝地求生》最低配置&#xff0c;最近看到一个大V自媒体竟然说显…

华为mate20 android,华为MateRS对比华为mate20RS,终于让安卓手机坐上了头等舱!

原标题&#xff1a;华为MateRS对比华为mate20RS&#xff0c;终于让安卓手机坐上了头等舱&#xff01; 最近华为mate20RS正式开卖了&#xff0c;但是却没有现货&#xff0c;因此也出现了很多黄牛在加价售卖这款限量版的手机。今天我们来跟大家说说上一代的限量版华为MateRS跟最新…