安卓屏幕自动息屏时亮度突然变亮

2024-01-17 23:36

本文主要是介绍安卓屏幕自动息屏时亮度突然变亮,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

自然息屏流程

USER_ACTIVITY_SCREEN_BRIGHT(亮屏) → USER_ACTIVITY_SCREEN_DIM(DIM) → USER_ACTIVITY_SCREEN_DREAM(灭屏)变化,最终进入ASLEEP后。在息屏时会执行一个变暗的动画

frameworks\base\services\core\java\com\android\server\display\DisplayPowerController.java

变暗的动画,执行动画代码中 会获取屏幕亮度,并且把亮度值进行转换:

private void animateScreenBrightness(float target, float sdrTarget, float rate) {
if (DEBUG) {
Slog.d(TAG, “Animating brightness: target=” + target + “, sdrTarget=” + sdrTarget
+ “, rate=” + rate);
}
if (mScreenBrightnessRampAnimator.animateTo(target, sdrTarget, rate)) {
Trace.traceCounter(Trace.TRACE_TAG_POWER, “TargetScreenBrightness”, (int) target);
// TODO(b/153319140) remove when we can get this from the above trace invocation
SystemProperties.set(“debug.tracing.screen_brightness”, String.valueOf(target));
noteScreenBrightness(target);
}
}

其中mScreenBrightnessRampAnimator.animateTo(target, sdrTarget, rate)在

frameworks\base\services\core\java\com\android\server\display\RampAnimator.java

public boolean animateTo(float targetLinear, float rate) {
// Convert the target from the linear into the HLG space.
final float target = BrightnessUtils.convertLinearToGamma(targetLinear);

    // Immediately jump to the target the first time.if (mFirstTime || rate <= 0) {if (mFirstTime || target != mCurrentValue) {mFirstTime = false;mRate = 0;mTargetValue = target;mCurrentValue = target;setPropertyValue(target);if (mAnimating) {mAnimating = false;cancelAnimationCallback();}if (mListener != null) {mListener.onAnimationEnd();}return true;}return false;}// Adjust the rate based on the closest target.// If a faster rate is specified, then use the new rate so that we converge// more rapidly based on the new request.// If a slower rate is specified, then use the new rate only if the current// value is somewhere in between the new and the old target meaning that// we will be ramping in a different direction to get there.// Otherwise, continue at the previous rate.if (!mAnimating|| rate > mRate|| (target <= mCurrentValue && mCurrentValue <= mTargetValue)|| (mTargetValue <= mCurrentValue && mCurrentValue <= target)) {mRate = rate;}final boolean changed = (mTargetValue != target);mTargetValue = target;// Start animating.if (!mAnimating && target != mCurrentValue) {mAnimating = true;mAnimatedValue = mCurrentValue;mLastFrameTimeNanos = System.nanoTime();postAnimationCallback();}return changed;
}

其中setPropertyValue是设置亮度值

private void setPropertyValue(float val) {
final float linearVal = BrightnessUtils.convertGammaToLinear(val);
mProperty.setValue(mObject, linearVal);
}

再看2.中的

postAnimationCallback();
private void postAnimationCallback() {
mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, mAnimationCallback, null);
}

