Android frameworks去掉熄屏前先变暗的功能

设置>显示:这里可以设置自动休眠超时时间。

当设置为30s时,到24s左右屏幕会先变暗,告知用户屏幕快熄灭了,6s以后才会真正熄屏。


现在需要去掉这个功能,在PowerManagerService里可以看到:

  1. private int getScreenDimDurationLocked(int screenOffTimeout) {  
  2.     return Math.min(SCREEN_DIM_DURATION,  
  3.             (int)(screenOffTimeout * MAXIMUM_SCREEN_DIM_RATIO));  
  4. }  

也就是dim的时长,取决于SCREEN_DIM_DURATION和screenOffTimeout * MAXIMUM_SCREEN_DIM_RATIO这两个数值,哪个小就用哪个。

可以看到SCREEN_DIM_DURATION是7s:

  1. // The screen dim duration, in milliseconds.  
  2. // This is subtracted from the end of the screen off timeout so the  
  3. // minimum screen off timeout should be longer than this.  
  4. private static final int SCREEN_DIM_DURATION = 7 * 1000;  

MAXIMUM_SCREEN_DIM_RATIO的值:
  1. // The maximum screen dim time expressed as a ratio relative to the screen  
  2. // off timeout.  If the screen off timeout is very short then we want the  
  3. // dim timeout to also be quite short so that most of the time is spent on.  
  4. // Otherwise the user won't get much screen on time before dimming occurs.  
  5. private static final float MAXIMUM_SCREEN_DIM_RATIO = 0.2f;  

比率是0.2,也就是说30s的超时时间,dim的时长就是30 * 0.2 = 6s

最终getScreenDimDurationLocked()的返回值是6和7之间的最小值6s。


30S是系统里最短的超时时间,也就是说其他screenOffTimeout乘以0.2是比6要大的,所以就不用考虑了。


要想去掉DIM这个Feature,直接把SCREEN_DIM_DURATION设为0,这样getScreenDimDurationLocked()的返回值也就是0,这样就不再有屏幕先变暗这个步骤了。

实测可行。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值