blob: 6061a4037d3336de0e78a790ee5d7dd9c2a87c9c [file] [log] [blame]
Jeff Brown96307042012-07-27 15:51:34 -07001/*
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
17package com.android.server.power;
18
19import 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 */
31final class DisplayPowerRequest {
32 public static final int SCREEN_STATE_OFF = 0;
Jeff Brown26875502014-01-30 21:47:47 -080033 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 Brown96307042012-07-27 15:51:34 -070036
Jeff Brown26875502014-01-30 21:47:47 -080037 // The requested minimum screen power state: off, doze, dim or bright.
Jeff Brown96307042012-07-27 15:51:34 -070038 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 Brown330560f2012-08-21 22:10:57 -070050 // The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter).
51 public float screenAutoBrightnessAdjustment;
52
Jeff Brown96307042012-07-27 15:51:34 -070053 // If true, enables automatic brightness control.
54 public boolean useAutoBrightness;
55
Jeff Brown8b9cf1c2012-10-07 14:54:17 -070056 // 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 Brownc38c9be2012-10-04 13:16:19 -070064 public boolean blockScreenOn;
65
Jeff Brown96307042012-07-27 15:51:34 -070066 public DisplayPowerRequest() {
67 screenState = SCREEN_STATE_BRIGHT;
68 useProximitySensor = false;
69 screenBrightness = PowerManager.BRIGHTNESS_ON;
Jeff Brown330560f2012-08-21 22:10:57 -070070 screenAutoBrightnessAdjustment = 0.0f;
Jeff Brown96307042012-07-27 15:51:34 -070071 useAutoBrightness = false;
Jeff Brownc38c9be2012-10-04 13:16:19 -070072 blockScreenOn = false;
Jeff Brown96307042012-07-27 15:51:34 -070073 }
74
75 public DisplayPowerRequest(DisplayPowerRequest other) {
76 copyFrom(other);
77 }
78
Jeff Brown26875502014-01-30 21:47:47 -080079 // 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 Brown96307042012-07-27 15:51:34 -070096 public void copyFrom(DisplayPowerRequest other) {
97 screenState = other.screenState;
98 useProximitySensor = other.useProximitySensor;
99 screenBrightness = other.screenBrightness;
Jeff Brown330560f2012-08-21 22:10:57 -0700100 screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
Jeff Brown96307042012-07-27 15:51:34 -0700101 useAutoBrightness = other.useAutoBrightness;
Jeff Brownc38c9be2012-10-04 13:16:19 -0700102 blockScreenOn = other.blockScreenOn;
Jeff Brown96307042012-07-27 15:51:34 -0700103 }
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 Brown330560f2012-08-21 22:10:57 -0700116 && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
Jeff Brownc38c9be2012-10-04 13:16:19 -0700117 && useAutoBrightness == other.useAutoBrightness
118 && blockScreenOn == other.blockScreenOn;
Jeff Brown96307042012-07-27 15:51:34 -0700119 }
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 Brown330560f2012-08-21 22:10:57 -0700131 + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
Jeff Brownc38c9be2012-10-04 13:16:19 -0700132 + ", useAutoBrightness=" + useAutoBrightness
133 + ", blockScreenOn=" + blockScreenOn;
Jeff Brown96307042012-07-27 15:51:34 -0700134 }
135}