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; |
| 33 | public static final int SCREEN_STATE_DIM = 1; |
| 34 | public static final int SCREEN_STATE_BRIGHT = 2; |
| 35 | |
| 36 | // The requested minimum screen power state: off, dim or bright. |
| 37 | public int screenState; |
| 38 | |
| 39 | // If true, the proximity sensor overrides the screen state when an object is |
| 40 | // nearby, turning it off temporarily until the object is moved away. |
| 41 | public boolean useProximitySensor; |
| 42 | |
| 43 | // The desired screen brightness in the range 0 (minimum / off) to 255 (brightest). |
| 44 | // The display power controller may choose to clamp the brightness. |
| 45 | // When auto-brightness is enabled, this field should specify a nominal default |
| 46 | // value to use while waiting for the light sensor to report enough data. |
| 47 | public int screenBrightness; |
| 48 | |
Jeff Brown | 330560f | 2012-08-21 22:10:57 -0700 | [diff] [blame] | 49 | // The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter). |
| 50 | public float screenAutoBrightnessAdjustment; |
| 51 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 52 | // If true, enables automatic brightness control. |
| 53 | public boolean useAutoBrightness; |
| 54 | |
| 55 | public DisplayPowerRequest() { |
| 56 | screenState = SCREEN_STATE_BRIGHT; |
| 57 | useProximitySensor = false; |
| 58 | screenBrightness = PowerManager.BRIGHTNESS_ON; |
Jeff Brown | 330560f | 2012-08-21 22:10:57 -0700 | [diff] [blame] | 59 | screenAutoBrightnessAdjustment = 0.0f; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 60 | useAutoBrightness = false; |
| 61 | } |
| 62 | |
| 63 | public DisplayPowerRequest(DisplayPowerRequest other) { |
| 64 | copyFrom(other); |
| 65 | } |
| 66 | |
| 67 | public void copyFrom(DisplayPowerRequest other) { |
| 68 | screenState = other.screenState; |
| 69 | useProximitySensor = other.useProximitySensor; |
| 70 | screenBrightness = other.screenBrightness; |
Jeff Brown | 330560f | 2012-08-21 22:10:57 -0700 | [diff] [blame] | 71 | screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 72 | useAutoBrightness = other.useAutoBrightness; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public boolean equals(Object o) { |
| 77 | return o instanceof DisplayPowerRequest |
| 78 | && equals((DisplayPowerRequest)o); |
| 79 | } |
| 80 | |
| 81 | public boolean equals(DisplayPowerRequest other) { |
| 82 | return other != null |
| 83 | && screenState == other.screenState |
| 84 | && useProximitySensor == other.useProximitySensor |
| 85 | && screenBrightness == other.screenBrightness |
Jeff Brown | 330560f | 2012-08-21 22:10:57 -0700 | [diff] [blame] | 86 | && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 87 | && useAutoBrightness == other.useAutoBrightness; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public int hashCode() { |
| 92 | return 0; // don't care |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public String toString() { |
| 97 | return "screenState=" + screenState |
| 98 | + ", useProximitySensor=" + useProximitySensor |
| 99 | + ", screenBrightness=" + screenBrightness |
Jeff Brown | 330560f | 2012-08-21 22:10:57 -0700 | [diff] [blame] | 100 | + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 101 | + ", useAutoBrightness=" + useAutoBrightness; |
| 102 | } |
| 103 | } |