diff options
author | Jeff Brown <jeffbrown@google.com> | 2014-04-08 17:27:14 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2014-04-08 21:34:32 -0700 |
commit | 131206b8a9d07400d7c98aea50cc45c38769448f (patch) | |
tree | e09f13d723f0829900c2ebc33d834c59997a01e6 /core/java/android/hardware | |
parent | 91c8f753ab841342a904fa3efa81f4c6edf2b72a (diff) | |
download | frameworks_base-131206b8a9d07400d7c98aea50cc45c38769448f.zip frameworks_base-131206b8a9d07400d7c98aea50cc45c38769448f.tar.gz frameworks_base-131206b8a9d07400d7c98aea50cc45c38769448f.tar.bz2 |
Move display power controller to display manager service.
This refactoring is in preparation for enabling the display manager
to have more control over the blanking state of individual displays.
There are no functional changes. Some bits will be cleaned up in
a subsequent patch.
Bug: 13133142
Change-Id: I159a060088344d8e6fcdf9208a1f242960f7ab90
Diffstat (limited to 'core/java/android/hardware')
-rw-r--r-- | core/java/android/hardware/display/DisplayManagerInternal.java | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/core/java/android/hardware/display/DisplayManagerInternal.java b/core/java/android/hardware/display/DisplayManagerInternal.java index 8430973..03fa1d5 100644 --- a/core/java/android/hardware/display/DisplayManagerInternal.java +++ b/core/java/android/hardware/display/DisplayManagerInternal.java @@ -16,6 +16,9 @@ package android.hardware.display; +import android.hardware.SensorManager; +import android.os.Handler; +import android.os.PowerManager; import android.view.DisplayInfo; /** @@ -25,6 +28,36 @@ import android.view.DisplayInfo; */ public abstract class DisplayManagerInternal { /** + * Called by the power manager to initialize power management facilities. + */ + public abstract void initPowerManagement(DisplayPowerCallbacks callbacks, + Handler handler, SensorManager sensorManager); + + /** + * Called by the power manager to request a new power state. + * <p> + * The display power controller makes a copy of the provided object and then + * begins adjusting the power state to match what was requested. + * </p> + * + * @param request The requested power state. + * @param waitForNegativeProximity If true, issues a request to wait for + * negative proximity before turning the screen back on, assuming the screen + * was turned off by the proximity sensor. + * @return True if display is ready, false if there are important changes that must + * be made asynchronously (such as turning the screen on), in which case the caller + * should grab a wake lock, watch for {@link DisplayPowerCallbacks#onStateChanged()} + * then try the request again later until the state converges. + */ + public abstract boolean requestPowerState(DisplayPowerRequest request, + boolean waitForNegativeProximity); + + /** + * Returns true if the proximity sensor screen-off function is available. + */ + public abstract boolean isProximitySensorAvailable(); + + /** * Called by the power manager to blank all displays. */ public abstract void blankAllDisplaysFromPowerManager(); @@ -99,6 +132,137 @@ public abstract class DisplayManagerInternal { boolean inTraversal); /** + * Describes the requested power state of the display. + * + * This object is intended to describe the general characteristics of the + * power state, such as whether the screen should be on or off and the current + * brightness controls leaving the DisplayPowerController to manage the + * details of how the transitions between states should occur. The goal is for + * the PowerManagerService to focus on the global power state and not + * have to micro-manage screen off animations, auto-brightness and other effects. + */ + public static final class DisplayPowerRequest { + public static final int SCREEN_STATE_OFF = 0; + public static final int SCREEN_STATE_DOZE = 1; + public static final int SCREEN_STATE_DIM = 2; + public static final int SCREEN_STATE_BRIGHT = 3; + + // The requested minimum screen power state: off, doze, dim or bright. + public int screenState; + + // If true, the proximity sensor overrides the screen state when an object is + // nearby, turning it off temporarily until the object is moved away. + public boolean useProximitySensor; + + // The desired screen brightness in the range 0 (minimum / off) to 255 (brightest). + // The display power controller may choose to clamp the brightness. + // When auto-brightness is enabled, this field should specify a nominal default + // value to use while waiting for the light sensor to report enough data. + public int screenBrightness; + + // The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter). + public float screenAutoBrightnessAdjustment; + + // If true, enables automatic brightness control. + public boolean useAutoBrightness; + + // If true, prevents the screen from completely turning on if it is currently off. + // The display does not enter a "ready" state if this flag is true and screen on is + // blocked. The window manager policy blocks screen on while it prepares the keyguard to + // prevent the user from seeing intermediate updates. + // + // Technically, we may not block the screen itself from turning on (because that introduces + // extra unnecessary latency) but we do prevent content on screen from becoming + // visible to the user. + public boolean blockScreenOn; + + public DisplayPowerRequest() { + screenState = SCREEN_STATE_BRIGHT; + useProximitySensor = false; + screenBrightness = PowerManager.BRIGHTNESS_ON; + screenAutoBrightnessAdjustment = 0.0f; + useAutoBrightness = false; + blockScreenOn = false; + } + + public DisplayPowerRequest(DisplayPowerRequest other) { + copyFrom(other); + } + + // Returns true if we want the screen on in any mode, including doze. + public boolean wantScreenOnAny() { + return screenState != SCREEN_STATE_OFF; + } + + // Returns true if we want the screen on in a normal mode, excluding doze. + // This is usually what we want to tell the rest of the system. For compatibility + // reasons, we pretend the screen is off when dozing. + public boolean wantScreenOnNormal() { + return screenState == SCREEN_STATE_DIM || screenState == SCREEN_STATE_BRIGHT; + } + + public boolean wantLightSensorEnabled() { + // Specifically, we don't want the light sensor while dozing. + return useAutoBrightness && wantScreenOnNormal(); + } + + public void copyFrom(DisplayPowerRequest other) { + screenState = other.screenState; + useProximitySensor = other.useProximitySensor; + screenBrightness = other.screenBrightness; + screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment; + useAutoBrightness = other.useAutoBrightness; + blockScreenOn = other.blockScreenOn; + } + + @Override + public boolean equals(Object o) { + return o instanceof DisplayPowerRequest + && equals((DisplayPowerRequest)o); + } + + public boolean equals(DisplayPowerRequest other) { + return other != null + && screenState == other.screenState + && useProximitySensor == other.useProximitySensor + && screenBrightness == other.screenBrightness + && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment + && useAutoBrightness == other.useAutoBrightness + && blockScreenOn == other.blockScreenOn; + } + + @Override + public int hashCode() { + return 0; // don't care + } + + @Override + public String toString() { + return "screenState=" + screenState + + ", useProximitySensor=" + useProximitySensor + + ", screenBrightness=" + screenBrightness + + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment + + ", useAutoBrightness=" + useAutoBrightness + + ", blockScreenOn=" + blockScreenOn; + } + } + + /** + * Asynchronous callbacks from the power controller to the power manager service. + */ + public interface DisplayPowerCallbacks { + void onStateChanged(); + void onProximityPositive(); + void onProximityNegative(); + + void acquireSuspendBlocker(); + void releaseSuspendBlocker(); + + void blankAllDisplays(); + void unblankAllDisplays(); + } + + /** * Called within a Surface transaction whenever the size or orientation of a * display may have changed. Provides an opportunity for the client to * update the position of its surfaces as part of the same transaction. |