Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.power; |
| 18 | |
| 19 | import android.os.PowerManager; |
| 20 | |
| 21 | /** |
| 22 | * Describes the requested power state of the display. |
| 23 | * |
| 24 | * This object is intended to describe the general characteristics of the |
| 25 | * power state, such as whether the screen should be on or off and the current |
| 26 | * brightness controls leaving the {@link DisplayPowerController} to manage the |
| 27 | * details of how the transitions between states should occur. The goal is for |
| 28 | * the {@link PowerManagerService} to focus on the global power state and not |
| 29 | * have to micro-manage screen off animations, auto-brightness and other effects. |
| 30 | */ |
| 31 | final class DisplayPowerRequest { |
| 32 | public static final int SCREEN_STATE_OFF = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 33 | public static final int SCREEN_STATE_DOZE = 1; |
| 34 | public static final int SCREEN_STATE_DIM = 2; |
| 35 | public static final int SCREEN_STATE_BRIGHT = 3; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 36 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 37 | // The requested minimum screen power state: off, doze, dim or bright. |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 38 | public int screenState; |
| 39 | |
| 40 | // If true, the proximity sensor overrides the screen state when an object is |
| 41 | // nearby, turning it off temporarily until the object is moved away. |
| 42 | public boolean useProximitySensor; |
| 43 | |
| 44 | // The desired screen brightness in the range 0 (minimum / off) to 255 (brightest). |
| 45 | // The display power controller may choose to clamp the brightness. |
| 46 | // When auto-brightness is enabled, this field should specify a nominal default |
| 47 | // value to use while waiting for the light sensor to report enough data. |
| 48 | public int screenBrightness; |
| 49 | |
Jeff Brown | 330560f | 2012-08-21 22:10:57 -0700 | [diff] [blame] | 50 | // The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter). |
| 51 | public float screenAutoBrightnessAdjustment; |
| 52 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 53 | // If true, enables automatic brightness control. |
| 54 | public boolean useAutoBrightness; |
| 55 | |
Jeff Brown | 8b9cf1c | 2012-10-07 14:54:17 -0700 | [diff] [blame] | 56 | // If true, prevents the screen from completely turning on if it is currently off. |
| 57 | // The display does not enter a "ready" state if this flag is true and screen on is |
| 58 | // blocked. The window manager policy blocks screen on while it prepares the keyguard to |
| 59 | // prevent the user from seeing intermediate updates. |
| 60 | // |
| 61 | // Technically, we may not block the screen itself from turning on (because that introduces |
| 62 | // extra unnecessary latency) but we do prevent content on screen from becoming |
| 63 | // visible to the user. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 64 | public boolean blockScreenOn; |
| 65 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 66 | public DisplayPowerRequest() { |
| 67 | screenState = SCREEN_STATE_BRIGHT; |
| 68 | useProximitySensor = false; |
| 69 | screenBrightness = PowerManager.BRIGHTNESS_ON; |
Jeff Brown | 330560f | 2012-08-21 22:10:57 -0700 | [diff] [blame] | 70 | screenAutoBrightnessAdjustment = 0.0f; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 71 | useAutoBrightness = false; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 72 | blockScreenOn = false; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | public DisplayPowerRequest(DisplayPowerRequest other) { |
| 76 | copyFrom(other); |
| 77 | } |
| 78 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 79 | // Returns true if we want the screen on in any mode, including doze. |
| 80 | public boolean wantScreenOnAny() { |
| 81 | return screenState != SCREEN_STATE_OFF; |
| 82 | } |
| 83 | |
| 84 | // Returns true if we want the screen on in a normal mode, excluding doze. |
| 85 | // This is usually what we want to tell the rest of the system. For compatibility |
| 86 | // reasons, we pretend the screen is off when dozing. |
| 87 | public boolean wantScreenOnNormal() { |
| 88 | return screenState == SCREEN_STATE_DIM || screenState == SCREEN_STATE_BRIGHT; |
| 89 | } |
| 90 | |
| 91 | public boolean wantLightSensorEnabled() { |
| 92 | // Specifically, we don't want the light sensor while dozing. |
| 93 | return useAutoBrightness && wantScreenOnNormal(); |
| 94 | } |
| 95 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 96 | public void copyFrom(DisplayPowerRequest other) { |
| 97 | screenState = other.screenState; |
| 98 | useProximitySensor = other.useProximitySensor; |
| 99 | screenBrightness = other.screenBrightness; |
Jeff Brown | 330560f | 2012-08-21 22:10:57 -0700 | [diff] [blame] | 100 | screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 101 | useAutoBrightness = other.useAutoBrightness; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 102 | blockScreenOn = other.blockScreenOn; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public boolean equals(Object o) { |
| 107 | return o instanceof DisplayPowerRequest |
| 108 | && equals((DisplayPowerRequest)o); |
| 109 | } |
| 110 | |
| 111 | public boolean equals(DisplayPowerRequest other) { |
| 112 | return other != null |
| 113 | && screenState == other.screenState |
| 114 | && useProximitySensor == other.useProximitySensor |
| 115 | && screenBrightness == other.screenBrightness |
Jeff Brown | 330560f | 2012-08-21 22:10:57 -0700 | [diff] [blame] | 116 | && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 117 | && useAutoBrightness == other.useAutoBrightness |
| 118 | && blockScreenOn == other.blockScreenOn; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public int hashCode() { |
| 123 | return 0; // don't care |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public String toString() { |
| 128 | return "screenState=" + screenState |
| 129 | + ", useProximitySensor=" + useProximitySensor |
| 130 | + ", screenBrightness=" + screenBrightness |
Jeff Brown | 330560f | 2012-08-21 22:10:57 -0700 | [diff] [blame] | 131 | + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 132 | + ", useAutoBrightness=" + useAutoBrightness |
| 133 | + ", blockScreenOn=" + blockScreenOn; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 134 | } |
| 135 | } |