@@ -130,11 +130,17 @@ public final class PowerManagerService extends IPowerManager.Stub
130130 private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15 * 1000 ;
131131 private static final int MINIMUM_SCREEN_OFF_TIMEOUT = 10 * 1000 ;
132132
133- // The screen dim duration, in seconds .
133+ // The screen dim duration, in milliseconds .
134134 // This is subtracted from the end of the screen off timeout so the
135135 // minimum screen off timeout should be longer than this.
136136 private static final int SCREEN_DIM_DURATION = 7 * 1000 ;
137137
138+ // The maximum screen dim time expressed as a ratio relative to the screen
139+ // off timeout. If the screen off timeout is very short then we want the
140+ // dim timeout to also be quite short so that most of the time is spent on.
141+ // Otherwise the user won't get much screen on time before dimming occurs.
142+ private static final float MAXIMUM_SCREEN_DIM_RATIO = 0.2f ;
143+
138144 // Upper bound on the battery charge percentage in order to consider turning
139145 // the screen on when the device starts charging wirelessly.
140146 // See point of use for more details.
@@ -1168,7 +1174,7 @@ private void updateUserActivitySummaryLocked(long now, int dirty) {
11681174 long nextTimeout = 0 ;
11691175 if (mWakefulness != WAKEFULNESS_ASLEEP ) {
11701176 final int screenOffTimeout = getScreenOffTimeoutLocked ();
1171- final int screenDimDuration = getScreenDimDurationLocked ();
1177+ final int screenDimDuration = getScreenDimDurationLocked (screenOffTimeout );
11721178
11731179 mUserActivitySummary = 0 ;
11741180 if (mLastUserActivityTime >= mLastWakeTime ) {
@@ -1242,8 +1248,9 @@ private int getScreenOffTimeoutLocked() {
12421248 return Math .max (timeout , MINIMUM_SCREEN_OFF_TIMEOUT );
12431249 }
12441250
1245- private int getScreenDimDurationLocked () {
1246- return SCREEN_DIM_DURATION ;
1251+ private int getScreenDimDurationLocked (int screenOffTimeout ) {
1252+ return Math .min (SCREEN_DIM_DURATION ,
1253+ (int )(screenOffTimeout * MAXIMUM_SCREEN_DIM_RATIO ));
12471254 }
12481255
12491256 /**
@@ -1987,6 +1994,12 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
19871994 pw .println (" mScreenBrightnessSettingMaximum=" + mScreenBrightnessSettingMaximum );
19881995 pw .println (" mScreenBrightnessSettingDefault=" + mScreenBrightnessSettingDefault );
19891996
1997+ final int screenOffTimeout = getScreenOffTimeoutLocked ();
1998+ final int screenDimDuration = getScreenDimDurationLocked (screenOffTimeout );
1999+ pw .println ();
2000+ pw .println ("Screen off timeout: " + screenOffTimeout + " ms" );
2001+ pw .println ("Screen dim duration: " + screenDimDuration + " ms" );
2002+
19902003 pw .println ();
19912004 pw .println ("Wake Locks: size=" + mWakeLocks .size ());
19922005 for (WakeLock wl : mWakeLocks ) {
0 commit comments