Android(安卓)frameworks去掉熄屏前先变暗的功能
16lz
2021-01-26
设置>显示:这里可以设置自动休眠超时时间。
当设置为30s时,到24s左右屏幕会先变暗,告知用户屏幕快熄灭了,6s以后才会真正熄屏。
现在需要去掉这个功能,在PowerManagerService里可以看到:
private int getScreenDimDurationLocked(int screenOffTimeout) { return Math.min(SCREEN_DIM_DURATION, (int)(screenOffTimeout * MAXIMUM_SCREEN_DIM_RATIO)); }
也就是dim的时长,取决于SCREEN_DIM_DURATION和screenOffTimeout * MAXIMUM_SCREEN_DIM_RATIO这两个数值,哪个小就用哪个。
可以看到SCREEN_DIM_DURATION是7s:
// The screen dim duration, in milliseconds. // This is subtracted from the end of the screen off timeout so the // minimum screen off timeout should be longer than this. private static final int SCREEN_DIM_DURATION = 7 * 1000;
MAXIMUM_SCREEN_DIM_RATIO的值:
// The maximum screen dim time expressed as a ratio relative to the screen // off timeout. If the screen off timeout is very short then we want the // dim timeout to also be quite short so that most of the time is spent on. // Otherwise the user won't get much screen on time before dimming occurs. 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,这样就不再有屏幕先变暗这个步骤了。
实测可行。
更多相关文章
- Android获取屏幕或View宽度和高度的方法
- android 在电脑上显示真机屏幕
- 移动开发:Android官方提供的支持不同屏幕大小的全部方法
- [WebView学习之二]:使用Web Apps 支持不同分辨率屏
- 屏幕适配备忘录
- (4.1.2.5)Android(安卓)屏幕旋转 处理 AsyncTask 和 ProgressDialo
- Android(安卓)好用的三方选择器 时间选择/条件选择/三级联动
- android 自定义Toast,可设定显示时间
- android中实现“再按一次退出”功能