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

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

相关文章

Apache服务器IP自动跳转域名的问题及解决方案

《Apache服务器IP自动跳转域名的问题及解决方案》本教程将详细介绍如何通过Apache虚拟主机配置实现这一功能,并解决常见问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,... 目录​​问题背景​​解决方案​​方法 1:修改 httpd-vhosts.conf(推荐)​​步骤

idea-java序列化serialversionUID自动生成方式

《idea-java序列化serialversionUID自动生成方式》Java的Serializable接口用于实现对象的序列化和反序列化,通过将对象转换为字节流来存储或传输,实现Serializa... 目录简介实现序列化serialVersionUID配置使用总结简介Java.io.Seripyth

Linux下屏幕亮度的调节方式

《Linux下屏幕亮度的调节方式》文章介绍了Linux下屏幕亮度调节的几种方法,包括图形界面、手动调节(使用ACPI内核模块)和外接显示屏调节,以及自动调节软件(CaliseRedshift和Reds... 目录1 概述2 手动调节http://www.chinasem.cn2.1 手动屏幕调节2.2 外接显

idea突然报错Malformed \uxxxx encoding问题及解决

《idea突然报错Malformeduxxxxencoding问题及解决》Maven项目在切换Git分支时报错,提示project元素为描述符根元素,解决方法:删除Maven仓库中的resolv... 目www.chinasem.cn录问题解决方式总结问题idea 上的 maven China编程项目突然报错,是

JAVA实现Token自动续期机制的示例代码

《JAVA实现Token自动续期机制的示例代码》本文主要介绍了JAVA实现Token自动续期机制的示例代码,通过动态调整会话生命周期平衡安全性与用户体验,解决固定有效期Token带来的风险与不便,感兴... 目录1. 固定有效期Token的内在局限性2. 自动续期机制:兼顾安全与体验的解决方案3. 总结PS

Python屏幕抓取和录制的详细代码示例

《Python屏幕抓取和录制的详细代码示例》随着现代计算机性能的提高和网络速度的加快,越来越多的用户需要对他们的屏幕进行录制,:本文主要介绍Python屏幕抓取和录制的相关资料,需要的朋友可以参考... 目录一、常用 python 屏幕抓取库二、pyautogui 截屏示例三、mss 高性能截图四、Pill

linux部署NFS和autofs自动挂载实现过程

《linux部署NFS和autofs自动挂载实现过程》文章介绍了NFS(网络文件系统)和Autofs的原理与配置,NFS通过RPC实现跨系统文件共享,需配置/etc/exports和nfs.conf,... 目录(一)NFS1. 什么是NFS2.NFS守护进程3.RPC服务4. 原理5. 部署5.1安装NF

MyBatis Plus实现时间字段自动填充的完整方案

《MyBatisPlus实现时间字段自动填充的完整方案》在日常开发中,我们经常需要记录数据的创建时间和更新时间,传统的做法是在每次插入或更新操作时手动设置这些时间字段,这种方式不仅繁琐,还容易遗漏,... 目录前言解决目标技术栈实现步骤1. 实体类注解配置2. 创建元数据处理器3. 服务层代码优化填充机制详

深入浅出Spring中的@Autowired自动注入的工作原理及实践应用

《深入浅出Spring中的@Autowired自动注入的工作原理及实践应用》在Spring框架的学习旅程中,@Autowired无疑是一个高频出现却又让初学者头疼的注解,它看似简单,却蕴含着Sprin... 目录深入浅出Spring中的@Autowired:自动注入的奥秘什么是依赖注入?@Autowired

基于Redis自动过期的流处理暂停机制

《基于Redis自动过期的流处理暂停机制》基于Redis自动过期的流处理暂停机制是一种高效、可靠且易于实现的解决方案,防止延时过大的数据影响实时处理自动恢复处理,以避免积压的数据影响实时性,下面就来详... 目录核心思路代码实现1. 初始化Redis连接和键前缀2. 接收数据时检查暂停状态3. 检测到延时过