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

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

当设置为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)