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

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

相关文章

一文详解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.

MyBatis Plus 中 update_time 字段自动填充失效的原因分析及解决方案(最新整理)

《MyBatisPlus中update_time字段自动填充失效的原因分析及解决方案(最新整理)》在使用MyBatisPlus时,通常我们会在数据库表中设置create_time和update... 目录前言一、问题现象二、原因分析三、总结:常见原因与解决方法对照表四、推荐写法前言在使用 MyBATis

Python使用smtplib库开发一个邮件自动发送工具

《Python使用smtplib库开发一个邮件自动发送工具》在现代软件开发中,自动化邮件发送是一个非常实用的功能,无论是系统通知、营销邮件、还是日常工作报告,Python的smtplib库都能帮助我们... 目录代码实现与知识点解析1. 导入必要的库2. 配置邮件服务器参数3. 创建邮件发送类4. 实现邮件

使用Python实现获取屏幕像素颜色值

《使用Python实现获取屏幕像素颜色值》这篇文章主要为大家详细介绍了如何使用Python实现获取屏幕像素颜色值,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 一、一个小工具,按住F10键,颜色值会跟着显示。完整代码import tkinter as tkimport pyau

Python使用pynput模拟实现键盘自动输入工具

《Python使用pynput模拟实现键盘自动输入工具》在日常办公和软件开发中,我们经常需要处理大量重复的文本输入工作,所以本文就来和大家介绍一款使用Python的PyQt5库结合pynput键盘控制... 目录概述:当自动化遇上可视化功能全景图核心功能矩阵技术栈深度效果展示使用教程四步操作指南核心代码解析

SpringBoot实现文件记录日志及日志文件自动归档和压缩

《SpringBoot实现文件记录日志及日志文件自动归档和压缩》Logback是Java日志框架,通过Logger收集日志并经Appender输出至控制台、文件等,SpringBoot配置logbac... 目录1、什么是Logback2、SpringBoot实现文件记录日志,日志文件自动归档和压缩2.1、

SpringCloud使用Nacos 配置中心实现配置自动刷新功能使用

《SpringCloud使用Nacos配置中心实现配置自动刷新功能使用》SpringCloud项目中使用Nacos作为配置中心可以方便开发及运维人员随时查看配置信息,及配置共享,并且Nacos支持配... 目录前言一、Nacos中集中配置方式?二、使用步骤1.使用$Value 注解2.使用@Configur

Golang实现Redis分布式锁(Lua脚本+可重入+自动续期)

《Golang实现Redis分布式锁(Lua脚本+可重入+自动续期)》本文主要介绍了Golang分布式锁实现,采用Redis+Lua脚本确保原子性,持可重入和自动续期,用于防止超卖及重复下单,具有一定... 目录1 概念应用场景分布式锁必备特性2 思路分析宕机与过期防止误删keyLua保证原子性可重入锁自动

python利用backoff实现异常自动重试详解

《python利用backoff实现异常自动重试详解》backoff是一个用于实现重试机制的Python库,通过指数退避或其他策略自动重试失败的操作,下面小编就来和大家详细讲讲如何利用backoff实... 目录1. backoff 库简介2. on_exception 装饰器的原理2.1 核心逻辑2.2