private final Runnable mAnimationCallback = new Runnable() {
@Override // Choreographer callback
public void run() {
final long frameTimeNanos = mChoreographer.getFrameTimeNanos();
final float timeDelta = (frameTimeNanos - mLastFrameTimeNanos)
* 0.000000001f;
mLastFrameTimeNanos = frameTimeNanos;

        // Advance the animated value towards the target at the specified rate// and clamp to the target. This gives us the new current value but// we keep the animated value around to allow for fractional increments// towards the target.final float scale = ValueAnimator.getDurationScale();if (scale == 0) {// Animation off.mAnimatedValue = mTargetValue;} else {final float amount = timeDelta * mRate / scale;if (mTargetValue > mCurrentValue) {mAnimatedValue = Math.min(mAnimatedValue + amount, mTargetValue);} else {mAnimatedValue = Math.max(mAnimatedValue - amount, mTargetValue);}}final float oldCurrentValue = mCurrentValue;mCurrentValue = mAnimatedValue;if (!BrightnessSynchronizer.floatEquals(oldCurrentValue, mCurrentValue)) {setPropertyValue(mCurrentValue);}if (!BrightnessSynchronizer.floatEquals(mTargetValue, mCurrentValue)) {postAnimationCallback();} else {mAnimating = false;if (mListener != null) {mListener.onAnimationEnd();}}}
};

其中修改亮度调用的却是

if (!BrightnessSynchronizer.floatEquals(oldCurrentValue, mCurrentValue)) {
mProperty.setValue(mObject, mCurrentValue);
}
将此处改变亮度的api改成3.的设置亮度

if (!BrightnessSynchronizer.floatEquals(oldCurrentValue, mCurrentValue)) {
setPropertyValue(mCurrentValue);
}
其他项目此处是有谷歌提交记录 这个项目没完全改掉

在这里插入图片描述

在这里插入图片描述

这篇关于安卓屏幕自动息屏时亮度突然变亮的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/617524

相关文章

Go Mongox轻松实现MongoDB的时间字段自动填充

《GoMongox轻松实现MongoDB的时间字段自动填充》这篇文章主要为大家详细介绍了Go语言如何使用mongox库,在插入和更新数据时自动填充时间字段,从而提升开发效率并减少重复代码,需要的可以... 目录前言时间字段填充规则Mongox 的安装使用 Mongox 进行插入操作使用 Mongox 进行更

C语言中自动与强制转换全解析

《C语言中自动与强制转换全解析》在编写C程序时,类型转换是确保数据正确性和一致性的关键环节,无论是隐式转换还是显式转换,都各有特点和应用场景,本文将详细探讨C语言中的类型转换机制,帮助您更好地理解并在... 目录类型转换的重要性自动类型转换(隐式转换)强制类型转换(显式转换)常见错误与注意事项总结与建议类型

Python利用自带模块实现屏幕像素高效操作

《Python利用自带模块实现屏幕像素高效操作》这篇文章主要为大家详细介绍了Python如何利用自带模块实现屏幕像素高效操作,文中的示例代码讲解详,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1、获取屏幕放缩比例2、获取屏幕指定坐标处像素颜色3、一个简单的使用案例4、总结1、获取屏幕放缩比例from

IDEA如何让控制台自动换行

《IDEA如何让控制台自动换行》本文介绍了如何在IDEA中设置控制台自动换行,具体步骤为:File-Settings-Editor-General-Console,然后勾选Usesoftwrapsin... 目录IDEA如何让控制台自http://www.chinasem.cn动换行操作流http://www

vscode保存代码时自动eslint格式化图文教程

《vscode保存代码时自动eslint格式化图文教程》:本文主要介绍vscode保存代码时自动eslint格式化的相关资料,包括打开设置文件并复制特定内容,文中通过代码介绍的非常详细,需要的朋友... 目录1、点击设置2、选择远程--->点击右上角打开设置3、会弹出settings.json文件,将以下内

Python脚本实现自动删除C盘临时文件夹

《Python脚本实现自动删除C盘临时文件夹》在日常使用电脑的过程中,临时文件夹往往会积累大量的无用数据,占用宝贵的磁盘空间,下面我们就来看看Python如何通过脚本实现自动删除C盘临时文件夹吧... 目录一、准备工作二、python脚本编写三、脚本解析四、运行脚本五、案例演示六、注意事项七、总结在日常使用

SpringBoot项目启动后自动加载系统配置的多种实现方式

《SpringBoot项目启动后自动加载系统配置的多种实现方式》:本文主要介绍SpringBoot项目启动后自动加载系统配置的多种实现方式,并通过代码示例讲解的非常详细,对大家的学习或工作有一定的... 目录1. 使用 CommandLineRunner实现方式:2. 使用 ApplicationRunne

Springboot的ThreadPoolTaskScheduler线程池轻松搞定15分钟不操作自动取消订单

《Springboot的ThreadPoolTaskScheduler线程池轻松搞定15分钟不操作自动取消订单》:本文主要介绍Springboot的ThreadPoolTaskScheduler线... 目录ThreadPoolTaskScheduler线程池实现15分钟不操作自动取消订单概要1,创建订单后

python实现自动登录12306自动抢票功能

《python实现自动登录12306自动抢票功能》随着互联网技术的发展,越来越多的人选择通过网络平台购票,特别是在中国,12306作为官方火车票预订平台,承担了巨大的访问量,对于热门线路或者节假日出行... 目录一、遇到的问题?二、改进三、进阶–展望总结一、遇到的问题?1.url-正确的表头:就是首先ur

Spring使用@Retryable实现自动重试机制

《Spring使用@Retryable实现自动重试机制》在微服务架构中,服务之间的调用可能会因为一些暂时性的错误而失败,例如网络波动、数据库连接超时或第三方服务不可用等,在本文中,我们将介绍如何在Sp... 目录引言1. 什么是 @Retryable?2. 如何在 Spring 中使用 @Retryable