DisplayPowerRequest.java revision c38c9be031ddad5cf551b55458889f11e01dc5b2
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 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; 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 49 // The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter). 50 public float screenAutoBrightnessAdjustment; 51 52 // If true, enables automatic brightness control. 53 public boolean useAutoBrightness; 54 55 // If true, prevents the screen from turning on if it is currently off. 56 // The display does not enter a "ready" state if this flag is true and the screen 57 // is off and is being prevented from turning on. The window manager policy blocks 58 // screen on while it prepares the keyguard to prevent the user from seeing 59 // intermediate updates. 60 public boolean blockScreenOn; 61 62 public DisplayPowerRequest() { 63 screenState = SCREEN_STATE_BRIGHT; 64 useProximitySensor = false; 65 screenBrightness = PowerManager.BRIGHTNESS_ON; 66 screenAutoBrightnessAdjustment = 0.0f; 67 useAutoBrightness = false; 68 blockScreenOn = false; 69 } 70 71 public DisplayPowerRequest(DisplayPowerRequest other) { 72 copyFrom(other); 73 } 74 75 public void copyFrom(DisplayPowerRequest other) { 76 screenState = other.screenState; 77 useProximitySensor = other.useProximitySensor; 78 screenBrightness = other.screenBrightness; 79 screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment; 80 useAutoBrightness = other.useAutoBrightness; 81 blockScreenOn = other.blockScreenOn; 82 } 83 84 @Override 85 public boolean equals(Object o) { 86 return o instanceof DisplayPowerRequest 87 && equals((DisplayPowerRequest)o); 88 } 89 90 public boolean equals(DisplayPowerRequest other) { 91 return other != null 92 && screenState == other.screenState 93 && useProximitySensor == other.useProximitySensor 94 && screenBrightness == other.screenBrightness 95 && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment 96 && useAutoBrightness == other.useAutoBrightness 97 && blockScreenOn == other.blockScreenOn; 98 } 99 100 @Override 101 public int hashCode() { 102 return 0; // don't care 103 } 104 105 @Override 106 public String toString() { 107 return "screenState=" + screenState 108 + ", useProximitySensor=" + useProximitySensor 109 + ", screenBrightness=" + screenBrightness 110 + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment 111 + ", useAutoBrightness=" + useAutoBrightness 112 + ", blockScreenOn=" + blockScreenOn; 113 } 114} 115