OSDN Git Service

Improve the screen dim duration calculation.
authorJeff Brown <jeffbrown@google.com>
Wed, 3 Oct 2012 04:18:04 +0000 (21:18 -0700)
committerJeff Brown <jeffbrown@google.com>
Wed, 3 Oct 2012 04:18:04 +0000 (21:18 -0700)
Take into account whether the screen off timeout is very short.
If so, we use a shorter dim timeout.  Don't allow the dim
time to be more than 20% of the total screen on time so that
the screen remains bright at least 80% of the time even when
the timeout is short.

Bug: 7273646
Change-Id: Iccea764b90f0d8b1df7009d26160c6bcf6eabe5b

services/java/com/android/server/power/PowerManagerService.java

index 2ddda6c..d1c24eb 100644 (file)
@@ -130,11 +130,17 @@ public final class PowerManagerService extends IPowerManager.Stub
     private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15 * 1000;
     private static final int MINIMUM_SCREEN_OFF_TIMEOUT = 10 * 1000;
 
-    // The screen dim duration, in seconds.
+    // 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;
 
+    // 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;
+
     // Upper bound on the battery charge percentage in order to consider turning
     // the screen on when the device starts charging wirelessly.
     // See point of use for more details.
@@ -1168,7 +1174,7 @@ public final class PowerManagerService extends IPowerManager.Stub
             long nextTimeout = 0;
             if (mWakefulness != WAKEFULNESS_ASLEEP) {
                 final int screenOffTimeout = getScreenOffTimeoutLocked();
-                final int screenDimDuration = getScreenDimDurationLocked();
+                final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout);
 
                 mUserActivitySummary = 0;
                 if (mLastUserActivityTime >= mLastWakeTime) {
@@ -1242,8 +1248,9 @@ public final class PowerManagerService extends IPowerManager.Stub
         return Math.max(timeout, MINIMUM_SCREEN_OFF_TIMEOUT);
     }
 
-    private int getScreenDimDurationLocked() {
-        return SCREEN_DIM_DURATION;
+    private int getScreenDimDurationLocked(int screenOffTimeout) {
+        return Math.min(SCREEN_DIM_DURATION,
+                (int)(screenOffTimeout * MAXIMUM_SCREEN_DIM_RATIO));
     }
 
     /**
@@ -1987,6 +1994,12 @@ public final class PowerManagerService extends IPowerManager.Stub
             pw.println("  mScreenBrightnessSettingMaximum=" + mScreenBrightnessSettingMaximum);
             pw.println("  mScreenBrightnessSettingDefault=" + mScreenBrightnessSettingDefault);
 
+            final int screenOffTimeout = getScreenOffTimeoutLocked();
+            final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout);
+            pw.println();
+            pw.println("Screen off timeout: " + screenOffTimeout + " ms");
+            pw.println("Screen dim duration: " + screenDimDuration + " ms");
+
             pw.println();
             pw.println("Wake Locks: size=" + mWakeLocks.size());
             for (WakeLock wl : mWakeLocks) {