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

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

相关文章

Python使用Tenacity一行代码实现自动重试详解

《Python使用Tenacity一行代码实现自动重试详解》tenacity是一个专为Python设计的通用重试库,它的核心理念就是用简单、清晰的方式,为任何可能失败的操作添加重试能力,下面我们就来看... 目录一切始于一个简单的 API 调用Tenacity 入门:一行代码实现优雅重试精细控制:让重试按我

SQL Server跟踪自动统计信息更新实战指南

《SQLServer跟踪自动统计信息更新实战指南》本文详解SQLServer自动统计信息更新的跟踪方法,推荐使用扩展事件实时捕获更新操作及详细信息,同时结合系统视图快速检查统计信息状态,重点强调修... 目录SQL Server 如何跟踪自动统计信息更新:深入解析与实战指南 核心跟踪方法1️⃣ 利用系统目录

Spring Security 单点登录与自动登录机制的实现原理

《SpringSecurity单点登录与自动登录机制的实现原理》本文探讨SpringSecurity实现单点登录(SSO)与自动登录机制,涵盖JWT跨系统认证、RememberMe持久化Token... 目录一、核心概念解析1.1 单点登录(SSO)1.2 自动登录(Remember Me)二、代码分析三、

MyBatis-Plus 自动赋值实体字段最佳实践指南

《MyBatis-Plus自动赋值实体字段最佳实践指南》MyBatis-Plus通过@TableField注解与填充策略,实现时间戳、用户信息、逻辑删除等字段的自动填充,减少手动赋值,提升开发效率与... 目录1. MyBATis-Plus 自动赋值概述1.1 适用场景1.2 自动填充的原理1.3 填充策略

SpringBoot+Docker+Graylog 如何让错误自动报警

《SpringBoot+Docker+Graylog如何让错误自动报警》SpringBoot默认使用SLF4J与Logback,支持多日志级别和配置方式,可输出到控制台、文件及远程服务器,集成ELK... 目录01 Spring Boot 默认日志框架解析02 Spring Boot 日志级别详解03 Sp

浏览器插件cursor实现自动注册、续杯的详细过程

《浏览器插件cursor实现自动注册、续杯的详细过程》Cursor简易注册助手脚本通过自动化邮箱填写和验证码获取流程,大大简化了Cursor的注册过程,它不仅提高了注册效率,还通过友好的用户界面和详细... 目录前言功能概述使用方法安装脚本使用流程邮箱输入页面验证码页面实战演示技术实现核心功能实现1. 随机

HTML5实现的移动端购物车自动结算功能示例代码

《HTML5实现的移动端购物车自动结算功能示例代码》本文介绍HTML5实现移动端购物车自动结算,通过WebStorage、事件监听、DOM操作等技术,确保实时更新与数据同步,优化性能及无障碍性,提升用... 目录1. 移动端购物车自动结算概述2. 数据存储与状态保存机制2.1 浏览器端的数据存储方式2.1.

基于Python开发Windows屏幕控制工具

《基于Python开发Windows屏幕控制工具》在数字化办公时代,屏幕管理已成为提升工作效率和保护眼睛健康的重要环节,本文将分享一个基于Python和PySide6开发的Windows屏幕控制工具,... 目录概述功能亮点界面展示实现步骤详解1. 环境准备2. 亮度控制模块3. 息屏功能实现4. 息屏时间

一文详解MySQL如何设置自动备份任务

《一文详解MySQL如何设置自动备份任务》设置自动备份任务可以确保你的数据库定期备份,防止数据丢失,下面我们就来详细介绍一下如何使用Bash脚本和Cron任务在Linux系统上设置MySQL数据库的自... 目录1. 编写备份脚本1.1 创建并编辑备份脚本1.2 给予脚本执行权限2. 设置 Cron 任务2

使用Python开发一个现代化屏幕取色器

《使用Python开发一个现代化屏幕取色器》在UI设计、网页开发等场景中,颜色拾取是高频需求,:本文主要介绍如何使用Python开发一个现代化屏幕取色器,有需要的小伙伴可以参考一下... 目录一、项目概述二、核心功能解析2.1 实时颜色追踪2.2 智能颜色显示三、效果展示四、实现步骤详解4.1 环境配置4.